xref: /dflybsd-src/usr.sbin/makefs/hammer2/hammer2_lz4.h (revision 2d60b848f2503f28d840ceae174d07eb149ccce9)
1*2d60b848STomohiro Kusumi /*
2*2d60b848STomohiro Kusumi    LZ4 - Fast LZ compression algorithm
3*2d60b848STomohiro Kusumi    Header File
4*2d60b848STomohiro Kusumi    Copyright (C) 2011-2013, Yann Collet.
5*2d60b848STomohiro Kusumi    BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6*2d60b848STomohiro Kusumi 
7*2d60b848STomohiro Kusumi    Redistribution and use in source and binary forms, with or without
8*2d60b848STomohiro Kusumi    modification, are permitted provided that the following conditions are
9*2d60b848STomohiro Kusumi    met:
10*2d60b848STomohiro Kusumi 
11*2d60b848STomohiro Kusumi        * Redistributions of source code must retain the above copyright
12*2d60b848STomohiro Kusumi    notice, this list of conditions and the following disclaimer.
13*2d60b848STomohiro Kusumi        * Redistributions in binary form must reproduce the above
14*2d60b848STomohiro Kusumi    copyright notice, this list of conditions and the following disclaimer
15*2d60b848STomohiro Kusumi    in the documentation and/or other materials provided with the
16*2d60b848STomohiro Kusumi    distribution.
17*2d60b848STomohiro Kusumi 
18*2d60b848STomohiro Kusumi    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*2d60b848STomohiro Kusumi    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*2d60b848STomohiro Kusumi    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*2d60b848STomohiro Kusumi    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*2d60b848STomohiro Kusumi    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*2d60b848STomohiro Kusumi    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*2d60b848STomohiro Kusumi    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*2d60b848STomohiro Kusumi    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*2d60b848STomohiro Kusumi    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*2d60b848STomohiro Kusumi    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*2d60b848STomohiro Kusumi    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*2d60b848STomohiro Kusumi 
30*2d60b848STomohiro Kusumi    You can contact the author at :
31*2d60b848STomohiro Kusumi    - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
32*2d60b848STomohiro Kusumi    - LZ4 source repository : http://code.google.com/p/lz4/
33*2d60b848STomohiro Kusumi */
34*2d60b848STomohiro Kusumi #pragma once
35*2d60b848STomohiro Kusumi 
36*2d60b848STomohiro Kusumi #if defined (__cplusplus)
37*2d60b848STomohiro Kusumi extern "C" {
38*2d60b848STomohiro Kusumi #endif
39*2d60b848STomohiro Kusumi 
40*2d60b848STomohiro Kusumi 
41*2d60b848STomohiro Kusumi //**************************************
42*2d60b848STomohiro Kusumi // Compiler Options
43*2d60b848STomohiro Kusumi //**************************************
44*2d60b848STomohiro Kusumi //Should go here if they are needed
45*2d60b848STomohiro Kusumi 
46*2d60b848STomohiro Kusumi //****************************
47*2d60b848STomohiro Kusumi // Simple Functions
48*2d60b848STomohiro Kusumi //****************************
49*2d60b848STomohiro Kusumi 
50*2d60b848STomohiro Kusumi int LZ4_decompress_safe (char* source, char* dest, int inputSize,
51*2d60b848STomohiro Kusumi 						int maxOutputSize);
52*2d60b848STomohiro Kusumi 
53*2d60b848STomohiro Kusumi /*
54*2d60b848STomohiro Kusumi LZ4_decompress_safe() :
55*2d60b848STomohiro Kusumi     maxOutputSize :
56*2d60b848STomohiro Kusumi      is the size of the destination buffer (which must be already allocated)
57*2d60b848STomohiro Kusumi     return :
58*2d60b848STomohiro Kusumi      the number of bytes decoded in the destination buffer
59*2d60b848STomohiro Kusumi      (necessarily <= maxOutputSize)
60*2d60b848STomohiro Kusumi      If the source stream is malformed or too large, the function will
61*2d60b848STomohiro Kusumi      stop decoding and return a negative result.
62*2d60b848STomohiro Kusumi      This function is protected against any kind of buffer overflow attemps
63*2d60b848STomohiro Kusumi      (never writes outside of output buffer, and never reads outside of
64*2d60b848STomohiro Kusumi      input buffer). It is therefore protected against malicious data packets
65*2d60b848STomohiro Kusumi */
66*2d60b848STomohiro Kusumi 
67*2d60b848STomohiro Kusumi 
68*2d60b848STomohiro Kusumi //****************************
69*2d60b848STomohiro Kusumi // Advanced Functions
70*2d60b848STomohiro Kusumi //****************************
71*2d60b848STomohiro Kusumi 
72*2d60b848STomohiro Kusumi int LZ4_compress_limitedOutput(char* source, char* dest, int inputSize,
73*2d60b848STomohiro Kusumi 						int maxOutputSize);
74*2d60b848STomohiro Kusumi 
75*2d60b848STomohiro Kusumi /*
76*2d60b848STomohiro Kusumi LZ4_compress_limitedOutput() :
77*2d60b848STomohiro Kusumi     Compress 'inputSize' bytes from 'source' into an output buffer 'dest'
78*2d60b848STomohiro Kusumi     of maximum size 'maxOutputSize'.
79*2d60b848STomohiro Kusumi     If it cannot achieve it, compression will stop, and result of
80*2d60b848STomohiro Kusumi     the function will be zero.
81*2d60b848STomohiro Kusumi     This function never writes outside of provided output buffer.
82*2d60b848STomohiro Kusumi 
83*2d60b848STomohiro Kusumi     inputSize  :
84*2d60b848STomohiro Kusumi      Max supported value is ~1.9GB
85*2d60b848STomohiro Kusumi     maxOutputSize :
86*2d60b848STomohiro Kusumi      is the size of the destination buffer (which must bealready allocated)
87*2d60b848STomohiro Kusumi     return :
88*2d60b848STomohiro Kusumi      the number of bytes written in buffer 'dest' or 0 if the compression fails
89*2d60b848STomohiro Kusumi */
90*2d60b848STomohiro Kusumi 
91*2d60b848STomohiro Kusumi #if defined (__cplusplus)
92*2d60b848STomohiro Kusumi }
93*2d60b848STomohiro Kusumi #endif
94