X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fstr.c;h=98a8e52e3caf543b1afe47313ca59e9fcb98a732;hb=def7e6026513a3ee7c2b38416b30a2e890e34311;hp=8912f3e58b6a4ec5921e58a952fd316dcb137560;hpb=c87013b64d1731dac5da8f738ae8d1b4c1030a90;p=pspp-builds.git diff --git a/src/str.c b/src/str.c index 8912f3e5..98a8e52e 100644 --- a/src/str.c +++ b/src/str.c @@ -350,40 +350,50 @@ ds_concat_buffer (struct string *st, const char *buf, size_t len) st->length += len; } +void ds_vprintf (struct string *st, const char *format, va_list args); + + /* Formats FORMAT as a printf string and appends the result to ST. */ void ds_printf (struct string *st, const char *format, ...) +{ + va_list args; + + va_start (args, format); + ds_vprintf(st,format,args); + va_end (args); + +} + +/* Formats FORMAT as a printf string and appends the result to ST. */ +void +ds_vprintf (struct string *st, const char *format, va_list args) { /* Fscking glibc silently changed behavior between 2.0 and 2.1. Fsck fsck fsck. Before, it returned -1 on buffer overflow. Now, it returns the number of characters (not bytes) that would have been written. */ - va_list args; int avail, needed; - va_start (args, format); avail = st->size - st->length + 1; needed = vsnprintf (st->string + st->length, avail, format, args); - va_end (args); + if (needed >= avail) { ds_extend (st, st->length + needed); - va_start (args, format); vsprintf (st->string + st->length, format, args); - va_end (args); } else while (needed == -1) { ds_extend (st, (st->size + 1) * 2); avail = st->size - st->length + 1; - - va_start (args, format); + needed = vsnprintf (st->string + st->length, avail, format, args); - va_end (args); + } st->length += needed;