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