summaryrefslogtreecommitdiff
path: root/strbuf.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-09-12 04:53:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-09-12 04:53:13 (GMT)
commiteff7c32cfd12867000d6449d335fad0e7c9751f1 (patch)
tree392708c905f6d77ea5052dee5f1b76e7fe7f0a31 /strbuf.c
parent7baf32a829e6e253f8b3b683da470be36b54c377 (diff)
parentf77bccaeba7a4c542e9b89d144af74bddd36fd08 (diff)
downloadgit-eff7c32cfd12867000d6449d335fad0e7c9751f1.zip
git-eff7c32cfd12867000d6449d335fad0e7c9751f1.tar.gz
git-eff7c32cfd12867000d6449d335fad0e7c9751f1.tar.bz2
Merge branch 'jk/maint-config-param' into maint
* 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 09c43ae..1a7df12 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);