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