diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-02-11 00:27:12 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-02-11 00:27:12 +0100 |
commit | 4099a281bb1e7bbb941c55de559dbfb9abf5897b (patch) | |
tree | 99e2094881e6e0f115f164b0d4a7dbec5172286c /src | |
parent | 89f134406af6a4b4c7493f624a89dcd654b48e81 (diff) |
util: fix handling of empty files in read_one_line_file()
https://bugs.freedesktop.org/show_bug.cgi?id=45362
Diffstat (limited to 'src')
-rw-r--r-- | src/util.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/util.c b/src/util.c index 11f77abde1..33299229bf 100644 --- a/src/util.c +++ b/src/util.c @@ -705,15 +705,22 @@ int read_one_line_file(const char *fn, char **line) { assert(fn); assert(line); - if (!(f = fopen(fn, "re"))) + f = fopen(fn, "re"); + if (!f) return -errno; - if (!(fgets(t, sizeof(t), f))) { - r = feof(f) ? -EIO : -errno; - goto finish; + if (!fgets(t, sizeof(t), f)) { + + if (ferror(f)) { + r = -errno; + goto finish; + } + + t[0] = 0; } - if (!(c = strdup(t))) { + c = strdup(t); + if (!c) { r = -ENOMEM; goto finish; } |