diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-02-25 13:00:12 -0500 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2022-02-25 13:00:12 -0500 |
commit | 41021e56c4b5e8d35483929f9b1cd28e1eae0ee7 (patch) | |
tree | d24b70bdd7e31467c9bd962697776a9986950922 /zwrapper.c | |
parent | 5f33f9cdde2900cb74e6281f8d848bc874c12d95 (diff) | |
download | libzip-wrapper-41021e56c4b5e8d35483929f9b1cd28e1eae0ee7.tar.gz libzip-wrapper-41021e56c4b5e8d35483929f9b1cd28e1eae0ee7.zip |
All files are now checked for proper existing directories regardless of directory entries in the zip file.HEADmaster
Diffstat (limited to 'zwrapper.c')
-rw-r--r-- | zwrapper.c | 47 |
1 files changed, 47 insertions, 0 deletions
@@ -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) { |