summaryrefslogtreecommitdiff
path: root/tools/firmware-utils/src
diff options
context:
space:
mode:
authornbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2008-09-23 16:12:40 +0000
committernbd <nbd@3c298f89-4303-0410-b956-a3cf2f4a3e73>2008-09-23 16:12:40 +0000
commit1e232a2ad2d353f7d125b9e993cd8f6152900937 (patch)
tree09b12c533c55b8a667b08101a98477c33429186a /tools/firmware-utils/src
parentafb3c4be87e4be8e77f30070167eccd28b50cd79 (diff)
firmware-utils: when using open with O_CREAT and O_WRONLY, also use O_TRUNC to ensure that overwritten files have the right size (fixes #3505)
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@12667 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'tools/firmware-utils/src')
-rw-r--r--tools/firmware-utils/src/add_header.c2
-rw-r--r--tools/firmware-utils/src/motorola-bin.c4
-rw-r--r--tools/firmware-utils/src/ptgen.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/tools/firmware-utils/src/add_header.c b/tools/firmware-utils/src/add_header.c
index 946068c392..37775c3e0c 100644
--- a/tools/firmware-utils/src/add_header.c
+++ b/tools/firmware-utils/src/add_header.c
@@ -122,7 +122,7 @@ int main(int argc, char **argv)
memcpy(buf, &header, sizeof(header));
// write the buf
- if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0
+ if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0
|| write(fd, buf, buflen) != buflen
|| close(fd) < 0)
{
diff --git a/tools/firmware-utils/src/motorola-bin.c b/tools/firmware-utils/src/motorola-bin.c
index 680249c007..58563add32 100644
--- a/tools/firmware-utils/src/motorola-bin.c
+++ b/tools/firmware-utils/src/motorola-bin.c
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
exit(3);
} else {
// all is well, write the file without the prefix
- if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0
+ if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0
|| write(fd, trx + sizeof(struct motorola), len - sizeof(struct motorola)) != len - sizeof(struct motorola)
|| close(fd) < 0)
{
@@ -211,7 +211,7 @@ int main(int argc, char **argv)
firmware->crc = htonl(crc32buf((unsigned char *)&firmware->flags, sizeof(firmware->flags) + len));
// write the firmware
- if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0
+ if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0
|| write(fd, firmware, sizeof(struct motorola) + len) != sizeof(struct motorola) + len
|| close(fd) < 0)
{
diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
index 8733e252cb..d94aabb5fc 100644
--- a/tools/firmware-utils/src/ptgen.c
+++ b/tools/firmware-utils/src/ptgen.c
@@ -143,7 +143,7 @@ static int gen_ptable(int nr)
printf("%ld\n", ((long) len * 512));
}
- if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
+ if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) {
fprintf(stderr, "Can't open output file '%s'\n",filename);
return -1;
}