diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-03-03 21:53:19 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-03-03 21:53:19 +0100 |
commit | 8f2665a463ffb2b822c1e3effdb292d2bddf72be (patch) | |
tree | 6036e78491cefbbca2a41bc67f906d3f5aa0d6fc /src/shared/conf-parser.c | |
parent | 3b43629240c82bf270542dc3ea13868980b30f07 (diff) |
conf-parser: minor optimization in config_parse_string()
Diffstat (limited to 'src/shared/conf-parser.c')
-rw-r--r-- | src/shared/conf-parser.c | 70 |
1 files changed, 34 insertions, 36 deletions
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 1ad2b4fcba..86435d3bde 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -565,57 +565,55 @@ int config_parse_bool(const char* unit, return 0; } -int config_parse_string(const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - char **s = data; - char *n; +int config_parse_string( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + char **s = data, *n; assert(filename); assert(lvalue); assert(rvalue); assert(data); - n = strdup(rvalue); - if (!n) - return log_oom(); - - if (!utf8_is_valid(n)) { - log_syntax(unit, LOG_ERR, filename, line, EINVAL, - "String is not UTF-8 clean, ignoring assignment: %s", rvalue); - free(n); + if (!utf8_is_valid(rvalue)) { + log_syntax(unit, LOG_ERR, filename, line, EINVAL, "String is not UTF-8 clean, ignoring assignment: %s", rvalue); return 0; } - free(*s); - if (*n) - *s = n; + if (isempty(rvalue)) + n = NULL; else { - free(n); - *s = NULL; + n = strdup(rvalue); + if (!n) + return log_oom(); } + free(*s); + *s = n; + return 0; } -int config_parse_path(const char *unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { +int config_parse_path( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { char **s = data, *n; |