summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zwrapper.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/zwrapper.c b/zwrapper.c
index 3d73835..b4d5f89 100644
--- a/zwrapper.c
+++ b/zwrapper.c
@@ -61,6 +61,50 @@ char *fix;
}
+void ensure_directory(const char *base, const char *filename)
+{
+char *onedir;
+char *fulldir;
+char *tmp;
+
+ if(filename == NULL || base == NULL) return;
+ if(strlen(filename) == 0) return;
+
+ onedir = (char *)malloc((strlen(filename)+1)*sizeof(char));
+ fulldir = (char *)malloc((strlen(filename)+strlen(base)+2)*sizeof(char));
+
+ strcpy(onedir, filename);
+ tmp = onedir;
+
+ tmp = strchr(onedir, pathsep);
+#ifdef WIN32
+ if(tmp == NULL)
+ tmp = strchr(onedir, '/');
+#endif
+
+ while(tmp != NULL) {
+
+ *tmp = '\0';
+
+ gen_full_filename(base, onedir, fulldir, (strlen(filename)+strlen(base)+2));
+ makedir(fulldir);
+
+ *tmp = pathsep;
+ tmp++;
+#ifdef WIN32
+ if(strchr(tmp, pathsep) == NULL)
+ tmp = strchr(tmp, '/');
+ else
+ tmp = strchr(tmp, pathsep);
+#else
+ tmp = strchr(tmp, pathsep);
+#endif
+ }
+
+ free(onedir);
+ free(fulldir);
+}
+
int unzip_file(const char *filename, const char *directory, const char *index_of_files_file)
{
struct zip *za;
@@ -94,6 +138,9 @@ FILE *fp_index;
makedir(fullfile);
} else {
+
+ ensure_directory(directory, sb.name);
+
zf = zip_fopen_index(za, i, 0);
fp = fopen(fullfile, "wb");
if(zf != NULL && fp != NULL) {