base.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /**
  2. * \file lzma/base.h
  3. * \brief Data types and functions used in many places in liblzma API
  4. */
  5. /*
  6. * Author: Lasse Collin
  7. *
  8. * This file has been put into the public domain.
  9. * You can do whatever you want with this file.
  10. *
  11. * See ../lzma.h for information about liblzma as a whole.
  12. */
  13. #ifndef LZMA_H_INTERNAL
  14. # error Never include this file directly. Use <lzma.h> instead.
  15. #endif
  16. /**
  17. * \brief Boolean
  18. *
  19. * This is here because C89 doesn't have stdbool.h. To set a value for
  20. * variables having type lzma_bool, you can use
  21. * - C99's `true' and `false' from stdbool.h;
  22. * - C++'s internal `true' and `false'; or
  23. * - integers one (true) and zero (false).
  24. */
  25. typedef unsigned char lzma_bool;
  26. /**
  27. * \brief Type of reserved enumeration variable in structures
  28. *
  29. * To avoid breaking library ABI when new features are added, several
  30. * structures contain extra variables that may be used in future. Since
  31. * sizeof(enum) can be different than sizeof(int), and sizeof(enum) may
  32. * even vary depending on the range of enumeration constants, we specify
  33. * a separate type to be used for reserved enumeration variables. All
  34. * enumeration constants in liblzma API will be non-negative and less
  35. * than 128, which should guarantee that the ABI won't break even when
  36. * new constants are added to existing enumerations.
  37. */
  38. typedef enum {
  39. LZMA_RESERVED_ENUM = 0
  40. } lzma_reserved_enum;
  41. /**
  42. * \brief Return values used by several functions in liblzma
  43. *
  44. * Check the descriptions of specific functions to find out which return
  45. * values they can return. With some functions the return values may have
  46. * more specific meanings than described here; those differences are
  47. * described per-function basis.
  48. */
  49. typedef enum {
  50. LZMA_OK = 0,
  51. /**<
  52. * \brief Operation completed successfully
  53. */
  54. LZMA_STREAM_END = 1,
  55. /**<
  56. * \brief End of stream was reached
  57. *
  58. * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
  59. * LZMA_FINISH was finished. In decoder, this indicates
  60. * that all the data was successfully decoded.
  61. *
  62. * In all cases, when LZMA_STREAM_END is returned, the last
  63. * output bytes should be picked from strm->next_out.
  64. */
  65. LZMA_NO_CHECK = 2,
  66. /**<
  67. * \brief Input stream has no integrity check
  68. *
  69. * This return value can be returned only if the
  70. * LZMA_TELL_NO_CHECK flag was used when initializing
  71. * the decoder. LZMA_NO_CHECK is just a warning, and
  72. * the decoding can be continued normally.
  73. *
  74. * It is possible to call lzma_get_check() immediately after
  75. * lzma_code has returned LZMA_NO_CHECK. The result will
  76. * naturally be LZMA_CHECK_NONE, but the possibility to call
  77. * lzma_get_check() may be convenient in some applications.
  78. */
  79. LZMA_UNSUPPORTED_CHECK = 3,
  80. /**<
  81. * \brief Cannot calculate the integrity check
  82. *
  83. * The usage of this return value is different in encoders
  84. * and decoders.
  85. *
  86. * Encoders can return this value only from the initialization
  87. * function. If initialization fails with this value, the
  88. * encoding cannot be done, because there's no way to produce
  89. * output with the correct integrity check.
  90. *
  91. * Decoders can return this value only from lzma_code() and
  92. * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when
  93. * initializing the decoder. The decoding can still be
  94. * continued normally even if the check type is unsupported,
  95. * but naturally the check will not be validated, and possible
  96. * errors may go undetected.
  97. *
  98. * With decoder, it is possible to call lzma_get_check()
  99. * immediately after lzma_code() has returned
  100. * LZMA_UNSUPPORTED_CHECK. This way it is possible to find
  101. * out what the unsupported Check ID was.
  102. */
  103. LZMA_GET_CHECK = 4,
  104. /**<
  105. * \brief Integrity check type is now available
  106. *
  107. * This value can be returned only by the lzma_code() function
  108. * and only if the decoder was initialized with the
  109. * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the
  110. * application that it may now call lzma_get_check() to find
  111. * out the Check ID. This can be used, for example, to
  112. * implement a decoder that accepts only files that have
  113. * strong enough integrity check.
  114. */
  115. LZMA_MEM_ERROR = 5,
  116. /**<
  117. * \brief Cannot allocate memory
  118. *
  119. * Memory allocation failed, or the size of the allocation
  120. * would be greater than SIZE_MAX.
  121. *
  122. * Due to internal implementation reasons, the coding cannot
  123. * be continued even if more memory were made available after
  124. * LZMA_MEM_ERROR.
  125. */
  126. LZMA_MEMLIMIT_ERROR = 6,
  127. /**
  128. * \brief Memory usage limit was reached
  129. *
  130. * Decoder would need more memory than allowed by the
  131. * specified memory usage limit. To continue decoding,
  132. * the memory usage limit has to be increased with
  133. * lzma_memlimit_set().
  134. *
  135. * liblzma 5.2.6 and earlier had a bug in single-threaded .xz
  136. * decoder (lzma_stream_decoder()) which made it impossible
  137. * to continue decoding after LZMA_MEMLIMIT_ERROR even if
  138. * the limit was increased using lzma_memlimit_set().
  139. * Other decoders worked correctly.
  140. */
  141. LZMA_FORMAT_ERROR = 7,
  142. /**<
  143. * \brief File format not recognized
  144. *
  145. * The decoder did not recognize the input as supported file
  146. * format. This error can occur, for example, when trying to
  147. * decode .lzma format file with lzma_stream_decoder,
  148. * because lzma_stream_decoder accepts only the .xz format.
  149. */
  150. LZMA_OPTIONS_ERROR = 8,
  151. /**<
  152. * \brief Invalid or unsupported options
  153. *
  154. * Invalid or unsupported options, for example
  155. * - unsupported filter(s) or filter options; or
  156. * - reserved bits set in headers (decoder only).
  157. *
  158. * Rebuilding liblzma with more features enabled, or
  159. * upgrading to a newer version of liblzma may help.
  160. */
  161. LZMA_DATA_ERROR = 9,
  162. /**<
  163. * \brief Data is corrupt
  164. *
  165. * The usage of this return value is different in encoders
  166. * and decoders. In both encoder and decoder, the coding
  167. * cannot continue after this error.
  168. *
  169. * Encoders return this if size limits of the target file
  170. * format would be exceeded. These limits are huge, thus
  171. * getting this error from an encoder is mostly theoretical.
  172. * For example, the maximum compressed and uncompressed
  173. * size of a .xz Stream is roughly 8 EiB (2^63 bytes).
  174. *
  175. * Decoders return this error if the input data is corrupt.
  176. * This can mean, for example, invalid CRC32 in headers
  177. * or invalid check of uncompressed data.
  178. */
  179. LZMA_BUF_ERROR = 10,
  180. /**<
  181. * \brief No progress is possible
  182. *
  183. * This error code is returned when the coder cannot consume
  184. * any new input and produce any new output. The most common
  185. * reason for this error is that the input stream being
  186. * decoded is truncated or corrupt.
  187. *
  188. * This error is not fatal. Coding can be continued normally
  189. * by providing more input and/or more output space, if
  190. * possible.
  191. *
  192. * Typically the first call to lzma_code() that can do no
  193. * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only
  194. * the second consecutive call doing no progress will return
  195. * LZMA_BUF_ERROR. This is intentional.
  196. *
  197. * With zlib, Z_BUF_ERROR may be returned even if the
  198. * application is doing nothing wrong, so apps will need
  199. * to handle Z_BUF_ERROR specially. The above hack
  200. * guarantees that liblzma never returns LZMA_BUF_ERROR
  201. * to properly written applications unless the input file
  202. * is truncated or corrupt. This should simplify the
  203. * applications a little.
  204. */
  205. LZMA_PROG_ERROR = 11,
  206. /**<
  207. * \brief Programming error
  208. *
  209. * This indicates that the arguments given to the function are
  210. * invalid or the internal state of the decoder is corrupt.
  211. * - Function arguments are invalid or the structures
  212. * pointed by the argument pointers are invalid
  213. * e.g. if strm->next_out has been set to NULL and
  214. * strm->avail_out > 0 when calling lzma_code().
  215. * - lzma_* functions have been called in wrong order
  216. * e.g. lzma_code() was called right after lzma_end().
  217. * - If errors occur randomly, the reason might be flaky
  218. * hardware.
  219. *
  220. * If you think that your code is correct, this error code
  221. * can be a sign of a bug in liblzma. See the documentation
  222. * how to report bugs.
  223. */
  224. } lzma_ret;
  225. /**
  226. * \brief The `action' argument for lzma_code()
  227. *
  228. * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER,
  229. * or LZMA_FINISH, the same `action' must is used until lzma_code() returns
  230. * LZMA_STREAM_END. Also, the amount of input (that is, strm->avail_in) must
  231. * not be modified by the application until lzma_code() returns
  232. * LZMA_STREAM_END. Changing the `action' or modifying the amount of input
  233. * will make lzma_code() return LZMA_PROG_ERROR.
  234. */
  235. typedef enum {
  236. LZMA_RUN = 0,
  237. /**<
  238. * \brief Continue coding
  239. *
  240. * Encoder: Encode as much input as possible. Some internal
  241. * buffering will probably be done (depends on the filter
  242. * chain in use), which causes latency: the input used won't
  243. * usually be decodeable from the output of the same
  244. * lzma_code() call.
  245. *
  246. * Decoder: Decode as much input as possible and produce as
  247. * much output as possible.
  248. */
  249. LZMA_SYNC_FLUSH = 1,
  250. /**<
  251. * \brief Make all the input available at output
  252. *
  253. * Normally the encoder introduces some latency.
  254. * LZMA_SYNC_FLUSH forces all the buffered data to be
  255. * available at output without resetting the internal
  256. * state of the encoder. This way it is possible to use
  257. * compressed stream for example for communication over
  258. * network.
  259. *
  260. * Only some filters support LZMA_SYNC_FLUSH. Trying to use
  261. * LZMA_SYNC_FLUSH with filters that don't support it will
  262. * make lzma_code() return LZMA_OPTIONS_ERROR. For example,
  263. * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does.
  264. *
  265. * Using LZMA_SYNC_FLUSH very often can dramatically reduce
  266. * the compression ratio. With some filters (for example,
  267. * LZMA2), fine-tuning the compression options may help
  268. * mitigate this problem significantly (for example,
  269. * match finder with LZMA2).
  270. *
  271. * Decoders don't support LZMA_SYNC_FLUSH.
  272. */
  273. LZMA_FULL_FLUSH = 2,
  274. /**<
  275. * \brief Finish encoding of the current Block
  276. *
  277. * All the input data going to the current Block must have
  278. * been given to the encoder (the last bytes can still be
  279. * pending in *next_in). Call lzma_code() with LZMA_FULL_FLUSH
  280. * until it returns LZMA_STREAM_END. Then continue normally
  281. * with LZMA_RUN or finish the Stream with LZMA_FINISH.
  282. *
  283. * This action is currently supported only by Stream encoder
  284. * and easy encoder (which uses Stream encoder). If there is
  285. * no unfinished Block, no empty Block is created.
  286. */
  287. LZMA_FULL_BARRIER = 4,
  288. /**<
  289. * \brief Finish encoding of the current Block
  290. *
  291. * This is like LZMA_FULL_FLUSH except that this doesn't
  292. * necessarily wait until all the input has been made
  293. * available via the output buffer. That is, lzma_code()
  294. * might return LZMA_STREAM_END as soon as all the input
  295. * has been consumed (avail_in == 0).
  296. *
  297. * LZMA_FULL_BARRIER is useful with a threaded encoder if
  298. * one wants to split the .xz Stream into Blocks at specific
  299. * offsets but doesn't care if the output isn't flushed
  300. * immediately. Using LZMA_FULL_BARRIER allows keeping
  301. * the threads busy while LZMA_FULL_FLUSH would make
  302. * lzma_code() wait until all the threads have finished
  303. * until more data could be passed to the encoder.
  304. *
  305. * With a lzma_stream initialized with the single-threaded
  306. * lzma_stream_encoder() or lzma_easy_encoder(),
  307. * LZMA_FULL_BARRIER is an alias for LZMA_FULL_FLUSH.
  308. */
  309. LZMA_FINISH = 3
  310. /**<
  311. * \brief Finish the coding operation
  312. *
  313. * All the input data must have been given to the encoder
  314. * (the last bytes can still be pending in next_in).
  315. * Call lzma_code() with LZMA_FINISH until it returns
  316. * LZMA_STREAM_END. Once LZMA_FINISH has been used,
  317. * the amount of input must no longer be changed by
  318. * the application.
  319. *
  320. * When decoding, using LZMA_FINISH is optional unless the
  321. * LZMA_CONCATENATED flag was used when the decoder was
  322. * initialized. When LZMA_CONCATENATED was not used, the only
  323. * effect of LZMA_FINISH is that the amount of input must not
  324. * be changed just like in the encoder.
  325. */
  326. } lzma_action;
  327. /**
  328. * \brief Custom functions for memory handling
  329. *
  330. * A pointer to lzma_allocator may be passed via lzma_stream structure
  331. * to liblzma, and some advanced functions take a pointer to lzma_allocator
  332. * as a separate function argument. The library will use the functions
  333. * specified in lzma_allocator for memory handling instead of the default
  334. * malloc() and free(). C++ users should note that the custom memory
  335. * handling functions must not throw exceptions.
  336. *
  337. * Single-threaded mode only: liblzma doesn't make an internal copy of
  338. * lzma_allocator. Thus, it is OK to change these function pointers in
  339. * the middle of the coding process, but obviously it must be done
  340. * carefully to make sure that the replacement `free' can deallocate
  341. * memory allocated by the earlier `alloc' function(s).
  342. *
  343. * Multithreaded mode: liblzma might internally store pointers to the
  344. * lzma_allocator given via the lzma_stream structure. The application
  345. * must not change the allocator pointer in lzma_stream or the contents
  346. * of the pointed lzma_allocator structure until lzma_end() has been used
  347. * to free the memory associated with that lzma_stream. The allocation
  348. * functions might be called simultaneously from multiple threads, and
  349. * thus they must be thread safe.
  350. */
  351. typedef struct {
  352. /**
  353. * \brief Pointer to a custom memory allocation function
  354. *
  355. * If you don't want a custom allocator, but still want
  356. * custom free(), set this to NULL and liblzma will use
  357. * the standard malloc().
  358. *
  359. * \param opaque lzma_allocator.opaque (see below)
  360. * \param nmemb Number of elements like in calloc(). liblzma
  361. * will always set nmemb to 1, so it is safe to
  362. * ignore nmemb in a custom allocator if you like.
  363. * The nmemb argument exists only for
  364. * compatibility with zlib and libbzip2.
  365. * \param size Size of an element in bytes.
  366. * liblzma never sets this to zero.
  367. *
  368. * \return Pointer to the beginning of a memory block of
  369. * `size' bytes, or NULL if allocation fails
  370. * for some reason. When allocation fails, functions
  371. * of liblzma return LZMA_MEM_ERROR.
  372. *
  373. * The allocator should not waste time zeroing the allocated buffers.
  374. * This is not only about speed, but also memory usage, since the
  375. * operating system kernel doesn't necessarily allocate the requested
  376. * memory in physical memory until it is actually used. With small
  377. * input files, liblzma may actually need only a fraction of the
  378. * memory that it requested for allocation.
  379. *
  380. * \note LZMA_MEM_ERROR is also used when the size of the
  381. * allocation would be greater than SIZE_MAX. Thus,
  382. * don't assume that the custom allocator must have
  383. * returned NULL if some function from liblzma
  384. * returns LZMA_MEM_ERROR.
  385. */
  386. void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size);
  387. /**
  388. * \brief Pointer to a custom memory freeing function
  389. *
  390. * If you don't want a custom freeing function, but still
  391. * want a custom allocator, set this to NULL and liblzma
  392. * will use the standard free().
  393. *
  394. * \param opaque lzma_allocator.opaque (see below)
  395. * \param ptr Pointer returned by lzma_allocator.alloc(),
  396. * or when it is set to NULL, a pointer returned
  397. * by the standard malloc().
  398. */
  399. void (LZMA_API_CALL *free)(void *opaque, void *ptr);
  400. /**
  401. * \brief Pointer passed to .alloc() and .free()
  402. *
  403. * opaque is passed as the first argument to lzma_allocator.alloc()
  404. * and lzma_allocator.free(). This intended to ease implementing
  405. * custom memory allocation functions for use with liblzma.
  406. *
  407. * If you don't need this, you should set this to NULL.
  408. */
  409. void *opaque;
  410. } lzma_allocator;
  411. /**
  412. * \brief Internal data structure
  413. *
  414. * The contents of this structure is not visible outside the library.
  415. */
  416. typedef struct lzma_internal_s lzma_internal;
  417. /**
  418. * \brief Passing data to and from liblzma
  419. *
  420. * The lzma_stream structure is used for
  421. * - passing pointers to input and output buffers to liblzma;
  422. * - defining custom memory handler functions; and
  423. * - holding a pointer to coder-specific internal data structures.
  424. *
  425. * Typical usage:
  426. *
  427. * - After allocating lzma_stream (on stack or with malloc()), it must be
  428. * initialized to LZMA_STREAM_INIT (see LZMA_STREAM_INIT for details).
  429. *
  430. * - Initialize a coder to the lzma_stream, for example by using
  431. * lzma_easy_encoder() or lzma_auto_decoder(). Some notes:
  432. * - In contrast to zlib, strm->next_in and strm->next_out are
  433. * ignored by all initialization functions, thus it is safe
  434. * to not initialize them yet.
  435. * - The initialization functions always set strm->total_in and
  436. * strm->total_out to zero.
  437. * - If the initialization function fails, no memory is left allocated
  438. * that would require freeing with lzma_end() even if some memory was
  439. * associated with the lzma_stream structure when the initialization
  440. * function was called.
  441. *
  442. * - Use lzma_code() to do the actual work.
  443. *
  444. * - Once the coding has been finished, the existing lzma_stream can be
  445. * reused. It is OK to reuse lzma_stream with different initialization
  446. * function without calling lzma_end() first. Old allocations are
  447. * automatically freed.
  448. *
  449. * - Finally, use lzma_end() to free the allocated memory. lzma_end() never
  450. * frees the lzma_stream structure itself.
  451. *
  452. * Application may modify the values of total_in and total_out as it wants.
  453. * They are updated by liblzma to match the amount of data read and
  454. * written but aren't used for anything else except as a possible return
  455. * values from lzma_get_progress().
  456. */
  457. typedef struct {
  458. const uint8_t *next_in; /**< Pointer to the next input byte. */
  459. size_t avail_in; /**< Number of available input bytes in next_in. */
  460. uint64_t total_in; /**< Total number of bytes read by liblzma. */
  461. uint8_t *next_out; /**< Pointer to the next output position. */
  462. size_t avail_out; /**< Amount of free space in next_out. */
  463. uint64_t total_out; /**< Total number of bytes written by liblzma. */
  464. /**
  465. * \brief Custom memory allocation functions
  466. *
  467. * In most cases this is NULL which makes liblzma use
  468. * the standard malloc() and free().
  469. *
  470. * \note In 5.0.x this is not a const pointer.
  471. */
  472. const lzma_allocator *allocator;
  473. /** Internal state is not visible to applications. */
  474. lzma_internal *internal;
  475. /*
  476. * Reserved space to allow possible future extensions without
  477. * breaking the ABI. Excluding the initialization of this structure,
  478. * you should not touch these, because the names of these variables
  479. * may change.
  480. */
  481. void *reserved_ptr1;
  482. void *reserved_ptr2;
  483. void *reserved_ptr3;
  484. void *reserved_ptr4;
  485. uint64_t reserved_int1;
  486. uint64_t reserved_int2;
  487. size_t reserved_int3;
  488. size_t reserved_int4;
  489. lzma_reserved_enum reserved_enum1;
  490. lzma_reserved_enum reserved_enum2;
  491. } lzma_stream;
  492. /**
  493. * \brief Initialization for lzma_stream
  494. *
  495. * When you declare an instance of lzma_stream, you can immediately
  496. * initialize it so that initialization functions know that no memory
  497. * has been allocated yet:
  498. *
  499. * lzma_stream strm = LZMA_STREAM_INIT;
  500. *
  501. * If you need to initialize a dynamically allocated lzma_stream, you can use
  502. * memset(strm_pointer, 0, sizeof(lzma_stream)). Strictly speaking, this
  503. * violates the C standard since NULL may have different internal
  504. * representation than zero, but it should be portable enough in practice.
  505. * Anyway, for maximum portability, you can use something like this:
  506. *
  507. * lzma_stream tmp = LZMA_STREAM_INIT;
  508. * *strm = tmp;
  509. */
  510. #define LZMA_STREAM_INIT \
  511. { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \
  512. NULL, NULL, NULL, NULL, 0, 0, 0, 0, \
  513. LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM }
  514. /**
  515. * \brief Encode or decode data
  516. *
  517. * Once the lzma_stream has been successfully initialized (e.g. with
  518. * lzma_stream_encoder()), the actual encoding or decoding is done
  519. * using this function. The application has to update strm->next_in,
  520. * strm->avail_in, strm->next_out, and strm->avail_out to pass input
  521. * to and get output from liblzma.
  522. *
  523. * See the description of the coder-specific initialization function to find
  524. * out what `action' values are supported by the coder.
  525. */
  526. extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
  527. lzma_nothrow lzma_attr_warn_unused_result;
  528. /**
  529. * \brief Free memory allocated for the coder data structures
  530. *
  531. * \param strm Pointer to lzma_stream that is at least initialized
  532. * with LZMA_STREAM_INIT.
  533. *
  534. * After lzma_end(strm), strm->internal is guaranteed to be NULL. No other
  535. * members of the lzma_stream structure are touched.
  536. *
  537. * \note zlib indicates an error if application end()s unfinished
  538. * stream structure. liblzma doesn't do this, and assumes that
  539. * application knows what it is doing.
  540. */
  541. extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
  542. /**
  543. * \brief Get progress information
  544. *
  545. * In single-threaded mode, applications can get progress information from
  546. * strm->total_in and strm->total_out. In multi-threaded mode this is less
  547. * useful because a significant amount of both input and output data gets
  548. * buffered internally by liblzma. This makes total_in and total_out give
  549. * misleading information and also makes the progress indicator updates
  550. * non-smooth.
  551. *
  552. * This function gives realistic progress information also in multi-threaded
  553. * mode by taking into account the progress made by each thread. In
  554. * single-threaded mode *progress_in and *progress_out are set to
  555. * strm->total_in and strm->total_out, respectively.
  556. */
  557. extern LZMA_API(void) lzma_get_progress(lzma_stream *strm,
  558. uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow;
  559. /**
  560. * \brief Get the memory usage of decoder filter chain
  561. *
  562. * This function is currently supported only when *strm has been initialized
  563. * with a function that takes a memlimit argument. With other functions, you
  564. * should use e.g. lzma_raw_encoder_memusage() or lzma_raw_decoder_memusage()
  565. * to estimate the memory requirements.
  566. *
  567. * This function is useful e.g. after LZMA_MEMLIMIT_ERROR to find out how big
  568. * the memory usage limit should have been to decode the input. Note that
  569. * this may give misleading information if decoding .xz Streams that have
  570. * multiple Blocks, because each Block can have different memory requirements.
  571. *
  572. * \return How much memory is currently allocated for the filter
  573. * decoders. If no filter chain is currently allocated,
  574. * some non-zero value is still returned, which is less than
  575. * or equal to what any filter chain would indicate as its
  576. * memory requirement.
  577. *
  578. * If this function isn't supported by *strm or some other error
  579. * occurs, zero is returned.
  580. */
  581. extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm)
  582. lzma_nothrow lzma_attr_pure;
  583. /**
  584. * \brief Get the current memory usage limit
  585. *
  586. * This function is supported only when *strm has been initialized with
  587. * a function that takes a memlimit argument.
  588. *
  589. * \return On success, the current memory usage limit is returned
  590. * (always non-zero). On error, zero is returned.
  591. */
  592. extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
  593. lzma_nothrow lzma_attr_pure;
  594. /**
  595. * \brief Set the memory usage limit
  596. *
  597. * This function is supported only when *strm has been initialized with
  598. * a function that takes a memlimit argument.
  599. *
  600. * liblzma 5.2.3 and earlier has a bug where memlimit value of 0 causes
  601. * this function to do nothing (leaving the limit unchanged) and still
  602. * return LZMA_OK. Later versions treat 0 as if 1 had been specified (so
  603. * lzma_memlimit_get() will return 1 even if you specify 0 here).
  604. *
  605. * liblzma 5.2.6 and earlier had a bug in single-threaded .xz decoder
  606. * (lzma_stream_decoder()) which made it impossible to continue decoding
  607. * after LZMA_MEMLIMIT_ERROR even if the limit was increased using
  608. * lzma_memlimit_set(). Other decoders worked correctly.
  609. *
  610. * \return - LZMA_OK: New memory usage limit successfully set.
  611. * - LZMA_MEMLIMIT_ERROR: The new limit is too small.
  612. * The limit was not changed.
  613. * - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
  614. * support memory usage limit.
  615. */
  616. extern LZMA_API(lzma_ret) lzma_memlimit_set(
  617. lzma_stream *strm, uint64_t memlimit) lzma_nothrow;