diff options
author | Andrey Smirnov <andrew.smirnov@gmail.com> | 2019-05-27 22:58:53 -0700 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-05-28 10:17:02 +0200 |
commit | 8f945131a18e68121f6e7ea4c12992a5eb108466 (patch) | |
tree | 4b3c2d72d5ce14da5ba7bb56ed5c07714ee5b01f /lib | |
parent | 6ce2ee8ce47afb21aaaa8cfee4fca744ebf520a9 (diff) | |
download | barebox-8f945131a18e68121f6e7ea4c12992a5eb108466.tar.gz barebox-8f945131a18e68121f6e7ea4c12992a5eb108466.tar.xz |
libfile: Do not return 0 from write_full()
None of the callers of write_full() expect a zero return value. Given
how the documentation explicitly states that either all of the buffer
is going to be written out or an error generated, treat 0 retrun from
write() as a error, set errno to ENOSPC and return -1.
Same logic applies to pwrite_full() as well, so make the change there
while at it.
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfile.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libfile.c b/lib/libfile.c index 814cd9c2cd..b42753c2b5 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -36,7 +36,11 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset) while (size) { now = pwrite(fd, buf, size, offset); - if (now <= 0) + if (now == 0) { + errno = ENOSPC; + return -1; + } + if (now < 0) return now; size -= now; buf += now; @@ -60,7 +64,11 @@ int write_full(int fd, const void *buf, size_t size) while (size) { now = write(fd, buf, size); - if (now <= 0) + if (now == 0) { + errno = ENOSPC; + return -1; + } + if (now < 0) return now; size -= now; buf += now; |