mz_compat.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* mz_compat.h -- Backwards compatible interface for older versions
  2. Version 2.8.6, April 8, 2019
  3. part of the MiniZip project
  4. Copyright (C) 2010-2019 Nathan Moinvaziri
  5. https://github.com/nmoinvaz/minizip
  6. Copyright (C) 1998-2010 Gilles Vollant
  7. https://www.winimage.com/zLibDll/minizip.html
  8. This program is distributed under the terms of the same license as zlib.
  9. See the accompanying LICENSE file for the full text of the license.
  10. */
  11. #ifndef MZ_COMPAT_H
  12. #define MZ_COMPAT_H
  13. #include "mz.h"
  14. #include "../SSZipCommon.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /***************************************************************************/
  19. #if defined(HAVE_ZLIB) && defined(MAX_MEM_LEVEL)
  20. #ifndef DEF_MEM_LEVEL
  21. # if MAX_MEM_LEVEL >= 8
  22. # define DEF_MEM_LEVEL 8
  23. # else
  24. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  25. # endif
  26. #endif
  27. #endif
  28. #ifndef MAX_WBITS
  29. #define MAX_WBITS 15
  30. #endif
  31. #ifndef DEF_MEM_LEVEL
  32. #define DEF_MEM_LEVEL 8
  33. #endif
  34. #ifndef ZEXPORT
  35. # define ZEXPORT MZ_EXPORT
  36. #endif
  37. /***************************************************************************/
  38. #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
  39. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  40. from (void*) without cast */
  41. typedef struct TagzipFile__ { int unused; } zip_file__;
  42. typedef zip_file__ *zipFile;
  43. #else
  44. typedef void *zipFile;
  45. #endif
  46. /***************************************************************************/
  47. typedef void *zlib_filefunc_def;
  48. typedef void *zlib_filefunc64_def;
  49. typedef const char *zipcharpc;
  50. typedef struct tm tm_unz;
  51. typedef struct tm tm_zip;
  52. typedef uint64_t ZPOS64_T;
  53. /***************************************************************************/
  54. // ZipArchive 2.x uses dos_date
  55. #define MZ_COMPAT_VERSION 120
  56. #if MZ_COMPAT_VERSION <= 110
  57. #define mz_dos_date dosDate
  58. #else
  59. #define mz_dos_date dos_date
  60. #endif
  61. typedef struct
  62. {
  63. uint32_t mz_dos_date;
  64. struct tm tmz_date;
  65. uint16_t internal_fa; /* internal file attributes 2 bytes */
  66. uint32_t external_fa; /* external file attributes 4 bytes */
  67. } zip_fileinfo;
  68. /***************************************************************************/
  69. #define ZIP_OK (0)
  70. #define ZIP_EOF (0)
  71. #define ZIP_ERRNO (-1)
  72. #define ZIP_PARAMERROR (-102)
  73. #define ZIP_BADZIPFILE (-103)
  74. #define ZIP_INTERNALERROR (-104)
  75. #define Z_BZIP2ED (12)
  76. #define APPEND_STATUS_CREATE (0)
  77. #define APPEND_STATUS_CREATEAFTER (1)
  78. #define APPEND_STATUS_ADDINZIP (2)
  79. /***************************************************************************/
  80. /* Writing a zip file */
  81. ZEXPORT zipFile zipOpen(const char *path, int append);
  82. ZEXPORT zipFile zipOpen64(const void *path, int append);
  83. ZEXPORT zipFile zipOpen2(const char *path, int append, const char **globalcomment,
  84. zlib_filefunc_def *pzlib_filefunc_def);
  85. ZEXPORT zipFile zipOpen2_64(const void *path, int append, const char **globalcomment,
  86. zlib_filefunc64_def *pzlib_filefunc_def);
  87. zipFile zipOpen_MZ(void *stream, int append, const char **globalcomment);
  88. ZEXPORT int zipOpenNewFileInZip5(zipFile file, const char *filename, const zip_fileinfo *zipfi,
  89. const void *extrafield_local, uint16_t size_extrafield_local, const void *extrafield_global,
  90. uint16_t size_extrafield_global, const char *comment, uint16_t compression_method, int level,
  91. int raw, int windowBits, int memLevel, int strategy, const char *password,
  92. signed char aes, uint16_t version_madeby, uint16_t flag_base, int zip64);
  93. ZEXPORT int zipWriteInFileInZip(zipFile file, const void *buf, uint32_t len);
  94. ZEXPORT int zipCloseFileInZipRaw(zipFile file, uint32_t uncompressed_size, uint32_t crc32);
  95. ZEXPORT int zipCloseFileInZipRaw64(zipFile file, int64_t uncompressed_size, uint32_t crc32);
  96. ZEXPORT int zipCloseFileInZip(zipFile file);
  97. ZEXPORT int zipCloseFileInZip64(zipFile file);
  98. ZEXPORT int zipClose(zipFile file, const char *global_comment);
  99. ZEXPORT int zipClose_64(zipFile file, const char *global_comment);
  100. ZEXPORT int zipClose2_64(zipFile file, const char *global_comment, uint16_t version_madeby);
  101. int zipClose_MZ(zipFile file, const char *global_comment);
  102. int zipClose2_MZ(zipFile file, const char *global_comment, uint16_t version_madeby);
  103. ZEXPORT void* zipGetStream(zipFile file);
  104. /***************************************************************************/
  105. #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
  106. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  107. from (void*) without cast */
  108. typedef struct TagunzFile__ { int unused; } unz_file__;
  109. typedef unz_file__ *unzFile;
  110. #else
  111. typedef void *unzFile;
  112. #endif
  113. /***************************************************************************/
  114. #define UNZ_OK (0)
  115. #define UNZ_END_OF_LIST_OF_FILE (-100)
  116. #define UNZ_ERRNO (-1)
  117. #define UNZ_EOF (0)
  118. #define UNZ_PARAMERROR (-102)
  119. #define UNZ_BADZIPFILE (-103)
  120. #define UNZ_INTERNALERROR (-104)
  121. #define UNZ_CRCERROR (-105)
  122. #define UNZ_BADPASSWORD (-106)
  123. /***************************************************************************/
  124. typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
  125. typedef int (*unzIteratorFunction)(unzFile file);
  126. typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
  127. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
  128. uint16_t comment_size);
  129. /***************************************************************************/
  130. /* Reading a zip file */
  131. ZEXPORT unzFile unzOpen(const char *path);
  132. ZEXPORT unzFile unzOpen64(const void *path);
  133. ZEXPORT unzFile unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
  134. ZEXPORT unzFile unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
  135. unzFile unzOpen_MZ(void *stream);
  136. ZEXPORT int unzClose(unzFile file);
  137. int unzClose_MZ(unzFile file);
  138. ZEXPORT int unzGetGlobalInfo(unzFile file, unz_global_info* pglobal_info32);
  139. ZEXPORT int unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
  140. ZEXPORT int unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
  141. ZEXPORT int unzOpenCurrentFile(unzFile file);
  142. ZEXPORT int unzOpenCurrentFilePassword(unzFile file, const char *password);
  143. ZEXPORT int unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
  144. ZEXPORT int unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
  145. ZEXPORT int unzReadCurrentFile(unzFile file, void *buf, uint32_t len);
  146. ZEXPORT int unzCloseCurrentFile(unzFile file);
  147. ZEXPORT int unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
  148. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
  149. uint16_t comment_size);
  150. ZEXPORT int unzGetCurrentFileInfo64(unzFile file, unz_file_info64 * pfile_info, char *filename,
  151. uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment,
  152. uint16_t comment_size);
  153. ZEXPORT int unzGoToFirstFile(unzFile file);
  154. ZEXPORT int unzGoToNextFile(unzFile file);
  155. ZEXPORT int unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
  156. ZEXPORT int unzGetLocalExtrafield(unzFile file, void *buf, unsigned int len);
  157. /***************************************************************************/
  158. /* Raw access to zip file */
  159. typedef struct unz_file_pos_s
  160. {
  161. uint32_t pos_in_zip_directory; /* offset in zip file directory */
  162. uint32_t num_of_file; /* # of file */
  163. } unz_file_pos;
  164. ZEXPORT int unzGetFilePos(unzFile file, unz_file_pos *file_pos);
  165. ZEXPORT int unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
  166. typedef struct unz64_file_pos_s
  167. {
  168. int64_t pos_in_zip_directory; /* offset in zip file directory */
  169. uint64_t num_of_file; /* # of file */
  170. } unz64_file_pos;
  171. ZEXPORT int unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
  172. ZEXPORT int unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
  173. ZEXPORT int64_t unzGetOffset64(unzFile file);
  174. ZEXPORT int32_t unzGetOffset(unzFile file);
  175. ZEXPORT int unzSetOffset64(unzFile file, int64_t pos);
  176. ZEXPORT int unzSetOffset(unzFile file, uint32_t pos);
  177. ZEXPORT int64_t unztell(unzFile file);
  178. ZEXPORT int32_t unzTell(unzFile file);
  179. ZEXPORT int64_t unzTell64(unzFile file);
  180. ZEXPORT int unzSeek(unzFile file, int32_t offset, int origin);
  181. ZEXPORT int unzSeek64(unzFile file, int64_t offset, int origin);
  182. ZEXPORT int unzEndOfFile(unzFile file);
  183. ZEXPORT void* unzGetStream(unzFile file);
  184. /***************************************************************************/
  185. ZEXPORT void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
  186. ZEXPORT void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
  187. ZEXPORT void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
  188. ZEXPORT void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def);
  189. ZEXPORT void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def);
  190. ZEXPORT void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def);
  191. ZEXPORT void fill_memory_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
  192. /***************************************************************************/
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196. #endif