diff --git a/scripts/bareboximd.c b/scripts/bareboximd.c index d11b661..48c3e8a 100644 --- a/scripts/bareboximd.c +++ b/scripts/bareboximd.c @@ -53,7 +53,7 @@ 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 @@ 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)