_cleanup_free_ char *line = NULL;
char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
- l = strstrip(line);
-
- if (startswith(l, field)) {
- l += strlen(field);
+ l = startswith(line, field);
+ if (l) {
l += strspn(l, WHITESPACE);
l[strcspn(l, WHITESPACE)] = 0;
log_debug("Applying %s%s", pp, special_glyph(SPECIAL_GLYPH_ELLIPSIS));
for (unsigned line = 1;; line++) {
_cleanup_free_ char *text = NULL;
- char *p;
int k;
- k = read_line(f, LONG_LINE_MAX, &text);
+ k = read_stripped_line(f, LONG_LINE_MAX, &text);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;
- p = strstrip(text);
- if (isempty(p))
+ if (isempty(text))
continue;
- if (strchr(COMMENTS, p[0]))
+ if (strchr(COMMENTS, text[0]))
continue;
- RET_GATHER(r, apply_rule(filename, line, p));
+ RET_GATHER(r, apply_rule(filename, line, text));
}
return r;
uint64_t k, *q;
char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
- /* Trim and skip the device */
- l = strstrip(line);
- l += strcspn(l, WHITESPACE);
+ /* Skip the device */
+ l = line + strcspn(line, WHITESPACE);
l += strspn(l, WHITESPACE);
if (all_unified) {
}
static int manager_deserialize_units(Manager *m, FILE *f, FDSet *fds) {
- const char *unit_name;
int r;
for (;;) {
_cleanup_free_ char *line = NULL;
+
/* Start marker */
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0)
break;
- unit_name = strstrip(line);
-
- r = manager_deserialize_one_unit(m, unit_name, f, fds);
+ r = manager_deserialize_one_unit(m, line, f, fds);
if (r == -ENOMEM)
return r;
if (r < 0) {
int unit_deserialize_state_skip(FILE *f) {
int r;
+
assert(f);
/* Skip serialized data for this unit. We don't know what it is. */
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0)
return 0;
- l = strstrip(line);
-
/* End marker */
- if (isempty(l))
+ if (isempty(line))
return 1;
}
}
_cleanup_free_ char *line = NULL, *name = NULL, *device = NULL, *keyspec = NULL, *options = NULL,
*keyfile = NULL, *keydev = NULL, *headerdev = NULL, *filtered_header = NULL;
crypto_device *d = NULL;
- char *l, *uuid;
+ char *uuid;
int k;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_crypttab);
if (r == 0)
crypttab_line++;
- l = strstrip(line);
- if (IN_SET(l[0], 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- k = sscanf(l, "%ms %ms %ms %ms", &name, &device, &keyspec, &options);
+ k = sscanf(line, "%ms %ms %ms %ms", &name, &device, &keyspec, &options);
if (k < 2 || k > 4) {
log_error("Failed to parse %s:%u, ignoring.", arg_crypttab, crypttab_line);
continue;
for (;;) {
_cleanup_free_ char *tty = NULL;
- char *s;
- r = read_line(f, PATH_MAX, &tty);
+ r = read_stripped_line(f, PATH_MAX, &tty);
if (r == 0)
break;
if (r < 0) {
break;
}
- s = strstrip(tty);
- if (startswith(s, "#"))
+ if (startswith(tty, "#"))
continue;
- r = t->func(s);
+ r = t->func(tty);
if (r < 0)
return r;
}
for (;;) {
_cleanup_free_ char *line = NULL, *name = NULL, *device_id = NULL, *device_path = NULL, *key_file = NULL, *options = NULL;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_integritytab);
if (r == 0)
integritytab_line++;
- l = strstrip(line);
- if (!l)
- continue;
-
- if (IN_SET(l[0], 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
/* The key file and the options are optional */
- r = sscanf(l, "%ms %ms %ms %ms", &name, &device_id, &key_file, &options);
+ r = sscanf(line, "%ms %ms %ms %ms", &name, &device_id, &key_file, &options);
if (!IN_SET(r, 2, 3, 4)) {
- log_error("Failed to parse %s:%u, ignoring.", l, integritytab_line);
+ log_error("Failed to parse %s:%u, ignoring.", arg_integritytab, integritytab_line);
continue;
}
_cleanup_free_ char *b = NULL;
_cleanup_free_ const char *fn = NULL;
const char *c = NULL;
- size_t n;
int r;
assert(field);
return -errno;
}
- /* This is an awful parse, but it follows closely what
- * xdg-user-dirs does upstream */
-
- n = strlen(field);
+ /* This is an awful parse, but it follows closely what xdg-user-dirs does upstream */
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l, *p, *e;
+ char *p, *e;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
- l = strstrip(line);
-
- if (!strneq(l, field, n))
+ p = startswith(line, field);
+ if (!p)
continue;
- p = l + n;
p += strspn(p, WHITESPACE);
if (*p != '=')
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l, *w;
+ char *w;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read keyboard mapping list: %m");
if (r == 0)
break;
- l = strstrip(line);
-
- if (isempty(l))
+ if (isempty(line))
continue;
- if (l[0] == '!') {
- if (startswith(l, "! model"))
+ if (line[0] == '!') {
+ if (startswith(line, "! model"))
state = MODELS;
- else if (startswith(l, "! layout"))
+ else if (startswith(line, "! layout"))
state = LAYOUTS;
- else if (startswith(l, "! variant"))
+ else if (startswith(line, "! variant"))
state = VARIANTS;
- else if (startswith(l, "! option"))
+ else if (startswith(line, "! option"))
state = OPTIONS;
else
state = NONE;
if (state != look_for)
continue;
- w = l + strcspn(l, WHITESPACE);
+ w = line + strcspn(line, WHITESPACE);
if (argc > 1) {
char *e;
} else
*w = 0;
- r = strv_extend(&list, l);
- if (r < 0)
+ if (strv_consume(&list, TAKE_PTR(line)) < 0)
return log_oom();
}
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
- l = strstrip(line);
- if (IN_SET(l[0], 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- if (in_section && first_word(l, "Option")) {
+ if (in_section && first_word(line, "Option")) {
_cleanup_strv_free_ char **a = NULL;
- r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
+ r = strv_split_full(&a, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return r;
free_and_replace(*p, a[2]);
}
- } else if (!in_section && first_word(l, "Section")) {
+ } else if (!in_section && first_word(line, "Section")) {
_cleanup_strv_free_ char **a = NULL;
- r = strv_split_full(&a, l, WHITESPACE, EXTRACT_UNQUOTE);
+ r = strv_split_full(&a, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return -ENOMEM;
if (strv_length(a) == 2 && streq(a[1], "InputClass"))
in_section = true;
- } else if (in_section && first_word(l, "EndSection"))
+ } else if (in_section && first_word(line, "EndSection"))
in_section = false;
}
_cleanup_strv_free_ char **b = NULL;
_cleanup_free_ char *line = NULL;
size_t length;
- const char *l;
int r;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
(*n)++;
- l = strstrip(line);
- if (IN_SET(l[0], 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- r = strv_split_full(&b, l, WHITESPACE, EXTRACT_UNQUOTE);
+ r = strv_split_full(&b, line, WHITESPACE, EXTRACT_UNQUOTE);
if (r < 0)
return r;
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_debug_errno(r, "Failed to read /usr/share/i18n/SUPPORTED: %m");
if (r == 0)
return 0;
- l = strstrip(line);
- if (strcaseeq_ptr(l, locale_entry))
+ if (strcaseeq_ptr(line, locale_entry))
return 1;
}
}
log_debug("apply: %s", pp);
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
int k;
- k = read_line(f, LONG_LINE_MAX, &line);
+ k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;
- l = strstrip(line);
- if (isempty(l))
+ if (isempty(line))
continue;
- if (strchr(COMMENTS, *l))
+ if (strchr(COMMENTS, *line))
continue;
- k = module_load_and_warn(ctx, l, true);
+ k = module_load_and_warn(ctx, line, true);
if (k == -ENOENT)
continue;
RET_GATHER(r, k);
for (;;) {
_cleanup_free_ char *line = NULL;
const char *a;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read " PRIVATE_UPLINK_RESOLV_CONF ": %m");
if (r == 0)
break;
- l = strstrip(line);
- if (IN_SET(*l, '#', ';', 0))
+ if (IN_SET(*line, '#', ';', 0))
continue;
- a = first_word(l, "nameserver");
+ a = first_word(line, "nameserver");
if (!a)
continue;
for (;;) {
_cleanup_free_ char *line = NULL;
- const char *a, *l;
+ const char *a;
- r = read_line(stdin, LONG_LINE_MAX, &line);
+ r = read_stripped_line(stdin, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read from stdin: %m");
if (r == 0)
n++;
- l = strstrip(line);
- if (IN_SET(*l, '#', ';', 0))
+ if (IN_SET(*line, '#', ';', 0))
continue;
- a = first_word(l, "nameserver");
+ a = first_word(line, "nameserver");
if (a) {
(void) parse_nameserver(a);
continue;
}
- a = first_word(l, "domain");
+ a = first_word(line, "domain");
if (!a)
- a = first_word(l, "search");
+ a = first_word(line, "search");
if (a) {
(void) parse_search_domain(a);
continue;
}
- log_syntax(NULL, LOG_DEBUG, "stdin", n, 0, "Ignoring resolv.conf line: %s", l);
+ log_syntax(NULL, LOG_DEBUG, "stdin", n, 0, "Ignoring resolv.conf line: %s", line);
}
if (type == TYPE_EXCLUSIVE) {
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
- r = read_line(g, LONG_LINE_MAX, &line);
+ r = read_stripped_line(g, LONG_LINE_MAX, &line);
if (r < 0) {
log_warning_errno(r, "Failed to read '%s', ignoring: %m", *f);
break;
n++;
- l = strstrip(line);
- if (isempty(l))
+ if (isempty(line))
continue;
- if (*l == ';')
+ if (*line == ';')
continue;
- (void) loader(d, *f, n, l);
+ (void) loader(d, *f, n, line);
}
}
for (;;) {
_cleanup_free_ char *line = NULL;
const char *a;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0) {
log_error_errno(r, "Failed to read /etc/resolv.conf: %m");
goto clear;
n++;
- l = strstrip(line);
- if (IN_SET(*l, '#', ';', 0))
+ if (IN_SET(*line, '#', ';', 0))
continue;
- a = first_word(l, "nameserver");
+ a = first_word(line, "nameserver");
if (a) {
r = manager_parse_dns_server_string_and_warn(m, DNS_SERVER_SYSTEM, a);
if (r < 0)
continue;
}
- a = first_word(l, "domain");
+ a = first_word(line, "domain");
if (!a) /* We treat "domain" lines, and "search" lines as equivalent, and add both to our list. */
- a = first_word(l, "search");
+ a = first_word(line, "search");
if (a) {
r = manager_parse_search_domains_and_warn(m, a);
if (r < 0)
continue;
}
- log_syntax(NULL, LOG_DEBUG, "/etc/resolv.conf", n, 0, "Ignoring resolv.conf line: %s", l);
+ log_syntax(NULL, LOG_DEBUG, "/etc/resolv.conf", n, 0, "Ignoring resolv.conf line: %s", line);
}
m->resolv_conf_stat = st;
for (;;) {
_cleanup_free_ char *buf = NULL, *field = NULL;
- const char *p;
- r = read_line(f, LONG_LINE_MAX, &buf);
+ r = read_stripped_line(f, LONG_LINE_MAX, &buf);
if (r == 0)
break;
if (r == -ENOBUFS)
line++;
- p = strstrip(buf);
- if (IN_SET(p[0], '#', '\0'))
+ if (IN_SET(buf[0], '#', '\0'))
continue;
+ const char *p = buf;
r = extract_first_word(&p, &field, NULL, 0);
if (r < 0) {
log_syntax(NULL, LOG_WARNING, tmp.path, line, r, "Failed to parse, ignoring line: %m");
for (;;) {
_cleanup_free_ char *buf = NULL, *field = NULL;
- const char *p;
- r = read_line(file, LONG_LINE_MAX, &buf);
+ r = read_stripped_line(file, LONG_LINE_MAX, &buf);
if (r == 0)
break;
if (r == -ENOBUFS)
line++;
- p = strstrip(buf);
- if (IN_SET(p[0], '#', '\0'))
+ if (IN_SET(buf[0], '#', '\0'))
continue;
+ const char *p = buf;
r = extract_first_word(&p, &field, NULL, 0);
if (r < 0) {
log_syntax(NULL, LOG_WARNING, path, line, r, "Failed to parse, ignoring line: %m");
for (;;) {
_cleanup_free_ char *line = NULL;
- char *p;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0) /* EOF without any hostname? the file is empty, let's treat that exactly like no file at all: ENOENT */
return -ENOENT;
- p = strstrip(line);
-
/* File may have empty lines or comments, ignore them */
- if (!IN_SET(*p, '\0', '#')) {
- char *copy;
-
- hostname_cleanup(p); /* normalize the hostname */
+ if (IN_SET(line[0], '\0', '#'))
+ continue;
- if (!hostname_is_valid(p, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
- return -EBADMSG;
+ hostname_cleanup(line); /* normalize the hostname */
- copy = strdup(p);
- if (!copy)
- return -ENOMEM;
+ if (!hostname_is_valid(line, VALID_HOSTNAME_TRAILING_DOT)) /* check that the hostname we return is valid */
+ return -EBADMSG;
- *ret = copy;
- return 0;
- }
+ *ret = TAKE_PTR(line);
+ return 0;
}
}
_cleanup_free_ char *line = NULL;
_cleanup_(unit_file_preset_rule_done) UnitFilePresetRule rule = {};
const char *parameter;
- char *l;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return r;
if (r == 0)
break;
- l = strstrip(line);
n++;
- if (isempty(l))
+ if (isempty(line))
continue;
- if (strchr(COMMENTS, *l))
+ if (strchr(COMMENTS, line[0]))
continue;
- parameter = first_word(l, "enable");
+ parameter = first_word(line, "enable");
if (parameter) {
char *unit_name;
char **instances = NULL;
};
}
- parameter = first_word(l, "disable");
+ parameter = first_word(line, "disable");
if (parameter) {
char *pattern;
};
}
- parameter = first_word(l, "ignore");
+ parameter = first_word(line, "ignore");
if (parameter) {
char *pattern;
assert(f);
assert(ret);
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read serialization line: %m");
if (r == 0) { /* eof */
return 0;
}
- const char *l = strstrip(line);
- if (isempty(l)) { /* End marker */
+ if (isempty(line)) { /* End marker */
*ret = NULL;
return 0;
}
- if (free_and_strdup(&line, l) < 0)
- return log_oom();
-
*ret = TAKE_PTR(line);
return 1;
}
_cleanup_free_ char *l = NULL;
bool ignore_failure = false;
Option *existing;
- char *p, *value;
+ char *value;
int k;
- k = read_line(f, LONG_LINE_MAX, &l);
+ k = read_stripped_line(f, LONG_LINE_MAX, &l);
if (k == 0)
break;
if (k < 0)
c++;
- p = strstrip(l);
-
- if (isempty(p))
+ if (isempty(l))
continue;
- if (strchr(COMMENTS "\n", *p))
+ if (strchr(COMMENTS, l[0]))
continue;
+ char *p = l;
value = strchr(p, '=');
if (value) {
if (p[0] == '-') {
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
int k;
- k = read_line(f, LONG_LINE_MAX, &line);
+ k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read '%s': %m", fn);
if (k == 0)
v++;
- l = strstrip(line);
- if (IN_SET(*l, 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- k = parse_line(c, fn, v, l);
+ k = parse_line(c, fn, v, line);
if (k < 0 && r == 0)
r = k;
}
for (;;) {
_cleanup_free_ char *l = NULL;
- char *t;
- r = read_line(f, LONG_LINE_MAX, &l);
+ r = read_stripped_line(f, LONG_LINE_MAX, &l);
if (r < 0)
return log_error_errno(r, "Failed to read configuration file '%s': %m", s->path);
if (r == 0)
line++;
- t = strstrip(l);
- if (*t != '#') {
+ if (l[0] != '#') {
/* Try to figure out whether this init script supports
* the reload operation. This heuristic looks for
* "Usage" lines which include the reload option. */
if (state == USAGE_CONTINUATION ||
- (state == NORMAL && strcasestr(t, "usage"))) {
- if (usage_contains_reload(t)) {
+ (state == NORMAL && strcasestr(l, "usage"))) {
+ if (usage_contains_reload(l)) {
supports_reload = true;
state = NORMAL;
- } else if (t[strlen(t)-1] == '\\')
+ } else if (endswith(l, "\\"))
state = USAGE_CONTINUATION;
else
state = NORMAL;
continue;
}
- if (state == NORMAL && streq(t, "### BEGIN INIT INFO")) {
+ if (state == NORMAL && streq(l, "### BEGIN INIT INFO")) {
state = LSB;
s->has_lsb = true;
continue;
}
- if (IN_SET(state, LSB_DESCRIPTION, LSB) && streq(t, "### END INIT INFO")) {
+ if (IN_SET(state, LSB_DESCRIPTION, LSB) && streq(l, "### END INIT INFO")) {
state = NORMAL;
continue;
}
- t++;
+ char *t = l + 1;
t += strspn(t, WHITESPACE);
if (state == NORMAL) {
for (;;) {
_cleanup_free_ char *line = NULL;
- const char *word;
- r = read_line(file, LINE_MAX, &line);
+ r = read_stripped_line(file, LINE_MAX, &line);
if (r < 0) {
log_error_errno(r, "Failed to read %s, ignoring: %m", *f);
continue;
if (r == 0)
break;
- word = strstrip(line);
- if (isempty(word) || startswith(word, "#"))
+ if (isempty(line) || startswith(line, "#"))
continue;
- r = context_add_ntp_service(c, word, *f);
+ r = context_add_ntp_service(c, line, *f);
if (r < 0)
- log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", word);
+ log_warning_errno(r, "Failed to add NTP service \"%s\", ignoring: %m", line);
}
}
for (;;) {
_cleanup_free_ char *line = NULL;
bool invalid_line = false;
- char *l;
int k;
- k = read_line(f, LONG_LINE_MAX, &line);
+ k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read '%s': %m", fn);
if (k == 0)
v++;
- l = strstrip(line);
- if (IN_SET(*l, 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- k = parse_line(c, fn, v, l, &invalid_line, &uid_cache, &gid_cache);
+ k = parse_line(c, fn, v, line, &invalid_line, &uid_cache, &gid_cache);
if (k < 0) {
if (invalid_line)
/* Allow reporting with a special code if the caller requested this */
for (;;) {
_cleanup_free_ char *line = NULL, *name = NULL, *data_device = NULL, *hash_device = NULL,
*roothash = NULL, *options = NULL;
- char *l, *data_uuid, *hash_uuid;
+ char *data_uuid, *hash_uuid;
- r = read_line(f, LONG_LINE_MAX, &line);
+ r = read_stripped_line(f, LONG_LINE_MAX, &line);
if (r < 0)
return log_error_errno(r, "Failed to read %s: %m", arg_veritytab);
if (r == 0)
veritytab_line++;
- l = strstrip(line);
- if (IN_SET(l[0], 0, '#'))
+ if (IN_SET(line[0], 0, '#'))
continue;
- r = sscanf(l, "%ms %ms %ms %ms %ms", &name, &data_device, &hash_device, &roothash, &options);
+ r = sscanf(line, "%ms %ms %ms %ms %ms", &name, &data_device, &hash_device, &roothash, &options);
if (!IN_SET(r, 4, 5)) {
log_error("Failed to parse %s:%u, ignoring.", arg_veritytab, veritytab_line);
continue;