lzma.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /**
  2. * \file api/lzma.h
  3. * \brief The public API of liblzma data compression library
  4. * \mainpage
  5. *
  6. * liblzma is a public domain general-purpose data compression library with
  7. * a zlib-like API. The native file format is .xz, but also the old .lzma
  8. * format and raw (no headers) streams are supported. Multiple compression
  9. * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
  10. *
  11. * liblzma is part of XZ Utils <https://tukaani.org/xz/>. XZ Utils includes
  12. * a gzip-like command line tool named xz and some other tools. XZ Utils
  13. * is developed and maintained by Lasse Collin.
  14. *
  15. * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
  16. * <https://7-zip.org/sdk.html>.
  17. *
  18. * The SHA-256 implementation is based on the public domain code found from
  19. * 7-Zip <https://7-zip.org/>, which has a modified version of the public
  20. * domain SHA-256 code found from Crypto++ <https://www.cryptopp.com/>.
  21. * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
  22. */
  23. /*
  24. * Author: Lasse Collin
  25. *
  26. * This file has been put into the public domain.
  27. * You can do whatever you want with this file.
  28. */
  29. #ifndef LZMA_H
  30. #define LZMA_H
  31. /*****************************
  32. * Required standard headers *
  33. *****************************/
  34. /*
  35. * liblzma API headers need some standard types and macros. To allow
  36. * including lzma.h without requiring the application to include other
  37. * headers first, lzma.h includes the required standard headers unless
  38. * they already seem to be included already or if LZMA_MANUAL_HEADERS
  39. * has been defined.
  40. *
  41. * Here's what types and macros are needed and from which headers:
  42. * - stddef.h: size_t, NULL
  43. * - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
  44. * UINT32_MAX, UINT64_MAX
  45. *
  46. * However, inttypes.h is a little more portable than stdint.h, although
  47. * inttypes.h declares some unneeded things compared to plain stdint.h.
  48. *
  49. * The hacks below aren't perfect, specifically they assume that inttypes.h
  50. * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
  51. * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
  52. * If the application already takes care of setting up all the types and
  53. * macros properly (for example by using gnulib's stdint.h or inttypes.h),
  54. * we try to detect that the macros are already defined and don't include
  55. * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
  56. * force this file to never include any system headers.
  57. *
  58. * Some could argue that liblzma API should provide all the required types,
  59. * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
  60. * seen as an unnecessary mess, since most systems already provide all the
  61. * necessary types and macros in the standard headers.
  62. *
  63. * Note that liblzma API still has lzma_bool, because using stdbool.h would
  64. * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
  65. * necessarily the same as sizeof(bool) in C++.
  66. */
  67. #ifndef LZMA_MANUAL_HEADERS
  68. /*
  69. * I suppose this works portably also in C++. Note that in C++,
  70. * we need to get size_t into the global namespace.
  71. */
  72. # include <stddef.h>
  73. /*
  74. * Skip inttypes.h if we already have all the required macros. If we
  75. * have the macros, we assume that we have the matching typedefs too.
  76. */
  77. # if !defined(UINT32_C) || !defined(UINT64_C) \
  78. || !defined(UINT32_MAX) || !defined(UINT64_MAX)
  79. /*
  80. * MSVC versions older than 2013 have no C99 support, and
  81. * thus they cannot be used to compile liblzma. Using an
  82. * existing liblzma.dll with old MSVC can work though(*),
  83. * but we need to define the required standard integer
  84. * types here in a MSVC-specific way.
  85. *
  86. * (*) If you do this, the existing liblzma.dll probably uses
  87. * a different runtime library than your MSVC-built
  88. * application. Mixing runtimes is generally bad, but
  89. * in this case it should work as long as you avoid
  90. * the few rarely-needed liblzma functions that allocate
  91. * memory and expect the caller to free it using free().
  92. */
  93. # if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
  94. typedef unsigned __int8 uint8_t;
  95. typedef unsigned __int32 uint32_t;
  96. typedef unsigned __int64 uint64_t;
  97. # else
  98. /* Use the standard inttypes.h. */
  99. # ifdef __cplusplus
  100. /*
  101. * C99 sections 7.18.2 and 7.18.4 specify
  102. * that C++ implementations define the limit
  103. * and constant macros only if specifically
  104. * requested. Note that if you want the
  105. * format macros (PRIu64 etc.) too, you need
  106. * to define __STDC_FORMAT_MACROS before
  107. * including lzma.h, since re-including
  108. * inttypes.h with __STDC_FORMAT_MACROS
  109. * defined doesn't necessarily work.
  110. */
  111. # ifndef __STDC_LIMIT_MACROS
  112. # define __STDC_LIMIT_MACROS 1
  113. # endif
  114. # ifndef __STDC_CONSTANT_MACROS
  115. # define __STDC_CONSTANT_MACROS 1
  116. # endif
  117. # endif
  118. # include <inttypes.h>
  119. # endif
  120. /*
  121. * Some old systems have only the typedefs in inttypes.h, and
  122. * lack all the macros. For those systems, we need a few more
  123. * hacks. We assume that unsigned int is 32-bit and unsigned
  124. * long is either 32-bit or 64-bit. If these hacks aren't
  125. * enough, the application has to setup the types manually
  126. * before including lzma.h.
  127. */
  128. # ifndef UINT32_C
  129. # if defined(_WIN32) && defined(_MSC_VER)
  130. # define UINT32_C(n) n ## UI32
  131. # else
  132. # define UINT32_C(n) n ## U
  133. # endif
  134. # endif
  135. # ifndef UINT64_C
  136. # if defined(_WIN32) && defined(_MSC_VER)
  137. # define UINT64_C(n) n ## UI64
  138. # else
  139. /* Get ULONG_MAX. */
  140. # include <limits.h>
  141. # if ULONG_MAX == 4294967295UL
  142. # define UINT64_C(n) n ## ULL
  143. # else
  144. # define UINT64_C(n) n ## UL
  145. # endif
  146. # endif
  147. # endif
  148. # ifndef UINT32_MAX
  149. # define UINT32_MAX (UINT32_C(4294967295))
  150. # endif
  151. # ifndef UINT64_MAX
  152. # define UINT64_MAX (UINT64_C(18446744073709551615))
  153. # endif
  154. # endif
  155. #endif /* ifdef LZMA_MANUAL_HEADERS */
  156. /******************
  157. * LZMA_API macro *
  158. ******************/
  159. /*
  160. * Some systems require that the functions and function pointers are
  161. * declared specially in the headers. LZMA_API_IMPORT is for importing
  162. * symbols and LZMA_API_CALL is to specify the calling convention.
  163. *
  164. * By default it is assumed that the application will link dynamically
  165. * against liblzma. #define LZMA_API_STATIC in your application if you
  166. * want to link against static liblzma. If you don't care about portability
  167. * to operating systems like Windows, or at least don't care about linking
  168. * against static liblzma on them, don't worry about LZMA_API_STATIC. That
  169. * is, most developers will never need to use LZMA_API_STATIC.
  170. *
  171. * The GCC variants are a special case on Windows (Cygwin and MinGW).
  172. * We rely on GCC doing the right thing with its auto-import feature,
  173. * and thus don't use __declspec(dllimport). This way developers don't
  174. * need to worry about LZMA_API_STATIC. Also the calling convention is
  175. * omitted on Cygwin but not on MinGW.
  176. */
  177. #ifndef LZMA_API_IMPORT
  178. # if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
  179. # define LZMA_API_IMPORT __declspec(dllimport)
  180. # else
  181. # define LZMA_API_IMPORT
  182. # endif
  183. #endif
  184. #ifndef LZMA_API_CALL
  185. # if defined(_WIN32) && !defined(__CYGWIN__)
  186. # define LZMA_API_CALL __cdecl
  187. # else
  188. # define LZMA_API_CALL
  189. # endif
  190. #endif
  191. #ifndef LZMA_API
  192. # define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
  193. #endif
  194. /***********
  195. * nothrow *
  196. ***********/
  197. /*
  198. * None of the functions in liblzma may throw an exception. Even
  199. * the functions that use callback functions won't throw exceptions,
  200. * because liblzma would break if a callback function threw an exception.
  201. */
  202. #ifndef lzma_nothrow
  203. # if defined(__cplusplus)
  204. # if __cplusplus >= 201103L || (defined(_MSVC_LANG) \
  205. && _MSVC_LANG >= 201103L)
  206. # define lzma_nothrow noexcept
  207. # else
  208. # define lzma_nothrow throw()
  209. # endif
  210. # elif defined(__GNUC__) && (__GNUC__ > 3 \
  211. || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
  212. # define lzma_nothrow __attribute__((__nothrow__))
  213. # else
  214. # define lzma_nothrow
  215. # endif
  216. #endif
  217. /********************
  218. * GNU C extensions *
  219. ********************/
  220. /*
  221. * GNU C extensions are used conditionally in the public API. It doesn't
  222. * break anything if these are sometimes enabled and sometimes not, only
  223. * affects warnings and optimizations.
  224. */
  225. #if defined(__GNUC__) && __GNUC__ >= 3
  226. # ifndef lzma_attribute
  227. # define lzma_attribute(attr) __attribute__(attr)
  228. # endif
  229. /* warn_unused_result was added in GCC 3.4. */
  230. # ifndef lzma_attr_warn_unused_result
  231. # if __GNUC__ == 3 && __GNUC_MINOR__ < 4
  232. # define lzma_attr_warn_unused_result
  233. # endif
  234. # endif
  235. #else
  236. # ifndef lzma_attribute
  237. # define lzma_attribute(attr)
  238. # endif
  239. #endif
  240. #ifndef lzma_attr_pure
  241. # define lzma_attr_pure lzma_attribute((__pure__))
  242. #endif
  243. #ifndef lzma_attr_const
  244. # define lzma_attr_const lzma_attribute((__const__))
  245. #endif
  246. #ifndef lzma_attr_warn_unused_result
  247. # define lzma_attr_warn_unused_result \
  248. lzma_attribute((__warn_unused_result__))
  249. #endif
  250. /**************
  251. * Subheaders *
  252. **************/
  253. #ifdef __cplusplus
  254. extern "C" {
  255. #endif
  256. /*
  257. * Subheaders check that this is defined. It is to prevent including
  258. * them directly from applications.
  259. */
  260. #define LZMA_H_INTERNAL 1
  261. /* Basic features */
  262. #include "lzma/version.h"
  263. #include "lzma/base.h"
  264. #include "lzma/vli.h"
  265. #include "lzma/check.h"
  266. /* Filters */
  267. #include "lzma/filter.h"
  268. #include "lzma/bcj.h"
  269. #include "lzma/delta.h"
  270. #include "lzma/lzma12.h"
  271. /* Container formats */
  272. #include "lzma/container.h"
  273. /* Advanced features */
  274. #include "lzma/stream_flags.h"
  275. #include "lzma/block.h"
  276. #include "lzma/index.h"
  277. #include "lzma/index_hash.h"
  278. /* Hardware information */
  279. #include "lzma/hardware.h"
  280. /*
  281. * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
  282. * re-including the subheaders.
  283. */
  284. #undef LZMA_H_INTERNAL
  285. #ifdef __cplusplus
  286. }
  287. #endif
  288. #endif /* ifndef LZMA_H */