]> git.zerfleddert.de Git - rsbs2/commitdiff
use unified write_file function everywhere...
authorMichael Gernoth <michael@gernoth.net>
Wed, 4 Feb 2009 22:55:49 +0000 (23:55 +0100)
committerMichael Gernoth <michael@gernoth.net>
Wed, 4 Feb 2009 22:55:49 +0000 (23:55 +0100)
filesystem.c
filesystem.h
firmware.c
rsb-lz.c

index 175cbc4d0670479af52999da0c800f3c69d4b24b..d4b207e7b8b5cca78e86a9c82f6b72dc83ec48e0 100644 (file)
@@ -86,11 +86,11 @@ void extract_files(unsigned char *fw, int len)
        fent = get_next_file(fw, len);
        
        while (fent) {
        fent = get_next_file(fw, len);
        
        while (fent) {
-               printf("%s: unknown: 0x%02x, length: %d",
+               printf("%s: unknown: 0x%02x, length: %d",
                        fent->name, fent->unknown, fent->length);
 
                if (fent->length > 0) {
                        fent->name, fent->unknown, fent->length);
 
                if (fent->length > 0) {
-                       write_file(fent->name, fent->start, fent->length);
+                       write_file(extracted_file(fent->name), fent->start, fent->length);
                        if (*((unsigned int*)fent->start) == LZ_MAGIC) {
                                char *lzname;
 
                        if (*((unsigned int*)fent->start) == LZ_MAGIC) {
                                char *lzname;
 
@@ -105,7 +105,7 @@ void extract_files(unsigned char *fw, int len)
                                }
                                lzname[strlen(lzname) - 3] = 0x00;
 
                                }
                                lzname[strlen(lzname) - 3] = 0x00;
 
-                               printf("%s: packed file found", lzname);
+                               printf("%s: packed file found", lzname);
 
                                extract_lz_file(fent->start, (unsigned char*)lzname, 0);
                                free(lzname);
 
                                extract_lz_file(fent->start, (unsigned char*)lzname, 0);
                                free(lzname);
@@ -120,7 +120,7 @@ void extract_files(unsigned char *fw, int len)
                                memcpy(lzname + strlen(lzname), lzpos - 4, 4);
                                lzpos += 4;
                                if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
                                memcpy(lzname + strlen(lzname), lzpos - 4, 4);
                                lzpos += 4;
                                if (*((unsigned int*)(lzpos)) == LZ_MAGIC) {
-                                       printf("%s: compressed firmware part found", lzname);
+                                       printf("%s: compressed firmware part found", lzname);
                                        extract_lz_file(lzpos, (unsigned char*)lzname, 1);
                                }
                        }
                                        extract_lz_file(lzpos, (unsigned char*)lzname, 1);
                                }
                        }
@@ -174,16 +174,12 @@ void mkdir_p(char *dir)
 
 void write_file(char *fname, unsigned char *buf, int len)
 {
 
 void write_file(char *fname, unsigned char *buf, int len)
 {
-       char filename[PATH_MAX];
        char *filename_c, *dirn;
        int fd;
        int remaining;
        int ret;
 
        char *filename_c, *dirn;
        int fd;
        int remaining;
        int ret;
 
-       strcpy(filename, "extracted/");
-       strcat(filename, fname);
-
-       if ((filename_c = strdup(filename)) == NULL) {
+       if ((filename_c = strdup(fname)) == NULL) {
                perror("strdup");
                exit(1);
        }
                perror("strdup");
                exit(1);
        }
@@ -191,8 +187,8 @@ void write_file(char *fname, unsigned char *buf, int len)
        mkdir_p(dirn);
        free(filename_c);
 
        mkdir_p(dirn);
        free(filename_c);
 
-       if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) == -1) {
-               fprintf(stderr, "%s: ", filename);
+       if ((fd = open(fname, O_WRONLY|O_CREAT, 0644)) == -1) {
+               fprintf(stderr, "%s: ", fname);
                perror("open");
                exit(1);
        }
                perror("open");
                exit(1);
        }
@@ -208,7 +204,17 @@ void write_file(char *fname, unsigned char *buf, int len)
                remaining -= ret;
        }
 
                remaining -= ret;
        }
 
-       printf(", %s written.\n", filename);
+       printf("%s written.\n", fname);
 
        close(fd);
 }
 
        close(fd);
 }
+
+char *extracted_file(char *fname)
+{
+       static char filename[PATH_MAX];
+
+       strcpy(filename, "extracted/");
+       strcat(filename, fname);
+
+       return filename;
+}
index d4b91c77b7461ad99f5ba311a988f3963e8b5530..bf9a4c8f81bcb1d298f70a18c3fcdce62e845bc3 100644 (file)
@@ -10,3 +10,4 @@ void extract_files(unsigned char *fw, int len);
 void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname);
 void list_files(unsigned char *fw, int len);
 void write_file(char *fname, unsigned char *buf, int len);
 void replace_add_file(unsigned char *fw, int len, char *fwname, char *lname);
 void list_files(unsigned char *fw, int len);
 void write_file(char *fname, unsigned char *buf, int len);
+char *extracted_file(char *fname);
index 80e12e54f9ff73aaaa15449524dde10055601a7d..b57501277aa90b091d189e7fec940696c8d19458 100644 (file)
@@ -519,23 +519,8 @@ int main(int argc, char **argv)
                        strcpy(newfile, file);
                        strcat(newfile, ".patched");
 
                        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");
                }
                } else {
                        fprintf(stderr,"Can't set correct checksum, aborting...\n");
                }
index 2e50252d2f1786266a114ac3bdd197a7147ff91e..c771b894ffa4ddc314635bf23e1677de0d3cf687 100644 (file)
--- a/rsb-lz.c
+++ b/rsb-lz.c
@@ -312,8 +312,7 @@ void extract_lz_file(unsigned char *inbuf, unsigned char *name, unsigned char ch
                        err_exit(__func__);
                }
        }
                        err_exit(__func__);
                }
        }
-
-       write_file((char*)name, outbuf, len);
+       write_file(extracted_file((char*)name), outbuf, len);
        
        free(outbuf);
 }
        
        free(outbuf);
 }
Impressum, Datenschutz