From: Lennart Poettering Date: Wed, 8 Nov 2017 20:38:51 +0000 (+0100) Subject: conf-parser: simplify things a bit by using strextend() X-Git-Tag: v236~226^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=92b5e6054254b1d6cf7fcb342720fe58a58d0d7e;p=thirdparty%2Fsystemd.git conf-parser: simplify things a bit by using strextend() --- diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index c304ae33349..d1c73b6f2dd 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -186,7 +186,6 @@ static int parse_line(const char* unit, assert(l); l = strstrip(l); - if (!*l) return 0; @@ -319,8 +318,8 @@ int config_parse(const char *unit, for (;;) { _cleanup_free_ char *buf = NULL; - char *l, *p, *c = NULL, *e; bool escaped = false; + char *l, *p, *e; r = read_line(f, LONG_LINE_MAX, &buf); if (r == 0) @@ -356,15 +355,13 @@ int config_parse(const char *unit, return -ENOBUFS; } - c = strappend(continuation, l); - if (!c) { + if (!strextend(&continuation, l, NULL)) { if (warn) log_oom(); return -ENOMEM; } - continuation = mfree(continuation); - p = c; + p = continuation; } else p = l; @@ -378,9 +375,7 @@ int config_parse(const char *unit, if (escaped) { *(e-1) = ' '; - if (c) - continuation = c; - else { + if (!continuation) { continuation = strdup(l); if (!continuation) { if (warn) @@ -405,13 +400,14 @@ int config_parse(const char *unit, §ion_ignored, p, userdata); - free(c); - if (r < 0) { if (warn) log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line); return r; + } + + continuation = mfree(continuation); } return 0;