mz_compat.h 18 KB

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