summaryrefslogtreecommitdiffstats
path: root/src/locale
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-10-16 18:01:00 +0200
committerLennart Poettering <lennart@poettering.net>2023-10-17 14:36:54 +0200
commit0ff6ff2b29dfb02a803515fb0160d9963d2389d5 (patch)
tree378b5d42024534e03b59fb67034e5f95d3e62e69 /src/locale
parentfileio: add read_stripped_line() as trivial read_line() + strstrip() combo (diff)
downloadsystemd-0ff6ff2b29dfb02a803515fb0160d9963d2389d5.tar.xz
systemd-0ff6ff2b29dfb02a803515fb0160d9963d2389d5.zip
tree-wide: port various parsers over to read_stripped_line()
Diffstat (limited to 'src/locale')
-rw-r--r--src/locale/localectl.c23
-rw-r--r--src/locale/localed-util.c30
2 files changed, 22 insertions, 31 deletions
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index d8db9d9d22..32354027f1 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -314,27 +314,25 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
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;
@@ -345,7 +343,7 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
if (state != look_for)
continue;
- w = l + strcspn(l, WHITESPACE);
+ w = line + strcspn(line, WHITESPACE);
if (argc > 1) {
char *e;
@@ -368,8 +366,7 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
} else
*w = 0;
- r = strv_extend(&list, l);
- if (r < 0)
+ if (strv_consume(&list, TAKE_PTR(line)) < 0)
return log_oom();
}
diff --git a/src/locale/localed-util.c b/src/locale/localed-util.c
index 9b6949e14d..d78b878cf9 100644
--- a/src/locale/localed-util.c
+++ b/src/locale/localed-util.c
@@ -434,22 +434,20 @@ int x11_read_data(Context *c, sd_bus_message *m) {
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;
@@ -469,17 +467,17 @@ int x11_read_data(Context *c, sd_bus_message *m) {
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;
}
@@ -618,10 +616,9 @@ static int read_next_mapping(
_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)
@@ -629,11 +626,10 @@ static int read_next_mapping(
(*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;
@@ -1008,16 +1004,14 @@ static int locale_gen_locale_supported(const char *locale_entry) {
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;
}
}