X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fbbuf.c;h=fae5870053c91ba3f56fb51efeaeee24438a9f83;hb=72b8acb9dee50bf94aac3288eade0e91381cb082;hp=b664a79d4db675f11aa007a9333999d5c177b653;hpb=6a3e2a5bc9b84ac6b0b8efc38455fb93a212fea7;p=libucw.git diff --git a/lib/bbuf.c b/lib/bbuf.c index b664a79d..fae58700 100644 --- a/lib/bbuf.c +++ b/lib/bbuf.c @@ -13,7 +13,7 @@ #include char * -bb_ofs_vprintf(bb_t *bb, uns ofs, char *fmt, va_list args) +bb_vprintf_at(bb_t *bb, uns ofs, char *fmt, va_list args) { bb_grow(bb, ofs + 1); va_list args2; @@ -32,7 +32,7 @@ bb_ofs_vprintf(bb_t *bb, uns ofs, char *fmt, va_list args) } while (cnt < 0); } - else if (cnt >= bb->len - ofs) + else if ((uns)cnt >= bb->len - ofs) { bb_do_grow(bb, ofs + cnt + 1); va_copy(args2, args); @@ -44,11 +44,27 @@ bb_ofs_vprintf(bb_t *bb, uns ofs, char *fmt, va_list args) } char * -bb_ofs_printf(bb_t *bb, uns ofs, char *fmt, ...) +bb_printf_at(bb_t *bb, uns ofs, char *fmt, ...) { va_list args; va_start(args, fmt); - char *res = bb_ofs_vprintf(bb, ofs, fmt, args); + char *res = bb_vprintf_at(bb, ofs, fmt, args); + va_end(args); + return res; +} + +char * +bb_vprintf(bb_t *bb, char *fmt, va_list args) +{ + return bb_vprintf_at(bb, 0, fmt, args); +} + +char * +bb_printf(bb_t *bb, char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + char *res = bb_vprintf_at(bb, 0, fmt, args); va_end(args); return res; } @@ -59,9 +75,9 @@ int main(void) { bb_t bb; bb_init(&bb); - char *x = bb_ofs_printf(&bb, 0, "", "World"); + char *x = bb_printf(&bb, "", "World"); fputs(x, stdout); - x = bb_ofs_printf(&bb, 5, "\n", "World"); + x = bb_printf_at(&bb, 5, "\n", "World"); fputs(x, stdout); bb_done(&bb); return 0;