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