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