Debian Codegraph @

upstream/debian-unstable/man3/sprintf.3

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