Enabled some keys which need the alt qualifier (brackets, back slash etc.)
[AROS.git] / compiler / stdc / snprintf.c
blob58f619fe40d78a4f4c2d86543b0a224b1ce143e3
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function snprintf().
6 */
8 #define DEBUG 0
9 #include <aros/debug.h>
11 /*****************************************************************************
13 NAME */
14 #include <stdio.h>
16 int snprintf (
18 /* SYNOPSIS */
19 char * str,
20 size_t n,
21 const char * format,
22 ...)
24 /* FUNCTION
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.
33 INPUTS
34 str - The formatted string is written into this variable. You
35 must make sure that it is large enough to contain the
36 result.
37 n - At most n characters are written into the string. This
38 includes the final 0.
39 format - Format string as described above
40 ... - Arguments for the format string
42 RESULT
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.
49 NOTES
51 EXAMPLE
53 BUGS
55 SEE ALSO
56 fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
57 vsnprintf()
59 INTERNALS
61 ******************************************************************************/
63 int retval;
64 va_list args;
66 D(bug("[snprintf] start; str %p('%s'), format: %p('%s')\n",
67 str, str, format, format
68 ));
70 va_start (args, format);
72 retval = vsnprintf (str, n, format, args);
74 va_end (args);
76 D(bug("[snprintf] end; str %p('%s'), format: %p('%s')\n",
77 str, str, format, format
78 ));
80 return retval;
81 } /* snprintf */
83 #ifdef TEST
84 #include <stdio.h>
86 int main (int argc, char ** argv)
88 char buffer[11];
89 int rc;
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);
97 else
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);
104 else
105 printf ("rc=%d\n", rc);
107 return 0;
108 } /* main */
110 #endif /* TEST */