From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 2/2] libfile: Do not return 0 from write_full()
Date: Mon, 27 May 2019 22:58:53 -0700 [thread overview]
Message-ID: <20190528055853.4863-2-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20190528055853.4863-1-andrew.smirnov@gmail.com>
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>
---
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
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2019-05-28 5:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-28 5:58 [PATCH 1/2] libfile: Simplify read_full() Andrey Smirnov
2019-05-28 5:58 ` Andrey Smirnov [this message]
2019-05-28 8:17 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190528055853.4863-2-andrew.smirnov@gmail.com \
--to=andrew.smirnov@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox