aboutsummaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-07-19 09:45:21 -0700
committerJunio C Hamano <gitster@pobox.com>2011-07-19 09:45:21 -0700
commitfe01ef31b79af85ca50738b11b048e3fad856d34 (patch)
tree0083d9d0b45381ff59856ba612f7f1b851a31a76 /strbuf.c
parent20a80d04a4835dfec2823570719f17b6892e4841 (diff)
parentf77bccaeba7a4c542e9b89d144af74bddd36fd08 (diff)
downloadgit-fe01ef31b79af85ca50738b11b048e3fad856d34.tar.gz
git-fe01ef31b79af85ca50738b11b048e3fad856d34.tar.xz
Merge branch 'jk/maint-config-param'
* jk/maint-config-param: config: use strbuf_split_str instead of a temporary strbuf strbuf: allow strbuf_split to work on non-strbufs config: avoid segfault when parsing command-line config config: die on error in command-line config fix "git -c" parsing of values with equals signs strbuf_split: add a max parameter
Diffstat (limited to 'strbuf.c')
-rw-r--r--strbuf.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/strbuf.c b/strbuf.c
index 09c43ae59..1a7df12e8 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -103,24 +103,27 @@ void strbuf_ltrim(struct strbuf *sb)
sb->buf[sb->len] = '\0';
}
-struct strbuf **strbuf_split(const struct strbuf *sb, int delim)
+struct strbuf **strbuf_split_buf(const char *str, size_t slen, int delim, int max)
{
int alloc = 2, pos = 0;
- char *n, *p;
+ const char *n, *p;
struct strbuf **ret;
struct strbuf *t;
ret = xcalloc(alloc, sizeof(struct strbuf *));
- p = n = sb->buf;
- while (n < sb->buf + sb->len) {
+ p = n = str;
+ while (n < str + slen) {
int len;
- n = memchr(n, delim, sb->len - (n - sb->buf));
+ if (max <= 0 || pos + 1 < max)
+ n = memchr(n, delim, slen - (n - str));
+ else
+ n = NULL;
if (pos + 1 >= alloc) {
alloc = alloc * 2;
ret = xrealloc(ret, sizeof(struct strbuf *) * alloc);
}
if (!n)
- n = sb->buf + sb->len - 1;
+ n = str + slen - 1;
len = n - p + 1;
t = xmalloc(sizeof(struct strbuf));
strbuf_init(t, len);