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