6 #include "xmlrpc_config.h" /* For HAVE_ASPRINTF, __inline__ */
11 static __inline__ void
12 simpleVasprintf(char ** const retvalP,
13 const char * const fmt,
15 /*----------------------------------------------------------------------------
16 This is a poor man's implementation of vasprintf(), of GNU fame.
17 -----------------------------------------------------------------------------*/
18 size_t const initialSize = 4096;
21 result = malloc(initialSize);
24 bytesNeeded = vsnprintf(result, initialSize, fmt, varargs);
25 if (bytesNeeded > initialSize) {
27 result = malloc(bytesNeeded);
29 vsnprintf(result, bytesNeeded, fmt, varargs);
30 } else if (bytesNeeded == initialSize) {
31 if (result[initialSize-1] != '\0') {
32 /* This is one of those old systems where vsnprintf()
33 returns the number of bytes it used, instead of the
34 number that it needed, and it in fact needed more than
35 we gave it. Rather than mess with this highly unlikely
36 case (old system and string > 4095 characters), we just
37 treat this like an out of memory failure.
49 const char * const strsol = "[Insufficient memory to build string]";
54 cvasprintf(const char ** const retvalP,
55 const char * const fmt,
61 vasprintf(&string, fmt, varargs);
63 simpleVasprintf(&string, fmt, varargs);
74 void GNU_PRINTF_ATTR(2,3)
75 casprintf(const char ** const retvalP, const char * const fmt, ...) {
77 va_list varargs; /* mysterious structure used by variable arg facility */
79 va_start(varargs, fmt); /* start up the mysterious variable arg facility */
81 cvasprintf(retvalP, fmt, varargs);
89 strfree(const char * const string) {