X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=osl.c;h=5786939088bf9ef0147694fca40be43f320d6b7e;hb=42a43cd4cc1849658130214cb244e0c88e824471;hp=31f49a231f5f8e99ead466caf72b815c0ff8ffae;hpb=d1a980cd400e730e3be89c8b5e648a25d1cca0ac;p=osl.git diff --git a/osl.c b/osl.c index 31f49a2..5786939 100644 --- a/osl.c +++ b/osl.c @@ -30,10 +30,34 @@ */ static __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) { - char *msg; + int n; + size_t size = 100; + char *p = malloc(size); - VSPRINTF(fmt, msg); - return msg; + if (!p) + return NULL; + while (1) { + char *q; + va_list ap; + /* Try to print in the allocated space. */ + va_start(ap, fmt); + n = vsnprintf(p, size, fmt, ap); + va_end(ap); + /* If that worked, return the string. */ + if (n > -1 && n < size) + break; + /* Else try again with more space. */ + if (n > -1) /* glibc 2.1 */ + size = n + 1; /* precisely what is needed */ + else /* glibc 2.0 */ + size *= 2; /* twice the old size */ + q = realloc(p, size); + if (!q) { + free(p); + return NULL; + } + } + return p; } /**