vsprintf.c revision 102227
12SN/A/*-
21612Smhaupt * Copyright (c) 1990, 1993
32SN/A *	The Regents of the University of California.  All rights reserved.
42SN/A *
52SN/A * This code is derived from software contributed to Berkeley by
62SN/A * Chris Torek.
72SN/A *
82SN/A * Redistribution and use in source and binary forms, with or without
92SN/A * modification, are permitted provided that the following conditions
102SN/A * are met:
112SN/A * 1. Redistributions of source code must retain the above copyright
122SN/A *    notice, this list of conditions and the following disclaimer.
132SN/A * 2. Redistributions in binary form must reproduce the above copyright
142SN/A *    notice, this list of conditions and the following disclaimer in the
152SN/A *    documentation and/or other materials provided with the distribution.
162SN/A * 3. All advertising materials mentioning features or use of this software
172SN/A *    must display the following acknowledgement:
182SN/A *	This product includes software developed by the University of
192SN/A *	California, Berkeley and its contributors.
202SN/A * 4. Neither the name of the University nor the names of its contributors
212SN/A *    may be used to endorse or promote products derived from this software
222SN/A *    without specific prior written permission.
232SN/A *
242SN/A * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
252SN/A * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
262SN/A * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
272SN/A * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28380SN/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29380SN/A * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30380SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31111SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32695SN/A * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33111SN/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
342SN/A * SUCH DAMAGE.
35111SN/A */
36111SN/A
37111SN/A#if defined(LIBC_SCCS) && !defined(lint)
38111SN/Astatic char sccsid[] = "@(#)vsprintf.c	8.1 (Berkeley) 6/4/93";
39111SN/A#endif /* LIBC_SCCS and not lint */
40111SN/A#include <sys/cdefs.h>
41111SN/A__FBSDID("$FreeBSD: head/lib/libc/stdio/vsprintf.c 102227 2002-08-21 16:20:02Z mike $");
42111SN/A
43111SN/A#include <stdio.h>
441156Ssundar#include <limits.h>
451156Ssundar#include "local.h"
462SN/A
472SN/Aint
48111SN/Avsprintf(char *__restrict str, const char *__restrict fmt, __va_list ap)
491631Ssundar{
501631Ssundar	int ret;
512SN/A	FILE f;
52712SN/A	struct __sFILEX ext;
532SN/A
54712SN/A	f._file = -1;
551403Sattila	f._flags = __SWR | __SSTR;
561403Sattila	f._bf._base = f._p = (unsigned char *)str;
572SN/A	f._bf._size = f._w = INT_MAX;
58712SN/A	f._extra = &ext;
59695SN/A	INITEXTRA(&f);
60695SN/A	ret = __vfprintf(&f, fmt, ap);
612SN/A	*f._p = 0;
622SN/A	return (ret);
631631Ssundar}
642SN/A