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