a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Copyright (c) 2000-2008 Marc Alexander Lehmann <schmorp@schmorp.de>
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Redistribution and use in source and binary forms, with or without modifica-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * tion, are permitted provided that the following conditions are met:
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * 1. Redistributions of source code must retain the above copyright notice,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * this list of conditions and the following disclaimer.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * 2. Redistributions in binary form must reproduce the above copyright
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * notice, this list of conditions and the following disclaimer in the
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * documentation and/or other materials provided with the distribution.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * OF THE POSSIBILITY OF SUCH DAMAGE.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Alternatively, the contents of this file may be used under the terms of
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the GNU General Public License ("GPL") version 2 or any later version,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * in which case the provisions of the GPL are applicable instead of
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * the above. If you wish to allow the use of your version of this file
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * only under the terms of the GPL and not to allow others to use your
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * version of this file under the BSD license, indicate your decision
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * by deleting the provisions above and replace them with the notice
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * and other provisions required by the GPL. If you do not delete the
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * provisions above, a recipient may use your version of this file under
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * either the BSD or the GPL.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifndef LZF_H
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#define LZF_H
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifdef __cplusplus /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsyncextern "C" { /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/***********************************************************************
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync**
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync** lzf -- an extremely fast/free compression/decompression-method
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync** http://liblzf.plan9.de/
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync**
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync** This algorithm is believed to be patent-free.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync**
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync***********************************************************************/
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#define LZF_VERSION 0x0105 /* 1.5, API version */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Compress in_len bytes stored at the memory block starting at
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * in_data and write the result to out_data, up to a maximum length
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * of out_len bytes.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * If the output buffer is not large enough or any error occurs return 0,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * otherwise return the number of bytes used, which might be considerably
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * more than in_len (but less than 104% of the original size), so it
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * makes sense to always use out_len == in_len - 1), to ensure _some_
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * compression, and store the data uncompressed otherwise (with a flag, of
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * course.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * lzf_compress might use different algorithms on different systems and
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * even different runs, thus might result in different compressed strings
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * depending on the phase of the moon or similar factors. However, all
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * these strings are architecture-independent and will result in the
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * original data when decompressed using lzf_decompress.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * The buffers must not be overlapping.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * If the option LZF_STATE_ARG is enabled, an extra argument must be
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * supplied which is not reflected in this header file. Refer to lzfP.h
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * and lzf_c.c.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsyncunsigned int
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsynclzf_compress (const void *const in_data, unsigned int in_len,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync void *out_data, unsigned int out_len);
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync/*
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * Decompress data compressed with some version of the lzf_compress
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * function and stored at location in_data and length in_len. The result
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * will be stored at out_data up to a maximum of out_len characters.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * If the output buffer is not large enough to hold the decompressed
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * data, a 0 is returned and errno is set to E2BIG. Otherwise the number
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * of decompressed bytes (i.e. the original length of the data) is
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * returned.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * If an error in the compressed data is detected, a zero is returned and
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * errno is set to EINVAL.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync *
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync * This function is very fast, about as fast as a copying loop.
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsyncunsigned int
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsynclzf_decompress (const void *const in_data, unsigned int in_len,
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync void *out_data, unsigned int out_len);
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#ifdef __cplusplus /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync} /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif /* vbox */
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync#endif
a260560bdbc7bd737d59547882cd5e8d77b80d0avboxsync