lzma.h 9.7 KB

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