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