asprintf.c revision 38889
1/* Like sprintf but provides a pointer to malloc'd storage, which must 2 be freed by the caller. 3 Copyright (C) 1997 Free Software Foundation, Inc. 4 Contributed by Cygnus Solutions. 5 6This file is part of the libiberty library. 7Libiberty is free software; you can redistribute it and/or 8modify it under the terms of the GNU Library General Public 9License as published by the Free Software Foundation; either 10version 2 of the License, or (at your option) any later version. 11 12Libiberty is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15Library General Public License for more details. 16 17You should have received a copy of the GNU Library General Public 18License along with libiberty; see the file COPYING.LIB. If 19not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20Boston, MA 02111-1307, USA. */ 21 22#include "ansidecl.h" 23#include "libiberty.h" 24 25#if defined (ANSI_PROTOTYPES) || defined (ALMOST_STDC) 26#define USE_STDARG 27#endif 28 29#ifdef USE_STDARG 30#include <stdarg.h> 31#else 32#include <varargs.h> 33#endif 34 35/* VARARGS */ 36#ifdef USE_STDARG 37int 38asprintf (char **buf, const char *fmt, ...) 39#else 40int 41asprintf (buf, fmt, va_alist) 42 char **buf; 43 const char *fmt; 44 va_dcl 45#endif 46{ 47 int status; 48 va_list ap; 49#ifdef USE_STDARG 50 va_start (ap, fmt); 51#else 52 va_start (ap); 53#endif 54 status = vasprintf (buf, fmt, ap); 55 va_end (ap); 56 return status; 57} 58