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 <[email protected]>
---
 lib/libfile.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index 814cd9c2c..b42753c2b 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;
-- 
2.21.0


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Reply via email to