From 62b8ccf01ff22fb623731a04949c5f174dbcd0e6 Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Mon, 15 Mar 2010 13:51:42 +0100 Subject: [PATCH] fix firmware extraction --- src/filesystem.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/filesystem.c b/src/filesystem.c index d644679..ef26de4 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -161,16 +161,17 @@ void list_files(unsigned char *fw, int len) void mkdir_p(char *dir) { - char *copy, *parent; + char *parent; if ((dir == NULL) || (!strcmp(dir, "."))) return; - if ((copy = strdup(dir)) == NULL) { + parent = strdup(dirname(dir)); + if (parent == NULL) { perror("strdup"); exit(1); } - parent = dirname(copy); + mkdir_p(parent); errno = 0; @@ -181,7 +182,7 @@ void mkdir_p(char *dir) exit(1); } } - free(copy); + free(parent); } void write_file(char *fname, unsigned char *buf, int len) @@ -195,8 +196,13 @@ void write_file(char *fname, unsigned char *buf, int len) perror("strdup"); exit(1); } - dirn = dirname(filename_c); + dirn = strdup(dirname(filename_c)); + if (dirn == NULL) { + perror("strdup"); + exit(1); + } mkdir_p(dirn); + free(dirn); free(filename_c); if ((fd = open(fname, O_WRONLY|O_CREAT, 0644)) == -1) { -- 2.39.5