X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/blobdiff_plain/05b6bf30040b7d3f2219919168b4c159045a909b..99922f0bbaa2b7304136fa3bdb46996ce2beee0f:/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) {