summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2022-02-25 13:00:12 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2022-02-25 13:00:12 -0500
commit41021e56c4b5e8d35483929f9b1cd28e1eae0ee7 (patch)
treed24b70bdd7e31467c9bd962697776a9986950922
parent5f33f9cdde2900cb74e6281f8d848bc874c12d95 (diff)
downloadlibzip-wrapper-master.tar.gz
libzip-wrapper-master.zip
All files are now checked for proper existing directories regardless of directory entries in the zip file.HEADmaster
-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) {