mz.h 7.7 KB

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