diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-11 10:42:30 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-02-11 11:47:08 +0100 |
commit | eea304f8a561a10e1d6aab66eb4562cc3616393c (patch) | |
tree | dc94dc33c2295eb5a965d53e5c421624f877c28f | |
parent | 013e8ea757f50b502efa56fff00d7321a4745f50 (diff) | |
download | barebox-eea304f8a561a10e1d6aab66eb4562cc3616393c.tar.gz barebox-eea304f8a561a10e1d6aab66eb4562cc3616393c.tar.xz |
Revert "scripts/common: fix write_file when opened with mmap"
mmap() is no longer used in read_file_2(), so this patch is no longer
necessary.
This reverts commit 738601e1258c55953284ee10801b26b9977918c2.
Link: https://lore.barebox.org/20220211094230.1807262-3-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | scripts/common.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/scripts/common.c b/scripts/common.c index 3d07be3630..2be41615ea 100644 --- a/scripts/common.c +++ b/scripts/common.c @@ -102,33 +102,26 @@ int write_file(const char *filename, const void *buf, size_t size) { int fd, ret = 0; int now; - size_t left = size; - /* The same file may be mmapped currently, so can't use O_TRUNC here */ - fd = open(filename, O_WRONLY | O_CREAT, + fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) { fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno)); return -errno; } - while (left) { - now = write(fd, buf, left); + while (size) { + now = write(fd, buf, size); if (now < 0) { fprintf(stderr, "Cannot write to %s: %s\n", filename, strerror(errno)); ret = -errno; goto out; } - left -= now; + size -= now; buf += now; } - if (ftruncate(fd, size) < 0) { - fprintf(stderr, "Cannot truncate file: %s", strerror(errno)); - ret = -errno; - } - out: close(fd); |