From 37f85e9b99ba7346412bb68ff6691dfd423ec55b Mon Sep 17 00:00:00 2001 From: Guido Draheim Date: Mon, 24 Apr 2017 23:12:38 +0200 Subject: [PATCH] implement makedirs for zzip_extract examples --- bins/unzzipcat-big.c | 15 ++++++++++++++- bins/unzzipcat-mem.c | 17 +++++++++++++++-- bins/unzzipcat-mix.c | 17 +++++++++++++++-- bins/unzzipcat-zip.c | 17 +++++++++++++++-- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/bins/unzzipcat-big.c b/bins/unzzipcat-big.c index 6f18e5f..d2df75b 100644 --- a/bins/unzzipcat-big.c +++ b/bins/unzzipcat-big.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "unzzipcat-zip.h" #ifdef ZZIP_HAVE_FNMATCH_H @@ -62,6 +63,18 @@ static void unzzip_cat_file(FILE* disk, char* name, FILE* out) } } +static void makedirs(const char* name) +{ + char* p = strrchr(name, '/'); + if (p) { + char* dir_name = strndup(name, p-name); + makedirs(dir_name); + free (dir_name); + } else { + mkdir(name, 775); + errno = 0; + } +} static FILE* create_fopen(char* name, char* mode, int subdirs) { @@ -70,7 +83,7 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) char* p = strrchr(name, '/'); if (p) { char* dir_name = strndup(name, p-name); - // makedirs(dir_name); // TODO + makedirs(dir_name); free (dir_name); } } diff --git a/bins/unzzipcat-mem.c b/bins/unzzipcat-mem.c index c7abd51..34d369f 100644 --- a/bins/unzzipcat-mem.c +++ b/bins/unzzipcat-mem.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "unzzipcat-zip.h" #ifdef ZZIP_HAVE_UNISTD_H @@ -57,6 +58,19 @@ static void unzzip_mem_disk_cat_file(ZZIP_MEM_DISK* disk, char* name, FILE* out) } } +static void makedirs(const char* name) +{ + char* p = strrchr(name, '/'); + if (p) { + char* dir_name = strndup(name, p-name); + makedirs(dir_name); + free (dir_name); + } else { + mkdir(name, 775); + errno = 0; + } +} + static FILE* create_fopen(char* name, char* mode, int subdirs) { if (subdirs) @@ -64,14 +78,13 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) char* p = strrchr(name, '/'); if (p) { char* dir_name = strndup(name, p-name); - // makedirs(dir_name); // TODO + makedirs(dir_name); free (dir_name); } } return fopen(name, mode); } - static int unzzip_cat (int argc, char ** argv, int extract) { int argn; diff --git a/bins/unzzipcat-mix.c b/bins/unzzipcat-mix.c index 0611e80..9d06ca2 100644 --- a/bins/unzzipcat-mix.c +++ b/bins/unzzipcat-mix.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "unzzipcat-zip.h" #ifdef ZZIP_HAVE_UNISTD_H @@ -43,6 +44,19 @@ static void unzzip_cat_file(ZZIP_DIR* disk, char* name, FILE* out) } } +static void makedirs(const char* name) +{ + char* p = strrchr(name, '/'); + if (p) { + char* dir_name = strndup(name, p-name); + makedirs(dir_name); + free (dir_name); + } else { + mkdir(name, 775); + errno = 0; + } +} + static FILE* create_fopen(char* name, char* mode, int subdirs) { if (subdirs) @@ -50,14 +64,13 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) char* p = strrchr(name, '/'); if (p) { char* dir_name = strndup(name, p-name); - // makedirs(dir_name); // TODO + makedirs(dir_name); free (dir_name); } } return fopen(name, mode); } - static int unzzip_cat (int argc, char ** argv, int extract) { int argn; diff --git a/bins/unzzipcat-zip.c b/bins/unzzipcat-zip.c index cc546e2..216fabb 100644 --- a/bins/unzzipcat-zip.c +++ b/bins/unzzipcat-zip.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "unzzipcat-zip.h" #ifdef ZZIP_HAVE_UNISTD_H @@ -43,6 +44,19 @@ static void unzzip_cat_file(ZZIP_DIR* disk, char* name, FILE* out) } } +static void makedirs(const char* name) +{ + char* p = strrchr(name, '/'); + if (p) { + char* dir_name = strndup(name, p-name); + makedirs(dir_name); + free (dir_name); + } else { + mkdir(name, 775); + errno = 0; + } +} + static FILE* create_fopen(char* name, char* mode, int subdirs) { if (subdirs) @@ -50,14 +64,13 @@ static FILE* create_fopen(char* name, char* mode, int subdirs) char* p = strrchr(name, '/'); if (p) { char* dir_name = strndup(name, p-name); - // makedirs(dir_name); // TODO + makedirs(dir_name); free (dir_name); } } return fopen(name, mode); } - static int unzzip_cat (int argc, char ** argv, int extract) { int argn; -- 2.40.0