xref: /aosp_15_r20/external/coreboot/payloads/libpayload/include/lz4.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * Alternatively, this software may be distributed under the terms of the
16  * GNU General Public License ("GPL") version 2 as published by the Free
17  * Software Foundation.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef __LZ4_H_
33 #define __LZ4_H_
34 
35 #include <stddef.h>
36 
37 /* Decompresses an LZ4F image (multiple LZ4 blocks with frame header) from src
38  * to dst, ensuring that it doesn't read more than srcn bytes and doesn't write
39  * more than dstn. Buffer sizes must stay below 2GB. Can decompress files loaded
40  * to the end of a buffer in-place, as long as buffer is larger than the final
41  * output size. (Usually just a few bytes, but may be up to (8 + dstn/255) in
42  * worst case. Will reliably return an error if buffer was too small.)
43  * Returns amount of decompressed bytes, or 0 on error.
44  */
45 size_t ulz4fn(const void *src, size_t srcn, void *dst, size_t dstn);
46 
47 /* Same as ulz4fn() but does not perform any bounds checks. */
48 size_t ulz4f(const void *src, void *dst);
49 
50 #endif /* __LZ4_H_ */
51