X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/blobdiff_plain/05b6bf30040b7d3f2219919168b4c159045a909b..fd5efab92f5780ffc0484401b7a9de715ed062a0:/src/filesystem.c 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) {