1207753Smm/** 2207753Smm * \file lzma/base.h 3207753Smm * \brief Data types and functions used in many places in liblzma API 4207753Smm */ 5207753Smm 6207753Smm/* 7207753Smm * Author: Lasse Collin 8207753Smm * 9207753Smm * This file has been put into the public domain. 10207753Smm * You can do whatever you want with this file. 11207753Smm * 12207753Smm * See ../lzma.h for information about liblzma as a whole. 13207753Smm */ 14207753Smm 15207753Smm#ifndef LZMA_H_INTERNAL 16207753Smm# error Never include this file directly. Use <lzma.h> instead. 17207753Smm#endif 18207753Smm 19207753Smm 20207753Smm/** 21207753Smm * \brief Boolean 22207753Smm * 23207753Smm * This is here because C89 doesn't have stdbool.h. To set a value for 24207753Smm * variables having type lzma_bool, you can use 25207753Smm * - C99's `true' and `false' from stdbool.h; 26207753Smm * - C++'s internal `true' and `false'; or 27207753Smm * - integers one (true) and zero (false). 28207753Smm */ 29207753Smmtypedef unsigned char lzma_bool; 30207753Smm 31207753Smm 32207753Smm/** 33207753Smm * \brief Type of reserved enumeration variable in structures 34207753Smm * 35207753Smm * To avoid breaking library ABI when new features are added, several 36207753Smm * structures contain extra variables that may be used in future. Since 37207753Smm * sizeof(enum) can be different than sizeof(int), and sizeof(enum) may 38207753Smm * even vary depending on the range of enumeration constants, we specify 39207753Smm * a separate type to be used for reserved enumeration variables. All 40207753Smm * enumeration constants in liblzma API will be non-negative and less 41207753Smm * than 128, which should guarantee that the ABI won't break even when 42207753Smm * new constants are added to existing enumerations. 43207753Smm */ 44207753Smmtypedef enum { 45207753Smm LZMA_RESERVED_ENUM = 0 46207753Smm} lzma_reserved_enum; 47207753Smm 48207753Smm 49207753Smm/** 50207753Smm * \brief Return values used by several functions in liblzma 51207753Smm * 52207753Smm * Check the descriptions of specific functions to find out which return 53207753Smm * values they can return. With some functions the return values may have 54207753Smm * more specific meanings than described here; those differences are 55207753Smm * described per-function basis. 56207753Smm */ 57207753Smmtypedef enum { 58207753Smm LZMA_OK = 0, 59207753Smm /**< 60207753Smm * \brief Operation completed successfully 61207753Smm */ 62207753Smm 63207753Smm LZMA_STREAM_END = 1, 64207753Smm /**< 65207753Smm * \brief End of stream was reached 66207753Smm * 67207753Smm * In encoder, LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or 68207753Smm * LZMA_FINISH was finished. In decoder, this indicates 69207753Smm * that all the data was successfully decoded. 70207753Smm * 71207753Smm * In all cases, when LZMA_STREAM_END is returned, the last 72207753Smm * output bytes should be picked from strm->next_out. 73207753Smm */ 74207753Smm 75207753Smm LZMA_NO_CHECK = 2, 76207753Smm /**< 77207753Smm * \brief Input stream has no integrity check 78207753Smm * 79207753Smm * This return value can be returned only if the 80207753Smm * LZMA_TELL_NO_CHECK flag was used when initializing 81207753Smm * the decoder. LZMA_NO_CHECK is just a warning, and 82207753Smm * the decoding can be continued normally. 83207753Smm * 84207753Smm * It is possible to call lzma_get_check() immediately after 85207753Smm * lzma_code has returned LZMA_NO_CHECK. The result will 86207753Smm * naturally be LZMA_CHECK_NONE, but the possibility to call 87207753Smm * lzma_get_check() may be convenient in some applications. 88207753Smm */ 89207753Smm 90207753Smm LZMA_UNSUPPORTED_CHECK = 3, 91207753Smm /**< 92207753Smm * \brief Cannot calculate the integrity check 93207753Smm * 94207753Smm * The usage of this return value is different in encoders 95207753Smm * and decoders. 96207753Smm * 97207753Smm * Encoders can return this value only from the initialization 98207753Smm * function. If initialization fails with this value, the 99207753Smm * encoding cannot be done, because there's no way to produce 100207753Smm * output with the correct integrity check. 101207753Smm * 102207753Smm * Decoders can return this value only from lzma_code() and 103207753Smm * only if the LZMA_TELL_UNSUPPORTED_CHECK flag was used when 104207753Smm * initializing the decoder. The decoding can still be 105207753Smm * continued normally even if the check type is unsupported, 106207753Smm * but naturally the check will not be validated, and possible 107207753Smm * errors may go undetected. 108207753Smm * 109207753Smm * With decoder, it is possible to call lzma_get_check() 110207753Smm * immediately after lzma_code() has returned 111207753Smm * LZMA_UNSUPPORTED_CHECK. This way it is possible to find 112207753Smm * out what the unsupported Check ID was. 113207753Smm */ 114207753Smm 115207753Smm LZMA_GET_CHECK = 4, 116207753Smm /**< 117207753Smm * \brief Integrity check type is now available 118207753Smm * 119207753Smm * This value can be returned only by the lzma_code() function 120207753Smm * and only if the decoder was initialized with the 121207753Smm * LZMA_TELL_ANY_CHECK flag. LZMA_GET_CHECK tells the 122207753Smm * application that it may now call lzma_get_check() to find 123207753Smm * out the Check ID. This can be used, for example, to 124207753Smm * implement a decoder that accepts only files that have 125207753Smm * strong enough integrity check. 126207753Smm */ 127207753Smm 128207753Smm LZMA_MEM_ERROR = 5, 129207753Smm /**< 130207753Smm * \brief Cannot allocate memory 131207753Smm * 132207753Smm * Memory allocation failed, or the size of the allocation 133207753Smm * would be greater than SIZE_MAX. 134207753Smm * 135207753Smm * Due to internal implementation reasons, the coding cannot 136207753Smm * be continued even if more memory were made available after 137207753Smm * LZMA_MEM_ERROR. 138207753Smm */ 139207753Smm 140207753Smm LZMA_MEMLIMIT_ERROR = 6, 141207753Smm /** 142207753Smm * \brief Memory usage limit was reached 143207753Smm * 144207753Smm * Decoder would need more memory than allowed by the 145207753Smm * specified memory usage limit. To continue decoding, 146207753Smm * the memory usage limit has to be increased with 147207753Smm * lzma_memlimit_set(). 148207753Smm */ 149207753Smm 150207753Smm LZMA_FORMAT_ERROR = 7, 151207753Smm /**< 152207753Smm * \brief File format not recognized 153207753Smm * 154207753Smm * The decoder did not recognize the input as supported file 155207753Smm * format. This error can occur, for example, when trying to 156207753Smm * decode .lzma format file with lzma_stream_decoder, 157207753Smm * because lzma_stream_decoder accepts only the .xz format. 158207753Smm */ 159207753Smm 160207753Smm LZMA_OPTIONS_ERROR = 8, 161207753Smm /**< 162207753Smm * \brief Invalid or unsupported options 163207753Smm * 164207753Smm * Invalid or unsupported options, for example 165207753Smm * - unsupported filter(s) or filter options; or 166207753Smm * - reserved bits set in headers (decoder only). 167207753Smm * 168207753Smm * Rebuilding liblzma with more features enabled, or 169207753Smm * upgrading to a newer version of liblzma may help. 170207753Smm */ 171207753Smm 172207753Smm LZMA_DATA_ERROR = 9, 173207753Smm /**< 174207753Smm * \brief Data is corrupt 175207753Smm * 176207753Smm * The usage of this return value is different in encoders 177207753Smm * and decoders. In both encoder and decoder, the coding 178207753Smm * cannot continue after this error. 179207753Smm * 180207753Smm * Encoders return this if size limits of the target file 181207753Smm * format would be exceeded. These limits are huge, thus 182207753Smm * getting this error from an encoder is mostly theoretical. 183207753Smm * For example, the maximum compressed and uncompressed 184207753Smm * size of a .xz Stream is roughly 8 EiB (2^63 bytes). 185207753Smm * 186207753Smm * Decoders return this error if the input data is corrupt. 187207753Smm * This can mean, for example, invalid CRC32 in headers 188207753Smm * or invalid check of uncompressed data. 189207753Smm */ 190207753Smm 191207753Smm LZMA_BUF_ERROR = 10, 192207753Smm /**< 193207753Smm * \brief No progress is possible 194207753Smm * 195207753Smm * This error code is returned when the coder cannot consume 196207753Smm * any new input and produce any new output. The most common 197207753Smm * reason for this error is that the input stream being 198207753Smm * decoded is truncated or corrupt. 199207753Smm * 200207753Smm * This error is not fatal. Coding can be continued normally 201207753Smm * by providing more input and/or more output space, if 202207753Smm * possible. 203207753Smm * 204207753Smm * Typically the first call to lzma_code() that can do no 205207753Smm * progress returns LZMA_OK instead of LZMA_BUF_ERROR. Only 206207753Smm * the second consecutive call doing no progress will return 207207753Smm * LZMA_BUF_ERROR. This is intentional. 208207753Smm * 209207753Smm * With zlib, Z_BUF_ERROR may be returned even if the 210207753Smm * application is doing nothing wrong, so apps will need 211207753Smm * to handle Z_BUF_ERROR specially. The above hack 212207753Smm * guarantees that liblzma never returns LZMA_BUF_ERROR 213207753Smm * to properly written applications unless the input file 214207753Smm * is truncated or corrupt. This should simplify the 215207753Smm * applications a little. 216207753Smm */ 217207753Smm 218207753Smm LZMA_PROG_ERROR = 11, 219207753Smm /**< 220207753Smm * \brief Programming error 221207753Smm * 222207753Smm * This indicates that the arguments given to the function are 223207753Smm * invalid or the internal state of the decoder is corrupt. 224207753Smm * - Function arguments are invalid or the structures 225207753Smm * pointed by the argument pointers are invalid 226207753Smm * e.g. if strm->next_out has been set to NULL and 227207753Smm * strm->avail_out > 0 when calling lzma_code(). 228207753Smm * - lzma_* functions have been called in wrong order 229207753Smm * e.g. lzma_code() was called right after lzma_end(). 230207753Smm * - If errors occur randomly, the reason might be flaky 231207753Smm * hardware. 232207753Smm * 233207753Smm * If you think that your code is correct, this error code 234207753Smm * can be a sign of a bug in liblzma. See the documentation 235207753Smm * how to report bugs. 236207753Smm */ 237207753Smm} lzma_ret; 238207753Smm 239207753Smm 240207753Smm/** 241207753Smm * \brief The `action' argument for lzma_code() 242207753Smm * 243207753Smm * After the first use of LZMA_SYNC_FLUSH, LZMA_FULL_FLUSH, or LZMA_FINISH, 244207753Smm * the same `action' must is used until lzma_code() returns LZMA_STREAM_END. 245207753Smm * Also, the amount of input (that is, strm->avail_in) must not be modified 246207753Smm * by the application until lzma_code() returns LZMA_STREAM_END. Changing the 247207753Smm * `action' or modifying the amount of input will make lzma_code() return 248207753Smm * LZMA_PROG_ERROR. 249207753Smm */ 250207753Smmtypedef enum { 251207753Smm LZMA_RUN = 0, 252207753Smm /**< 253207753Smm * \brief Continue coding 254207753Smm * 255207753Smm * Encoder: Encode as much input as possible. Some internal 256207753Smm * buffering will probably be done (depends on the filter 257207753Smm * chain in use), which causes latency: the input used won't 258207753Smm * usually be decodeable from the output of the same 259207753Smm * lzma_code() call. 260207753Smm * 261207753Smm * Decoder: Decode as much input as possible and produce as 262207753Smm * much output as possible. 263207753Smm */ 264207753Smm 265207753Smm LZMA_SYNC_FLUSH = 1, 266207753Smm /**< 267207753Smm * \brief Make all the input available at output 268207753Smm * 269207753Smm * Normally the encoder introduces some latency. 270207753Smm * LZMA_SYNC_FLUSH forces all the buffered data to be 271207753Smm * available at output without resetting the internal 272207753Smm * state of the encoder. This way it is possible to use 273207753Smm * compressed stream for example for communication over 274207753Smm * network. 275207753Smm * 276207753Smm * Only some filters support LZMA_SYNC_FLUSH. Trying to use 277207753Smm * LZMA_SYNC_FLUSH with filters that don't support it will 278207753Smm * make lzma_code() return LZMA_OPTIONS_ERROR. For example, 279207753Smm * LZMA1 doesn't support LZMA_SYNC_FLUSH but LZMA2 does. 280207753Smm * 281207753Smm * Using LZMA_SYNC_FLUSH very often can dramatically reduce 282207753Smm * the compression ratio. With some filters (for example, 283207753Smm * LZMA2), fine-tuning the compression options may help 284215187Smm * mitigate this problem significantly (for example, 285215187Smm * match finder with LZMA2). 286207753Smm * 287207753Smm * Decoders don't support LZMA_SYNC_FLUSH. 288207753Smm */ 289207753Smm 290207753Smm LZMA_FULL_FLUSH = 2, 291207753Smm /**< 292215187Smm * \brief Finish encoding of the current Block 293207753Smm * 294215187Smm * All the input data going to the current Block must have 295215187Smm * been given to the encoder (the last bytes can still be 296215187Smm * pending in* next_in). Call lzma_code() with LZMA_FULL_FLUSH 297215187Smm * until it returns LZMA_STREAM_END. Then continue normally 298215187Smm * with LZMA_RUN or finish the Stream with LZMA_FINISH. 299207753Smm * 300207753Smm * This action is currently supported only by Stream encoder 301207753Smm * and easy encoder (which uses Stream encoder). If there is 302207753Smm * no unfinished Block, no empty Block is created. 303207753Smm */ 304207753Smm 305207753Smm LZMA_FINISH = 3 306207753Smm /**< 307207753Smm * \brief Finish the coding operation 308207753Smm * 309215187Smm * All the input data must have been given to the encoder 310215187Smm * (the last bytes can still be pending in next_in). 311215187Smm * Call lzma_code() with LZMA_FINISH until it returns 312215187Smm * LZMA_STREAM_END. Once LZMA_FINISH has been used, 313215187Smm * the amount of input must no longer be changed by 314215187Smm * the application. 315207753Smm * 316207753Smm * When decoding, using LZMA_FINISH is optional unless the 317207753Smm * LZMA_CONCATENATED flag was used when the decoder was 318207753Smm * initialized. When LZMA_CONCATENATED was not used, the only 319207753Smm * effect of LZMA_FINISH is that the amount of input must not 320207753Smm * be changed just like in the encoder. 321207753Smm */ 322207753Smm} lzma_action; 323207753Smm 324207753Smm 325207753Smm/** 326207753Smm * \brief Custom functions for memory handling 327207753Smm * 328207753Smm * A pointer to lzma_allocator may be passed via lzma_stream structure 329207753Smm * to liblzma, and some advanced functions take a pointer to lzma_allocator 330207753Smm * as a separate function argument. The library will use the functions 331207753Smm * specified in lzma_allocator for memory handling instead of the default 332207753Smm * malloc() and free(). C++ users should note that the custom memory 333207753Smm * handling functions must not throw exceptions. 334207753Smm * 335207753Smm * liblzma doesn't make an internal copy of lzma_allocator. Thus, it is 336207753Smm * OK to change these function pointers in the middle of the coding 337207753Smm * process, but obviously it must be done carefully to make sure that the 338207753Smm * replacement `free' can deallocate memory allocated by the earlier 339207753Smm * `alloc' function(s). 340207753Smm */ 341207753Smmtypedef struct { 342207753Smm /** 343207753Smm * \brief Pointer to a custom memory allocation function 344207753Smm * 345207753Smm * If you don't want a custom allocator, but still want 346207753Smm * custom free(), set this to NULL and liblzma will use 347207753Smm * the standard malloc(). 348207753Smm * 349207753Smm * \param opaque lzma_allocator.opaque (see below) 350207753Smm * \param nmemb Number of elements like in calloc(). liblzma 351207753Smm * will always set nmemb to 1, so it is safe to 352207753Smm * ignore nmemb in a custom allocator if you like. 353207753Smm * The nmemb argument exists only for 354207753Smm * compatibility with zlib and libbzip2. 355207753Smm * \param size Size of an element in bytes. 356207753Smm * liblzma never sets this to zero. 357207753Smm * 358207753Smm * \return Pointer to the beginning of a memory block of 359207753Smm * `size' bytes, or NULL if allocation fails 360207753Smm * for some reason. When allocation fails, functions 361207753Smm * of liblzma return LZMA_MEM_ERROR. 362207753Smm * 363207753Smm * The allocator should not waste time zeroing the allocated buffers. 364207753Smm * This is not only about speed, but also memory usage, since the 365207753Smm * operating system kernel doesn't necessarily allocate the requested 366207753Smm * memory in physical memory until it is actually used. With small 367207753Smm * input files, liblzma may actually need only a fraction of the 368207753Smm * memory that it requested for allocation. 369207753Smm * 370207753Smm * \note LZMA_MEM_ERROR is also used when the size of the 371207753Smm * allocation would be greater than SIZE_MAX. Thus, 372207753Smm * don't assume that the custom allocator must have 373207753Smm * returned NULL if some function from liblzma 374207753Smm * returns LZMA_MEM_ERROR. 375207753Smm */ 376207753Smm void *(LZMA_API_CALL *alloc)(void *opaque, size_t nmemb, size_t size); 377207753Smm 378207753Smm /** 379207753Smm * \brief Pointer to a custom memory freeing function 380207753Smm * 381207753Smm * If you don't want a custom freeing function, but still 382207753Smm * want a custom allocator, set this to NULL and liblzma 383207753Smm * will use the standard free(). 384207753Smm * 385207753Smm * \param opaque lzma_allocator.opaque (see below) 386207753Smm * \param ptr Pointer returned by lzma_allocator.alloc(), 387207753Smm * or when it is set to NULL, a pointer returned 388207753Smm * by the standard malloc(). 389207753Smm */ 390207753Smm void (LZMA_API_CALL *free)(void *opaque, void *ptr); 391207753Smm 392207753Smm /** 393207753Smm * \brief Pointer passed to .alloc() and .free() 394207753Smm * 395207753Smm * opaque is passed as the first argument to lzma_allocator.alloc() 396207753Smm * and lzma_allocator.free(). This intended to ease implementing 397207753Smm * custom memory allocation functions for use with liblzma. 398207753Smm * 399207753Smm * If you don't need this, you should set this to NULL. 400207753Smm */ 401207753Smm void *opaque; 402207753Smm 403207753Smm} lzma_allocator; 404207753Smm 405207753Smm 406207753Smm/** 407207753Smm * \brief Internal data structure 408207753Smm * 409207753Smm * The contents of this structure is not visible outside the library. 410207753Smm */ 411207753Smmtypedef struct lzma_internal_s lzma_internal; 412207753Smm 413207753Smm 414207753Smm/** 415207753Smm * \brief Passing data to and from liblzma 416207753Smm * 417207753Smm * The lzma_stream structure is used for 418207753Smm * - passing pointers to input and output buffers to liblzma; 419207753Smm * - defining custom memory hander functions; and 420207753Smm * - holding a pointer to coder-specific internal data structures. 421207753Smm * 422207753Smm * Typical usage: 423207753Smm * 424207753Smm * - After allocating lzma_stream (on stack or with malloc()), it must be 425207753Smm * initialized to LZMA_STREAM_INIT (see LZMA_STREAM_INIT for details). 426207753Smm * 427207753Smm * - Initialize a coder to the lzma_stream, for example by using 428207753Smm * lzma_easy_encoder() or lzma_auto_decoder(). Some notes: 429207753Smm * - In contrast to zlib, strm->next_in and strm->next_out are 430207753Smm * ignored by all initialization functions, thus it is safe 431207753Smm * to not initialize them yet. 432207753Smm * - The initialization functions always set strm->total_in and 433207753Smm * strm->total_out to zero. 434207753Smm * - If the initialization function fails, no memory is left allocated 435207753Smm * that would require freeing with lzma_end() even if some memory was 436207753Smm * associated with the lzma_stream structure when the initialization 437207753Smm * function was called. 438207753Smm * 439207753Smm * - Use lzma_code() to do the actual work. 440207753Smm * 441207753Smm * - Once the coding has been finished, the existing lzma_stream can be 442207753Smm * reused. It is OK to reuse lzma_stream with different initialization 443207753Smm * function without calling lzma_end() first. Old allocations are 444207753Smm * automatically freed. 445207753Smm * 446207753Smm * - Finally, use lzma_end() to free the allocated memory. lzma_end() never 447207753Smm * frees the lzma_stream structure itself. 448207753Smm * 449207753Smm * Application may modify the values of total_in and total_out as it wants. 450207753Smm * They are updated by liblzma to match the amount of data read and 451207753Smm * written, but aren't used for anything else. 452207753Smm */ 453207753Smmtypedef struct { 454207753Smm const uint8_t *next_in; /**< Pointer to the next input byte. */ 455207753Smm size_t avail_in; /**< Number of available input bytes in next_in. */ 456207753Smm uint64_t total_in; /**< Total number of bytes read by liblzma. */ 457207753Smm 458207753Smm uint8_t *next_out; /**< Pointer to the next output position. */ 459207753Smm size_t avail_out; /**< Amount of free space in next_out. */ 460207753Smm uint64_t total_out; /**< Total number of bytes written by liblzma. */ 461207753Smm 462207753Smm /** 463207753Smm * \brief Custom memory allocation functions 464207753Smm * 465207753Smm * In most cases this is NULL which makes liblzma use 466207753Smm * the standard malloc() and free(). 467207753Smm */ 468207753Smm lzma_allocator *allocator; 469207753Smm 470207753Smm /** Internal state is not visible to applications. */ 471207753Smm lzma_internal *internal; 472207753Smm 473207753Smm /* 474207753Smm * Reserved space to allow possible future extensions without 475207753Smm * breaking the ABI. Excluding the initialization of this structure, 476207753Smm * you should not touch these, because the names of these variables 477207753Smm * may change. 478207753Smm */ 479207753Smm void *reserved_ptr1; 480207753Smm void *reserved_ptr2; 481215187Smm void *reserved_ptr3; 482215187Smm void *reserved_ptr4; 483207753Smm uint64_t reserved_int1; 484207753Smm uint64_t reserved_int2; 485215187Smm size_t reserved_int3; 486215187Smm size_t reserved_int4; 487207753Smm lzma_reserved_enum reserved_enum1; 488207753Smm lzma_reserved_enum reserved_enum2; 489207753Smm 490207753Smm} lzma_stream; 491207753Smm 492207753Smm 493207753Smm/** 494207753Smm * \brief Initialization for lzma_stream 495207753Smm * 496207753Smm * When you declare an instance of lzma_stream, you can immediately 497207753Smm * initialize it so that initialization functions know that no memory 498207753Smm * has been allocated yet: 499207753Smm * 500207753Smm * lzma_stream strm = LZMA_STREAM_INIT; 501207753Smm * 502207753Smm * If you need to initialize a dynamically allocated lzma_stream, you can use 503207753Smm * memset(strm_pointer, 0, sizeof(lzma_stream)). Strictly speaking, this 504207753Smm * violates the C standard since NULL may have different internal 505207753Smm * representation than zero, but it should be portable enough in practice. 506207753Smm * Anyway, for maximum portability, you can use something like this: 507207753Smm * 508207753Smm * lzma_stream tmp = LZMA_STREAM_INIT; 509207753Smm * *strm = tmp; 510207753Smm */ 511207753Smm#define LZMA_STREAM_INIT \ 512207753Smm { NULL, 0, 0, NULL, 0, 0, NULL, NULL, \ 513215187Smm NULL, NULL, NULL, NULL, 0, 0, 0, 0, \ 514215187Smm LZMA_RESERVED_ENUM, LZMA_RESERVED_ENUM } 515207753Smm 516207753Smm 517207753Smm/** 518207753Smm * \brief Encode or decode data 519207753Smm * 520207753Smm * Once the lzma_stream has been successfully initialized (e.g. with 521207753Smm * lzma_stream_encoder()), the actual encoding or decoding is done 522207753Smm * using this function. The application has to update strm->next_in, 523207753Smm * strm->avail_in, strm->next_out, and strm->avail_out to pass input 524207753Smm * to and get output from liblzma. 525207753Smm * 526207753Smm * See the description of the coder-specific initialization function to find 527207753Smm * out what `action' values are supported by the coder. 528207753Smm */ 529207753Smmextern LZMA_API(lzma_ret) lzma_code(lzma_stream *strm, lzma_action action) 530207753Smm lzma_nothrow lzma_attr_warn_unused_result; 531207753Smm 532207753Smm 533207753Smm/** 534207753Smm * \brief Free memory allocated for the coder data structures 535207753Smm * 536207753Smm * \param strm Pointer to lzma_stream that is at least initialized 537207753Smm * with LZMA_STREAM_INIT. 538207753Smm * 539207753Smm * After lzma_end(strm), strm->internal is guaranteed to be NULL. No other 540207753Smm * members of the lzma_stream structure are touched. 541207753Smm * 542207753Smm * \note zlib indicates an error if application end()s unfinished 543207753Smm * stream structure. liblzma doesn't do this, and assumes that 544207753Smm * application knows what it is doing. 545207753Smm */ 546207753Smmextern LZMA_API(void) lzma_end(lzma_stream *strm) lzma_nothrow; 547207753Smm 548207753Smm 549207753Smm/** 550207753Smm * \brief Get the memory usage of decoder filter chain 551207753Smm * 552207753Smm * This function is currently supported only when *strm has been initialized 553207753Smm * with a function that takes a memlimit argument. With other functions, you 554207753Smm * should use e.g. lzma_raw_encoder_memusage() or lzma_raw_decoder_memusage() 555207753Smm * to estimate the memory requirements. 556207753Smm * 557207753Smm * This function is useful e.g. after LZMA_MEMLIMIT_ERROR to find out how big 558207753Smm * the memory usage limit should have been to decode the input. Note that 559207753Smm * this may give misleading information if decoding .xz Streams that have 560207753Smm * multiple Blocks, because each Block can have different memory requirements. 561207753Smm * 562215187Smm * \return How much memory is currently allocated for the filter 563215187Smm * decoders. If no filter chain is currently allocated, 564215187Smm * some non-zero value is still returned, which is less than 565215187Smm * or equal to what any filter chain would indicate as its 566215187Smm * memory requirement. 567207753Smm * 568207753Smm * If this function isn't supported by *strm or some other error 569207753Smm * occurs, zero is returned. 570207753Smm */ 571207753Smmextern LZMA_API(uint64_t) lzma_memusage(const lzma_stream *strm) 572207753Smm lzma_nothrow lzma_attr_pure; 573207753Smm 574207753Smm 575207753Smm/** 576207753Smm * \brief Get the current memory usage limit 577207753Smm * 578207753Smm * This function is supported only when *strm has been initialized with 579207753Smm * a function that takes a memlimit argument. 580207753Smm * 581207753Smm * \return On success, the current memory usage limit is returned 582207753Smm * (always non-zero). On error, zero is returned. 583207753Smm */ 584207753Smmextern LZMA_API(uint64_t) lzma_memlimit_get(const lzma_stream *strm) 585207753Smm lzma_nothrow lzma_attr_pure; 586207753Smm 587207753Smm 588207753Smm/** 589207753Smm * \brief Set the memory usage limit 590207753Smm * 591207753Smm * This function is supported only when *strm has been initialized with 592207753Smm * a function that takes a memlimit argument. 593207753Smm * 594207753Smm * \return - LZMA_OK: New memory usage limit successfully set. 595207753Smm * - LZMA_MEMLIMIT_ERROR: The new limit is too small. 596207753Smm * The limit was not changed. 597207753Smm * - LZMA_PROG_ERROR: Invalid arguments, e.g. *strm doesn't 598207753Smm * support memory usage limit or memlimit was zero. 599207753Smm */ 600207753Smmextern LZMA_API(lzma_ret) lzma_memlimit_set( 601207753Smm lzma_stream *strm, uint64_t memlimit) lzma_nothrow; 602