xref: /netbsd-src/external/bsd/liblzf/dist/lzf.h (revision e6ea0ca4b63c68aa4d6153608fa0eb4fc2f96f72)
105206c06Stls /*
205206c06Stls  * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
305206c06Stls  *
405206c06Stls  * Redistribution and use in source and binary forms, with or without modifica-
505206c06Stls  * tion, are permitted provided that the following conditions are met:
605206c06Stls  *
705206c06Stls  *   1.  Redistributions of source code must retain the above copyright notice,
805206c06Stls  *       this list of conditions and the following disclaimer.
905206c06Stls  *
1005206c06Stls  *   2.  Redistributions in binary form must reproduce the above copyright
1105206c06Stls  *       notice, this list of conditions and the following disclaimer in the
1205206c06Stls  *       documentation and/or other materials provided with the distribution.
1305206c06Stls  *
1405206c06Stls  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1505206c06Stls  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
1605206c06Stls  * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
1705206c06Stls  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
1805206c06Stls  * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1905206c06Stls  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
2005206c06Stls  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2105206c06Stls  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
2205206c06Stls  * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2305206c06Stls  * OF THE POSSIBILITY OF SUCH DAMAGE.
2405206c06Stls  *
2505206c06Stls  * Alternatively, the contents of this file may be used under the terms of
2605206c06Stls  * the GNU General Public License ("GPL") version 2 or any later version,
2705206c06Stls  * in which case the provisions of the GPL are applicable instead of
2805206c06Stls  * the above. If you wish to allow the use of your version of this file
2905206c06Stls  * only under the terms of the GPL and not to allow others to use your
3005206c06Stls  * version of this file under the BSD license, indicate your decision
3105206c06Stls  * by deleting the provisions above and replace them with the notice
3205206c06Stls  * and other provisions required by the GPL. If you do not delete the
3305206c06Stls  * provisions above, a recipient may use your version of this file under
3405206c06Stls  * either the BSD or the GPL.
3505206c06Stls  */
3605206c06Stls 
3705206c06Stls #ifndef LZF_H
3805206c06Stls #define LZF_H
3905206c06Stls 
4055a82c0aStls #include "lzfP.h"
4155a82c0aStls 
4205206c06Stls /***********************************************************************
4305206c06Stls **
4405206c06Stls **	lzf -- an extremely fast/free compression/decompression-method
4505206c06Stls **	http://liblzf.plan9.de/
4605206c06Stls **
4705206c06Stls **	This algorithm is believed to be patent-free.
4805206c06Stls **
4905206c06Stls ***********************************************************************/
5005206c06Stls 
5105206c06Stls #define LZF_VERSION 0x0105 /* 1.5, API version */
5205206c06Stls 
5305206c06Stls /*
5405206c06Stls  * Compress in_len bytes stored at the memory block starting at
5505206c06Stls  * in_data and write the result to out_data, up to a maximum length
5605206c06Stls  * of out_len bytes.
5705206c06Stls  *
5805206c06Stls  * If the output buffer is not large enough or any error occurs return 0,
5905206c06Stls  * otherwise return the number of bytes used, which might be considerably
6005206c06Stls  * more than in_len (but less than 104% of the original size), so it
6105206c06Stls  * makes sense to always use out_len == in_len - 1), to ensure _some_
6205206c06Stls  * compression, and store the data uncompressed otherwise (with a flag, of
6305206c06Stls  * course.
6405206c06Stls  *
6505206c06Stls  * lzf_compress might use different algorithms on different systems and
6605206c06Stls  * even different runs, thus might result in different compressed strings
6705206c06Stls  * depending on the phase of the moon or similar factors. However, all
6805206c06Stls  * these strings are architecture-independent and will result in the
6905206c06Stls  * original data when decompressed using lzf_decompress.
7005206c06Stls  *
7105206c06Stls  * The buffers must not be overlapping.
7205206c06Stls  *
73*e6ea0ca4Stls  * This function formerly had two API variants depending on a
74*e6ea0ca4Stls  * compile-time constant: one took a 64K state structure as an
75*e6ea0ca4Stls  * argument, the other allocated it internally on the stack (yuck).
76*e6ea0ca4Stls  *
77*e6ea0ca4Stls  * We define the stack-unfriendly version in terms of the stack-friendly
78*e6ea0ca4Stls  * one.
7905206c06Stls  *
8005206c06Stls  */
8105206c06Stls unsigned int
82*e6ea0ca4Stls lzf_compress_r (const void *const,  unsigned int,
83*e6ea0ca4Stls                 void *, unsigned int, LZF_STATE);
84*e6ea0ca4Stls 
85*e6ea0ca4Stls static inline int
lzf_compress(const void * const in,unsigned int in_len,void * out,unsigned int out_len)86*e6ea0ca4Stls lzf_compress (const void *const in, unsigned int in_len,
87*e6ea0ca4Stls 	      void *out, unsigned int out_len)
88*e6ea0ca4Stls {
89*e6ea0ca4Stls   LZF_STATE htab;
90*e6ea0ca4Stls 
91*e6ea0ca4Stls   return lzf_compress_r(in, in_len, out, out_len, htab);
92*e6ea0ca4Stls }
9305206c06Stls 
9405206c06Stls /*
9505206c06Stls  * Decompress data compressed with some version of the lzf_compress
9605206c06Stls  * function and stored at location in_data and length in_len. The result
9705206c06Stls  * will be stored at out_data up to a maximum of out_len characters.
9805206c06Stls  *
9905206c06Stls  * If the output buffer is not large enough to hold the decompressed
10005206c06Stls  * data, a 0 is returned and errno is set to E2BIG. Otherwise the number
10105206c06Stls  * of decompressed bytes (i.e. the original length of the data) is
10205206c06Stls  * returned.
10305206c06Stls  *
10405206c06Stls  * If an error in the compressed data is detected, a zero is returned and
10505206c06Stls  * errno is set to EINVAL.
10605206c06Stls  *
10705206c06Stls  * This function is very fast, about as fast as a copying loop.
10805206c06Stls  */
10905206c06Stls unsigned int
1100b168fdfSagc lzf_decompress (const void *const ,  unsigned int,
1110b168fdfSagc                 void             *, unsigned int);
11205206c06Stls 
11305206c06Stls #endif
11405206c06Stls 
115