strcpy(newfile, file);
strcat(newfile, ".patched");
- printf("Writing %s\n", newfile);
- if ((fd = open(newfile, O_WRONLY|O_CREAT, 0644)) == -1) {
- fprintf(stderr,"%s: ", newfile);
- perror("open");
- exit(1);
- }
-
- remaining = statbuf.st_size;
-
- while(remaining) {
- if ((ret = write(fd, fw + (statbuf.st_size - remaining), remaining)) == -1) {
- perror("write");
- exit(1);
- }
- remaining -= ret;
- }
- close(fd);
+ printf("Firmware ");
+ write_file(newfile, fw, statbuf.st_size);
} else {
fprintf(stderr,"Can't set correct checksum, aborting...\n");
}