xref: /dflybsd-src/lib/libc/stdio/asprintf.c (revision dc71b7ab81c4f5270d3668e1625d94a58895fa7a)
1e0f95098SPeter Avalos /*-
2e0f95098SPeter Avalos  * Copyright (c) 1990, 1993
3e0f95098SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
4e0f95098SPeter Avalos  *
5e0f95098SPeter Avalos  * This code is derived from software contributed to Berkeley by
6e0f95098SPeter Avalos  * Chris Torek.
7984263bcSMatthew Dillon  *
8984263bcSMatthew Dillon  * Redistribution and use in source and binary forms, with or without
9984263bcSMatthew Dillon  * modification, are permitted provided that the following conditions
10984263bcSMatthew Dillon  * are met:
11984263bcSMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
12984263bcSMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
13984263bcSMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
14984263bcSMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
15984263bcSMatthew Dillon  *    documentation and/or other materials provided with the distribution.
16*dc71b7abSJustin C. Sherrill  * 3. Neither the name of the University nor the names of its contributors
17e0f95098SPeter Avalos  *    may be used to endorse or promote products derived from this software
18e0f95098SPeter Avalos  *    without specific prior written permission.
19984263bcSMatthew Dillon  *
20e0f95098SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21e0f95098SPeter Avalos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22e0f95098SPeter Avalos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23e0f95098SPeter Avalos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24e0f95098SPeter Avalos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25e0f95098SPeter Avalos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26e0f95098SPeter Avalos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27e0f95098SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28e0f95098SPeter Avalos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29e0f95098SPeter Avalos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30e0f95098SPeter Avalos  * SUCH DAMAGE.
311de703daSMatthew Dillon  *
32e0f95098SPeter Avalos  * $FreeBSD: src/lib/libc/stdio/asprintf.c,v 1.15 2009/03/02 04:11:42 das Exp $
33704ee28cSJoerg Sonnenberger  * $DragonFly: src/lib/libc/stdio/asprintf.c,v 1.8 2006/03/02 18:05:30 joerg Exp $
34984263bcSMatthew Dillon  */
35984263bcSMatthew Dillon 
36984263bcSMatthew Dillon #include <stdarg.h>
37e0f95098SPeter Avalos #include <stdio.h>
3819c7a913SDavid Xu 
39984263bcSMatthew Dillon int
40e0f95098SPeter Avalos asprintf(char ** __restrict s, const char * __restrict fmt, ...)
41984263bcSMatthew Dillon {
42984263bcSMatthew Dillon 	int ret;
43984263bcSMatthew Dillon 	va_list ap;
44984263bcSMatthew Dillon 
45a71425d5SHiten Pandya 	va_start(ap, fmt);
46e0f95098SPeter Avalos 	ret = vasprintf(s, fmt, ap);
47984263bcSMatthew Dillon 	va_end(ap);
48984263bcSMatthew Dillon 	return (ret);
49984263bcSMatthew Dillon }
50