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