2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
5 ANSI C function snprintf().
8 /*****************************************************************************
22 C99 says:The snprintf function is equivalent to fprintf, except that the output is
23 written into an array (specified by argument s) rather than to a stream. If
24 n is zero, nothing is written, and s may be a null pointer. Otherwise,
25 output characters beyond the n-1st are discarded rather than being written
26 to the array, and a null character is written at the end of the characters
27 actually written into the array. If copying takes place between objects
28 that overlap, the behavior is undefined.
31 str - The formatted string is written into this variable. You
32 must make sure that it is large enough to contain the
34 n - At most n characters are written into the string. This
36 format - Format string as described above
37 ... - Arguments for the format string
40 The snprintf function returns the number of characters that would have been
41 written had n been sufficiently large, not counting the terminating null
42 character, or a negative value if an encoding error occurred. Thus, the
43 null-terminated output has been completely written if and only if the
44 returned value is nonnegative and less than n.
53 fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
58 ******************************************************************************/
63 va_start (args
, format
);
65 retval
= vsnprintf (str
, n
, format
, args
);
75 int main (int argc
, char ** argv
)
80 printf ("snprintf test\n");
82 rc
= snprintf (buffer
, sizeof (buffer
), "%10d", 5);
84 if (rc
< sizeof (buffer
))
85 printf ("rc=%d, buffer=\"%s\"\n", rc
, buffer
);
87 printf ("rc=%d\n", rc
);
89 rc
= snprintf (buffer
, sizeof (buffer
), "%11d", 5);
91 if (rc
< sizeof (buffer
))
92 printf ("rc=%d, buffer=\"%s\"\n", rc
, buffer
);
94 printf ("rc=%d\n", rc
);