12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- #ifndef __vasprintf_compat_h
- #define __vasprintf_compat_h
- #include "snprintf_compat.h"
- #if !defined(HAVE_VASPRINTF)
- static int vasprintf(char **buf, const char *fmt, va_list ap)
- {
- #ifndef WIN32
- static char _T_emptybuffer = '\0';
- #endif
- int chars;
- char *b;
- if(!buf) { return -1; }
- #ifdef WIN32
- chars = _vscprintf(fmt, ap)+1;
- #else
-
- chars = vsnprintf(&_T_emptybuffer, 0, fmt, ap)+1;
- if(chars < 0) { chars *= -1; }
- #endif
- b = (char*)malloc(sizeof(char)*chars);
- if(!b) { return -1; }
- if((chars = vsprintf(b, fmt, ap)) < 0)
- {
- free(b);
- } else {
- *buf = b;
- }
- return chars;
- }
- #endif
- #endif
|