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 * 8*0d5acd74SJohn Marino * Copyright (c) 2011 The FreeBSD Foundation 9*0d5acd74SJohn Marino * All rights reserved. 10*0d5acd74SJohn Marino * Portions of this software were developed by David Chisnall 11*0d5acd74SJohn Marino * under sponsorship from the FreeBSD Foundation. 12*0d5acd74SJohn Marino * 13984263bcSMatthew Dillon * Redistribution and use in source and binary forms, with or without 14984263bcSMatthew Dillon * modification, are permitted provided that the following conditions 15984263bcSMatthew Dillon * are met: 16984263bcSMatthew Dillon * 1. Redistributions of source code must retain the above copyright 17984263bcSMatthew Dillon * notice, this list of conditions and the following disclaimer. 18984263bcSMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 19984263bcSMatthew Dillon * notice, this list of conditions and the following disclaimer in the 20984263bcSMatthew Dillon * documentation and/or other materials provided with the distribution. 21dc71b7abSJustin C. Sherrill * 3. Neither the name of the University nor the names of its contributors 22e0f95098SPeter Avalos * may be used to endorse or promote products derived from this software 23e0f95098SPeter Avalos * without specific prior written permission. 24984263bcSMatthew Dillon * 25e0f95098SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26e0f95098SPeter Avalos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27e0f95098SPeter Avalos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28e0f95098SPeter Avalos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29e0f95098SPeter Avalos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30e0f95098SPeter Avalos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31e0f95098SPeter Avalos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32e0f95098SPeter Avalos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33e0f95098SPeter Avalos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34e0f95098SPeter Avalos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35e0f95098SPeter Avalos * SUCH DAMAGE. 361de703daSMatthew Dillon * 37*0d5acd74SJohn Marino * $FreeBSD: head/lib/libc/stdio/asprintf.c 249808 2013-04-23 13:33:13Z emaste $ 38984263bcSMatthew Dillon */ 39984263bcSMatthew Dillon 40*0d5acd74SJohn Marino 41e0f95098SPeter Avalos #include <stdio.h> 42*0d5acd74SJohn Marino #include <stdarg.h> 43*0d5acd74SJohn Marino #include <xlocale.h> 4419c7a913SDavid Xu 45984263bcSMatthew Dillon int asprintf(char ** __restrict s,char const * __restrict fmt,...)46*0d5acd74SJohn Marinoasprintf(char ** __restrict s, char const * __restrict fmt, ...) 47984263bcSMatthew Dillon { 48984263bcSMatthew Dillon int ret; 49984263bcSMatthew Dillon va_list ap; 50984263bcSMatthew Dillon 51a71425d5SHiten Pandya va_start(ap, fmt); 52e0f95098SPeter Avalos ret = vasprintf(s, fmt, ap); 53984263bcSMatthew Dillon va_end(ap); 54984263bcSMatthew Dillon return (ret); 55984263bcSMatthew Dillon } 56*0d5acd74SJohn Marino int asprintf_l(char ** __restrict s,locale_t locale,char const * __restrict fmt,...)57*0d5acd74SJohn Marinoasprintf_l(char ** __restrict s, locale_t locale, char const * __restrict fmt, 58*0d5acd74SJohn Marino ...) 59*0d5acd74SJohn Marino { 60*0d5acd74SJohn Marino int ret; 61*0d5acd74SJohn Marino va_list ap; 62*0d5acd74SJohn Marino 63*0d5acd74SJohn Marino va_start(ap, fmt); 64*0d5acd74SJohn Marino ret = vasprintf_l(s, locale, fmt, ap); 65*0d5acd74SJohn Marino va_end(ap); 66*0d5acd74SJohn Marino return (ret); 67*0d5acd74SJohn Marino } 68