1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 00:51:24 +03:00

conf-parser: simplify things a bit by using strextend()

This commit is contained in:
Lennart Poettering 2017-11-08 21:38:51 +01:00
parent 57d6f70019
commit 92b5e60542

View File

@ -186,7 +186,6 @@ static int parse_line(const char* unit,
assert(l); assert(l);
l = strstrip(l); l = strstrip(l);
if (!*l) if (!*l)
return 0; return 0;
@ -319,8 +318,8 @@ int config_parse(const char *unit,
for (;;) { for (;;) {
_cleanup_free_ char *buf = NULL; _cleanup_free_ char *buf = NULL;
char *l, *p, *c = NULL, *e;
bool escaped = false; bool escaped = false;
char *l, *p, *e;
r = read_line(f, LONG_LINE_MAX, &buf); r = read_line(f, LONG_LINE_MAX, &buf);
if (r == 0) if (r == 0)
@ -356,15 +355,13 @@ int config_parse(const char *unit,
return -ENOBUFS; return -ENOBUFS;
} }
c = strappend(continuation, l); if (!strextend(&continuation, l, NULL)) {
if (!c) {
if (warn) if (warn)
log_oom(); log_oom();
return -ENOMEM; return -ENOMEM;
} }
continuation = mfree(continuation); p = continuation;
p = c;
} else } else
p = l; p = l;
@ -378,9 +375,7 @@ int config_parse(const char *unit,
if (escaped) { if (escaped) {
*(e-1) = ' '; *(e-1) = ' ';
if (c) if (!continuation) {
continuation = c;
else {
continuation = strdup(l); continuation = strdup(l);
if (!continuation) { if (!continuation) {
if (warn) if (warn)
@ -405,13 +400,14 @@ int config_parse(const char *unit,
&section_ignored, &section_ignored,
p, p,
userdata); userdata);
free(c);
if (r < 0) { if (r < 0) {
if (warn) if (warn)
log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line); log_warning_errno(r, "%s:%u: Failed to parse file: %m", filename, line);
return r; return r;
} }
continuation = mfree(continuation);
} }
return 0; return 0;