daemon/config: factor out duplicate xstrdup_tolower
We have two implementations of the same function; let's drop that to one. We take the name from daemon.c, but the implementation (which is just slightly more efficient) from the config code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
May 22, 2014 at 05:44 UTC
88d5a6f6cd1b63e1637027322cdfdbeefe38c3ed
4 files changed
+16
-22
builtin/config.c
+1
-14
@@ -396,19 +396,6 @@ static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
396
return 0;
397
}
398
399
-static char *dup_downcase(const char *string)
400
-{
401
- char *result;
402
- size_t len, i;
403
-
404
- len = strlen(string);
405
- result = xmalloc(len + 1);
406
- for (i = 0; i < len; i++)
407
- result[i] = tolower(string[i]);
408
- result[i] = '\0';
409
- return result;
410
-}
411
-
399
static int get_urlmatch(const char *var, const char *url)
400
{
401
char *section_tail;
@@ -423,7 +410,7 @@ static int get_urlmatch(const char *var, const char *url)
410
if (!url_normalize(url, &config.url))
411
die("%s", config.url.err);
412
426
- config.section = dup_downcase(var);
413
+ config.section = xstrdup_tolower(var);
414
section_tail = strchr(config.section, '.');
415
if (section_tail) {
416
*section_tail = '\0';
daemon.c
-8
@@ -475,14 +475,6 @@ static void make_service_overridable(const char *name, int ena)
475
die("No such service %s", name);
476
}
477
478
-static char *xstrdup_tolower(const char *str)
479
-{
480
- char *p, *dup = xstrdup(str);
481
- for (p = dup; *p; p++)
482
- *p = tolower(*p);
483
- return dup;
484
-}
485
-
478
static void parse_host_and_port(char *hostport, char **host,
479
char **port)
480
{
strbuf.c
+13
@@ -570,3 +570,16 @@ int fprintf_ln(FILE *fp, const char *fmt, ...)
570
return -1;
571
return ret + 1;
572
}
573
+
574
+char *xstrdup_tolower(const char *string)
575
+{
576
+ char *result;
577
+ size_t len, i;
578
+
579
+ len = strlen(string);
580
+ result = xmalloc(len + 1);
581
+ for (i = 0; i < len; i++)
582
+ result[i] = tolower(string[i]);
583
+ result[i] = '\0';
584
+ return result;
585
+}
strbuf.h
+2
@@ -177,4 +177,6 @@ extern int printf_ln(const char *fmt, ...);
177
__attribute__((format (printf,2,3)))
178
extern int fprintf_ln(FILE *fp, const char *fmt, ...);
179
180
+char *xstrdup_tolower(const char *);
181
+
182
#endif /* STRBUF_H */