Renamed include file aros/_timeval.h to aros/types/timeval_s.h.
[AROS.git] / compiler / clib / vsnprintf.c
blobcbe7df2342d3a70ad64003cab5cd0197f8733bde
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 C function vsnprintf().
6 */
7 /* Original source from libnix */
9 #include <stdio.h>
11 struct data
13 char * str;
14 size_t n;
17 static int _vsnprintf_uc (int c, struct data * data)
19 if (data->n)
21 *(data->str) ++ = c;
22 data->n --;
25 return 1;
28 /*****************************************************************************
30 NAME */
31 #include <stdio.h>
32 #include <stdarg.h>
34 int vsnprintf (
36 /* SYNOPSIS */
37 char * str,
38 size_t n,
39 const char * format,
40 va_list args)
42 /* FUNCTION
43 Format a list of arguments and put them into the string str.
44 The function makes sure that no more than n characters (including
45 the terminal 0 byte) are written into str.
47 INPUTS
48 str - The formatted result is stored here
49 n - The size of str
50 format - A printf() format string.
51 args - A list of arguments for the format string.
53 RESULT
54 The number of characters written into the string. The 0 byte at the
55 end is not included. If this is greater than or equal to n then
56 there was not enough room to write all characters. In this case the
57 output string is not null-terminated, and the return value is the
58 number of characters which would have been written if enough space had
59 been available.
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
68 printf(), sprintf(), fprintf(), vprintf(), vfprintf(), snprintf(),
69 vsnprintf()
71 INTERNALS
73 ******************************************************************************/
75 int rc;
76 struct data data;
78 data.n = n;
79 data.str = str;
81 rc = __vcformat (&data, (void *)_vsnprintf_uc, format, args);
83 if (data.n)
85 *(data.str) = 0;
88 return rc;
89 } /* vsnprintf */