Skip to content

Commit

Permalink
daemon: cleanup: factor out xstrdup_tolower()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
René Scharfe authored and Junio C Hamano committed Dec 27, 2008
1 parent a583971 commit 6720e95
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,14 @@ static void make_service_overridable(const char *name, int ena)
die("No such service %s", name);
}

static char *xstrdup_tolower(const char *str)
{
char *p, *dup = xstrdup(str);
for (p = dup; *p; p++)
*p = tolower(*p);
return dup;
}

/*
* Separate the "extra args" information as supplied by the client connection.
*/
Expand All @@ -405,7 +413,6 @@ static void parse_extra_args(char *extra_args, int buflen)
char *val;
int vallen;
char *end = extra_args + buflen;
char *hp;

while (extra_args < end && *extra_args) {
saw_extended_args = 1;
Expand All @@ -423,28 +430,19 @@ static void parse_extra_args(char *extra_args, int buflen)
tcp_port = xstrdup(port);
}
free(hostname);
hostname = xstrdup(host);
hostname = xstrdup_tolower(host);
}

/* On to the next one */
extra_args = val + vallen;
}
}

/*
* Replace literal host with lowercase-ized hostname.
*/
hp = hostname;
if (!hp)
return;
for ( ; *hp; hp++)
*hp = tolower(*hp);

/*
* Locate canonical hostname and its IP address.
*/
if (hostname) {
#ifndef NO_IPV6
{
struct addrinfo hints;
struct addrinfo *ai, *ai0;
int gai;
Expand All @@ -468,9 +466,7 @@ static void parse_extra_args(char *extra_args, int buflen)
}
freeaddrinfo(ai0);
}
}
#else
{
struct hostent *hent;
struct sockaddr_in sa;
char **ap;
Expand All @@ -491,8 +487,8 @@ static void parse_extra_args(char *extra_args, int buflen)
canon_hostname = xstrdup(hent->h_name);
free(ip_address);
ip_address = xstrdup(addrbuf);
}
#endif
}
}


Expand Down Expand Up @@ -945,12 +941,8 @@ int main(int argc, char **argv)
char *arg = argv[i];

if (!prefixcmp(arg, "--listen=")) {
char *p = arg + 9;
char *ph = listen_addr = xmalloc(strlen(arg + 9) + 1);
while (*p)
*ph++ = tolower(*p++);
*ph = 0;
continue;
listen_addr = xstrdup_tolower(arg + 9);
continue;
}
if (!prefixcmp(arg, "--port=")) {
char *end;
Expand Down

0 comments on commit 6720e95

Please sign in to comment.