diff options
author | Steffen Trumtrar <s.trumtrar@pengutronix.de> | 2020-05-04 10:35:41 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-05-05 07:55:47 +0200 |
commit | 8a92fae86eb261ee9349a5d148d5c9d865c91177 (patch) | |
tree | 48d87d4c4a3fecb4a365db770c913502e63c9ba0 /scripts | |
parent | f62bb30044dbad752bf0414239f793585d66960c (diff) | |
download | barebox-8a92fae86eb261ee9349a5d148d5c9d865c91177.tar.gz barebox-8a92fae86eb261ee9349a5d148d5c9d865c91177.tar.xz |
scripts: bareboximd: fix write_file error handling
write will never return 0 on POSIX conformant systems. Remove this error
path.
Also, close the file on error.
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/bareboximd.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c index d11b661fa3..48c3e8ab3f 100644 --- a/scripts/bareboximd.c +++ b/scripts/bareboximd.c @@ -53,7 +53,7 @@ int imd_command_setenv(const char *variable_name, const char *value) static int write_file(const char *filename, const void *buf, size_t size) { - int fd; + int fd, ret = 0; int now; fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); @@ -62,19 +62,18 @@ static int write_file(const char *filename, const void *buf, size_t size) while (size) { now = write(fd, buf, size); - if (now == 0) { - errno = ENOSPC; - return -1; + if (now < 0) { + ret = now; + goto out; } - if (now < 0) - return now; size -= now; buf += now; } +out: close(fd); - return 0; + return ret; } static int read_file_2(const char *filename, size_t *size, void **outbuf, size_t max_size) |