daemon: cleanup: factor out xstrdup_tolower()
Add xstrdup_tolower(), a helper to get a lower case copy of a string, and use it in two cases. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 26, 2008 at 11:12 UTC
6720e95b305737fddc776f2904c339a0701e6ae2
1 file changed
+13
-21
daemon.c
+13
-21
@@ -397,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)
397
die("No such service %s", name);
398
}
399
400
+static char *xstrdup_tolower(const char *str)
401
+{
402
+ char *p, *dup = xstrdup(str);
403
+ for (p = dup; *p; p++)
404
+ *p = tolower(*p);
405
+ return dup;
406
+}
407
+
408
/*
409
* Separate the "extra args" information as supplied by the client connection.
410
*/
@@ -405,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
413
char *val;
414
int vallen;
415
char *end = extra_args + buflen;
408
- char *hp;
416
417
while (extra_args < end && *extra_args) {
418
saw_extended_args = 1;
@@ -423,7 +430,7 @@ static void parse_extra_args(char *extra_args, int buflen)
430
tcp_port = xstrdup(port);
431
}
432
free(hostname);
426
- hostname = xstrdup(host);
433
+ hostname = xstrdup_tolower(host);
434
}
435
436
/* On to the next one */
@@ -431,20 +438,11 @@ static void parse_extra_args(char *extra_args, int buflen)
438
}
439
}
440
434
- /*
435
- * Replace literal host with lowercase-ized hostname.
436
- */
437
- hp = hostname;
438
- if (!hp)
439
- return;
440
- for ( ; *hp; hp++)
441
- *hp = tolower(*hp);
442
-
441
/*
442
* Locate canonical hostname and its IP address.
443
*/
444
+ if (hostname) {
445
#ifndef NO_IPV6
447
- {
446
struct addrinfo hints;
447
struct addrinfo *ai, *ai0;
448
int gai;
@@ -468,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
466
}
467
freeaddrinfo(ai0);
468
}
471
- }
469
#else
473
- {
470
struct hostent *hent;
471
struct sockaddr_in sa;
472
char **ap;
@@ -491,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)
487
canon_hostname = xstrdup(hent->h_name);
488
free(ip_address);
489
ip_address = xstrdup(addrbuf);
494
- }
490
#endif
491
+ }
492
}
493
494
@@ -945,12 +941,8 @@ int main(int argc, char **argv)
941
char *arg = argv[i];
942
943
if (!prefixcmp(arg, "--listen=")) {
948
- char *p = arg + 9;
949
- char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
950
- while (*p)
951
- *ph++ = tolower(*p++);
952
- *ph = 0;
953
- continue;
944
+ listen_addr = xstrdup_tolower(arg + 9);
945
+ continue;
946
}
947
if (!prefixcmp(arg, "--port=")) {
948
char *end;