xref: /csrg-svn/lib/libc/stdio/sprintf.c (revision 61180)
146105Sbostic /*-
2*61180Sbostic  * Copyright (c) 1990, 1993
3*61180Sbostic  *	The Regents of the University of California.  All rights reserved.
432989Sbostic  *
546105Sbostic  * This code is derived from software contributed to Berkeley by
646105Sbostic  * Chris Torek.
746105Sbostic  *
842633Sbostic  * %sccs.include.redist.c%
932989Sbostic  */
1032989Sbostic 
1126663Sdonn #if defined(LIBC_SCCS) && !defined(lint)
12*61180Sbostic static char sccsid[] = "@(#)sprintf.c	8.1 (Berkeley) 06/04/93";
1332989Sbostic #endif /* LIBC_SCCS and not lint */
1422148Smckusick 
1532989Sbostic #include <stdio.h>
1646105Sbostic #if __STDC__
1746105Sbostic #include <stdarg.h>
1846105Sbostic #else
1946105Sbostic #include <varargs.h>
2046105Sbostic #endif
2146105Sbostic #include <limits.h>
2246105Sbostic #include "local.h"
232033Swnj 
2446105Sbostic #if __STDC__
sprintf(char * str,char const * fmt,...)2546105Sbostic sprintf(char *str, char const *fmt, ...)
2646105Sbostic #else
2746105Sbostic sprintf(str, fmt, va_alist)
2846105Sbostic 	char *str;
2946105Sbostic 	char *fmt;
3046105Sbostic 	va_dcl
3146105Sbostic #endif
322033Swnj {
3346105Sbostic 	int ret;
3446105Sbostic 	va_list ap;
3546105Sbostic 	FILE f;
362033Swnj 
3746105Sbostic 	f._flags = __SWR | __SSTR;
3846105Sbostic 	f._bf._base = f._p = (unsigned char *)str;
3946105Sbostic 	f._bf._size = f._w = INT_MAX;
4046105Sbostic #if __STDC__
4146105Sbostic 	va_start(ap, fmt);
4246105Sbostic #else
4346105Sbostic 	va_start(ap);
4446105Sbostic #endif
4546105Sbostic 	ret = vfprintf(&f, fmt, ap);
4646105Sbostic 	va_end(ap);
4746105Sbostic 	*f._p = 0;
4846105Sbostic 	return (ret);
492033Swnj }
50