| 1 | /* |
| 2 | * LZ4 - Fast LZ compression algorithm |
| 3 | * Header File |
| 4 | * Copyright (C) 2011-2017, Yann Collet. |
| 5 | |
| 6 | BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) |
| 7 | |
| 8 | Redistribution and use in source and binary forms, with or without |
| 9 | modification, are permitted provided that the following conditions are |
| 10 | met: |
| 11 | |
| 12 | * Redistributions of source code must retain the above copyright |
| 13 | notice, this list of conditions and the following disclaimer. |
| 14 | * Redistributions in binary form must reproduce the above |
| 15 | copyright notice, this list of conditions and the following disclaimer |
| 16 | in the documentation and/or other materials provided with the |
| 17 | distribution. |
| 18 | |
| 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | |
| 31 | You can contact the author at : |
| 32 | - LZ4 homepage : http://www.lz4.org |
| 33 | - LZ4 source repository : https://github.com/lz4/lz4 |
| 34 | */ |
| 35 | #if defined (__cplusplus) |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
| 39 | #ifndef LZ4_H_2983827168210 |
| 40 | #define LZ4_H_2983827168210 |
| 41 | |
| 42 | /* --- Dependency --- */ |
| 43 | #include <stddef.h> /* size_t */ |
| 44 | |
| 45 | |
| 46 | /** |
| 47 | Introduction |
| 48 | |
| 49 | LZ4 is lossless compression algorithm, providing compression speed at 400 MB/s per core, |
| 50 | scalable with multi-cores CPU. It features an extremely fast decoder, with speed in |
| 51 | multiple GB/s per core, typically reaching RAM speed limits on multi-core systems. |
| 52 | |
| 53 | The LZ4 compression library provides in-memory compression and decompression functions. |
| 54 | Compression can be done in: |
| 55 | - a single step (described as Simple Functions) |
| 56 | - a single step, reusing a context (described in Advanced Functions) |
| 57 | - unbounded multiple steps (described as Streaming compression) |
| 58 | |
| 59 | lz4.h provides block compression functions. It gives full buffer control to user. |
| 60 | Decompressing an lz4-compressed block also requires metadata (such as compressed size). |
| 61 | Each application is free to encode such metadata in whichever way it wants. |
| 62 | |
| 63 | An additional format, called LZ4 frame specification (doc/lz4_Frame_format.md), |
| 64 | take care of encoding standard metadata alongside LZ4-compressed blocks. |
| 65 | If your application requires interoperability, it's recommended to use it. |
| 66 | A library is provided to take care of it, see lz4frame.h. |
| 67 | */ |
| 68 | |
| 69 | /*^*************************************************************** |
| 70 | * Export parameters |
| 71 | *****************************************************************/ |
| 72 | /* |
| 73 | * LZ4_DLL_EXPORT : |
| 74 | * Enable exporting of functions when building a Windows DLL |
| 75 | * LZ4LIB_VISIBILITY : |
| 76 | * Control library symbols visibility. |
| 77 | */ |
| 78 | #ifndef LZ4LIB_VISIBILITY |
| 79 | # if defined(__GNUC__) && (__GNUC__ >= 4) |
| 80 | # define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default"))) |
| 81 | # else |
| 82 | # define LZ4LIB_VISIBILITY |
| 83 | # endif |
| 84 | #endif |
| 85 | #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1) |
| 86 | # define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY |
| 87 | #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1) |
| 88 | # define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ |
| 89 | #else |
| 90 | # define LZ4LIB_API LZ4LIB_VISIBILITY |
| 91 | #endif |
| 92 | |
| 93 | /*------ Version ------*/ |
| 94 | #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */ |
| 95 | #define LZ4_VERSION_MINOR 8 /* for new (non-breaking) interface capabilities */ |
| 96 | #define LZ4_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ |
| 97 | |
| 98 | #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) |
| 99 | |
| 100 | #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE |
| 101 | #define LZ4_QUOTE(str) #str |
| 102 | #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str) |
| 103 | #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) |
| 104 | |
| 105 | LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; to be used when checking dll version */ |
| 106 | LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; to be used when checking dll version */ |
| 107 | |
| 108 | |
| 109 | /*-************************************ |
| 110 | * Tuning parameter |
| 111 | **************************************/ |
| 112 | /*! |
| 113 | * LZ4_MEMORY_USAGE : |
| 114 | * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) |
| 115 | * Increasing memory usage improves compression ratio |
| 116 | * Reduced memory usage can improve speed, due to cache effect |
| 117 | * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache |
| 118 | */ |
| 119 | #ifndef LZ4_MEMORY_USAGE |
| 120 | # define LZ4_MEMORY_USAGE 14 |
| 121 | #endif |
| 122 | |
| 123 | /*-************************************ |
| 124 | * Simple Functions |
| 125 | **************************************/ |
| 126 | /*! LZ4_compress_default() : |
| 127 | Compresses 'srcSize' bytes from buffer 'src' |
| 128 | into already allocated 'dst' buffer of size 'dstCapacity'. |
| 129 | Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize). |
| 130 | It also runs faster, so it's a recommended setting. |
| 131 | If the function cannot compress 'src' into a limited 'dst' budget, |
| 132 | compression stops *immediately*, and the function result is zero. |
| 133 | As a consequence, 'dst' content is not valid. |
| 134 | This function never writes outside 'dst' buffer, nor read outside 'source' buffer. |
| 135 | srcSize : supported max value is LZ4_MAX_INPUT_VALUE |
| 136 | dstCapacity : full or partial size of buffer 'dst' (which must be already allocated) |
| 137 | return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity) |
| 138 | or 0 if compression fails */ |
| 139 | LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity); |
| 140 | |
| 141 | /*! LZ4_decompress_safe() : |
| 142 | compressedSize : is the exact complete size of the compressed block. |
| 143 | dstCapacity : is the size of destination buffer, which must be already allocated. |
| 144 | return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity) |
| 145 | If destination buffer is not large enough, decoding will stop and output an error code (negative value). |
| 146 | If the source stream is detected malformed, the function will stop decoding and return a negative result. |
| 147 | This function is protected against buffer overflow exploits, including malicious data packets. |
| 148 | It never writes outside output buffer, nor reads outside input buffer. |
| 149 | */ |
| 150 | LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity); |
| 151 | |
| 152 | |
| 153 | /*-************************************ |
| 154 | * Advanced Functions |
| 155 | **************************************/ |
| 156 | #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */ |
| 157 | #define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16) |
| 158 | |
| 159 | /*! |
| 160 | LZ4_compressBound() : |
| 161 | Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible) |
| 162 | This function is primarily useful for memory allocation purposes (destination buffer size). |
| 163 | Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example). |
| 164 | Note that LZ4_compress_default() compress faster when dest buffer size is >= LZ4_compressBound(srcSize) |
| 165 | inputSize : max supported value is LZ4_MAX_INPUT_SIZE |
| 166 | return : maximum output size in a "worst case" scenario |
| 167 | or 0, if input size is too large ( > LZ4_MAX_INPUT_SIZE) |
| 168 | */ |
| 169 | LZ4LIB_API int LZ4_compressBound(int inputSize); |
| 170 | |
| 171 | /*! |
| 172 | LZ4_compress_fast() : |
| 173 | Same as LZ4_compress_default(), but allows to select an "acceleration" factor. |
| 174 | The larger the acceleration value, the faster the algorithm, but also the lesser the compression. |
| 175 | It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed. |
| 176 | An acceleration value of "1" is the same as regular LZ4_compress_default() |
| 177 | Values <= 0 will be replaced by ACCELERATION_DEFAULT (see lz4.c), which is 1. |
| 178 | */ |
| 179 | LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); |
| 180 | |
| 181 | |
| 182 | /*! |
| 183 | LZ4_compress_fast_extState() : |
| 184 | Same compression function, just using an externally allocated memory space to store compression state. |
| 185 | Use LZ4_sizeofState() to know how much memory must be allocated, |
| 186 | and allocate it on 8-bytes boundaries (using malloc() typically). |
| 187 | Then, provide it as 'void* state' to compression function. |
| 188 | */ |
| 189 | LZ4LIB_API int LZ4_sizeofState(void); |
| 190 | LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); |
| 191 | |
| 192 | |
| 193 | /*! |
| 194 | LZ4_compress_destSize() : |
| 195 | Reverse the logic : compresses as much data as possible from 'src' buffer |
| 196 | into already allocated buffer 'dst' of size 'targetDestSize'. |
| 197 | This function either compresses the entire 'src' content into 'dst' if it's large enough, |
| 198 | or fill 'dst' buffer completely with as much data as possible from 'src'. |
| 199 | *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'. |
| 200 | New value is necessarily <= old value. |
| 201 | return : Nb bytes written into 'dst' (necessarily <= targetDestSize) |
| 202 | or 0 if compression fails |
| 203 | */ |
| 204 | LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize); |
| 205 | |
| 206 | |
| 207 | /*! |
| 208 | LZ4_decompress_fast() : (unsafe!!) |
| 209 | originalSize : is the original uncompressed size |
| 210 | return : the number of bytes read from the source buffer (in other words, the compressed size) |
| 211 | If the source stream is detected malformed, the function will stop decoding and return a negative result. |
| 212 | Destination buffer must be already allocated. Its size must be >= 'originalSize' bytes. |
| 213 | note : This function respects memory boundaries for *properly formed* compressed data. |
| 214 | It is a bit faster than LZ4_decompress_safe(). |
| 215 | However, it does not provide any protection against intentionally modified data stream (malicious input). |
| 216 | Use this function in trusted environment only (data to decode comes from a trusted source). |
| 217 | */ |
| 218 | LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize); |
| 219 | |
| 220 | /*! |
| 221 | LZ4_decompress_safe_partial() : |
| 222 | This function decompress a compressed block of size 'srcSize' at position 'src' |
| 223 | into destination buffer 'dst' of size 'dstCapacity'. |
| 224 | The function will decompress a minimum of 'targetOutputSize' bytes, and stop after that. |
| 225 | However, it's not accurate, and may write more than 'targetOutputSize' (but <= dstCapacity). |
| 226 | @return : the number of bytes decoded in the destination buffer (necessarily <= dstCapacity) |
| 227 | Note : this number can be < 'targetOutputSize' should the compressed block contain less data. |
| 228 | Always control how many bytes were decoded. |
| 229 | If the source stream is detected malformed, the function will stop decoding and return a negative result. |
| 230 | This function never writes outside of output buffer, and never reads outside of input buffer. It is therefore protected against malicious data packets. |
| 231 | */ |
| 232 | LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity); |
| 233 | |
| 234 | |
| 235 | /*-********************************************* |
| 236 | * Streaming Compression Functions |
| 237 | ***********************************************/ |
| 238 | typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */ |
| 239 | |
| 240 | /*! LZ4_createStream() and LZ4_freeStream() : |
| 241 | * LZ4_createStream() will allocate and initialize an `LZ4_stream_t` structure. |
| 242 | * LZ4_freeStream() releases its memory. |
| 243 | */ |
| 244 | LZ4LIB_API LZ4_stream_t* LZ4_createStream(void); |
| 245 | LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr); |
| 246 | |
| 247 | /*! LZ4_resetStream() : |
| 248 | * An LZ4_stream_t structure can be allocated once and re-used multiple times. |
| 249 | * Use this function to start compressing a new stream. |
| 250 | */ |
| 251 | LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr); |
| 252 | |
| 253 | /*! LZ4_loadDict() : |
| 254 | * Use this function to load a static dictionary into LZ4_stream_t. |
| 255 | * Any previous data will be forgotten, only 'dictionary' will remain in memory. |
| 256 | * Loading a size of 0 is allowed, and is the same as reset. |
| 257 | * @return : dictionary size, in bytes (necessarily <= 64 KB) |
| 258 | */ |
| 259 | LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize); |
| 260 | |
| 261 | /*! LZ4_compress_fast_continue() : |
| 262 | * Compress content into 'src' using data from previously compressed blocks, improving compression ratio. |
| 263 | * 'dst' buffer must be already allocated. |
| 264 | * If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster. |
| 265 | * |
| 266 | * Important : Up to 64KB of previously compressed data is assumed to remain present and unmodified in memory ! |
| 267 | * Special 1 : If input buffer is a double-buffer, it can have any size, including < 64 KB. |
| 268 | * Special 2 : If input buffer is a ring-buffer, it can have any size, including < 64 KB. |
| 269 | * |
| 270 | * @return : size of compressed block |
| 271 | * or 0 if there is an error (typically, compressed data cannot fit into 'dst') |
| 272 | * After an error, the stream status is invalid, it can only be reset or freed. |
| 273 | */ |
| 274 | LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration); |
| 275 | |
| 276 | /*! LZ4_saveDict() : |
| 277 | * If previously compressed data block is not guaranteed to remain available at its current memory location, |
| 278 | * save it into a safer place (char* safeBuffer). |
| 279 | * Note : it's not necessary to call LZ4_loadDict() after LZ4_saveDict(), dictionary is immediately usable. |
| 280 | * @return : saved dictionary size in bytes (necessarily <= dictSize), or 0 if error. |
| 281 | */ |
| 282 | LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int dictSize); |
| 283 | |
| 284 | |
| 285 | /*-********************************************** |
| 286 | * Streaming Decompression Functions |
| 287 | * Bufferless synchronous API |
| 288 | ************************************************/ |
| 289 | typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* incomplete type (defined later) */ |
| 290 | |
| 291 | /*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() : |
| 292 | * creation / destruction of streaming decompression tracking structure. |
| 293 | * A tracking structure can be re-used multiple times sequentially. */ |
| 294 | LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void); |
| 295 | LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream); |
| 296 | |
| 297 | /*! LZ4_setStreamDecode() : |
| 298 | * An LZ4_streamDecode_t structure can be allocated once and re-used multiple times. |
| 299 | * Use this function to start decompression of a new stream of blocks. |
| 300 | * A dictionary can optionnally be set. Use NULL or size 0 for a simple reset order. |
| 301 | * @return : 1 if OK, 0 if error |
| 302 | */ |
| 303 | LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize); |
| 304 | |
| 305 | /*! LZ4_decompress_*_continue() : |
| 306 | * These decoding functions allow decompression of consecutive blocks in "streaming" mode. |
| 307 | * A block is an unsplittable entity, it must be presented entirely to a decompression function. |
| 308 | * Decompression functions only accept one block at a time. |
| 309 | * Previously decoded blocks *must* remain available at the memory position where they were decoded (up to 64 KB). |
| 310 | * |
| 311 | * Special : if application sets a ring buffer for decompression, it must respect one of the following conditions : |
| 312 | * - Exactly same size as encoding buffer, with same update rule (block boundaries at same positions) |
| 313 | * In which case, the decoding & encoding ring buffer can have any size, including very small ones ( < 64 KB). |
| 314 | * - Larger than encoding buffer, by a minimum of maxBlockSize more bytes. |
| 315 | * maxBlockSize is implementation dependent. It's the maximum size of any single block. |
| 316 | * In which case, encoding and decoding buffers do not need to be synchronized, |
| 317 | * and encoding ring buffer can have any size, including small ones ( < 64 KB). |
| 318 | * - _At least_ 64 KB + 8 bytes + maxBlockSize. |
| 319 | * In which case, encoding and decoding buffers do not need to be synchronized, |
| 320 | * and encoding ring buffer can have any size, including larger than decoding buffer. |
| 321 | * Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer, |
| 322 | * and indicate where it is saved using LZ4_setStreamDecode() before decompressing next block. |
| 323 | */ |
| 324 | LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity); |
| 325 | LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize); |
| 326 | |
| 327 | |
| 328 | /*! LZ4_decompress_*_usingDict() : |
| 329 | * These decoding functions work the same as |
| 330 | * a combination of LZ4_setStreamDecode() followed by LZ4_decompress_*_continue() |
| 331 | * They are stand-alone, and don't need an LZ4_streamDecode_t structure. |
| 332 | */ |
| 333 | LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize); |
| 334 | LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize); |
| 335 | |
| 336 | |
| 337 | /*^********************************************** |
| 338 | * !!!!!! STATIC LINKING ONLY !!!!!! |
| 339 | ***********************************************/ |
| 340 | /*-************************************ |
| 341 | * Private definitions |
| 342 | ************************************** |
| 343 | * Do not use these definitions. |
| 344 | * They are exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`. |
| 345 | * Using these definitions will expose code to API and/or ABI break in future versions of the library. |
| 346 | **************************************/ |
| 347 | #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2) |
| 348 | #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE) |
| 349 | #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */ |
| 350 | |
| 351 | #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) |
| 352 | #include <stdint.h> |
| 353 | |
| 354 | typedef struct { |
| 355 | uint32_t hashTable[LZ4_HASH_SIZE_U32]; |
| 356 | uint32_t currentOffset; |
| 357 | uint32_t initCheck; |
| 358 | const uint8_t* dictionary; |
| 359 | uint8_t* bufferStart; /* obsolete, used for slideInputBuffer */ |
| 360 | uint32_t dictSize; |
| 361 | } LZ4_stream_t_internal; |
| 362 | |
| 363 | typedef struct { |
| 364 | const uint8_t* externalDict; |
| 365 | size_t extDictSize; |
| 366 | const uint8_t* prefixEnd; |
| 367 | size_t prefixSize; |
| 368 | } LZ4_streamDecode_t_internal; |
| 369 | |
| 370 | #else |
| 371 | |
| 372 | typedef struct { |
| 373 | unsigned int hashTable[LZ4_HASH_SIZE_U32]; |
| 374 | unsigned int currentOffset; |
| 375 | unsigned int initCheck; |
| 376 | const unsigned char* dictionary; |
| 377 | unsigned char* bufferStart; /* obsolete, used for slideInputBuffer */ |
| 378 | unsigned int dictSize; |
| 379 | } LZ4_stream_t_internal; |
| 380 | |
| 381 | typedef struct { |
| 382 | const unsigned char* externalDict; |
| 383 | size_t extDictSize; |
| 384 | const unsigned char* prefixEnd; |
| 385 | size_t prefixSize; |
| 386 | } LZ4_streamDecode_t_internal; |
| 387 | |
| 388 | #endif |
| 389 | |
| 390 | /*! |
| 391 | * LZ4_stream_t : |
| 392 | * information structure to track an LZ4 stream. |
| 393 | * init this structure before first use. |
| 394 | * note : only use in association with static linking ! |
| 395 | * this definition is not API/ABI safe, |
| 396 | * it may change in a future version ! |
| 397 | */ |
| 398 | #define LZ4_STREAMSIZE_U64 ((1 << (LZ4_MEMORY_USAGE-3)) + 4) |
| 399 | #define LZ4_STREAMSIZE (LZ4_STREAMSIZE_U64 * sizeof(unsigned long long)) |
| 400 | union LZ4_stream_u { |
| 401 | unsigned long long table[LZ4_STREAMSIZE_U64]; |
| 402 | LZ4_stream_t_internal internal_donotuse; |
| 403 | } ; /* previously typedef'd to LZ4_stream_t */ |
| 404 | |
| 405 | |
| 406 | /*! |
| 407 | * LZ4_streamDecode_t : |
| 408 | * information structure to track an LZ4 stream during decompression. |
| 409 | * init this structure using LZ4_setStreamDecode (or memset()) before first use |
| 410 | * note : only use in association with static linking ! |
| 411 | * this definition is not API/ABI safe, |
| 412 | * and may change in a future version ! |
| 413 | */ |
| 414 | #define LZ4_STREAMDECODESIZE_U64 4 |
| 415 | #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long)) |
| 416 | union LZ4_streamDecode_u { |
| 417 | unsigned long long table[LZ4_STREAMDECODESIZE_U64]; |
| 418 | LZ4_streamDecode_t_internal internal_donotuse; |
| 419 | } ; /* previously typedef'd to LZ4_streamDecode_t */ |
| 420 | |
| 421 | |
| 422 | /*-************************************ |
| 423 | * Obsolete Functions |
| 424 | **************************************/ |
| 425 | |
| 426 | /*! Deprecation warnings |
| 427 | Should deprecation warnings be a problem, |
| 428 | it is generally possible to disable them, |
| 429 | typically with -Wno-deprecated-declarations for gcc |
| 430 | or _CRT_SECURE_NO_WARNINGS in Visual. |
| 431 | Otherwise, it's also possible to define LZ4_DISABLE_DEPRECATE_WARNINGS */ |
| 432 | #ifdef LZ4_DISABLE_DEPRECATE_WARNINGS |
| 433 | # define LZ4_DEPRECATED(message) /* disable deprecation warnings */ |
| 434 | #else |
| 435 | # define LZ4_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) |
| 436 | # if defined(__clang__) /* clang doesn't handle mixed C++11 and CNU attributes */ |
| 437 | # define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) |
| 438 | # elif defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */ |
| 439 | # define LZ4_DEPRECATED(message) [[deprecated(message)]] |
| 440 | # elif (LZ4_GCC_VERSION >= 405) |
| 441 | # define LZ4_DEPRECATED(message) __attribute__((deprecated(message))) |
| 442 | # elif (LZ4_GCC_VERSION >= 301) |
| 443 | # define LZ4_DEPRECATED(message) __attribute__((deprecated)) |
| 444 | # elif defined(_MSC_VER) |
| 445 | # define LZ4_DEPRECATED(message) __declspec(deprecated(message)) |
| 446 | # else |
| 447 | # pragma message("WARNING: You need to implement LZ4_DEPRECATED for this compiler") |
| 448 | # define LZ4_DEPRECATED(message) |
| 449 | # endif |
| 450 | #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */ |
| 451 | |
| 452 | /* Obsolete compression functions */ |
| 453 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead" ) int LZ4_compress (const char* source, char* dest, int sourceSize); |
| 454 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_default() instead" ) int LZ4_compress_limitedOutput (const char* source, char* dest, int sourceSize, int maxOutputSize); |
| 455 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead" ) int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize); |
| 456 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead" ) int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize); |
| 457 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead" ) int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize); |
| 458 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead" ) int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize); |
| 459 | |
| 460 | /* Obsolete decompression functions */ |
| 461 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast() instead" ) int LZ4_uncompress (const char* source, char* dest, int outputSize); |
| 462 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe() instead" ) int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize); |
| 463 | |
| 464 | /* Obsolete streaming functions; use new streaming interface whenever possible */ |
| 465 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead" ) void* LZ4_create (char* inputBuffer); |
| 466 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_createStream() instead" ) int LZ4_sizeofStreamState(void); |
| 467 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_resetStream() instead" ) int LZ4_resetStreamState(void* state, char* inputBuffer); |
| 468 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_saveDict() instead" ) char* LZ4_slideInputBuffer (void* state); |
| 469 | |
| 470 | /* Obsolete streaming decoding functions */ |
| 471 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead" ) int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize); |
| 472 | LZ4LIB_API LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead" ) int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize); |
| 473 | |
| 474 | #endif /* LZ4_H_2983827168210 */ |
| 475 | |
| 476 | |
| 477 | #if defined (__cplusplus) |
| 478 | } |
| 479 | #endif |
| 480 | |