Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:44:22

0001 /**
0002  * \file        lzma/base.h
0003  * \brief       Data types and functions used in many places in liblzma API
0004  * \note        Never include this file directly. Use <lzma.h> instead.
0005  */
0006 
0007 /*
0008  * Author: Lasse Collin
0009  *
0010  * This file has been put into the public domain.
0011  * You can do whatever you want with this file.
0012  */
0013 
0014 #ifndef LZMA_H_INTERNAL
0015 #   error Never include this file directly. Use <lzma.h> instead.
0016 #endif
0017 
0018 
0019 /**
0020  * \brief       Boolean
0021  *
0022  * This is here because C89 doesn't have stdbool.h. To set a value for
0023  * variables having type lzma_bool, you can use
0024  *   - C99's `true' and `false' from stdbool.h;
0025  *   - C++'s internal `true' and `false'; or
0026  *   - integers one (true) and zero (false).
0027  */
0028 typedef unsigned char lzma_bool;
0029 
0030 
0031 /**
0032  * \brief       Type of reserved enumeration variable in structures
0033  *
0034  * To avoid breaking library ABI when new features are added, several
0035  * structures contain extra variables that may be used in future. Since
0036  * sizeof(enum) can be different than sizeof(int), and sizeof(enum) may
0037  * even vary depending on the range of enumeration constants, we specify
0038  * a separate type to be used for reserved enumeration variables. All
0039  * enumeration constants in liblzma API will be non-negative and less
0040  * than 128, which should guarantee that the ABI won't break even when
0041  * new constants are added to existing enumerations.
0042  */
0043 typedef enum {
0044     LZMA_RESERVED_ENUM      = 0
0045 } lzma_reserved_enum;
0046 
0047 
0048 /**
0049  * \brief       Return values used by several functions in liblzma
0050  *
0051  * Check the descriptions of specific functions to find out which return
0052  * values they can return. With some functions the return values may have
0053  * more specific meanings than described here; those differences are
0054  * described per-function basis.
0055  */
0056 typedef enum {
0057     LZMA_OK                 = 0,
0058         /**<
0059          * \brief       Operation completed successfully
0060          */
0061 
0062     LZMA_STREAM_END         = 1,
0063         /**<
0064          * \brief       End of stream was reached
0065          *
0066          * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or
0067          * LZMA_FINISH was finished. In decoder, this indicates
0068          * that all the data was successfully decoded.
0069          *
0070          * In all cases, when LZMA_STREAM_END is returned, the last
0071          * output bytes should be picked from strm->next_out.
0072          */
0073 
0074     LZMA_NO_CHECK           = 2,
0075         /**<
0076          * \brief       Input stream has no integrity check
0077          *
0078          * This return value can be returned only if the
0079          * LZMA_TELL_NO_CHECK flag was used when initializing
0080          * the decoder. LZMA_NO_CHECK is just a warning, and
0081          * the decoding can be continued normally.
0082          *
0083          * It is possible to call lzma_get_check() immediately after
0084          * lzma_code has returned LZMA_NO_CHECK. The result will
0085          * naturally be LZMA_CHECK_NONE, but the possibility to call
0086          * lzma_get_check() may be convenient in some applications.
0087          */
0088 
0089     LZMA_UNSUPPORTED_CHECK  = 3,
0090         /**<
0091          * \brief       Cannot calculate the integrity check
0092          *
0093          * The usage of this return value is different in encoders
0094          * and decoders.
0095          *
0096          * Encoders can return this value only from the initialization
0097          * function. If initialization fails with this value, the
0098          * encoding cannot be done, because there's no way to produce
0099          * output with the correct integrity check.
0100          *
0101          * Decoders can return this value only from lzma_code() and
0102          * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when
0103          * initializing the decoder. The decoding can still be
0104          * continued normally even if the check type is unsupported,
0105          * but naturally the check will not be validated, and possible
0106          * errors may go undetected.
0107          *
0108          * With decoder, it is possible to call lzma_get_check()
0109          * immediately after lzma_code() has returned
0110          * LZMA_UNSUPPORTED_CHECK. This way it is possible to find
0111          * out what the unsupported Check ID was.
0112          */
0113 
0114     LZMA_GET_CHECK          = 4,
0115         /**<
0116          * \brief       Integrity check type is now available
0117          *
0118          * This value can be returned only by the lzma_code() function
0119          * and only if the decoder was initialized with the
0120          * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the
0121          * application that it may now call lzma_get_check() to find
0122          * out the Check ID. This can be used, for example, to
0123          * implement a decoder that accepts only files that have
0124          * strong enough integrity check.
0125          */
0126 
0127     LZMA_MEM_ERROR          = 5,
0128         /**<
0129          * \brief       Cannot allocate memory
0130          *
0131          * Memory allocation failed, or the size of the allocation
0132          * would be greater than SIZE_MAX.
0133          *
0134          * Due to internal implementation reasons, the coding cannot
0135          * be continued even if more memory were made available after
0136          * LZMA_MEM_ERROR.
0137          */
0138 
0139     LZMA_MEMLIMIT_ERROR     = 6,
0140         /**<
0141          * \brief       Memory usage limit was reached
0142          *
0143          * Decoder would need more memory than allowed by the
0144          * specified memory usage limit. To continue decoding,
0145          * the memory usage limit has to be increased with
0146          * lzma_memlimit_set().
0147          *
0148          * liblzma 5.2.6 and earlier had a bug in single-threaded .xz
0149          * decoder (lzma_stream_decoder()) which made it impossible
0150          * to continue decoding after LZMA_MEMLIMIT_ERROR even if
0151          * the limit was increased using lzma_memlimit_set().
0152          * Other decoders worked correctly.
0153          */
0154 
0155     LZMA_FORMAT_ERROR       = 7,
0156         /**<
0157          * \brief       File format not recognized
0158          *
0159          * The decoder did not recognize the input as supported file
0160          * format. This error can occur, for example, when trying to
0161          * decode .lzma format file with lzma_stream_decoder,
0162          * because lzma_stream_decoder accepts only the .xz format.
0163          */
0164 
0165     LZMA_OPTIONS_ERROR      = 8,
0166         /**<
0167          * \brief       Invalid or unsupported options
0168          *
0169          * Invalid or unsupported options, for example
0170          *  - unsupported filter(s) or filter options; or
0171          *  - reserved bits set in headers (decoder only).
0172          *
0173          * Rebuilding liblzma with more features enabled, or
0174          * upgrading to a newer version of liblzma may help.
0175          */
0176 
0177     LZMA_DATA_ERROR         = 9,
0178         /**<
0179          * \brief       Data is corrupt
0180          *
0181          * The usage of this return value is different in encoders
0182          * and decoders. In both encoder and decoder, the coding
0183          * cannot continue after this error.
0184          *
0185          * Encoders return this if size limits of the target file
0186          * format would be exceeded. These limits are huge, thus
0187          * getting this error from an encoder is mostly theoretical.
0188          * For example, the maximum compressed and uncompressed
0189          * size of a .xz Stream is roughly 8 EiB (2^63 bytes).
0190          *
0191          * Decoders return this error if the input data is corrupt.
0192          * This can mean, for example, invalid CRC32 in headers
0193          * or invalid check of uncompressed data.
0194          */
0195 
0196     LZMA_BUF_ERROR          = 10,
0197         /**<
0198          * \brief       No progress is possible
0199          *
0200          * This error code is returned when the coder cannot consume
0201          * any new input and produce any new output. The most common
0202          * reason for this error is that the input stream being
0203          * decoded is truncated or corrupt.
0204          *
0205          * This error is not fatal. Coding can be continued normally
0206          * by providing more input and/or more output space, if
0207          * possible.
0208          *
0209          * Typically the first call to lzma_code() that can do no
0210          * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only
0211          * the second consecutive call doing no progress will return
0212          * LZMA_BUF_ERROR. This is intentional.
0213          *
0214          * With zlib, Z_BUF_ERROR may be returned even if the
0215          * application is doing nothing wrong, so apps will need
0216          * to handle Z_BUF_ERROR specially. The above hack
0217          * guarantees that liblzma never returns LZMA_BUF_ERROR
0218          * to properly written applications unless the input file
0219          * is truncated or corrupt. This should simplify the
0220          * applications a little.
0221          */
0222 
0223     LZMA_PROG_ERROR         = 11,
0224         /**<
0225          * \brief       Programming error
0226          *
0227          * This indicates that the arguments given to the function are
0228          * invalid or the internal state of the decoder is corrupt.
0229          *   - Function arguments are invalid or the structures
0230          *     pointed by the argument pointers are invalid
0231          *     e.g. if strm->next_out has been set to NULL and
0232          *     strm->avail_out > 0 when calling lzma_code().
0233          *   - lzma_* functions have been called in wrong order
0234          *     e.g. lzma_code() was called right after lzma_end().
0235          *   - If errors occur randomly, the reason might be flaky
0236          *     hardware.
0237          *
0238          * If you think that your code is correct, this error code
0239          * can be a sign of a bug in liblzma. See the documentation
0240          * how to report bugs.
0241          */
0242 
0243     LZMA_SEEK_NEEDED        = 12,
0244         /**<
0245          * \brief       Request to change the input file position
0246          *
0247          * Some coders can do random access in the input file. The
0248          * initialization functions of these coders take the file size
0249          * as an argument. No other coders can return LZMA_SEEK_NEEDED.
0250          *
0251          * When this value is returned, the application must seek to
0252          * the file position given in lzma_stream.seek_pos. This value
0253          * is guaranteed to never exceed the file size that was
0254          * specified at the coder initialization.
0255          *
0256          * After seeking the application should read new input and
0257          * pass it normally via lzma_stream.next_in and .avail_in.
0258          */
0259 
0260     /*
0261      * These eumerations may be used internally by liblzma
0262      * but they will never be returned to applications.
0263      */
0264     LZMA_RET_INTERNAL1      = 101,
0265     LZMA_RET_INTERNAL2      = 102,
0266     LZMA_RET_INTERNAL3      = 103,
0267     LZMA_RET_INTERNAL4      = 104,
0268     LZMA_RET_INTERNAL5      = 105,
0269     LZMA_RET_INTERNAL6      = 106,
0270     LZMA_RET_INTERNAL7      = 107,
0271     LZMA_RET_INTERNAL8      = 108
0272 } lzma_ret;
0273 
0274 
0275 /**
0276  * \brief       The `action' argument for lzma_code()
0277  *
0278  * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, LZMA_FULL_BARRIER,
0279  * or LZMA_FINISH, the same `action' must be used until lzma_code() returns
0280  * LZMA_STREAM_END. Also, the amount of input (that is, strm->avail_in) must
0281  * not be modified by the application until lzma_code() returns
0282  * LZMA_STREAM_END. Changing the `action' or modifying the amount of input
0283  * will make lzma_code() return LZMA_PROG_ERROR.
0284  */
0285 typedef enum {
0286     LZMA_RUN = 0,
0287         /**<
0288          * \brief       Continue coding
0289          *
0290          * Encoder: Encode as much input as possible. Some internal
0291          * buffering will probably be done (depends on the filter
0292          * chain in use), which causes latency: the input used won't
0293          * usually be decodeable from the output of the same
0294          * lzma_code() call.
0295          *
0296          * Decoder: Decode as much input as possible and produce as
0297          * much output as possible.
0298          */
0299 
0300     LZMA_SYNC_FLUSH = 1,
0301         /**<
0302          * \brief       Make all the input available at output
0303          *
0304          * Normally the encoder introduces some latency.
0305          * LZMA_SYNC_FLUSH forces all the buffered data to be
0306          * available at output without resetting the internal
0307          * state of the encoder. This way it is possible to use
0308          * compressed stream for example for communication over
0309          * network.
0310          *
0311          * Only some filters support LZMA_SYNC_FLUSH. Trying to use
0312          * LZMA_SYNC_FLUSH with filters that don't support it will
0313          * make lzma_code() return LZMA_OPTIONS_ERROR. For example,
0314          * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does.
0315          *
0316          * Using LZMA_SYNC_FLUSH very often can dramatically reduce
0317          * the compression ratio. With some filters (for example,
0318          * LZMA2), fine-tuning the compression options may help
0319          * mitigate this problem significantly (for example,
0320          * match finder with LZMA2).
0321          *
0322          * Decoders don't support LZMA_SYNC_FLUSH.
0323          */
0324 
0325     LZMA_FULL_FLUSH = 2,
0326         /**<
0327          * \brief       Finish encoding of the current Block
0328          *
0329          * All the input data going to the current Block must have
0330          * been given to the encoder (the last bytes can still be
0331          * pending in *next_in). Call lzma_code() with LZMA_FULL_FLUSH
0332          * until it returns LZMA_STREAM_END. Then continue normally
0333          * with LZMA_RUN or finish the Stream with LZMA_FINISH.
0334          *
0335          * This action is currently supported only by Stream encoder
0336          * and easy encoder (which uses Stream encoder). If there is
0337          * no unfinished Block, no empty Block is created.
0338          */
0339 
0340     LZMA_FULL_BARRIER = 4,
0341         /**<
0342          * \brief       Finish encoding of the current Block
0343          *
0344          * This is like LZMA_FULL_FLUSH except that this doesn't
0345          * necessarily wait until all the input has been made
0346          * available via the output buffer. That is, lzma_code()
0347          * might return LZMA_STREAM_END as soon as all the input
0348          * has been consumed (avail_in == 0).
0349          *
0350          * LZMA_FULL_BARRIER is useful with a threaded encoder if
0351          * one wants to split the .xz Stream into Blocks at specific
0352          * offsets but doesn't care if the output isn't flushed
0353          * immediately. Using LZMA_FULL_BARRIER allows keeping
0354          * the threads busy while LZMA_FULL_FLUSH would make
0355          * lzma_code() wait until all the threads have finished
0356          * until more data could be passed to the encoder.
0357          *
0358          * With a lzma_stream initialized with the single-threaded
0359          * lzma_stream_encoder() or lzma_easy_encoder(),
0360          * LZMA_FULL_BARRIER is an alias for LZMA_FULL_FLUSH.
0361          */
0362 
0363     LZMA_FINISH = 3
0364         /**<
0365          * \brief       Finish the coding operation
0366          *
0367          * All the input data must have been given to the encoder
0368          * (the last bytes can still be pending in next_in).
0369          * Call lzma_code() with LZMA_FINISH until it returns
0370          * LZMA_STREAM_END. Once LZMA_FINISH has been used,
0371          * the amount of input must no longer be changed by
0372          * the application.
0373          *
0374          * When decoding, using LZMA_FINISH is optional unless the
0375          * LZMA_CONCATENATED flag was used when the decoder was
0376          * initialized. When LZMA_CONCATENATED was not used, the only
0377          * effect of LZMA_FINISH is that the amount of input must not
0378          * be changed just like in the encoder.
0379          */
0380 } lzma_action;
0381 
0382 
0383 /**
0384  * \brief       Custom functions for memory handling
0385  *
0386  * A pointer to lzma_allocator may be passed via lzma_stream structure
0387  * to liblzma, and some advanced functions take a pointer to lzma_allocator
0388  * as a separate function argument. The library will use the functions
0389  * specified in lzma_allocator for memory handling instead of the default
0390  * malloc() and free(). C++ users should note that the custom memory
0391  * handling functions must not throw exceptions.
0392  *
0393  * Single-threaded mode only: liblzma doesn't make an internal copy of
0394  * lzma_allocator. Thus, it is OK to change these function pointers in
0395  * the middle of the coding process, but obviously it must be done
0396  * carefully to make sure that the replacement `free' can deallocate
0397  * memory allocated by the earlier `alloc' function(s).
0398  *
0399  * Multithreaded mode: liblzma might internally store pointers to the
0400  * lzma_allocator given via the lzma_stream structure. The application
0401  * must not change the allocator pointer in lzma_stream or the contents
0402  * of the pointed lzma_allocator structure until lzma_end() has been used
0403  * to free the memory associated with that lzma_stream. The allocation
0404  * functions might be called simultaneously from multiple threads, and
0405  * thus they must be thread safe.
0406  */
0407 typedef struct {
0408     /**
0409      * \brief       Pointer to a custom memory allocation function
0410      *
0411      * If you don't want a custom allocator, but still want
0412      * custom free(), set this to NULL and liblzma will use
0413      * the standard malloc().
0414      *
0415      * \param       opaque  lzma_allocator.opaque (see below)
0416      * \param       nmemb   Number of elements like in calloc(). liblzma
0417      *                      will always set nmemb to 1, so it is safe to
0418      *                      ignore nmemb in a custom allocator if you like.
0419      *                      The nmemb argument exists only for
0420      *                      compatibility with zlib and libbzip2.
0421      * \param       size    Size of an element in bytes.
0422      *                      liblzma never sets this to zero.
0423      *
0424      * \return      Pointer to the beginning of a memory block of
0425      *              `size' bytes, or NULL if allocation fails
0426      *              for some reason. When allocation fails, functions
0427      *              of liblzma return LZMA_MEM_ERROR.
0428      *
0429      * The allocator should not waste time zeroing the allocated buffers.
0430      * This is not only about speed, but also memory usage, since the
0431      * operating system kernel doesn't necessarily allocate the requested
0432      * memory in physical memory until it is actually used. With small
0433      * input files, liblzma may actually need only a fraction of the
0434      * memory that it requested for allocation.
0435      *
0436      * \note        LZMA_MEM_ERROR is also used when the size of the
0437      *              allocation would be greater than SIZE_MAX. Thus,
0438      *              don't assume that the custom allocator must have
0439      *              returned NULL if some function from liblzma
0440      *              returns LZMA_MEM_ERROR.
0441      */
0442     void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size);
0443 
0444     /**
0445      * \brief       Pointer to a custom memory freeing function
0446      *
0447      * If you don't want a custom freeing function, but still
0448      * want a custom allocator, set this to NULL and liblzma
0449      * will use the standard free().
0450      *
0451      * \param       opaque  lzma_allocator.opaque (see below)
0452      * \param       ptr     Pointer returned by lzma_allocator.alloc(),
0453      *                      or when it is set to NULL, a pointer returned
0454      *                      by the standard malloc().
0455      */
0456     void (LZMA_API_CALL *free)(void *opaque, void *ptr);
0457 
0458     /**
0459      * \brief       Pointer passed to .alloc() and .free()
0460      *
0461      * opaque is passed as the first argument to lzma_allocator.alloc()
0462      * and lzma_allocator.free(). This intended to ease implementing
0463      * custom memory allocation functions for use with liblzma.
0464      *
0465      * If you don't need this, you should set this to NULL.
0466      */
0467     void *opaque;
0468 
0469 } lzma_allocator;
0470 
0471 
0472 /**
0473  * \brief       Internal data structure
0474  *
0475  * The contents of this structure is not visible outside the library.
0476  */
0477 typedef struct lzma_internal_s lzma_internal;
0478 
0479 
0480 /**
0481  * \brief       Passing data to and from liblzma
0482  *
0483  * The lzma_stream structure is used for
0484  *  - passing pointers to input and output buffers to liblzma;
0485  *  - defining custom memory handler functions; and
0486  *  - holding a pointer to coder-specific internal data structures.
0487  *
0488  * Typical usage:
0489  *
0490  *  - After allocating lzma_stream (on stack or with malloc()), it must be
0491  *    initialized to LZMA_STREAM_INIT (see LZMA_STREAM_INIT for details).
0492  *
0493  *  - Initialize a coder to the lzma_stream, for example by using
0494  *    lzma_easy_encoder() or lzma_auto_decoder(). Some notes:
0495  *      - In contrast to zlib, strm->next_in and strm->next_out are
0496  *        ignored by all initialization functions, thus it is safe
0497  *        to not initialize them yet.
0498  *      - The initialization functions always set strm->total_in and
0499  *        strm->total_out to zero.
0500  *      - If the initialization function fails, no memory is left allocated
0501  *        that would require freeing with lzma_end() even if some memory was
0502  *        associated with the lzma_stream structure when the initialization
0503  *        function was called.
0504  *
0505  *  - Use lzma_code() to do the actual work.
0506  *
0507  *  - Once the coding has been finished, the existing lzma_stream can be
0508  *    reused. It is OK to reuse lzma_stream with different initialization
0509  *    function without calling lzma_end() first. Old allocations are
0510  *    automatically freed.
0511  *
0512  *  - Finally, use lzma_end() to free the allocated memory. lzma_end() never
0513  *    frees the lzma_stream structure itself.
0514  *
0515  * Application may modify the values of total_in and total_out as it wants.
0516  * They are updated by liblzma to match the amount of data read and
0517  * written but aren't used for anything else except as a possible return
0518  * values from lzma_get_progress().
0519  */
0520 typedef struct {
0521     const uint8_t *next_in; /**< Pointer to the next input byte. */
0522     size_t avail_in;    /**< Number of available input bytes in next_in. */
0523     uint64_t total_in;  /**< Total number of bytes read by liblzma. */
0524 
0525     uint8_t *next_out;  /**< Pointer to the next output position. */
0526     size_t avail_out;   /**< Amount of free space in next_out. */
0527     uint64_t total_out; /**< Total number of bytes written by liblzma. */
0528 
0529     /**
0530      * \brief       Custom memory allocation functions
0531      *
0532      * In most cases this is NULL which makes liblzma use
0533      * the standard malloc() and free().
0534      *
0535      * \note        In 5.0.x this is not a const pointer.
0536      */
0537     const lzma_allocator *allocator;
0538 
0539     /** Internal state is not visible to applications. */
0540     lzma_internal *internal;
0541 
0542     /*
0543      * Reserved space to allow possible future extensions without
0544      * breaking the ABI. Excluding the initialization of this structure,
0545      * you should not touch these, because the names of these variables
0546      * may change.
0547      */
0548 
0549     /** \private     Reserved member. */
0550     void *reserved_ptr1;
0551 
0552     /** \private     Reserved member. */
0553     void *reserved_ptr2;
0554 
0555     /** \private     Reserved member. */
0556     void *reserved_ptr3;
0557 
0558     /** \private     Reserved member. */
0559     void *reserved_ptr4;
0560 
0561     /**
0562      * \brief       New seek input position for LZMA_SEEK_NEEDED
0563      *
0564      * When lzma_code() returns LZMA_SEEK_NEEDED, the new input position
0565      * needed by liblzma will be available seek_pos. The value is
0566      * guaranteed to not exceed the file size that was specified when
0567      * this lzma_stream was initialized.
0568      *
0569      * In all other situations the value of this variable is undefined.
0570      */
0571     uint64_t seek_pos;
0572 
0573     /** \private     Reserved member. */
0574     uint64_t reserved_int2;
0575 
0576     /** \private     Reserved member. */
0577     size_t reserved_int3;
0578 
0579     /** \private     Reserved member. */
0580     size_t reserved_int4;
0581 
0582     /** \private     Reserved member. */
0583     lzma_reserved_enum reserved_enum1;
0584 
0585     /** \private     Reserved member. */
0586     lzma_reserved_enum reserved_enum2;
0587 
0588 } lzma_stream;
0589 
0590 
0591 /**
0592  * \brief       Initialization for lzma_stream
0593  *
0594  * When you declare an instance of lzma_stream, you can immediately
0595  * initialize it so that initialization functions know that no memory
0596  * has been allocated yet:
0597  *
0598  *     lzma_stream strm = LZMA_STREAM_INIT;
0599  *
0600  * If you need to initialize a dynamically allocated lzma_stream, you can use
0601  * memset(strm_pointer, 0, sizeof(lzma_stream)). Strictly speaking, this
0602  * violates the C standard since NULL may have different internal
0603  * representation than zero, but it should be portable enough in practice.
0604  * Anyway, for maximum portability, you can use something like this:
0605  *
0606  *     lzma_stream tmp = LZMA_STREAM_INIT;
0607  *     *strm = tmp;
0608  */
0609 #define LZMA_STREAM_INIT \
0610     { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \
0611     NULL, NULL, NULL, NULL, 0, 0, 0, 0, \
0612     LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM }
0613 
0614 
0615 /**
0616  * \brief       Encode or decode data
0617  *
0618  * Once the lzma_stream has been successfully initialized (e.g. with
0619  * lzma_stream_encoder()), the actual encoding or decoding is done
0620  * using this function. The application has to update strm->next_in,
0621  * strm->avail_in, strm->next_out, and strm->avail_out to pass input
0622  * to and get output from liblzma.
0623  *
0624  * See the description of the coder-specific initialization function to find
0625  * out what `action' values are supported by the coder.
0626  *
0627  * \param       strm    Pointer to lzma_stream that is at least initialized
0628  *                      with LZMA_STREAM_INIT.
0629  * \param       action  Action for this function to take. Must be a valid
0630  *                      lzma_action enum value.
0631  *
0632  * \return      Any valid lzma_ret. See the lzma_ret enum description for more
0633  *              information.
0634  */
0635 extern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action)
0636         lzma_nothrow lzma_attr_warn_unused_result;
0637 
0638 
0639 /**
0640  * \brief       Free memory allocated for the coder data structures
0641  *
0642  * After lzma_end(strm), strm->internal is guaranteed to be NULL. No other
0643  * members of the lzma_stream structure are touched.
0644  *
0645  * \note        zlib indicates an error if application end()s unfinished
0646  *              stream structure. liblzma doesn't do this, and assumes that
0647  *              application knows what it is doing.
0648  *
0649  * \param       strm    Pointer to lzma_stream that is at least initialized
0650  *                      with LZMA_STREAM_INIT.
0651  */
0652 extern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow;
0653 
0654 
0655 /**
0656  * \brief       Get progress information
0657  *
0658  * In single-threaded mode, applications can get progress information from
0659  * strm->total_in and strm->total_out. In multi-threaded mode this is less
0660  * useful because a significant amount of both input and output data gets
0661  * buffered internally by liblzma. This makes total_in and total_out give
0662  * misleading information and also makes the progress indicator updates
0663  * non-smooth.
0664  *
0665  * This function gives realistic progress information also in multi-threaded
0666  * mode by taking into account the progress made by each thread. In
0667  * single-threaded mode *progress_in and *progress_out are set to
0668  * strm->total_in and strm->total_out, respectively.
0669  *
0670  * \param       strm          Pointer to lzma_stream that is at least
0671  *                            initialized with LZMA_STREAM_INIT.
0672  * \param[out]  progress_in   Pointer to the number of input bytes processed.
0673  * \param[out]  progress_out  Pointer to the number of output bytes processed.
0674  */
0675 extern LZMA_API(void) lzma_get_progress(lzma_stream *strm,
0676         uint64_t *progress_in, uint64_t *progress_out) lzma_nothrow;
0677 
0678 
0679 /**
0680  * \brief       Get the memory usage of decoder filter chain
0681  *
0682  * This function is currently supported only when *strm has been initialized
0683  * with a function that takes a memlimit argument. With other functions, you
0684  * should use e.g. lzma_raw_encoder_memusage() or lzma_raw_decoder_memusage()
0685  * to estimate the memory requirements.
0686  *
0687  * This function is useful e.g. after LZMA_MEMLIMIT_ERROR to find out how big
0688  * the memory usage limit should have been to decode the input. Note that
0689  * this may give misleading information if decoding .xz Streams that have
0690  * multiple Blocks, because each Block can have different memory requirements.
0691  *
0692  * \param       strm    Pointer to lzma_stream that is at least initialized
0693  *                      with LZMA_STREAM_INIT.
0694  *
0695  * \return      How much memory is currently allocated for the filter
0696  *              decoders. If no filter chain is currently allocated,
0697  *              some non-zero value is still returned, which is less than
0698  *              or equal to what any filter chain would indicate as its
0699  *              memory requirement.
0700  *
0701  *              If this function isn't supported by *strm or some other error
0702  *              occurs, zero is returned.
0703  */
0704 extern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm)
0705         lzma_nothrow lzma_attr_pure;
0706 
0707 
0708 /**
0709  * \brief       Get the current memory usage limit
0710  *
0711  * This function is supported only when *strm has been initialized with
0712  * a function that takes a memlimit argument.
0713  *
0714  * \param       strm    Pointer to lzma_stream that is at least initialized
0715  *                      with LZMA_STREAM_INIT.
0716  *
0717  * \return      On success, the current memory usage limit is returned
0718  *              (always non-zero). On error, zero is returned.
0719  */
0720 extern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm)
0721         lzma_nothrow lzma_attr_pure;
0722 
0723 
0724 /**
0725  * \brief       Set the memory usage limit
0726  *
0727  * This function is supported only when *strm has been initialized with
0728  * a function that takes a memlimit argument.
0729  *
0730  * liblzma 5.2.3 and earlier has a bug where memlimit value of 0 causes
0731  * this function to do nothing (leaving the limit unchanged) and still
0732  * return LZMA_OK. Later versions treat 0 as if 1 had been specified (so
0733  * lzma_memlimit_get() will return 1 even if you specify 0 here).
0734  *
0735  * liblzma 5.2.6 and earlier had a bug in single-threaded .xz decoder
0736  * (lzma_stream_decoder()) which made it impossible to continue decoding
0737  * after LZMA_MEMLIMIT_ERROR even if the limit was increased using
0738  * lzma_memlimit_set(). Other decoders worked correctly.
0739  *
0740  * \return      Possible lzma_ret values:
0741  *              - LZMA_OK: New memory usage limit successfully set.
0742  *              - LZMA_MEMLIMIT_ERROR: The new limit is too small.
0743  *                The limit was not changed.
0744  *              - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't
0745  *                support memory usage limit.
0746  */
0747 extern LZMA_API(lzma_ret) lzma_memlimit_set(
0748         lzma_stream *strm, uint64_t memlimit) lzma_nothrow;