summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom@tomsmeding.com>2024-09-08 17:05:42 +0200
committerTom Smeding <tom@tomsmeding.com>2024-09-08 17:05:42 +0200
commitdcf17f88c617abe4d75b65666a78cca396e5d10e (patch)
tree58a8958f463ee49f311216c85a179c6ada394703
parent50f84ac9a2796789ec5bad409a5fb205128cc366 (diff)
grijp: minder strtok(3)
-rw-r--r--src/grijp.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/grijp.c b/src/grijp.c
index add2806..a616959 100644
--- a/src/grijp.c
+++ b/src/grijp.c
@@ -96,16 +96,22 @@ static void parse_patterns() {
patterns = calloc(cappat, sizeof(char*));
char *s = gpats;
- char *pat = NULL;
- while ((pat = strtok(s, "\n")) != NULL) {
- s = NULL;
+ size_t cursor = 0;
+ while (true) {
+ const size_t lfidx = strchrnul(s + cursor, '\n') - s;
+ const bool last = s[lfidx] == '\0';
+ s[lfidx] = '\0';
if (npat == cappat) {
cappat *= 2;
patterns = realloc(patterns, sizeof(char*)*cappat);
}
- patterns[npat] = strdup(pat);
+ patterns[npat] = strdup(s + cursor);
npat++;
+
+ cursor = lfidx + 1;
+
+ if (last) break;
}
}