1*e0f95098SPeter Avalos /*- 2*e0f95098SPeter Avalos * Copyright (c) 1990, 1993 3*e0f95098SPeter Avalos * The Regents of the University of California. All rights reserved. 4*e0f95098SPeter Avalos * 5*e0f95098SPeter Avalos * This code is derived from software contributed to Berkeley by 6*e0f95098SPeter 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*e0f95098SPeter Avalos * 4. Neither the name of the University nor the names of its contributors 17*e0f95098SPeter Avalos * may be used to endorse or promote products derived from this software 18*e0f95098SPeter Avalos * without specific prior written permission. 19984263bcSMatthew Dillon * 20*e0f95098SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21*e0f95098SPeter Avalos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22*e0f95098SPeter Avalos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23*e0f95098SPeter Avalos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24*e0f95098SPeter Avalos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25*e0f95098SPeter Avalos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26*e0f95098SPeter Avalos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27*e0f95098SPeter Avalos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28*e0f95098SPeter Avalos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29*e0f95098SPeter Avalos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30*e0f95098SPeter Avalos * SUCH DAMAGE. 311de703daSMatthew Dillon * 32*e0f95098SPeter 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> 37*e0f95098SPeter Avalos #include <stdio.h> 3819c7a913SDavid Xu 39984263bcSMatthew Dillon int 40*e0f95098SPeter 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); 46*e0f95098SPeter Avalos ret = vasprintf(s, fmt, ap); 47984263bcSMatthew Dillon va_end(ap); 48984263bcSMatthew Dillon return (ret); 49984263bcSMatthew Dillon } 50