Changeset 12667


Ignore:
Timestamp:
2008-09-23T18:12:40+02:00 (8 years ago)
Author:
nbd
Message:

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)

Location:
trunk/tools/firmware-utils/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/firmware-utils/src/add_header.c

    r11588 r12667  
    123123 
    124124        // write the buf 
    125         if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0 
     125        if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0 
    126126        || write(fd, buf, buflen) != buflen 
    127127        || close(fd) < 0) 
  • trunk/tools/firmware-utils/src/motorola-bin.c

    r9434 r12667  
    171171                } else { 
    172172                        // all is well, write the file without the prefix 
    173                         if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0 
     173                        if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0 
    174174                        || write(fd, trx + sizeof(struct motorola), len - sizeof(struct motorola)) !=  len - sizeof(struct motorola) 
    175175                        || close(fd) < 0) 
     
    212212 
    213213                // write the firmware 
    214                 if ((fd = open(argv[3], O_CREAT|O_WRONLY,0644)) < 0 
     214                if ((fd = open(argv[3], O_CREAT|O_WRONLY|O_TRUNC,0644)) < 0 
    215215                || write(fd, firmware, sizeof(struct motorola) + len) != sizeof(struct motorola) + len 
    216216                || close(fd) < 0) 
  • trunk/tools/firmware-utils/src/ptgen.c

    r7312 r12667  
    144144        } 
    145145 
    146         if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) { 
     146        if ((fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0644)) < 0) { 
    147147                fprintf(stderr, "Can't open output file '%s'\n",filename); 
    148148                return -1; 
Note: See TracChangeset for help on using the changeset viewer.