X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=strbuf.h;h=46a33f8c46985c4377071011d6ea48d6d3fe5331;hb=c34fe6304c0162c526b74e8639c94d8d026615fd;hp=4ce7dedee07efced23c1214de71e0687d7cb297a;hpb=34df9fe36a3627e1c2a9ae244820fb61e3891b90;p=git.git diff --git a/strbuf.h b/strbuf.h index 4ce7dedee..46a33f8c4 100644 --- a/strbuf.h +++ b/strbuf.h @@ -3,8 +3,6 @@ /* See Documentation/technical/api-strbuf.txt */ -#include - extern char strbuf_slopbuf[]; struct strbuf { size_t alloc; @@ -33,9 +31,8 @@ static inline size_t strbuf_avail(const struct strbuf *sb) { extern void strbuf_grow(struct strbuf *, size_t); static inline void strbuf_setlen(struct strbuf *sb, size_t len) { - if (!sb->alloc) - strbuf_grow(sb, 0); - assert(len < sb->alloc); + if (len > (sb->alloc ? sb->alloc - 1 : 0)) + die("BUG: strbuf_setlen() beyond buffer"); sb->len = len; sb->buf[len] = '\0'; } @@ -47,7 +44,22 @@ extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); -extern struct strbuf **strbuf_split(const struct strbuf *, int delim); +extern struct strbuf **strbuf_split_buf(const char *, size_t, + int delim, int max); +static inline struct strbuf **strbuf_split_str(const char *str, + int delim, int max) +{ + return strbuf_split_buf(str, strlen(str), delim, max); +} +static inline struct strbuf **strbuf_split_max(const struct strbuf *sb, + int delim, int max) +{ + return strbuf_split_buf(sb->buf, sb->len, delim, max); +} +static inline struct strbuf **strbuf_split(const struct strbuf *sb, int delim) +{ + return strbuf_split_max(sb, delim, 0); +} extern void strbuf_list_free(struct strbuf **); /*----- add data in your buffer -----*/ @@ -85,6 +97,8 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf * __attribute__((format (printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); +__attribute__((format (printf,2,0))) +extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); extern size_t strbuf_fread(struct strbuf *, size_t, FILE *); /* XXX: if read fails, any partial read is undone */