aboutsummaryrefslogtreecommitdiffstats
path: root/man/man3/sprintf.3
blob: b87eafa63e56e04006501daba0b91fcf3228ec49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'\" t
.\" Copyright, the authors of the Linux man-pages project
.\"
.\" SPDX-License-Identifier: GPL-2.0-or-later
.\"
.TH sprintf 3 (date) "Linux man-pages (unreleased)"
.SH NAME
sprintf,
vsprintf
\-
string print formatted
.SH LIBRARY
Standard C library
.RI ( libc ,\~ \-lc )
.SH SYNOPSIS
.nf
.B #include <stdio.h>
.P
.BI "int sprintf(char *restrict " str ,
.BI "            const char *restrict " format ", ...);"
.BI "int vsprintf(char *restrict " str ,
.BI "            const char *restrict " format ", va_list " ap );
.fi
.P
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.P
.BR snprintf (),
.BR vsnprintf ():
.nf
    _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE
        || /* glibc <= 2.19: */ _BSD_SOURCE
.fi
.SH DESCRIPTION
These functions are equivalent to
.BR snprintf (3)
and
.BR vsnprintf (3),
except that no check for buffer overrun is performed
(see BUGS below).
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.TS
allbox;
lbx lb lb
l l l.
Interface	Attribute	Value
T{
.na
.nh
.BR sprintf (),
.BR vsprintf ()
T}	Thread safety	MT-Safe locale
.TE
.SH STANDARDS
C11, POSIX.1-2008.
.SH HISTORY
C89, POSIX.1-2001.
.SH BUGS
See
.BR printf (3).
.SS sprintf(), vsprintf()
Because
.BR sprintf ()
and
.BR vsprintf ()
assume an arbitrarily long string,
callers must be careful not to overflow the actual space;
this is often impossible to assure.
Note that the length of the strings produced is locale-dependent
and difficult to predict.
Use
.BR snprintf ()
and
.BR vsnprintf ()
instead (or
.BR asprintf (3)
and
.BR vasprintf (3)).
.\" .P
.\" Linux libc4.[45] does not have a
.\" .BR snprintf (),
.\" but provides a libbsd that contains an
.\" .BR snprintf ()
.\" equivalent to
.\" .BR sprintf (),
.\" that is, one that ignores the
.\" .I size
.\" argument.
.\" Thus, the use of
.\" .BR snprintf ()
.\" with early libc4 leads to serious security problems.
.\" .P
.\" Some floating-point conversions under early libc4
.\" caused memory leaks.
.SH SEE ALSO
.BR asprintf (3),
.BR snprintf (3)