fileio: initialize errno to zero before we do fread()

if there was something in the read buffer already errno might not be set
on error, let's detect that case.
This commit is contained in:
Lennart Poettering
2017-09-22 21:05:03 +02:00
parent ff0e7e05c9
commit 5a89faf0e0
+2 -1
View File
@@ -287,12 +287,13 @@ int read_full_stream(FILE *f, char **contents, size_t *size) {
return -ENOMEM;
buf = t;
errno = 0;
k = fread(buf + l, 1, n - l, f);
if (k > 0)
l += k;
if (ferror(f))
return -errno;
return errno > 0 ? -errno : -EIO;
if (feof(f))
break;