daemon: use skip_prefix to avoid magic numbers

Like earlier cases, we can use skip_prefix to avoid magic numbers that must match the length of starts_with prefixes. However, the numbers are a little more complicated here, as we keep parsing past the prefix. We can solve it by keeping a running pointer as we parse; its final value is the location we want. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jun 18, 2014 at 15:49 UTC d12c24d2a96f8f9aeb100b800d8fb217f28a6a2a
1 file changed +6 -5
daemon.c
+6 -5
@@ -626,15 +626,16 @@ static int execute(void)
626
627 for (i = 0; i < ARRAY_SIZE(daemon_service); i++) {
628 struct daemon_service *s = &(daemon_service[i]);
629 - int namelen = strlen(s->name);
630 - if (starts_with(line, "git-") &&
631 - !strncmp(s->name, line + 4, namelen) &&
632 - line[namelen + 4] == ' ') {
629 + const char *arg;
630 +
631 + if (skip_prefix(line, "git-", &arg) &&
632 + skip_prefix(arg, s->name, &arg) &&
633 + *arg++ == ' ') {
634 /*
635 * Note: The directory here is probably context sensitive,
636 * and might depend on the actual service being performed.
637 */
637 - return run_service(line + namelen + 5, s);
638 + return run_service(arg, s);
639 }
640 }
641