1/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2// vim: expandtab:ts=8:sw=4:softtabstop=4:
3/**
4 * \file api/lzma.h
5 * \brief The public API of liblzma data compression library
6 *
7 * liblzma is a public domain general-purpose data compression library with
8 * a zlib-like API. The native file format is .xz, but also the old .lzma
9 * format and raw (no headers) streams are supported. Multiple compression
10 * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
11 *
12 * liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes
13 * a gzip-like command line tool named xz and some other tools. XZ Utils
14 * is developed and maintained by Lasse Collin.
15 *
16 * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
17 * <http://7-zip.org/sdk.html>.
18 *
19 * The SHA-256 implementation is based on the public domain code found from
20 * 7-Zip <http://7-zip.org/>, which has a modified version of the public
21 * domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>.
22 * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
23 */
24
25/*
26 * Author: Lasse Collin
27 *
28 * This file has been put into the public domain.
29 * You can do whatever you want with this file.
30 */
31
32#ifndef LZMA_H
33#define LZMA_H
34
35/*****************************
36 * Required standard headers *
37 *****************************/
38
39/*
40 * liblzma API headers need some standard types and macros. To allow
41 * including lzma.h without requiring the application to include other
42 * headers first, lzma.h includes the required standard headers unless
43 * they already seem to be included already or if LZMA_MANUAL_HEADERS
44 * has been defined.
45 *
46 * Here's what types and macros are needed and from which headers:
47 * - stddef.h: size_t, NULL
48 * - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
49 * UINT32_MAX, UINT64_MAX
50 *
51 * However, inttypes.h is a little more portable than stdint.h, although
52 * inttypes.h declares some unneeded things compared to plain stdint.h.
53 *
54 * The hacks below aren't perfect, specifically they assume that inttypes.h
55 * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
56 * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
57 * If the application already takes care of setting up all the types and
58 * macros properly (for example by using gnulib's stdint.h or inttypes.h),
59 * we try to detect that the macros are already defined and don't include
60 * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
61 * force this file to never include any system headers.
62 *
63 * Some could argue that liblzma API should provide all the required types,
64 * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
65 * seen unnecessary mess, since most systems already provide all the necessary
66 * types and macros in the standard headers.
67 *
68 * Note that liblzma API still has lzma_bool, because using stdbool.h would
69 * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
70 * necessarily the same as sizeof(bool) in C++.
71 */
72
73#ifndef LZMA_MANUAL_HEADERS
74 /*
75 * I suppose this works portably also in C++. Note that in C++,
76 * we need to get size_t into the global namespace.
77 */
78# include <stddef.h>
79
80 /*
81 * Skip inttypes.h if we already have all the required macros. If we
82 * have the macros, we assume that we have the matching typedefs too.
83 */
84# if !defined(UINT32_C) || !defined(UINT64_C) \
85 || !defined(UINT32_MAX) || !defined(UINT64_MAX)
86 /*
87 * MSVC has no C99 support, and thus it cannot be used to
88 * compile liblzma. The liblzma API has to still be usable
89 * from MSVC, so we need to define the required standard
90 * integer types here.
91 */
92# if defined(_WIN32) && defined(_MSC_VER)
93 typedef unsigned __int8 uint8_t;
94 typedef unsigned __int32 uint32_t;
95 typedef unsigned __int64 uint64_t;
96# else
97 /* Use the standard inttypes.h. */
98# ifdef __cplusplus
99 /*
100 * C99 sections 7.18.2 and 7.18.4 specify that
101 * in C++ implementations define the limit
102 * and constant macros only if specifically
103 * requested. Note that if you want the
104 * format macros (PRIu64 etc.) too, you need
105 * to define __STDC_FORMAT_MACROS before
106 * including lzma.h, since re-including
107 * inttypes.h with __STDC_FORMAT_MACROS
108 * defined doesn't necessarily work.
109 */
110# ifndef __STDC_LIMIT_MACROS
111# define __STDC_LIMIT_MACROS 1
112# endif
113# ifndef __STDC_CONSTANT_MACROS
114# define __STDC_CONSTANT_MACROS 1
115# endif
116# endif
117
118# include <inttypes.h>
119# endif
120
121 /*
122 * Some old systems have only the typedefs in inttypes.h, and
123 * lack all the macros. For those systems, we need a few more
124 * hacks. We assume that unsigned int is 32-bit and unsigned
125 * long is either 32-bit or 64-bit. If these hacks aren't
126 * enough, the application has to setup the types manually
127 * before including lzma.h.
128 */
129# ifndef UINT32_C
130# if defined(_WIN32) && defined(_MSC_VER)
131# define UINT32_C(n) n ## UI32
132# else
133# define UINT32_C(n) n ## U
134# endif
135# endif
136
137# ifndef UINT64_C
138# if defined(_WIN32) && defined(_MSC_VER)
139# define UINT64_C(n) n ## UI64
140# else
141 /* Get ULONG_MAX. */
142# include <limits.h>
143# if ULONG_MAX == 4294967295UL
144# define UINT64_C(n) n ## ULL
145# else
146# define UINT64_C(n) n ## UL
147# endif
148# endif
149# endif
150
151# ifndef UINT32_MAX
152# define UINT32_MAX (UINT32_C(4294967295))
153# endif
154
155# ifndef UINT64_MAX
156# define UINT64_MAX (UINT64_C(18446744073709551615))
157# endif
158# endif
159#endif /* ifdef LZMA_MANUAL_HEADERS */
160
161
162/******************
163 * LZMA_API macro *
164 ******************/
165
166/*
167 * Some systems require (or at least recommend) that the functions and
168 * function pointers are declared specially in the headers. LZMA_API_IMPORT
169 * is for importing symbols and LZMA_API_CALL is to specify calling
170 * convention.
171 *
172 * By default it is assumed that the application will link dynamically
173 * against liblzma. #define LZMA_API_STATIC in your application if you
174 * want to link against static liblzma. If you don't care about portability
175 * to operating systems like Windows, or at least don't care about linking
176 * against static liblzma on them, don't worry about LZMA_API_STATIC. That
177 * is, most developers will never need to use LZMA_API_STATIC.
178 *
179 * Cygwin is a special case on Windows. We rely on GCC doing the right thing
180 * and thus don't use dllimport and don't specify the calling convention.
181 */
182#ifndef LZMA_API_IMPORT
183# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__CYGWIN__)
184# define LZMA_API_IMPORT __declspec(dllimport)
185# else
186# define LZMA_API_IMPORT
187# endif
188#endif
189
190#ifndef LZMA_API_CALL
191# if defined(_WIN32) && !defined(__CYGWIN__)
192# define LZMA_API_CALL __cdecl
193# else
194# define LZMA_API_CALL
195# endif
196#endif
197
198#ifndef LZMA_API
199# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
200#endif
201
202
203/***********
204 * nothrow *
205 ***********/
206
207/*
208 * None of the functions in liblzma may throw an exception. Even
209 * the functions that use callback functions won't throw exceptions,
210 * because liblzma would break if a callback function threw an exception.
211 */
212#ifndef lzma_nothrow
213# if defined(__cplusplus)
214# define lzma_nothrow throw()
215# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
216# define lzma_nothrow __attribute__((__nothrow__))
217# else
218# define lzma_nothrow
219# endif
220#endif
221
222
223/********************
224 * GNU C extensions *
225 ********************/
226
227/*
228 * GNU C extensions are used conditionally in the public API. It doesn't
229 * break anything if these are sometimes enabled and sometimes not, only
230 * affects warnings and optimizations.
231 */
232#if __GNUC__ >= 3
233# ifndef lzma_attribute
234# define lzma_attribute(attr) __attribute__(attr)
235# endif
236
237# ifndef lzma_restrict
238# define lzma_restrict __restrict__
239# endif
240
241 /* warn_unused_result was added in GCC 3.4. */
242# ifndef lzma_attr_warn_unused_result
243# if __GNUC__ == 3 && __GNUC_MINOR__ < 4
244# define lzma_attr_warn_unused_result
245# endif
246# endif
247
248#else
249# ifndef lzma_attribute
250# define lzma_attribute(attr)
251# endif
252
253# ifndef lzma_restrict
254# if __STDC_VERSION__ >= 199901L
255# define lzma_restrict restrict
256# else
257# define lzma_restrict
258# endif
259# endif
260#endif
261
262
263#ifndef lzma_attr_pure
264# define lzma_attr_pure lzma_attribute((__pure__))
265#endif
266
267#ifndef lzma_attr_const
268# define lzma_attr_const lzma_attribute((__const__))
269#endif
270
271#ifndef lzma_attr_warn_unused_result
272# define lzma_attr_warn_unused_result \
273 lzma_attribute((__warn_unused_result__))
274#endif
275
276
277/**************
278 * Subheaders *
279 **************/
280
281#ifdef __cplusplus
282extern "C" {
283#endif
284
285/*
286 * Subheaders check that this is defined. It is to prevent including
287 * them directly from applications.
288 */
289#define LZMA_H_INTERNAL 1
290
291/* Basic features */
292#include "lzma/version.h"
293#include "lzma/base.h"
294#include "lzma/vli.h"
295#include "lzma/check.h"
296
297/* Filters */
298#include "lzma/filter.h"
299#include "lzma/subblock.h"
300#include "lzma/bcj.h"
301#include "lzma/delta.h"
302#include "lzma/lzma.h"
303
304/* Container formats */
305#include "lzma/container.h"
306
307/* Advanced features */
308#include "lzma/stream_flags.h"
309#include "lzma/block.h"
310#include "lzma/index.h"
311#include "lzma/index_hash.h"
312
313/*
314 * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
315 * re-including the subheaders.
316 */
317#undef LZMA_H_INTERNAL
318
319#ifdef __cplusplus
320}
321#endif
322
323#endif /* ifndef LZMA_H */
324