X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fstkstring.c;h=b583b24b870e4cf82482695fea874c57d89ad444;hb=d9e3b9f0bdd257d6287c5ba32cab5f648a98ed55;hp=c84d6279d890f21456b9175d0fdf100c263167df;hpb=449b6a65695233ea809c0f3c72dfb4fcc1f4308c;p=libucw.git diff --git a/lib/stkstring.c b/lib/stkstring.c index c84d6279..b583b24b 100644 --- a/lib/stkstring.c +++ b/lib/stkstring.c @@ -28,7 +28,7 @@ stk_array_join(char *x, char **s, uns cnt, uns sep) } uns -stk_printf_internal(char *fmt, ...) +stk_printf_internal(const char *fmt, ...) { uns len = 256; char *buf = alloca(len); @@ -50,6 +50,28 @@ stk_printf_internal(char *fmt, ...) } } +uns +stk_vprintf_internal(const char *fmt, va_list args) +{ + uns len = 256; + char *buf = alloca(len); + va_list args2; + for (;;) + { + va_copy(args2, args); + int l = vsnprintf(buf, len, fmt, args2); + va_end(args2); + if (l < 0) + len *= 2; + else + { + va_end(args); + return l+1; + } + buf = alloca(len); + } +} + void stk_hexdump_internal(char *dst, byte *src, uns n) { @@ -67,7 +89,7 @@ stk_fsize_internal(char *buf, u64 x) { if (x < 1<<10) sprintf(buf, "%dB", (int)x); - if (x < 10<<10) + else if (x < 10<<10) sprintf(buf, "%.1fK", (double)x/(1<<10)); else if (x < 1<<20) sprintf(buf, "%dK", (int)(x/(1<<10)));