X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=log.h;fp=log.h;h=dfb05652a56e6ae35c612bef0a34bb6d6dd81b1b;hb=02e6053e5976c6aa4bf538f3469335835d54e478;hp=d78b48a45b5b97b64ad38f0e913bdec888f91d67;hpb=5952112a37ecdaedf3b76e08f97d307f1056c512;p=osl.git diff --git a/log.h b/log.h index d78b48a..dfb0565 100644 --- a/log.h +++ b/log.h @@ -101,23 +101,29 @@ __printf_2_3 void __log(int, const char*, ...); { \ int n; \ size_t size = 100; \ - p = para_malloc(size); \ - while (1) { \ - 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 */ \ - p = realloc(p, size); \ - if (!p) \ - break; \ + p = malloc(size); \ + if (p) { \ + 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); \ + p = NULL; \ + break; \ + } \ + } \ } \ }