firmware-utils: when using open with O_CREAT and O_WRONLY, also use O_TRUNC to ensure...
authorFelix Fietkau <nbd@openwrt.org>
Tue, 23 Sep 2008 16:12:40 +0000 (16:12 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 23 Sep 2008 16:12:40 +0000 (16:12 +0000)
SVN-Revision: 12667

src/add_header.c
src/motorola-bin.c
src/ptgen.c

index 946068c392a7f17670dcaabe1ce38f18af43fef4..37775c3e0c73cfcd3fc60ad4453d5b430d4aa6e3 100644 (file)
@@ -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)
        {
index 680249c0072c5f7ca4348a7c57716abdea8dabe2..58563add3290652f6e0d58dfdac5e13504d98ead 100644 (file)
@@ -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)
                {
index 8733e252cb785610015ae2b227196662e9700dd0..d94aabb5fcf139bb47ced1a534c9decd8b906688 100644 (file)
@@ -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;
        }