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 968 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef __vasprintf_compat_h
  2. #define __vasprintf_compat_h
  3. #include "snprintf_compat.h"
  4. #if !defined(HAVE_VASPRINTF)
  5. /* CAW: compliant version of vasprintf */
  6. static int vasprintf(char **buf, const char *fmt, va_list ap)
  7. {
  8. #ifndef WIN32
  9. static char _T_emptybuffer = '\0';
  10. #endif /* !defined(WIN32) */
  11. int chars;
  12. char *b;
  13. if(!buf) { return -1; }
  14. #ifdef WIN32
  15. chars = _vscprintf(fmt, ap)+1;
  16. #else /* !defined(WIN32) */
  17. /* CAW: RAWR! We have to hope to god here that vsnprintf doesn't overwrite
  18. our buffer like on some 64bit sun systems.... but hey, its time to move on */
  19. chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1;
  20. if(chars < 0) { chars *= -1; } /* CAW: old glibc versions have this problem */
  21. #endif /* defined(WIN32) */
  22. b = (char*)malloc(sizeof(char)*chars);
  23. if(!b) { return -1; }
  24. if((chars = vsprintf(b, fmt, ap)) < 0)
  25. {
  26. free(b);
  27. } else {
  28. *buf = b;
  29. }
  30. return chars;
  31. }
  32. #endif /* !HAVE_VASPRINTF */
  33. #endif /* __vasprintf_compat_h */