xref: /minix3/lib/libc/stdio/vsprintf.c (revision 9a21d1a2fdca366d7697d6ecbfe4ed6d5851f9c7)
1 /*
2  * vsprintf - print formatted output without ellipsis on an array
3  */
4 /* $Header$ */
5 
6 #include	<stdio.h>
7 #include	<stdarg.h>
8 #include	<limits.h>
9 #include	"loc_incl.h"
10 
11 int
12 vsnprintf(char *s, size_t n, const char *format, va_list arg)
13 {
14 	int retval;
15 	FILE tmp_stream;
16 
17 	tmp_stream._fd     = -1;
18 	tmp_stream._flags  = _IOWRITE + _IONBF + _IOWRITING;
19 	tmp_stream._buf    = (unsigned char *) s;
20 	tmp_stream._ptr    = (unsigned char *) s;
21 	tmp_stream._count  = n-1;
22 
23 	retval = _doprnt(format, arg, &tmp_stream);
24 	if(n > 0) {
25 		tmp_stream._count  = 1;
26 		(void) putc('\0',&tmp_stream);
27 	}
28 
29 	return retval;
30 }
31 
32 int
33 vsprintf(char *s, const char *format, va_list arg)
34 {
35 	return vsnprintf(s, INT_MAX, format, arg);
36 }
37