| 1 | /* mz.h -- Errors codes, zip flags and magic |
| 2 | part of the minizip-ng project |
| 3 | |
| 4 | Copyright (C) Nathan Moinvaziri |
| 5 | https://github.com/zlib-ng/minizip-ng |
| 6 | |
| 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 | |
| 11 | #ifndef MZ_H |
| 12 | #define MZ_H |
| 13 | |
| 14 | /***************************************************************************/ |
| 15 | |
| 16 | /* MZ_VERSION */ |
| 17 | #define MZ_VERSION ("4.0.10") |
| 18 | #define MZ_VERSION_BUILD (0x04000A) |
| 19 | |
| 20 | /* MZ_ERROR */ |
| 21 | #define MZ_OK (0) /* zlib */ |
| 22 | #define MZ_STREAM_ERROR (-1) /* zlib */ |
| 23 | #define MZ_DATA_ERROR (-3) /* zlib */ |
| 24 | #define MZ_MEM_ERROR (-4) /* zlib */ |
| 25 | #define MZ_BUF_ERROR (-5) /* zlib */ |
| 26 | #define MZ_VERSION_ERROR (-6) /* zlib */ |
| 27 | |
| 28 | #define MZ_END_OF_LIST (-100) |
| 29 | #define MZ_END_OF_STREAM (-101) |
| 30 | |
| 31 | #define MZ_PARAM_ERROR (-102) |
| 32 | #define MZ_FORMAT_ERROR (-103) |
| 33 | #define MZ_INTERNAL_ERROR (-104) |
| 34 | #define MZ_CRC_ERROR (-105) |
| 35 | #define MZ_CRYPT_ERROR (-106) |
| 36 | #define MZ_EXIST_ERROR (-107) |
| 37 | #define MZ_PASSWORD_ERROR (-108) |
| 38 | #define MZ_SUPPORT_ERROR (-109) |
| 39 | #define MZ_HASH_ERROR (-110) |
| 40 | #define MZ_OPEN_ERROR (-111) |
| 41 | #define MZ_CLOSE_ERROR (-112) |
| 42 | #define MZ_SEEK_ERROR (-113) |
| 43 | #define MZ_TELL_ERROR (-114) |
| 44 | #define MZ_READ_ERROR (-115) |
| 45 | #define MZ_WRITE_ERROR (-116) |
| 46 | #define MZ_SIGN_ERROR (-117) |
| 47 | #define MZ_SYMLINK_ERROR (-118) |
| 48 | |
| 49 | /* MZ_OPEN */ |
| 50 | #define MZ_OPEN_MODE_READ (0x01) |
| 51 | #define MZ_OPEN_MODE_WRITE (0x02) |
| 52 | #define MZ_OPEN_MODE_READWRITE (MZ_OPEN_MODE_READ | MZ_OPEN_MODE_WRITE) |
| 53 | #define MZ_OPEN_MODE_APPEND (0x04) |
| 54 | #define MZ_OPEN_MODE_CREATE (0x08) |
| 55 | #define MZ_OPEN_MODE_EXISTING (0x10) |
| 56 | |
| 57 | /* MZ_SEEK */ |
| 58 | #define MZ_SEEK_SET (0) |
| 59 | #define MZ_SEEK_CUR (1) |
| 60 | #define MZ_SEEK_END (2) |
| 61 | |
| 62 | /* MZ_COMPRESS */ |
| 63 | #define MZ_COMPRESS_METHOD_STORE (0) |
| 64 | #define MZ_COMPRESS_METHOD_DEFLATE (8) |
| 65 | #define MZ_COMPRESS_METHOD_BZIP2 (12) |
| 66 | #define MZ_COMPRESS_METHOD_LZMA (14) |
| 67 | #define MZ_COMPRESS_METHOD_ZSTD (93) |
| 68 | #define MZ_COMPRESS_METHOD_XZ (95) |
| 69 | #define MZ_COMPRESS_METHOD_AES (99) |
| 70 | |
| 71 | #define MZ_COMPRESS_LEVEL_DEFAULT (-1) |
| 72 | #define MZ_COMPRESS_LEVEL_FAST (2) |
| 73 | #define MZ_COMPRESS_LEVEL_NORMAL (6) |
| 74 | #define MZ_COMPRESS_LEVEL_BEST (9) |
| 75 | |
| 76 | /* MZ_ZIP_FLAG */ |
| 77 | #define MZ_ZIP_FLAG_ENCRYPTED (1 << 0) |
| 78 | #define MZ_ZIP_FLAG_LZMA_EOS_MARKER (1 << 1) |
| 79 | #define MZ_ZIP_FLAG_DEFLATE_MAX (1 << 1) |
| 80 | #define MZ_ZIP_FLAG_DEFLATE_NORMAL (0) |
| 81 | #define MZ_ZIP_FLAG_DEFLATE_FAST (1 << 2) |
| 82 | #define MZ_ZIP_FLAG_DEFLATE_SUPER_FAST (MZ_ZIP_FLAG_DEFLATE_FAST | MZ_ZIP_FLAG_DEFLATE_MAX) |
| 83 | #define MZ_ZIP_FLAG_DATA_DESCRIPTOR (1 << 3) |
| 84 | #define MZ_ZIP_FLAG_UTF8 (1 << 11) |
| 85 | #define MZ_ZIP_FLAG_MASK_LOCAL_INFO (1 << 13) |
| 86 | |
| 87 | /* MZ_ZIP_EXTENSION */ |
| 88 | #define MZ_ZIP_EXTENSION_ZIP64 (0x0001) |
| 89 | #define MZ_ZIP_EXTENSION_NTFS (0x000a) |
| 90 | #define MZ_ZIP_EXTENSION_AES (0x9901) |
| 91 | #define MZ_ZIP_EXTENSION_UNIX1 (0x000d) |
| 92 | #define MZ_ZIP_EXTENSION_SIGN (0x10c5) |
| 93 | #define MZ_ZIP_EXTENSION_HASH (0x1a51) |
| 94 | #define MZ_ZIP_EXTENSION_CDCD (0xcdcd) |
| 95 | |
| 96 | /* MZ_ZIP64 */ |
| 97 | #define MZ_ZIP64_AUTO (0) |
| 98 | #define MZ_ZIP64_FORCE (1) |
| 99 | #define MZ_ZIP64_DISABLE (2) |
| 100 | |
| 101 | /* MZ_HOST_SYSTEM */ |
| 102 | #define MZ_HOST_SYSTEM(VERSION_MADEBY) ((uint8_t)(VERSION_MADEBY >> 8)) |
| 103 | #define MZ_HOST_SYSTEM_MSDOS (0) |
| 104 | #define MZ_HOST_SYSTEM_UNIX (3) |
| 105 | #define MZ_HOST_SYSTEM_WINDOWS_NTFS (10) |
| 106 | #define MZ_HOST_SYSTEM_RISCOS (13) |
| 107 | #define MZ_HOST_SYSTEM_OSX_DARWIN (19) |
| 108 | |
| 109 | /* MZ_PKCRYPT */ |
| 110 | #define MZ_PKCRYPT_HEADER_SIZE (12) |
| 111 | |
| 112 | /* MZ_AES */ |
| 113 | #define MZ_AES_VERSION (1) |
| 114 | #define MZ_AES_MODE_ECB (0) |
| 115 | #define MZ_AES_MODE_CBC (1) |
| 116 | #define MZ_AES_MODE_GCM (2) |
| 117 | #define MZ_AES_STRENGTH_128 (1) |
| 118 | #define MZ_AES_STRENGTH_192 (2) |
| 119 | #define MZ_AES_STRENGTH_256 (3) |
| 120 | #define MZ_AES_KEY_LENGTH_MAX (32) |
| 121 | #define MZ_AES_BLOCK_SIZE (16) |
| 122 | #define MZ_AES_FOOTER_SIZE (10) |
| 123 | |
| 124 | /* MZ_HASH */ |
| 125 | #define MZ_HASH_MD5 (10) |
| 126 | #define MZ_HASH_MD5_SIZE (16) |
| 127 | #define MZ_HASH_SHA1 (20) |
| 128 | #define MZ_HASH_SHA1_SIZE (20) |
| 129 | #define MZ_HASH_SHA224 (22) |
| 130 | #define MZ_HASH_SHA224_SIZE (28) |
| 131 | #define MZ_HASH_SHA256 (23) |
| 132 | #define MZ_HASH_SHA256_SIZE (32) |
| 133 | #define MZ_HASH_SHA384 (24) |
| 134 | #define MZ_HASH_SHA384_SIZE (48) |
| 135 | #define MZ_HASH_SHA512 (25) |
| 136 | #define MZ_HASH_SHA512_SIZE (64) |
| 137 | #define MZ_HASH_MAX_SIZE (256) |
| 138 | |
| 139 | /* MZ_ENCODING */ |
| 140 | #define MZ_ENCODING_CODEPAGE_437 (437) |
| 141 | #define MZ_ENCODING_CODEPAGE_932 (932) |
| 142 | #define MZ_ENCODING_CODEPAGE_936 (936) |
| 143 | #define MZ_ENCODING_CODEPAGE_950 (950) |
| 144 | #define MZ_ENCODING_UTF8 (65001) |
| 145 | |
| 146 | /* MZ_UTILITY */ |
| 147 | #define MZ_UNUSED(SYMBOL) ((void)SYMBOL) |
| 148 | |
| 149 | #if defined(_WIN32) && defined(MZ_EXPORTS) |
| 150 | # define MZ_EXPORT __declspec(dllexport) |
| 151 | #else |
| 152 | # define MZ_EXPORT |
| 153 | #endif |
| 154 | |
| 155 | /***************************************************************************/ |
| 156 | |
| 157 | #include <stdlib.h> /* size_t, NULL, malloc */ |
| 158 | #include <time.h> /* time_t, time() */ |
| 159 | #include <string.h> /* memset, strncpy, strlen */ |
| 160 | #include <limits.h> |
| 161 | |
| 162 | #if defined(HAVE_STDINT_H) |
| 163 | # include <stdint.h> |
| 164 | #elif defined(__has_include) |
| 165 | # if __has_include(<stdint.h>) |
| 166 | # include <stdint.h> |
| 167 | # endif |
| 168 | #endif |
| 169 | |
| 170 | #ifndef INT8_MAX |
| 171 | typedef signed char int8_t; |
| 172 | #endif |
| 173 | #ifndef INT16_MAX |
| 174 | typedef short int16_t; |
| 175 | #endif |
| 176 | #ifndef INT32_MAX |
| 177 | typedef int int32_t; |
| 178 | #endif |
| 179 | #ifndef INT64_MAX |
| 180 | typedef long long int64_t; |
| 181 | #endif |
| 182 | #ifndef UINT8_MAX |
| 183 | typedef unsigned char uint8_t; |
| 184 | #endif |
| 185 | #ifndef UINT16_MAX |
| 186 | typedef unsigned short uint16_t; |
| 187 | #endif |
| 188 | #ifndef UINT32_MAX |
| 189 | typedef unsigned int uint32_t; |
| 190 | #endif |
| 191 | #ifndef UINT64_MAX |
| 192 | typedef unsigned long long uint64_t; |
| 193 | #endif |
| 194 | |
| 195 | #if defined(HAVE_INTTYPES_H) |
| 196 | # include <inttypes.h> |
| 197 | #elif defined(__has_include) |
| 198 | # if __has_include(<inttypes.h>) |
| 199 | # include <inttypes.h> |
| 200 | # endif |
| 201 | #endif |
| 202 | |
| 203 | #ifndef PRId8 |
| 204 | # define PRId8 "hhd" |
| 205 | #endif |
| 206 | #ifndef PRIu8 |
| 207 | # define PRIu8 "hhu" |
| 208 | #endif |
| 209 | #ifndef PRIx8 |
| 210 | # define PRIx8 "hhx" |
| 211 | #endif |
| 212 | #ifndef PRId16 |
| 213 | # define PRId16 "hd" |
| 214 | #endif |
| 215 | #ifndef PRIu16 |
| 216 | # define PRIu16 "hu" |
| 217 | #endif |
| 218 | #ifndef PRIx16 |
| 219 | # define PRIx16 "hx" |
| 220 | #endif |
| 221 | #ifndef PRId32 |
| 222 | # define PRId32 "d" |
| 223 | #endif |
| 224 | #ifndef PRIu32 |
| 225 | # define PRIu32 "u" |
| 226 | #endif |
| 227 | #ifndef PRIx32 |
| 228 | # define PRIx32 "x" |
| 229 | #endif |
| 230 | #if ULONG_MAX == 0xfffffffful |
| 231 | # ifndef PRId64 |
| 232 | # define PRId64 "ld" |
| 233 | # endif |
| 234 | # ifndef PRIu64 |
| 235 | # define PRIu64 "lu" |
| 236 | # endif |
| 237 | # ifndef PRIx64 |
| 238 | # define PRIx64 "lx" |
| 239 | # endif |
| 240 | #else |
| 241 | # ifndef PRId64 |
| 242 | # define PRId64 "lld" |
| 243 | # endif |
| 244 | # ifndef PRIu64 |
| 245 | # define PRIu64 "llu" |
| 246 | # endif |
| 247 | # ifndef PRIx64 |
| 248 | # define PRIx64 "llx" |
| 249 | # endif |
| 250 | #endif |
| 251 | |
| 252 | #ifndef INT16_MAX |
| 253 | # define INT16_MAX 32767 |
| 254 | #endif |
| 255 | #ifndef INT32_MAX |
| 256 | # define INT32_MAX 2147483647L |
| 257 | #endif |
| 258 | #ifndef INT64_MAX |
| 259 | # define INT64_MAX 9223372036854775807LL |
| 260 | #endif |
| 261 | #ifndef UINT16_MAX |
| 262 | # define UINT16_MAX 65535U |
| 263 | #endif |
| 264 | #ifndef UINT32_MAX |
| 265 | # define UINT32_MAX 4294967295UL |
| 266 | #endif |
| 267 | #ifndef UINT64_MAX |
| 268 | # define UINT64_MAX 18446744073709551615ULL |
| 269 | #endif |
| 270 | |
| 271 | /***************************************************************************/ |
| 272 | |
| 273 | #endif |