vasprintf.h 2.1 KB

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