X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fstkstring.c;h=c3b77301adba1744725721b87e7deb8f7af633b8;hb=a996044f96a0600122c4f208663ae79715868bbc;hp=eaeacf00f7c950aaf27de5aefa570bf58d395f6d;hpb=47a0795e8a28e8ad6ff55cda89e300267d9e590c;p=libucw.git diff --git a/lib/stkstring.c b/lib/stkstring.c index eaeacf00..c3b77301 100644 --- a/lib/stkstring.c +++ b/lib/stkstring.c @@ -27,34 +27,26 @@ stk_array_join(char *x, char **s, uns cnt, uns sep) *x = 0; } -char *stk_printf_buf; -static int stk_printf_len; - uns stk_printf_internal(char *fmt, ...) { + uns len = 256; + char *buf = alloca(len); va_list args, args2; va_start(args, fmt); - if (!stk_printf_buf) - { - stk_printf_buf = xmalloc(256); - stk_printf_len = 256; - } for (;;) { va_copy(args2, args); - int l = vsnprintf(stk_printf_buf, stk_printf_len, fmt, args2); + int l = vsnprintf(buf, len, fmt, args2); va_end(args2); if (l < 0) - stk_printf_len *= 2; - else if (l < stk_printf_len) + len *= 2; + else { va_end(args); return l+1; } - else - stk_printf_len = MAX(stk_printf_len*2, l+1); - stk_printf_buf = xrealloc(stk_printf_buf, stk_printf_len); + buf = alloca(len); } }