1207753Smm/**
2207753Smm * \file        api/lzma.h
3207753Smm * \brief       The public API of liblzma data compression library
4207753Smm *
5207753Smm * liblzma is a public domain general-purpose data compression library with
6207753Smm * a zlib-like API. The native file format is .xz, but also the old .lzma
7207753Smm * format and raw (no headers) streams are supported. Multiple compression
8207753Smm * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
9207753Smm *
10207753Smm * liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes
11207753Smm * a gzip-like command line tool named xz and some other tools. XZ Utils
12207753Smm * is developed and maintained by Lasse Collin.
13207753Smm *
14207753Smm * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
15207753Smm * <http://7-zip.org/sdk.html>.
16207753Smm *
17207753Smm * The SHA-256 implementation is based on the public domain code found from
18207753Smm * 7-Zip <http://7-zip.org/>, which has a modified version of the public
19207753Smm * domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>.
20207753Smm * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
21207753Smm */
22207753Smm
23207753Smm/*
24207753Smm * Author: Lasse Collin
25207753Smm *
26207753Smm * This file has been put into the public domain.
27207753Smm * You can do whatever you want with this file.
28207753Smm */
29207753Smm
30207753Smm#ifndef LZMA_H
31207753Smm#define LZMA_H
32207753Smm
33207753Smm/*****************************
34207753Smm * Required standard headers *
35207753Smm *****************************/
36207753Smm
37207753Smm/*
38207753Smm * liblzma API headers need some standard types and macros. To allow
39207753Smm * including lzma.h without requiring the application to include other
40207753Smm * headers first, lzma.h includes the required standard headers unless
41207753Smm * they already seem to be included already or if LZMA_MANUAL_HEADERS
42207753Smm * has been defined.
43207753Smm *
44207753Smm * Here's what types and macros are needed and from which headers:
45207753Smm *  - stddef.h: size_t, NULL
46207753Smm *  - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
47207753Smm *    UINT32_MAX, UINT64_MAX
48207753Smm *
49207753Smm * However, inttypes.h is a little more portable than stdint.h, although
50207753Smm * inttypes.h declares some unneeded things compared to plain stdint.h.
51207753Smm *
52207753Smm * The hacks below aren't perfect, specifically they assume that inttypes.h
53207753Smm * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
54207753Smm * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
55207753Smm * If the application already takes care of setting up all the types and
56207753Smm * macros properly (for example by using gnulib's stdint.h or inttypes.h),
57207753Smm * we try to detect that the macros are already defined and don't include
58207753Smm * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
59207753Smm * force this file to never include any system headers.
60207753Smm *
61207753Smm * Some could argue that liblzma API should provide all the required types,
62207753Smm * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
63215187Smm * seen as an unnecessary mess, since most systems already provide all the
64215187Smm * necessary types and macros in the standard headers.
65207753Smm *
66207753Smm * Note that liblzma API still has lzma_bool, because using stdbool.h would
67207753Smm * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
68207753Smm * necessarily the same as sizeof(bool) in C++.
69207753Smm */
70207753Smm
71207753Smm#ifndef LZMA_MANUAL_HEADERS
72207753Smm	/*
73207753Smm	 * I suppose this works portably also in C++. Note that in C++,
74207753Smm	 * we need to get size_t into the global namespace.
75207753Smm	 */
76207753Smm#	include <stddef.h>
77207753Smm
78207753Smm	/*
79207753Smm	 * Skip inttypes.h if we already have all the required macros. If we
80207753Smm	 * have the macros, we assume that we have the matching typedefs too.
81207753Smm	 */
82207753Smm#	if !defined(UINT32_C) || !defined(UINT64_C) \
83207753Smm			|| !defined(UINT32_MAX) || !defined(UINT64_MAX)
84207753Smm		/*
85207753Smm		 * MSVC has no C99 support, and thus it cannot be used to
86207753Smm		 * compile liblzma. The liblzma API has to still be usable
87207753Smm		 * from MSVC, so we need to define the required standard
88207753Smm		 * integer types here.
89207753Smm		 */
90207753Smm#		if defined(_WIN32) && defined(_MSC_VER)
91207753Smm			typedef unsigned __int8 uint8_t;
92207753Smm			typedef unsigned __int32 uint32_t;
93207753Smm			typedef unsigned __int64 uint64_t;
94207753Smm#		else
95207753Smm			/* Use the standard inttypes.h. */
96207753Smm#			ifdef __cplusplus
97207753Smm				/*
98207753Smm				 * C99 sections 7.18.2 and 7.18.4 specify
99207753Smm				 * that C++ implementations define the limit
100207753Smm				 * and constant macros only if specifically
101207753Smm				 * requested. Note that if you want the
102207753Smm				 * format macros (PRIu64 etc.) too, you need
103207753Smm				 * to define __STDC_FORMAT_MACROS before
104207753Smm				 * including lzma.h, since re-including
105207753Smm				 * inttypes.h with __STDC_FORMAT_MACROS
106207753Smm				 * defined doesn't necessarily work.
107207753Smm				 */
108207753Smm#				ifndef __STDC_LIMIT_MACROS
109207753Smm#					define __STDC_LIMIT_MACROS 1
110207753Smm#				endif
111207753Smm#				ifndef __STDC_CONSTANT_MACROS
112207753Smm#					define __STDC_CONSTANT_MACROS 1
113207753Smm#				endif
114207753Smm#			endif
115207753Smm
116207753Smm#			include <inttypes.h>
117207753Smm#		endif
118207753Smm
119207753Smm		/*
120207753Smm		 * Some old systems have only the typedefs in inttypes.h, and
121207753Smm		 * lack all the macros. For those systems, we need a few more
122207753Smm		 * hacks. We assume that unsigned int is 32-bit and unsigned
123207753Smm		 * long is either 32-bit or 64-bit. If these hacks aren't
124207753Smm		 * enough, the application has to setup the types manually
125207753Smm		 * before including lzma.h.
126207753Smm		 */
127207753Smm#		ifndef UINT32_C
128207753Smm#			if defined(_WIN32) && defined(_MSC_VER)
129207753Smm#				define UINT32_C(n) n ## UI32
130207753Smm#			else
131207753Smm#				define UINT32_C(n) n ## U
132207753Smm#			endif
133207753Smm#		endif
134207753Smm
135207753Smm#		ifndef UINT64_C
136207753Smm#			if defined(_WIN32) && defined(_MSC_VER)
137207753Smm#				define UINT64_C(n) n ## UI64
138207753Smm#			else
139207753Smm				/* Get ULONG_MAX. */
140207753Smm#				include <limits.h>
141207753Smm#				if ULONG_MAX == 4294967295UL
142207753Smm#					define UINT64_C(n) n ## ULL
143207753Smm#				else
144207753Smm#					define UINT64_C(n) n ## UL
145207753Smm#				endif
146207753Smm#			endif
147207753Smm#		endif
148207753Smm
149207753Smm#		ifndef UINT32_MAX
150207753Smm#			define UINT32_MAX (UINT32_C(4294967295))
151207753Smm#		endif
152207753Smm
153207753Smm#		ifndef UINT64_MAX
154207753Smm#			define UINT64_MAX (UINT64_C(18446744073709551615))
155207753Smm#		endif
156207753Smm#	endif
157207753Smm#endif /* ifdef LZMA_MANUAL_HEADERS */
158207753Smm
159207753Smm
160207753Smm/******************
161207753Smm * LZMA_API macro *
162207753Smm ******************/
163207753Smm
164207753Smm/*
165207753Smm * Some systems require that the functions and function pointers are
166207753Smm * declared specially in the headers. LZMA_API_IMPORT is for importing
167207753Smm * symbols and LZMA_API_CALL is to specify the calling convention.
168207753Smm *
169207753Smm * By default it is assumed that the application will link dynamically
170207753Smm * against liblzma. #define LZMA_API_STATIC in your application if you
171207753Smm * want to link against static liblzma. If you don't care about portability
172207753Smm * to operating systems like Windows, or at least don't care about linking
173207753Smm * against static liblzma on them, don't worry about LZMA_API_STATIC. That
174207753Smm * is, most developers will never need to use LZMA_API_STATIC.
175207753Smm *
176207753Smm * The GCC variants are a special case on Windows (Cygwin and MinGW).
177207753Smm * We rely on GCC doing the right thing with its auto-import feature,
178207753Smm * and thus don't use __declspec(dllimport). This way developers don't
179207753Smm * need to worry about LZMA_API_STATIC. Also the calling convention is
180207753Smm * omitted on Cygwin but not on MinGW.
181207753Smm */
182207753Smm#ifndef LZMA_API_IMPORT
183207753Smm#	if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
184207753Smm#		define LZMA_API_IMPORT __declspec(dllimport)
185207753Smm#	else
186207753Smm#		define LZMA_API_IMPORT
187207753Smm#	endif
188207753Smm#endif
189207753Smm
190207753Smm#ifndef LZMA_API_CALL
191207753Smm#	if defined(_WIN32) && !defined(__CYGWIN__)
192207753Smm#		define LZMA_API_CALL __cdecl
193207753Smm#	else
194207753Smm#		define LZMA_API_CALL
195207753Smm#	endif
196207753Smm#endif
197207753Smm
198207753Smm#ifndef LZMA_API
199207753Smm#	define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
200207753Smm#endif
201207753Smm
202207753Smm
203207753Smm/***********
204207753Smm * nothrow *
205207753Smm ***********/
206207753Smm
207207753Smm/*
208207753Smm * None of the functions in liblzma may throw an exception. Even
209207753Smm * the functions that use callback functions won't throw exceptions,
210207753Smm * because liblzma would break if a callback function threw an exception.
211207753Smm */
212207753Smm#ifndef lzma_nothrow
213207753Smm#	if defined(__cplusplus)
214207753Smm#		define lzma_nothrow throw()
215207753Smm#	elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
216207753Smm#		define lzma_nothrow __attribute__((__nothrow__))
217207753Smm#	else
218207753Smm#		define lzma_nothrow
219207753Smm#	endif
220207753Smm#endif
221207753Smm
222207753Smm
223207753Smm/********************
224207753Smm * GNU C extensions *
225207753Smm ********************/
226207753Smm
227207753Smm/*
228207753Smm * GNU C extensions are used conditionally in the public API. It doesn't
229207753Smm * break anything if these are sometimes enabled and sometimes not, only
230207753Smm * affects warnings and optimizations.
231207753Smm */
232207753Smm#if __GNUC__ >= 3
233207753Smm#	ifndef lzma_attribute
234207753Smm#		define lzma_attribute(attr) __attribute__(attr)
235207753Smm#	endif
236207753Smm
237207753Smm	/* warn_unused_result was added in GCC 3.4. */
238207753Smm#	ifndef lzma_attr_warn_unused_result
239207753Smm#		if __GNUC__ == 3 && __GNUC_MINOR__ < 4
240207753Smm#			define lzma_attr_warn_unused_result
241207753Smm#		endif
242207753Smm#	endif
243207753Smm
244207753Smm#else
245207753Smm#	ifndef lzma_attribute
246207753Smm#		define lzma_attribute(attr)
247207753Smm#	endif
248207753Smm#endif
249207753Smm
250207753Smm
251207753Smm#ifndef lzma_attr_pure
252207753Smm#	define lzma_attr_pure lzma_attribute((__pure__))
253207753Smm#endif
254207753Smm
255207753Smm#ifndef lzma_attr_const
256207753Smm#	define lzma_attr_const lzma_attribute((__const__))
257207753Smm#endif
258207753Smm
259207753Smm#ifndef lzma_attr_warn_unused_result
260207753Smm#	define lzma_attr_warn_unused_result \
261207753Smm		lzma_attribute((__warn_unused_result__))
262207753Smm#endif
263207753Smm
264207753Smm
265207753Smm/**************
266207753Smm * Subheaders *
267207753Smm **************/
268207753Smm
269207753Smm#ifdef __cplusplus
270207753Smmextern "C" {
271207753Smm#endif
272207753Smm
273207753Smm/*
274207753Smm * Subheaders check that this is defined. It is to prevent including
275207753Smm * them directly from applications.
276207753Smm */
277207753Smm#define LZMA_H_INTERNAL 1
278207753Smm
279207753Smm/* Basic features */
280207753Smm#include "lzma/version.h"
281207753Smm#include "lzma/base.h"
282207753Smm#include "lzma/vli.h"
283207753Smm#include "lzma/check.h"
284207753Smm
285207753Smm/* Filters */
286207753Smm#include "lzma/filter.h"
287207753Smm#include "lzma/bcj.h"
288207753Smm#include "lzma/delta.h"
289207753Smm#include "lzma/lzma.h"
290207753Smm
291207753Smm/* Container formats */
292207753Smm#include "lzma/container.h"
293207753Smm
294207753Smm/* Advanced features */
295207753Smm#include "lzma/stream_flags.h"
296207753Smm#include "lzma/block.h"
297207753Smm#include "lzma/index.h"
298207753Smm#include "lzma/index_hash.h"
299207753Smm
300207753Smm/* Hardware information */
301207753Smm#include "lzma/hardware.h"
302207753Smm
303207753Smm/*
304207753Smm * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
305207753Smm * re-including the subheaders.
306207753Smm */
307207753Smm#undef LZMA_H_INTERNAL
308207753Smm
309207753Smm#ifdef __cplusplus
310207753Smm}
311207753Smm#endif
312207753Smm
313207753Smm#endif /* ifndef LZMA_H */
314