diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-12-22 11:51:38 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-12-22 11:51:38 +0000 |
commit | 8821237240c5374d83298b2da5ad88fa1e3c1ef7 (patch) | |
tree | e1bc03fa83c61165f48ffe3f528ac5496332872a /com32/lib/bufprintf.c | |
parent | 38dcca25c8855c95649e3f0b5b09fae862ed5c7a (diff) | |
parent | 7307d60063ee4303da4de45f9d984fdc8df92146 (diff) | |
download | syslinux-8821237240c5374d83298b2da5ad88fa1e3c1ef7.tar.gz |
Merge remote-tracking branch 'remotes/upstream/master' into baserock/morph
Diffstat (limited to 'com32/lib/bufprintf.c')
-rw-r--r-- | com32/lib/bufprintf.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/com32/lib/bufprintf.c b/com32/lib/bufprintf.c new file mode 100644 index 00000000..939bcec3 --- /dev/null +++ b/com32/lib/bufprintf.c @@ -0,0 +1,41 @@ +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <bufprintf.h> + +int vbufprintf(struct print_buf *buf, const char *format, va_list ap) +{ + va_list ap2; + int rv; + + va_copy(ap2, ap); + rv = vsnprintf(NULL, 0, format, ap); + + /* >= to make sure we have space for terminating null */ + if (rv + buf->len >= buf->size) { + size_t newsize = rv + buf->len + BUFPAD; + char *newbuf; + + newbuf = realloc(buf->buf, newsize); + if (!newbuf) + return -1; + + buf->buf = newbuf; + buf->size = newsize; + } + + rv = vsnprintf(buf->buf + buf->len, buf->size - buf->len, format, ap2); + buf->len += rv; + return rv; +} + +int bufprintf(struct print_buf *buf, const char *format, ...) +{ + va_list ap; + int rv; + + va_start(ap, format); + rv = vbufprintf(buf, format, ap); + va_end(ap); + return rv; +} |