2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
5 C99 function snprintf().
9 #include <aros/debug.h>
11 /*****************************************************************************
25 C99 says:The snprintf function is equivalent to fprintf, except that the output is
26 written into an array (specified by argument s) rather than to a stream. If
27 n is zero, nothing is written, and s may be a null pointer. Otherwise,
28 output characters beyond the n-1st are discarded rather than being written
29 to the array, and a null character is written at the end of the characters
30 actually written into the array. If copying takes place between objects
31 that overlap, the behavior is undefined.
34 str - The formatted string is written into this variable. You
35 must make sure that it is large enough to contain the
37 n - At most n characters are written into the string. This
39 format - Format string as described above
40 ... - Arguments for the format string
43 The snprintf function returns the number of characters that would have been
44 written had n been sufficiently large, not counting the terminating null
45 character, or a negative value if an encoding error occurred. Thus, the
46 null-terminated output has been completely written if and only if the
47 returned value is nonnegative and less than n.
56 fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
61 ******************************************************************************/
66 D(bug("[snprintf] start; str %p('%s'), format: %p('%s')\n",
67 str
, str
, format
, format
70 va_start (args
, format
);
72 retval
= vsnprintf (str
, n
, format
, args
);
76 D(bug("[snprintf] end; str %p('%s'), format: %p('%s')\n",
77 str
, str
, format
, format
86 int main (int argc
, char ** argv
)
91 printf ("snprintf test\n");
93 rc
= snprintf (buffer
, sizeof (buffer
), "%10d", 5);
95 if (rc
< sizeof (buffer
))
96 printf ("rc=%d, buffer=\"%s\"\n", rc
, buffer
);
98 printf ("rc=%d\n", rc
);
100 rc
= snprintf (buffer
, sizeof (buffer
), "%11d", 5);
102 if (rc
< sizeof (buffer
))
103 printf ("rc=%d, buffer=\"%s\"\n", rc
, buffer
);
105 printf ("rc=%d\n", rc
);