mz.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* mz.h -- Errors codes, zip flags and magic
  2. Version 2.9.2, February 12, 2020
  3. part of the MiniZip project
  4. Copyright (C) 2010-2020 Nathan Moinvaziri
  5. https://github.com/nmoinvaz/minizip
  6. This program is distributed under the terms of the same license as zlib.
  7. See the accompanying LICENSE file for the full text of the license.
  8. */
  9. #ifndef MZ_H
  10. #define MZ_H
  11. /***************************************************************************/
  12. /* MZ_VERSION */
  13. #define MZ_VERSION ("2.9.2")
  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_AES (99)
  57. #define MZ_COMPRESS_LEVEL_DEFAULT (-1)
  58. #define MZ_COMPRESS_LEVEL_FAST (2)
  59. #define MZ_COMPRESS_LEVEL_NORMAL (6)
  60. #define MZ_COMPRESS_LEVEL_BEST (9)
  61. /* MZ_ZIP_FLAG */
  62. #define MZ_ZIP_FLAG_ENCRYPTED (1 << 0)
  63. #define MZ_ZIP_FLAG_LZMA_EOS_MARKER (1 << 1)
  64. #define MZ_ZIP_FLAG_DEFLATE_MAX (1 << 1)
  65. #define MZ_ZIP_FLAG_DEFLATE_NORMAL (0)
  66. #define MZ_ZIP_FLAG_DEFLATE_FAST (1 << 2)
  67. #define MZ_ZIP_FLAG_DEFLATE_SUPER_FAST (MZ_ZIP_FLAG_DEFLATE_FAST | \
  68. MZ_ZIP_FLAG_DEFLATE_MAX)
  69. #define MZ_ZIP_FLAG_DATA_DESCRIPTOR (1 << 3)
  70. #define MZ_ZIP_FLAG_UTF8 (1 << 11)
  71. #define MZ_ZIP_FLAG_MASK_LOCAL_INFO (1 << 13)
  72. /* MZ_ZIP_EXTENSION */
  73. #define MZ_ZIP_EXTENSION_ZIP64 (0x0001)
  74. #define MZ_ZIP_EXTENSION_NTFS (0x000a)
  75. #define MZ_ZIP_EXTENSION_AES (0x9901)
  76. #define MZ_ZIP_EXTENSION_UNIX1 (0x000d)
  77. #define MZ_ZIP_EXTENSION_SIGN (0x10c5)
  78. #define MZ_ZIP_EXTENSION_HASH (0x1a51)
  79. #define MZ_ZIP_EXTENSION_CDCD (0xcdcd)
  80. /* MZ_ZIP64 */
  81. #define MZ_ZIP64_AUTO (0)
  82. #define MZ_ZIP64_FORCE (1)
  83. #define MZ_ZIP64_DISABLE (2)
  84. /* MZ_HOST_SYSTEM */
  85. #define MZ_HOST_SYSTEM(VERSION_MADEBY) ((uint8_t)(VERSION_MADEBY >> 8))
  86. #define MZ_HOST_SYSTEM_MSDOS (0)
  87. #define MZ_HOST_SYSTEM_UNIX (3)
  88. #define MZ_HOST_SYSTEM_WINDOWS_NTFS (10)
  89. #define MZ_HOST_SYSTEM_RISCOS (13)
  90. #define MZ_HOST_SYSTEM_OSX_DARWIN (19)
  91. /* MZ_PKCRYPT */
  92. #define MZ_PKCRYPT_HEADER_SIZE (12)
  93. /* MZ_AES */
  94. #define MZ_AES_VERSION (1)
  95. #define MZ_AES_ENCRYPTION_MODE_128 (0x01)
  96. #define MZ_AES_ENCRYPTION_MODE_192 (0x02)
  97. #define MZ_AES_ENCRYPTION_MODE_256 (0x03)
  98. #define MZ_AES_KEY_LENGTH(MODE) (8 * (MODE & 3) + 8)
  99. #define MZ_AES_KEY_LENGTH_MAX (32)
  100. #define MZ_AES_BLOCK_SIZE (16)
  101. #define MZ_AES_HEADER_SIZE(MODE) ((4 * (MODE & 3) + 4) + 2)
  102. #define MZ_AES_FOOTER_SIZE (10)
  103. /* MZ_HASH */
  104. #define MZ_HASH_MD5 (10)
  105. #define MZ_HASH_MD5_SIZE (16)
  106. #define MZ_HASH_SHA1 (20)
  107. #define MZ_HASH_SHA1_SIZE (20)
  108. #define MZ_HASH_SHA256 (23)
  109. #define MZ_HASH_SHA256_SIZE (32)
  110. #define MZ_HASH_MAX_SIZE (256)
  111. /* MZ_ENCODING */
  112. #define MZ_ENCODING_CODEPAGE_437 (437)
  113. #define MZ_ENCODING_CODEPAGE_932 (932)
  114. #define MZ_ENCODING_CODEPAGE_936 (936)
  115. #define MZ_ENCODING_CODEPAGE_950 (950)
  116. #define MZ_ENCODING_UTF8 (65001)
  117. /* MZ_UTILITY */
  118. #define MZ_UNUSED(SYMBOL) ((void)SYMBOL)
  119. #ifndef MZ_CUSTOM_ALLOC
  120. #define MZ_ALLOC(SIZE) (malloc(SIZE))
  121. #endif
  122. #ifndef MZ_CUSTOM_FREE
  123. #define MZ_FREE(PTR) (free(PTR))
  124. #endif
  125. #if defined(_WINDOWS) && defined(MZ_EXPORTS)
  126. #define MZ_EXPORT __declspec(dllexport)
  127. #else
  128. #define MZ_EXPORT
  129. #endif
  130. /***************************************************************************/
  131. #include <stdlib.h> /* size_t, NULL, malloc */
  132. #include <time.h> /* time_t, time() */
  133. #include <string.h> /* memset, strncpy, strlen */
  134. #include <limits.h>
  135. #ifdef HAVE_STDINT_H
  136. # include <stdint.h>
  137. #endif
  138. #ifndef __INT8_TYPE__
  139. typedef signed char int8_t;
  140. #endif
  141. #ifndef __INT16_TYPE__
  142. typedef short int16_t;
  143. #endif
  144. #ifndef __INT32_TYPE__
  145. typedef int int32_t;
  146. #endif
  147. #ifndef __INT64_TYPE__
  148. typedef long long int64_t;
  149. #endif
  150. #ifndef __UINT8_TYPE__
  151. typedef unsigned char uint8_t;
  152. #endif
  153. #ifndef __UINT16_TYPE__
  154. typedef unsigned short uint16_t;
  155. #endif
  156. #ifndef __UINT32_TYPE__
  157. typedef unsigned int uint32_t;
  158. #endif
  159. #ifndef __UINT64_TYPE__
  160. typedef unsigned long long uint64_t;
  161. #endif
  162. #ifdef HAVE_INTTYPES_H
  163. # include <inttypes.h>
  164. #endif
  165. #ifndef PRId8
  166. # define PRId8 "hhd"
  167. #endif
  168. #ifndef PRId16
  169. # define PRId16 "hd"
  170. #endif
  171. #ifndef PRId32
  172. # define PRId32 "d"
  173. #endif
  174. #ifndef PRIu32
  175. # define PRIu32 "u"
  176. #endif
  177. #ifndef PRIx32
  178. # define PRIx32 "x"
  179. #endif
  180. #if ULONG_MAX == 4294967295UL
  181. # ifndef PRId64
  182. # define PRId64 "lld"
  183. # endif
  184. # ifndef PRIu64
  185. # define PRIu64 "llu"
  186. # endif
  187. # ifndef PRIx64
  188. # define PRIx64 "llx"
  189. # endif
  190. #else
  191. # ifndef PRId64
  192. # define PRId64 "ld"
  193. # endif
  194. # ifndef PRIu64
  195. # define PRIu64 "lu"
  196. # endif
  197. # ifndef PRIx64
  198. # define PRIx64 "lx"
  199. # endif
  200. #endif
  201. #ifndef INT16_MAX
  202. # define INT16_MAX 32767
  203. #endif
  204. #ifndef INT32_MAX
  205. # define INT32_MAX 2147483647L
  206. #endif
  207. #ifndef INT64_MAX
  208. # define INT64_MAX 9223372036854775807LL
  209. #endif
  210. #ifndef UINT16_MAX
  211. # define UINT16_MAX 65535U
  212. #endif
  213. #ifndef UINT32_MAX
  214. # define UINT32_MAX 4294967295UL
  215. #endif
  216. #ifndef UINT64_MAX
  217. # define UINT64_MAX 18446744073709551615ULL
  218. #endif
  219. /***************************************************************************/
  220. #endif