xref: /csrg-svn/lib/libc/stdio/vsnprintf.c (revision 61180)
146111Sbostic /*-
2*61180Sbostic  * Copyright (c) 1990, 1993
3*61180Sbostic  *	The Regents of the University of California.  All rights reserved.
446111Sbostic  *
546111Sbostic  * This code is derived from software contributed to Berkeley by
646111Sbostic  * Chris Torek.
746111Sbostic  *
846111Sbostic  * %sccs.include.redist.c%
946111Sbostic  */
1046111Sbostic 
1146111Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*61180Sbostic static char sccsid[] = "@(#)vsnprintf.c	8.1 (Berkeley) 06/04/93";
1346111Sbostic #endif /* LIBC_SCCS and not lint */
1446111Sbostic 
1546111Sbostic #include <stdio.h>
1646111Sbostic 
vsnprintf(str,n,fmt,ap)1746111Sbostic vsnprintf(str, n, fmt, ap)
1846111Sbostic 	char *str;
1946111Sbostic 	size_t n;
2046271Storek 	const char *fmt;
2154268Sbostic 	_BSD_VA_LIST_ ap;
2246111Sbostic {
2346111Sbostic 	int ret;
2446111Sbostic 	FILE f;
2546111Sbostic 
2646111Sbostic 	if ((int)n < 1)
2746111Sbostic 		return (EOF);
2846111Sbostic 	f._flags = __SWR | __SSTR;
2946111Sbostic 	f._bf._base = f._p = (unsigned char *)str;
3046111Sbostic 	f._bf._size = f._w = n - 1;
3146111Sbostic 	ret = vfprintf(&f, fmt, ap);
3246111Sbostic 	*f._p = 0;
3346111Sbostic 	return (ret);
3446111Sbostic }
35