'\" 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 .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)