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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #if !defined(HAVE_VASPRINTF)
  9. /* CAW: compliant version of vasprintf */
  10. static int vasprintf(char **buf, const char *fmt, va_list ap)
  11. {
  12. #ifndef WIN32
  13. static char _T_emptybuffer = '\0';
  14. #endif /* !defined(WIN32) */
  15. int chars;
  16. char *b;
  17. if (!buf)
  18. {
  19. return -1;
  20. }
  21. #ifdef WIN32
  22. chars = _vscprintf(fmt, ap) + 1;
  23. #else /* !defined(WIN32) */
  24. /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
  25. * our buffer like on some 64bit sun systems.... but hey, its time to move on
  26. */
  27. chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap) + 1;
  28. if (chars < 0)
  29. {
  30. chars *= -1;
  31. } /* CAW: old glibc versions have this problem */
  32. #endif /* defined(WIN32) */
  33. b = (char *)malloc(sizeof(char) * chars);
  34. if (!b)
  35. {
  36. return -1;
  37. }
  38. if ((chars = vsprintf(b, fmt, ap)) < 0)
  39. {
  40. free(b);
  41. }
  42. else
  43. {
  44. *buf = b;
  45. }
  46. return chars;
  47. }
  48. #endif /* !HAVE_VASPRINTF */
  49. #endif /* __vasprintf_compat_h */