1 /* mz_compat.h -- Backwards compatible interface for older versions 2 Version 2.8.1, December 1, 2018 3 part of the MiniZip project 4 5 Copyright (C) 2010-2018 Nathan Moinvaziri 6 https://github.com/nmoinvaz/minizip 7 Copyright (C) 1998-2010 Gilles Vollant 8 https://www.winimage.com/zLibDll/minizip.html 9 10 This program is distributed under the terms of the same license as zlib. 11 See the accompanying LICENSE file for the full text of the license. 12 */ 13 14 #ifndef MZ_COMPAT_H 15 #define MZ_COMPAT_H 16 17 #include "mz.h" 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 /***************************************************************************/ 24 25 #if defined(HAVE_ZLIB) && defined(MAX_MEM_LEVEL) 26 #ifndef DEF_MEM_LEVEL 27 # if MAX_MEM_LEVEL >= 8 28 # define DEF_MEM_LEVEL 8 29 # else 30 # define DEF_MEM_LEVEL MAX_MEM_LEVEL 31 # endif 32 #endif 33 #endif 34 #ifndef MAX_WBITS 35 #define MAX_WBITS (15) 36 #endif 37 #ifndef DEF_MEM_LEVEL 38 #define DEF_MEM_LEVEL (8) 39 #endif 40 41 #ifndef ZEXPORT 42 # define ZEXPORT 43 #endif 44 45 /***************************************************************************/ 46 47 #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 48 /* like the STRICT of WIN32, we define a pointer that cannot be converted 49 from (void*) without cast */ 50 typedef struct TagzipFile__ { int unused; } zip_file__; 51 typedef zip_file__ *zipFile; 52 #else 53 typedef void *zipFile; 54 #endif 55 56 /***************************************************************************/ 57 58 typedef void *zlib_filefunc_def; 59 typedef void *zlib_filefunc64_def; 60 typedef const char *zipcharpc; 61 62 typedef struct tm tm_unz; 63 typedef struct tm tm_zip; 64 65 typedef uint64_t ZPOS64_T; 66 67 /***************************************************************************/ 68 69 typedef struct 70 { 71 uint32_t dosDate; 72 struct tm tmz_date; 73 uint16_t internal_fa; /* internal file attributes 2 bytes */ 74 uint32_t external_fa; /* external file attributes 4 bytes */ 75 } zip_fileinfo; 76 77 /***************************************************************************/ 78 79 #define ZIP_OK (0) 80 #define ZIP_EOF (0) 81 #define ZIP_ERRNO (-1) 82 #define ZIP_PARAMERROR (-102) 83 #define ZIP_BADZIPFILE (-103) 84 #define ZIP_INTERNALERROR (-104) 85 86 #define Z_BZIP2ED (12) 87 88 #define APPEND_STATUS_CREATE (0) 89 #define APPEND_STATUS_CREATEAFTER (1) 90 #define APPEND_STATUS_ADDINZIP (2) 91 92 /***************************************************************************/ 93 /* Writing a zip file */ 94 95 zipFile ZEXPORT zipOpen(const char *path, int append); 96 zipFile ZEXPORT zipOpen64(const void *path, int append); 97 zipFile ZEXPORT zipOpen2(const char *path, int append, const char **globalcomment, 98 zlib_filefunc_def *pzlib_filefunc_def); 99 zipFile ZEXPORT zipOpen2_64(const void *path, int append, const char **globalcomment, 100 zlib_filefunc64_def *pzlib_filefunc_def); 101 zipFile ZEXPORT zipOpen_MZ(void *stream, int append, const char **globalcomment); 102 103 int ZEXPORT zipOpenNewFileInZip3(zipFile file, const char *filename, const zip_fileinfo *zipfi, 104 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 105 uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level, 106 int raw, int windowBits, int memLevel, int strategy, const char *password, 107 uint32_t crc_for_crypting); 108 int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 109 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 110 uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level, 111 int raw, int windowBits, int memLevel, int strategy, const char *password, 112 uint32_t crc_for_crypting, int zip64); 113 int ZEXPORT zipOpenNewFileInZip4(zipFile file, const char *filename, const zip_fileinfo *zipfi, 114 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 115 uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level, 116 int raw, int windowBits, int memLevel, int strategy, const char *password, 117 uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base); 118 int ZEXPORT zipOpenNewFileInZip4_64(zipFile file, const char *filename, const zip_fileinfo *zipfi, 119 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 120 uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level, 121 int raw, int windowBits, int memLevel, int strategy, const char *password, 122 uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64); 123 int ZEXPORT zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi, 124 const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global, 125 uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level, 126 int raw, int windowBits, int memLevel, int strategy, const char *password, 127 uint32_t crc_for_crypting, uint16_t version_madeby, uint16_t flag_base, int zip64); 128 129 int ZEXPORT zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len); 130 131 int ZEXPORT zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32); 132 int ZEXPORT zipCloseFileInZipRaw64(zipFile file, int64_t uncompressed_size, uint32_t crc32); 133 int ZEXPORT zipCloseFileInZip(zipFile file); 134 int ZEXPORT zipCloseFileInZip64(zipFile file); 135 136 int ZEXPORT zipClose(zipFile file, const char *global_comment); 137 int ZEXPORT zipClose_64(zipFile file, const char *global_comment); 138 int ZEXPORT zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby); 139 int ZEXPORT zipClose_MZ(zipFile file, const char *global_comment); 140 int ZEXPORT zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby); 141 void* ZEXPORT zipGetStream(zipFile file); 142 143 /***************************************************************************/ 144 145 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 146 /* like the STRICT of WIN32, we define a pointer that cannot be converted 147 from (void*) without cast */ 148 typedef struct TagunzFile__ { int unused; } unz_file__; 149 typedef unz_file__ *unzFile; 150 #else 151 typedef void *unzFile; 152 #endif 153 154 /***************************************************************************/ 155 156 #define UNZ_OK (0) 157 #define UNZ_END_OF_LIST_OF_FILE (-100) 158 #define UNZ_ERRNO (-1) 159 #define UNZ_EOF (0) 160 #define UNZ_PARAMERROR (-102) 161 #define UNZ_BADZIPFILE (-103) 162 #define UNZ_INTERNALERROR (-104) 163 #define UNZ_CRCERROR (-105) 164 #define UNZ_BADPASSWORD (-106) 165 166 /***************************************************************************/ 167 168 typedef struct unz_global_info64_s 169 { 170 uint64_t number_entry; /* total number of entries in the central dir on this disk */ 171 uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */ 172 uint16_t size_comment; /* size of the global comment of the zipfile */ 173 } unz_global_info64; 174 175 typedef struct unz_global_info_s 176 { 177 uint32_t number_entry; /* total number of entries in the central dir on this disk */ 178 uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP */ 179 uint16_t size_comment; /* size of the global comment of the zipfile */ 180 } unz_global_info; 181 182 typedef struct unz_file_info64_s 183 { 184 uint16_t version; /* version made by 2 bytes */ 185 uint16_t version_needed; /* version needed to extract 2 bytes */ 186 uint16_t flag; /* general purpose bit flag 2 bytes */ 187 uint16_t compression_method; /* compression method 2 bytes */ 188 uint32_t dosDate; /* last mod file date in Dos fmt 4 bytes */ 189 struct tm tmu_date; 190 uint32_t crc; /* crc-32 4 bytes */ 191 uint64_t compressed_size; /* compressed size 8 bytes */ 192 uint64_t uncompressed_size; /* uncompressed size 8 bytes */ 193 uint16_t size_filename; /* filename length 2 bytes */ 194 uint16_t size_file_extra; /* extra field length 2 bytes */ 195 uint16_t size_file_comment; /* file comment length 2 bytes */ 196 197 uint32_t disk_num_start; /* disk number start 4 bytes */ 198 uint16_t internal_fa; /* internal file attributes 2 bytes */ 199 uint32_t external_fa; /* external file attributes 4 bytes */ 200 201 uint64_t disk_offset; 202 203 uint16_t size_file_extra_internal; 204 } unz_file_info64; 205 206 typedef struct unz_file_info_s 207 { 208 uint16_t version; /* version made by 2 bytes */ 209 uint16_t version_needed; /* version needed to extract 2 bytes */ 210 uint16_t flag; /* general purpose bit flag 2 bytes */ 211 uint16_t compression_method; /* compression method 2 bytes */ 212 uint32_t dosDate; /* last mod file date in Dos fmt 4 bytes */ 213 struct tm tmu_date; 214 uint32_t crc; /* crc-32 4 bytes */ 215 uint32_t compressed_size; /* compressed size 4 bytes */ 216 uint32_t uncompressed_size; /* uncompressed size 4 bytes */ 217 uint16_t size_filename; /* filename length 2 bytes */ 218 uint16_t size_file_extra; /* extra field length 2 bytes */ 219 uint16_t size_file_comment; /* file comment length 2 bytes */ 220 221 uint16_t disk_num_start; /* disk number start 2 bytes */ 222 uint16_t internal_fa; /* internal file attributes 2 bytes */ 223 uint32_t external_fa; /* external file attributes 4 bytes */ 224 225 uint64_t disk_offset; 226 } unz_file_info; 227 228 /***************************************************************************/ 229 230 typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2); 231 typedef int (*unzIteratorFunction)(unzFile file); 232 typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, 233 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, 234 uint16_t comment_size); 235 236 /***************************************************************************/ 237 /* Reading a zip file */ 238 239 unzFile ZEXPORT unzOpen(const char *path); 240 unzFile ZEXPORT unzOpen64(const void *path); 241 unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def); 242 unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def); 243 unzFile ZEXPORT unzOpen_MZ(void *stream); 244 245 int ZEXPORT unzClose(unzFile file); 246 int ZEXPORT unzClose_MZ(unzFile file); 247 248 int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32); 249 int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info); 250 int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size); 251 252 int ZEXPORT unzOpenCurrentFile(unzFile file); 253 int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password); 254 int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw); 255 int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password); 256 int ZEXPORT unzReadCurrentFile(unzFile file, void *buf, uint32_t len); 257 int ZEXPORT unzCloseCurrentFile(unzFile file); 258 259 260 int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename, 261 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, 262 uint16_t comment_size); 263 int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename, 264 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, 265 uint16_t comment_size); 266 267 int ZEXPORT unzGoToFirstFile(unzFile file); 268 int ZEXPORT unzGoToNextFile(unzFile file); 269 int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func); 270 271 int ZEXPORT unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len); 272 273 /***************************************************************************/ 274 /* Raw access to zip file */ 275 276 typedef struct unz_file_pos_s 277 { 278 uint32_t pos_in_zip_directory; /* offset in zip file directory */ 279 uint32_t num_of_file; /* # of file */ 280 } unz_file_pos; 281 282 int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos); 283 int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos); 284 285 typedef struct unz64_file_pos_s 286 { 287 int64_t pos_in_zip_directory; /* offset in zip file directory */ 288 uint64_t num_of_file; /* # of file */ 289 } unz64_file_pos; 290 291 int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos); 292 int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos); 293 294 int64_t ZEXPORT unzGetOffset64(unzFile file); 295 int32_t ZEXPORT unzGetOffset(unzFile file); 296 int ZEXPORT unzSetOffset64(unzFile file, int64_t pos); 297 int ZEXPORT unzSetOffset(unzFile file, uint32_t pos); 298 int32_t ZEXPORT unzTell(unzFile file); 299 int64_t ZEXPORT unzTell64(unzFile file); 300 int ZEXPORT unzSeek(unzFile file, int32_t offset, int origin); 301 int ZEXPORT unzSeek64(unzFile file, int64_t offset, int origin); 302 int ZEXPORT unzEndOfFile(unzFile file); 303 void* ZEXPORT unzGetStream(unzFile file); 304 305 /***************************************************************************/ 306 307 void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def); 308 void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def); 309 void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def); 310 void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def); 311 void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def); 312 void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def); 313 void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def); 314 315 /***************************************************************************/ 316 317 #define unztell unzTell64 318 #define check_file_exists mz_os_file_exists 319 #define dosdate_to_tm mz_zip_dosdate_to_tm 320 #define change_file_date mz_os_set_file_date 321 #define get_file_date mz_os_get_file_date 322 #define is_large_file(x) (mz_os_get_file_size(x) >= UINT32_MAX) 323 #define makedir mz_dir_make 324 #define get_file_crc(p,b,bs,rc) mz_file_get_crc(p,rc) 325 326 #define MKDIR mz_os_make_dir 327 #define CHDIR chdir 328 329 /***************************************************************************/ 330 331 #ifdef __cplusplus 332 } 333 #endif 334 335 #endif 336