chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
89f1344
)
util: fix handling of empty files in read_one_line_file()
author
Lennart Poettering
<lennart@poettering.net>
Fri, 10 Feb 2012 23:27:12 +0000
(
00:27
+0100)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 10 Feb 2012 23:27:12 +0000
(
00:27
+0100)
https://bugs.freedesktop.org/show_bug.cgi?id=45362
src/util.c
patch
|
blob
|
history
diff --git
a/src/util.c
b/src/util.c
index 11f77abde14412f50c6032d56c3616e2444a103d..33299229bfb4926bf9a2c795689baa2beeb9da79 100644
(file)
--- 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;
}