Mercurial > code
changeset 127:e00bc8f7eabf
Fixed buf printf
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 07 Mar 2012 10:22:18 +0100 |
parents | 911201e7574f |
children | 7e72d4008f6d |
files | buf.c buf.h |
diffstat | 2 files changed, 8 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/buf.c Wed Mar 07 09:52:52 2012 +0100 +++ b/buf.c Wed Mar 07 10:22:18 2012 +0100 @@ -111,7 +111,7 @@ } /* - * Copy the printf(3) like call to the string buffer, this function + * Concatenate the printf(3) like call to the string buffer, this function * returns -1 on fixed safe buffer, otherwise 0 is returned if there * is no allocation failure. */ @@ -124,12 +124,13 @@ if (BUF_FIXED(buf) && BUF_SAFE(buf)) return -1; - buf_clear(buf); + do { + copied = vsnprintf(&buf->text[buf->length], + BUF_AVAIL(buf), fmt, ap); - do { - copied = vsnprintf(buf->text, buf->alsize, fmt, ap); + buf->length = strlen(buf->text); - if (copied > BUF_AVAIL(buf) || copied == -1) { + if (copied >= (signed int)BUF_AVAIL(buf) || copied == -1) { if (BUF_FIXED(buf)) done = 1;
--- a/buf.h Wed Mar 07 09:52:52 2012 +0100 +++ b/buf.h Wed Mar 07 10:22:18 2012 +0100 @@ -53,6 +53,8 @@ int buf_cat(struct buf *, const char *); int buf_ncopy(struct buf *, const char *, size_t); int buf_copy(struct buf *, const char *); +int buf_vprintf(struct buf *, const char *, va_list); +int buf_printf(struct buf *, const char *, ...); void buf_clear(struct buf *); void buf_free(struct buf *);