summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2019-08-22 08:54:06 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-08-30 09:26:07 +0200
commitaba7cdb357e3d442359c29f7caefc49464bfd812 (patch)
treee8a524cac9c3a0303c5cacfaf8687254083b208c /lib
parentf32a61b9714f0da07c49d2ead8b10a79e1ddf9c0 (diff)
downloadbarebox-aba7cdb357e3d442359c29f7caefc49464bfd812.tar.gz
barebox-aba7cdb357e3d442359c29f7caefc49464bfd812.tar.xz
libfile: have write_full return a descriptive error code
So far (p|)write_full has been returning -1 on error. Some callers of write_full like imx_bbu_write_device print out the function's return value on error, effectively rendering every printed error message to be due to EPERM. On the other hand, some callers like do_memcpy, use it correctly and use errno. Sidestep the issue by having the function return -errno on errors as well. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/libfile.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index b42753c2b5..f6c588d737 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -38,7 +38,7 @@ int pwrite_full(int fd, const void *buf, size_t size, loff_t offset)
now = pwrite(fd, buf, size, offset);
if (now == 0) {
errno = ENOSPC;
- return -1;
+ return -errno;
}
if (now < 0)
return now;
@@ -66,7 +66,7 @@ int write_full(int fd, const void *buf, size_t size)
now = write(fd, buf, size);
if (now == 0) {
errno = ENOSPC;
- return -1;
+ return -errno;
}
if (now < 0)
return now;
@@ -194,6 +194,7 @@ again:
buf = calloc(read_size + 1, 1);
if (!buf) {
ret = -ENOMEM;
+ errno = ENOMEM;
goto err_out;
}