summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-06-03 19:59:16 +0200
committerVicent Marti <tanoku@gmail.com>2011-06-03 20:01:18 +0200
commit0291b5b76bd8dcbac1118533c7a79a619ade766c (patch)
tree199f3282d71a1cdbc8ce18fd4b3ab598362d7358 /src/util.c
parent1e9b7a09ff3d16c3d7a132cfaacb9d68b253e924 (diff)
downloadlibgit2-0291b5b76bd8dcbac1118533c7a79a619ade766c.tar.gz
odb: Fix loading ODB alternates
Fixed an issue with the `strtokz implementation and added support for comments and relative paths in the alternates file.
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/util.c b/src/util.c
index ebc1f43d5..560c40dbb 100644
--- a/src/util.c
+++ b/src/util.c
@@ -337,27 +337,29 @@ void git__joinpath_n(char *buffer_out, int count, ...)
*buffer_out = '\0';
}
-static char *strtok_raw(char *output, char *src, char *delimit, int keep)
+char *git__strtok(char **end, const char *sep)
{
- while (*src && strchr(delimit, *src) == NULL)
- *output++ = *src++;
+ char *ptr = *end;
- *output = 0;
+ while (*ptr && strchr(sep, *ptr))
+ ++ptr;
- if (keep)
- return src;
- else
- return *src ? src+1 : src;
-}
+ if (*ptr) {
+ char *start = ptr;
+ *end = start + 1;
-char *git__strtok(char *output, char *src, char *delimit)
-{
- return strtok_raw(output, src, delimit, 0);
-}
+ while (**end && !strchr(sep, **end))
+ ++*end;
-char *git__strtok_keep(char *output, char *src, char *delimit)
-{
- return strtok_raw(output, src, delimit, 1);
+ if (**end) {
+ **end = '\0';
+ ++*end;
+ }
+
+ return start;
+ }
+
+ return NULL;
}
void git__hexdump(const char *buffer, size_t len)