rom/exec/restoretaskstorage.c: Don't restore ETask data
[AROS.git] / compiler / clib / snprintf.c
blobc6ce47ef03ff310420f3e9cecf95aec29d99a612
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function snprintf().
6 */
8 /*****************************************************************************
10 NAME */
11 #include <stdio.h>
13 int snprintf (
15 /* SYNOPSIS */
16 char * str,
17 size_t n,
18 const char * format,
19 ...)
21 /* FUNCTION
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.
30 INPUTS
31 str - The formatted string is written into this variable. You
32 must make sure that it is large enough to contain the
33 result.
34 n - At most n characters are written into the string. This
35 includes the final 0.
36 format - Format string as described above
37 ... - Arguments for the format string
39 RESULT
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.
46 NOTES
48 EXAMPLE
50 BUGS
52 SEE ALSO
53 fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
54 vsnprintf()
56 INTERNALS
58 ******************************************************************************/
60 int retval;
61 va_list args;
63 va_start (args, format);
65 retval = vsnprintf (str, n, format, args);
67 va_end (args);
69 return retval;
70 } /* snprintf */
72 #ifdef TEST
73 #include <stdio.h>
75 int main (int argc, char ** argv)
77 char buffer[11];
78 int rc;
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);
86 else
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);
93 else
94 printf ("rc=%d\n", rc);
96 return 0;
97 } /* main */
99 #endif /* TEST */