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

vasprintf_compat.h 1.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef __vasprintf_compat_h
  2. #define __vasprintf_compat_h
  3. /**
  4. * @file
  5. * @brief Do not use, json-c internal, may be changed or removed at any time.
  6. */
  7. #include "snprintf_compat.h"
  8. #include <malloc.h>
  9. #if !defined(HAVE_VASPRINTF)
  10. /* CAW: compliant version of vasprintf */
  11. static int vasprintf(char **buf, const char *fmt, va_list ap)
  12. {
  13. #ifndef WIN32
  14. static char _T_emptybuffer = '\0';
  15. #endif /* !defined(WIN32) */
  16. int chars;
  17. char *b;
  18. if (!buf)
  19. {
  20. return -1;
  21. }
  22. #ifdef WIN32
  23. chars = _vscprintf(fmt, ap) + 1;
  24. #else /* !defined(WIN32) */
  25. /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
  26. * our buffer like on some 64bit sun systems.... but hey, its time to move on
  27. */
  28. chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap) + 1;
  29. if (chars < 0)
  30. {
  31. chars *= -1;
  32. } /* CAW: old glibc versions have this problem */
  33. #endif /* defined(WIN32) */
  34. b = (char *)malloc(sizeof(char) * chars);
  35. if (!b)
  36. {
  37. return -1;
  38. }
  39. if ((chars = vsprintf(b, fmt, ap)) < 0)
  40. {
  41. free(b);
  42. }
  43. else
  44. {
  45. *buf = b;
  46. }
  47. return chars;
  48. }
  49. #endif /* !HAVE_VASPRINTF */
  50. #endif /* __vasprintf_compat_h */