Small cleanup of extensions code
[AROS.git] / compiler / clib / snprintf.c
blob2e4a08d80a83ff5e44198597ce406a2ed3d1d616
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 Formats a list of arguments and writes them into the string str.
24 INPUTS
25 str - The formatted string is written into this variable. You
26 must make sure that it is large enough to contain the
27 result.
28 n - At most n characters are written into the string. This
29 includes the final 0.
30 format - Format string as described above
31 ... - Arguments for the format string
33 RESULT
34 The number of characters written into the string. The 0 byte at the
35 end is not included. If this is greater than or equal to n then
36 there was not enough room to write all characters. In this case the
37 output string is not null-terminated, and the return value is the
38 number of characters which would have been written if enough space had
39 been available.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 fprintf(), vprintf(), vfprintf(), snprintf(), vsprintf(),
49 vsnprintf()
51 INTERNALS
53 ******************************************************************************/
55 int retval;
56 va_list args;
58 va_start (args, format);
60 retval = vsnprintf (str, n, format, args);
62 va_end (args);
64 return retval;
65 } /* snprintf */
67 #ifdef TEST
68 #include <stdio.h>
70 int main (int argc, char ** argv)
72 char buffer[11];
73 int rc;
75 printf ("snprintf test\n");
77 rc = snprintf (buffer, sizeof (buffer), "%10d", 5);
79 if (rc < sizeof (buffer))
80 printf ("rc=%d, buffer=\"%s\"\n", rc, buffer);
81 else
82 printf ("rc=%d\n", rc);
84 rc = snprintf (buffer, sizeof (buffer), "%11d", 5);
86 if (rc < sizeof (buffer))
87 printf ("rc=%d, buffer=\"%s\"\n", rc, buffer);
88 else
89 printf ("rc=%d\n", rc);
91 return 0;
92 } /* main */
94 #endif /* TEST */