1*86d7f5d3SJohn Marino /* vsprintf with automatic memory allocation. 2*86d7f5d3SJohn Marino Copyright (C) 2002-2003 Free Software Foundation, Inc. 3*86d7f5d3SJohn Marino 4*86d7f5d3SJohn Marino This program is free software; you can redistribute it and/or modify 5*86d7f5d3SJohn Marino it under the terms of the GNU General Public License as published by 6*86d7f5d3SJohn Marino the Free Software Foundation; either version 2, or (at your option) 7*86d7f5d3SJohn Marino any later version. 8*86d7f5d3SJohn Marino 9*86d7f5d3SJohn Marino This program is distributed in the hope that it will be useful, 10*86d7f5d3SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 11*86d7f5d3SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*86d7f5d3SJohn Marino GNU General Public License for more details. 13*86d7f5d3SJohn Marino 14*86d7f5d3SJohn Marino You should have received a copy of the GNU General Public License along 15*86d7f5d3SJohn Marino with this program; if not, write to the Free Software Foundation, 16*86d7f5d3SJohn Marino Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 17*86d7f5d3SJohn Marino 18*86d7f5d3SJohn Marino #ifndef _VASPRINTF_H 19*86d7f5d3SJohn Marino #define _VASPRINTF_H 20*86d7f5d3SJohn Marino 21*86d7f5d3SJohn Marino #if HAVE_VASPRINTF 22*86d7f5d3SJohn Marino 23*86d7f5d3SJohn Marino /* Get asprintf(), vasprintf() declarations. */ 24*86d7f5d3SJohn Marino #include <stdio.h> 25*86d7f5d3SJohn Marino 26*86d7f5d3SJohn Marino #else 27*86d7f5d3SJohn Marino 28*86d7f5d3SJohn Marino /* Get va_list. */ 29*86d7f5d3SJohn Marino #include <stdarg.h> 30*86d7f5d3SJohn Marino 31*86d7f5d3SJohn Marino #ifndef __attribute__ 32*86d7f5d3SJohn Marino /* This feature is available in gcc versions 2.5 and later. */ 33*86d7f5d3SJohn Marino # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ 34*86d7f5d3SJohn Marino # define __attribute__(Spec) /* empty */ 35*86d7f5d3SJohn Marino # endif 36*86d7f5d3SJohn Marino /* The __-protected variants of `format' and `printf' attributes 37*86d7f5d3SJohn Marino are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ 38*86d7f5d3SJohn Marino # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) 39*86d7f5d3SJohn Marino # define __format__ format 40*86d7f5d3SJohn Marino # define __printf__ printf 41*86d7f5d3SJohn Marino # endif 42*86d7f5d3SJohn Marino #endif 43*86d7f5d3SJohn Marino 44*86d7f5d3SJohn Marino #ifdef __cplusplus 45*86d7f5d3SJohn Marino extern "C" { 46*86d7f5d3SJohn Marino #endif 47*86d7f5d3SJohn Marino 48*86d7f5d3SJohn Marino /* Write formatted output to a string dynamically allocated with malloc(). 49*86d7f5d3SJohn Marino If the memory allocation succeeds, store the address of the string in 50*86d7f5d3SJohn Marino *RESULT and return the number of resulting bytes, excluding the trailing 51*86d7f5d3SJohn Marino NUL. Upon memory allocation error, or some other error, return -1. */ 52*86d7f5d3SJohn Marino extern int asprintf (char **result, const char *format, ...) 53*86d7f5d3SJohn Marino __attribute__ ((__format__ (__printf__, 2, 3))); 54*86d7f5d3SJohn Marino extern int vasprintf (char **result, const char *format, va_list args) 55*86d7f5d3SJohn Marino __attribute__ ((__format__ (__printf__, 2, 0))); 56*86d7f5d3SJohn Marino 57*86d7f5d3SJohn Marino #ifdef __cplusplus 58*86d7f5d3SJohn Marino } 59*86d7f5d3SJohn Marino #endif 60*86d7f5d3SJohn Marino 61*86d7f5d3SJohn Marino #endif 62*86d7f5d3SJohn Marino 63*86d7f5d3SJohn Marino #endif /* _VASPRINTF_H */ 64