xref: /original-bsd/lib/libc/stdio/sprintf.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[] = "@(#)sprintf.c	8.1 (Berkeley) 06/04/93";
13 #endif /* LIBC_SCCS and not lint */
14 
15 #include <stdio.h>
16 #if __STDC__
17 #include <stdarg.h>
18 #else
19 #include <varargs.h>
20 #endif
21 #include <limits.h>
22 #include "local.h"
23 
24 #if __STDC__
25 sprintf(char *str, char const *fmt, ...)
26 #else
27 sprintf(str, fmt, va_alist)
28 	char *str;
29 	char *fmt;
30 	va_dcl
31 #endif
32 {
33 	int ret;
34 	va_list ap;
35 	FILE f;
36 
37 	f._flags = __SWR | __SSTR;
38 	f._bf._base = f._p = (unsigned char *)str;
39 	f._bf._size = f._w = INT_MAX;
40 #if __STDC__
41 	va_start(ap, fmt);
42 #else
43 	va_start(ap);
44 #endif
45 	ret = vfprintf(&f, fmt, ap);
46 	va_end(ap);
47 	*f._p = 0;
48 	return (ret);
49 }
50