xref: /original-bsd/lib/libc/stdio/vsnprintf.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Chris Torek.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #if defined(LIBC_SCCS) && !defined(lint)
12 static char sccsid[] = "@(#)vsnprintf.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <stdio.h>
16 
17 vsnprintf(str, n, fmt, ap)
18 	char *str;
19 	size_t n;
20 	const char *fmt;
21 	_BSD_VA_LIST_ ap;
22 {
23 	int ret;
24 	FILE f;
25 
26 	if ((int)n < 1)
27 		return (EOF);
28 	f._flags = __SWR | __SSTR;
29 	f._bf._base = f._p = (unsigned char *)str;
30 	f._bf._size = f._w = n - 1;
31 	ret = vfprintf(&f, fmt, ap);
32 	*f._p = 0;
33 	return (ret);
34 }
35