summaryrefslogtreecommitdiffstats
path: root/src/basic/fileio.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-03-19 18:29:40 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2024-03-20 15:18:21 +0100
commit94b75cdb06aae1e5fe91f5846dbed5781f8d5ecb (patch)
tree50a2c9d289f5e1a50d70fb638625d4f717bb3255 /src/basic/fileio.c
parentvarious: also use strdup_to() in cases where we don't return immediately (diff)
downloadsystemd-94b75cdb06aae1e5fe91f5846dbed5781f8d5ecb.tar.xz
systemd-94b75cdb06aae1e5fe91f5846dbed5781f8d5ecb.zip
basic/fileio: use strdup_to_full() in read_stripped_line()
The return value of read_stripped_line() is changed. Before we'd return the number of characters read, but that number was not meaningful after we called strstrip(). So just return 0 if nothing was read (EOF), and 1 if something was read (not EOF). All the callers were only checking for <0 or ==0.
Diffstat (limited to 'src/basic/fileio.c')
-rw-r--r--src/basic/fileio.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/basic/fileio.c b/src/basic/fileio.c
index 3aadb4bfab..523378177f 100644
--- a/src/basic/fileio.c
+++ b/src/basic/fileio.c
@@ -1504,7 +1504,7 @@ int read_line_full(FILE *f, size_t limit, ReadLineFlags flags, char **ret) {
int read_stripped_line(FILE *f, size_t limit, char **ret) {
_cleanup_free_ char *s = NULL;
- int r;
+ int r, k;
assert(f);
@@ -1513,23 +1513,17 @@ int read_stripped_line(FILE *f, size_t limit, char **ret) {
return r;
if (ret) {
- const char *p;
-
- p = strstrip(s);
+ const char *p = strstrip(s);
if (p == s)
*ret = TAKE_PTR(s);
else {
- char *copy;
-
- copy = strdup(p);
- if (!copy)
- return -ENOMEM;
-
- *ret = copy;
+ k = strdup_to(ret, p);
+ if (k < 0)
+ return k;
}
}
- return r;
+ return r > 0; /* Return 1 if something was read. */
}
int safe_fgetc(FILE *f, char *ret) {