Rizin
unix-like reverse engineering framework and cli tools
lz4.h
Go to the documentation of this file.
1 /*
2  * LZ4 - Fast LZ compression algorithm
3  * Header File
4  * Copyright (C) 2011-present, 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 
76 /*^***************************************************************
77 * Export parameters
78 *****************************************************************/
79 /*
80 * LZ4_DLL_EXPORT :
81 * Enable exporting of functions when building a Windows DLL
82 * LZ4LIB_VISIBILITY :
83 * Control library symbols visibility.
84 */
85 #ifndef LZ4LIB_VISIBILITY
86 # if defined(__GNUC__) && (__GNUC__ >= 4)
87 # define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
88 # else
89 # define LZ4LIB_VISIBILITY
90 # endif
91 #endif
92 #if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
93 # define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
94 #elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
95 # 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.*/
96 #else
97 # define LZ4LIB_API LZ4LIB_VISIBILITY
98 #endif
99 
100 /*------ Version ------*/
101 #define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
102 #define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
103 #define LZ4_VERSION_RELEASE 3 /* for tweaks, bug-fixes, or development */
104 
105 #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
106 
107 #define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
108 #define LZ4_QUOTE(str) #str
109 #define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
110 #define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION)
111 
112 LZ4LIB_API int LZ4_versionNumber (void);
113 LZ4LIB_API const char* LZ4_versionString (void);
116 /*-************************************
117 * Tuning parameter
118 **************************************/
126 #ifndef LZ4_MEMORY_USAGE
127 # define LZ4_MEMORY_USAGE 14
128 #endif
129 
130 
131 /*-************************************
132 * Simple Functions
133 **************************************/
148 LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
149 
164 LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
165 
166 
167 /*-************************************
168 * Advanced Functions
169 **************************************/
170 #define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
171 #define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
172 
183 
192 LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
193 
194 
201 LZ4LIB_API int LZ4_sizeofState(void);
202 LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
203 
204 
228 LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
229 
230 
265 LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
266 
267 
268 /*-*********************************************
269 * Streaming Compression Functions
270 ***********************************************/
271 typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
272 
274 LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
275 
299 
311 LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
312 
336 LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
337 
345 LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
346 
347 
348 /*-**********************************************
349 * Streaming Decompression Functions
350 * Bufferless synchronous API
351 ************************************************/
352 typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
353 
360 
368 LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
369 
381 LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
382 #define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
383 
409 LZ4LIB_API int LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int srcSize, int dstCapacity);
410 
411 
420 LZ4LIB_API int LZ4_decompress_safe_usingDict (const char* src, char* dst, int srcSize, int dstCapcity, const char* dictStart, int dictSize);
421 
422 #endif /* LZ4_H_2983827168210 */
423 
424 
425 /*^*************************************
426  * !!!!!! STATIC LINKING ONLY !!!!!!
427  ***************************************/
428 
429 /*-****************************************************************************
430  * Experimental section
431  *
432  * Symbols declared in this section must be considered unstable. Their
433  * signatures or semantics may change, or they may be removed altogether in the
434  * future. They are therefore only safe to depend on when the caller is
435  * statically linked against the library.
436  *
437  * To protect against unsafe usage, not only are the declarations guarded,
438  * the definitions are hidden by default
439  * when building LZ4 as a shared/dynamic library.
440  *
441  * In order to access these declarations,
442  * define LZ4_STATIC_LINKING_ONLY in your application
443  * before including LZ4's headers.
444  *
445  * In order to make their implementations accessible dynamically, you must
446  * define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
447  ******************************************************************************/
448 
449 #ifdef LZ4_STATIC_LINKING_ONLY
450 
451 #ifndef LZ4_STATIC_3504398509
452 #define LZ4_STATIC_3504398509
453 
454 #ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
455 #define LZ4LIB_STATIC_API LZ4LIB_API
456 #else
457 #define LZ4LIB_STATIC_API
458 #endif
459 
460 
471 LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
472 
499 LZ4LIB_STATIC_API void LZ4_attach_dictionary(LZ4_stream_t* workingStream, const LZ4_stream_t* dictionaryStream);
500 
501 
553 #define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
554 #define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize))
556 #ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
557 # define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
558 #endif
559 
560 #define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
561 #define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN)
563 #endif /* LZ4_STATIC_3504398509 */
564 #endif /* LZ4_STATIC_LINKING_ONLY */
565 
566 
567 
568 #ifndef LZ4_H_98237428734687
569 #define LZ4_H_98237428734687
570 
571 /*-************************************************************
572  * Private Definitions
573  **************************************************************
574  * Do not use these definitions directly.
575  * They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
576  * Accessing members will expose user code to API and/or ABI break in future versions of the library.
577  **************************************************************/
578 #define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
579 #define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
580 #define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
581 
582 #if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
583 # include <stdint.h>
584  typedef int8_t LZ4_i8;
585  typedef uint8_t LZ4_byte;
586  typedef uint16_t LZ4_u16;
587  typedef uint32_t LZ4_u32;
588 #else
589  typedef signed char LZ4_i8;
590  typedef unsigned char LZ4_byte;
591  typedef unsigned short LZ4_u16;
592  typedef unsigned int LZ4_u32;
593 #endif
594 
603 };
604 
605 typedef struct {
607  size_t extDictSize;
609  size_t prefixSize;
611 
612 
623 #define LZ4_STREAMSIZE 16416 /* static size, for inter-version compatibility */
624 #define LZ4_STREAMSIZE_VOIDP (LZ4_STREAMSIZE / sizeof(void*))
628 }; /* previously typedef'd to LZ4_stream_t */
629 
630 
646 
647 
655 #define LZ4_STREAMDECODESIZE_U64 (4 + ((sizeof(void*)==16) ? 2 : 0) /*AS-400*/ )
656 #define LZ4_STREAMDECODESIZE (LZ4_STREAMDECODESIZE_U64 * sizeof(unsigned long long))
658  unsigned long long table[LZ4_STREAMDECODESIZE_U64];
660 } ; /* previously typedef'd to LZ4_streamDecode_t */
661 
662 
663 
664 /*-************************************
665 * Obsolete Functions
666 **************************************/
667 
679 #ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
680 # define LZ4_DEPRECATED(message) /* disable deprecation warnings */
681 #else
682 # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
683 # define LZ4_DEPRECATED(message) [[deprecated(message)]]
684 # elif defined(_MSC_VER)
685 # define LZ4_DEPRECATED(message) __declspec(deprecated(message))
686 # elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
687 # define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
688 # elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
689 # define LZ4_DEPRECATED(message) __attribute__((deprecated))
690 # else
691 # pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
692 # define LZ4_DEPRECATED(message) /* disabled */
693 # endif
694 #endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
695 
697 LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
703 
707 
708 /* Obsolete streaming functions (since v1.7.0)
709  * degraded functionality; do not use!
710  *
711  * In order to perform streaming compression, these functions depended on data
712  * that is no longer tracked in the state. They have been preserved as well as
713  * possible: using them will still produce a correct output. However, they don't
714  * actually retain any history between compression calls. The compression ratio
715  * achieved will therefore be no better than compressing each chunk
716  * independently.
717  */
722 
726 
753 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
754 LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
755 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
756 LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
757 LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
758 LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
759 
766 LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
767 
768 
769 #endif /* LZ4_H_98237428734687 */
770 
771 
772 #if defined (__cplusplus)
773 }
774 #endif
lzma_index * src
Definition: index.h:567
static LZ4_stream_t LZ4_stream
Definition: fullbench.c:169
voidpf void uLong size
Definition: ioapi.h:138
#define const
Definition: ansidecl.h:240
LZ4_FORCE_O2 int LZ4_decompress_safe_withPrefix64k(const char *source, char *dest, int compressedSize, int maxOutputSize)
Definition: lz4.c:2198
void * LZ4_create(char *inputBuffer)
Definition: lz4.c:2483
int LZ4_compress_limitedOutput(const char *source, char *dest, int inputSize, int maxOutputSize)
Definition: lz4.c:2432
int LZ4_compress_limitedOutput_continue(LZ4_stream_t *LZ4_stream, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:2448
int LZ4_compress(const char *src, char *dest, int srcSize)
Definition: lz4.c:2436
int LZ4_uncompress(const char *source, char *dest, int outputSize)
Definition: lz4.c:2463
int LZ4_compress_continue(LZ4_stream_t *LZ4_stream, const char *source, char *dest, int inputSize)
Definition: lz4.c:2452
int LZ4_uncompress_unknownOutputSize(const char *source, char *dest, int isize, int maxOutputSize)
Definition: lz4.c:2467
char * LZ4_slideInputBuffer(void *state)
Definition: lz4.c:2489
int LZ4_sizeofStreamState(void)
Definition: lz4.c:2474
int LZ4_compress_withState(void *state, const char *src, char *dst, int srcSize)
Definition: lz4.c:2444
int LZ4_compress_limitedOutput_withState(void *state, const char *src, char *dst, int srcSize, int dstSize)
Definition: lz4.c:2440
int LZ4_resetStreamState(void *state, char *inputBuffer)
Definition: lz4.c:2476
int LZ4_compress_fast_extState_fastReset(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1316
void LZ4_attach_dictionary(LZ4_stream_t *workingStream, const LZ4_stream_t *dictionaryStream)
Definition: lz4.c:1517
int LZ4_decompress_fast_withPrefix64k(const char *source, char *dest, int originalSize)
Definition: lz4.c:2206
#define LZ4LIB_API
Definition: lz4.h:97
LZ4LIB_API int LZ4_decompress_fast_usingDict(const char *src, char *dst, int originalSize, const char *dictStart, int dictSize)
Definition: lz4.c:2419
const char * source
Definition: lz4.h:699
LZ4LIB_API int LZ4_compress_fast_continue(LZ4_stream_t *streamPtr, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1565
LZ4LIB_API int LZ4_decompress_safe_usingDict(const char *src, char *dst, int srcSize, int dstCapcity, const char *dictStart, int dictSize)
Definition: lz4.c:2404
char int srcSize
Definition: lz4.h:697
char int compressedSize
Definition: lz4.h:724
char int int maxOutputSize
Definition: lz4.h:698
LZ4LIB_API int LZ4_compress_fast(const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1354
LZ4LIB_API void LZ4_resetStream_fast(LZ4_stream_t *streamPtr)
Definition: lz4.c:1461
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize)
Definition: lz4.c:2306
LZ4LIB_API int LZ4_freeStreamDecode(LZ4_streamDecode_t *LZ4_stream)
Definition: lz4.c:2272
LZ4LIB_API int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int originalSize)
Definition: lz4.c:2362
#define LZ4_STREAMDECODESIZE_U64
Definition: lz4.h:655
LZ4LIB_API const char * LZ4_versionString(void)
Definition: lz4.c:673
#define LZ4_STREAMSIZE_VOIDP
Definition: lz4.h:624
LZ4LIB_API int LZ4_saveDict(LZ4_stream_t *streamPtr, char *safeBuffer, int maxDictSize)
Definition: lz4.c:1668
LZ4LIB_API int LZ4_versionNumber(void)
Definition: lz4.c:672
LZ4LIB_API LZ4_streamDecode_t * LZ4_createStreamDecode(void)
Definition: lz4.c:2265
LZ4LIB_API int LZ4_sizeofState(void)
Definition: lz4.c:675
char int int maxDstSize
Definition: lz4.h:724
char * inputBuffer
Definition: lz4.h:720
#define LZ4_HASH_SIZE_U32
Definition: lz4.h:580
LZ4LIB_API int LZ4_compressBound(int inputSize)
Definition: lz4.c:674
LZ4LIB_API int LZ4_decompress_safe(const char *src, char *dst, int compressedSize, int dstCapacity)
Definition: lz4.c:2171
LZ4LIB_API int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, const char *dictionary, int dictSize)
Definition: lz4.c:2285
LZ4LIB_API int LZ4_freeStream(LZ4_stream_t *streamPtr)
Definition: lz4.c:1465
const char char int inputSize
Definition: lz4.h:699
unsigned short LZ4_u16
Definition: lz4.h:591
char * dst
Definition: lz4.h:724
LZ4LIB_API int LZ4_compress_fast_extState(void *state, const char *src, char *dst, int srcSize, int dstCapacity, int acceleration)
Definition: lz4.c:1284
LZ4LIB_API int LZ4_decompress_safe_partial(const char *src, char *dst, int srcSize, int targetOutputSize, int dstCapacity)
Definition: lz4.c:2179
signed char LZ4_i8
Definition: lz4.h:589
LZ4LIB_API int LZ4_loadDict(LZ4_stream_t *streamPtr, const char *dictionary, int dictSize)
Definition: lz4.c:1475
LZ4LIB_API int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:2322
LZ4LIB_API void LZ4_resetStream(LZ4_stream_t *streamPtr)
Definition: lz4.c:1455
unsigned char LZ4_byte
Definition: lz4.h:590
char int originalSize
Definition: lz4.h:725
char * dest
Definition: lz4.h:697
LZ4LIB_API int LZ4_compress_destSize(const char *src, char *dst, int *srcSizePtr, int targetDstSize)
Definition: lz4.c:1399
LZ4LIB_API int LZ4_decompress_fast(const char *src, char *dst, int originalSize)
Definition: lz4.c:2188
char int outputSize
Definition: lz4.h:705
LZ4LIB_API int LZ4_compress_default(const char *src, char *dst, int srcSize, int dstCapacity)
Definition: lz4.c:1373
char int isize
Definition: lz4.h:706
LZ4LIB_API LZ4_stream_t * LZ4_createStream(void)
Definition: lz4.c:1423
LZ4LIB_API LZ4_stream_t * LZ4_initStream(void *buffer, size_t size)
Definition: lz4.c:1443
unsigned int LZ4_u32
Definition: lz4.h:592
#define LZ4_DEPRECATED(message)
Definition: lz4.h:692
unsigned short uint16_t
Definition: sftypes.h:30
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
char int8_t
Definition: sftypes.h:35
const LZ4_byte * prefixEnd
Definition: lz4.h:608
const LZ4_byte * externalDict
Definition: lz4.h:606
const LZ4_stream_t_internal * dictCtx
Definition: lz4.h:601
LZ4_u32 tableType
Definition: lz4.h:599
LZ4_u32 currentOffset
Definition: lz4.h:598
const LZ4_byte * dictionary
Definition: lz4.h:600
LZ4_u32 dictSize
Definition: lz4.h:602
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32]
Definition: lz4.h:597
Definition: buffer.h:15
Definition: dis.h:43
LZ4_streamDecode_t_internal internal_donotuse
Definition: lz4.h:659
unsigned long long table[LZ4_STREAMDECODESIZE_U64]
Definition: lz4.h:658
LZ4_stream_t_internal internal_donotuse
Definition: lz4.h:627
void * table[LZ4_STREAMSIZE_VOIDP]
Definition: lz4.h:626