You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vasnprintf.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 it
  4. under the terms of the GNU Library General Public License as published
  5. by 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 GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  14. USA. */
  15. #ifndef _VASNPRINTF_H
  16. #define _VASNPRINTF_H
  17. /* Get va_list. */
  18. #include <stdarg.h>
  19. /* Get size_t. */
  20. #include <stddef.h>
  21. #ifndef __attribute__
  22. /* This feature is available in gcc versions 2.5 and later. */
  23. # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
  24. # define __attribute__(Spec) /* empty */
  25. # endif
  26. /* The __-protected variants of `format' and `printf' attributes
  27. are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
  28. # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
  29. # define __format__ format
  30. # define __printf__ printf
  31. # endif
  32. #endif
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Write formatted output to a string dynamically allocated with malloc().
  37. You can pass a preallocated buffer for the result in RESULTBUF and its
  38. size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
  39. If successful, return the address of the string (this may be = RESULTBUF
  40. if no dynamic memory allocation was necessary) and set *LENGTHP to the
  41. number of resulting bytes, excluding the trailing NUL. Upon error, set
  42. errno and return NULL. */
  43. extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
  44. __attribute__ ((__format__ (__printf__, 3, 4)));
  45. extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
  46. __attribute__ ((__format__ (__printf__, 3, 0)));
  47. #ifdef __cplusplus
  48. }
  49. #endif
  50. #endif /* _VASNPRINTF_H */