xref: /freebsd/lib/libc/stdio/asprintf.c (revision 601b205e471e1c291ddaec1f10742a203b7106a2)
1601b205eSDavid Schultz /*-
2601b205eSDavid Schultz  * Copyright (c) 1990, 1993
3601b205eSDavid Schultz  *	The Regents of the University of California.  All rights reserved.
4601b205eSDavid Schultz  *
5601b205eSDavid Schultz  * This code is derived from software contributed to Berkeley by
6601b205eSDavid Schultz  * Chris Torek.
715aa00d5SPeter Wemm  *
815aa00d5SPeter Wemm  * Redistribution and use in source and binary forms, with or without
915aa00d5SPeter Wemm  * modification, are permitted provided that the following conditions
1015aa00d5SPeter Wemm  * are met:
1115aa00d5SPeter Wemm  * 1. Redistributions of source code must retain the above copyright
1215aa00d5SPeter Wemm  *    notice, this list of conditions and the following disclaimer.
1315aa00d5SPeter Wemm  * 2. Redistributions in binary form must reproduce the above copyright
1415aa00d5SPeter Wemm  *    notice, this list of conditions and the following disclaimer in the
1515aa00d5SPeter Wemm  *    documentation and/or other materials provided with the distribution.
16601b205eSDavid Schultz  * 4. Neither the name of the University nor the names of its contributors
17601b205eSDavid Schultz  *    may be used to endorse or promote products derived from this software
18601b205eSDavid Schultz  *    without specific prior written permission.
1915aa00d5SPeter Wemm  *
20601b205eSDavid Schultz  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21601b205eSDavid Schultz  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22601b205eSDavid Schultz  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23601b205eSDavid Schultz  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24601b205eSDavid Schultz  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25601b205eSDavid Schultz  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26601b205eSDavid Schultz  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27601b205eSDavid Schultz  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28601b205eSDavid Schultz  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29601b205eSDavid Schultz  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30601b205eSDavid Schultz  * SUCH DAMAGE.
3115aa00d5SPeter Wemm  */
3215aa00d5SPeter Wemm 
33333fc21eSDavid E. O'Brien #include <sys/cdefs.h>
34333fc21eSDavid E. O'Brien __FBSDID("$FreeBSD$");
3515aa00d5SPeter Wemm 
3615aa00d5SPeter Wemm #include <stdio.h>
3715aa00d5SPeter Wemm #include <stdarg.h>
3815aa00d5SPeter Wemm 
3915aa00d5SPeter Wemm int
40601b205eSDavid Schultz asprintf(char ** __restrict s, char const * __restrict fmt, ...)
4115aa00d5SPeter Wemm {
4215aa00d5SPeter Wemm 	int ret;
4315aa00d5SPeter Wemm 	va_list ap;
4415aa00d5SPeter Wemm 
45344141d1STim J. Robbins 	va_start(ap, fmt);
46601b205eSDavid Schultz 	ret = vasprintf(s, fmt, ap);
47344141d1STim J. Robbins 	va_end(ap);
48344141d1STim J. Robbins 	return (ret);
49344141d1STim J. Robbins }
50