]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma.h
Add LZMA_API to liblzma API headers. It's useful at least
[icculus/xz.git] / src / liblzma / api / lzma.h
1 /**
2  * \file        lzma.h
3  * \brief       The public API of liblzma
4  *
5  * liblzma is a LZMA compression library with a zlib-like API.
6  * liblzma is based on LZMA SDK found from http://7-zip.org/sdk.html.
7  *
8  * \author      Copyright (C) 1999-2006 Igor Pavlov
9  * \author      Copyright (C) 2007 Lasse Collin
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  */
21
22 #ifndef LZMA_H
23 #define LZMA_H
24
25 /*****************************
26  * Required standard headers *
27  *****************************/
28
29 /**
30  * liblzma API headers need some standard types and macros. To allow
31  * including lzma.h without requiring the application to include other
32  * headers first, lzma.h includes the required standard headers unless
33  * they already seem to be included already or if LZMA_MANUAL_HEADERS
34  * has been defined.
35  *
36  * Here's what types and macros are needed and from which headers:
37  *  - stddef.h: size_t, NULL
38  *  - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
39  *    UINT32_MAX, UINT64_MAX
40  *
41  * However, inttypes.h is a little more portable than stdint.h, although
42  * inttypes.h declares some unneeded things compared to plain stdint.h.
43  *
44  * The hacks below aren't perfect, specifically they assume that inttypes.h
45  * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
46  * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
47  * If the application already takes care of setting up all the types and
48  * macros properly (for example by using gnulib's stdint.h or inttypes.h),
49  * we try to detect that the macros are already defined and don't include
50  * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
51  * force this file to never include any system headers.
52  *
53  * Some could argue that liblzma API should provide all the required types,
54  * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
55  * seen unnecessary mess, since most systems already provide all the necessary
56  * types and macros in the standard headers.
57  *
58  * Note that liblzma API still has lzma_bool, because using stdbool.h would
59  * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
60  * necessarily the same as sizeof(bool) in C++.
61  */
62
63 #ifndef LZMA_MANUAL_HEADERS
64         /*
65          * I suppose this works portably also in C++. Note that in C++,
66          * we need to get size_t into the global namespace.
67          */
68 #       include <stddef.h>
69
70         /*
71          * Skip inttypes.h if we already have all the required macros. If we
72          * have the macros, we assume that we have the matching typedefs too.
73          */
74 #       if !defined(UINT32_C) || !defined(UINT64_C) \
75                         || !defined(UINT32_MAX) || !defined(UINT64_MAX)
76                 /*
77                  * MSVC has no C99 support, and thus it cannot be used to
78                  * compile liblzma. The liblzma API has to still be usable
79                  * from MSVC, so we need to define the required standard
80                  * integer types here.
81                  */
82 #               if defined(_WIN32) && defined(_MSC_VER)
83                         typedef unsigned __int8 uint8_t;
84                         typedef unsigned __int32 uint32_t;
85                         typedef unsigned __int64 uint64_t;
86 #               else
87                         /* Use the standard inttypes.h. */
88 #                       ifdef __cplusplus
89                                 /*
90                                  * C99 sections 7.18.2 and 7.18.4 specify that
91                                  * in C++ implementations define the limit
92                                  * and constant macros only if specifically
93                                  * requested. Note that if you want the
94                                  * format macros (PRIu64 etc.) too, you need
95                                  * to define __STDC_FORMAT_MACROS before
96                                  * including lzma.h, since re-including
97                                  * inttypes.h with __STDC_FORMAT_MACROS
98                                  * defined doesn't necessarily work.
99                                  */
100 #                               ifndef __STDC_LIMIT_MACROS
101 #                                       define __STDC_LIMIT_MACROS 1
102 #                               endif
103 #                               ifndef __STDC_CONSTANT_MACROS
104 #                                       define __STDC_CONSTANT_MACROS 1
105 #                               endif
106 #                       endif
107
108 #                       include <inttypes.h>
109 #               endif
110
111                 /*
112                  * Some old systems have only the typedefs in inttypes.h, and
113                  * lack all the macros. For those systems, we need a few more
114                  * hacks. We assume that unsigned int is 32-bit and unsigned
115                  * long is either 32-bit or 64-bit. If these hacks aren't
116                  * enough, the application has to setup the types manually
117                  * before including lzma.h.
118                  */
119 #               ifndef UINT32_C
120 #                       if defined(_WIN32) && defined(_MSC_VER)
121 #                               define UINT32_C(n) n ## UI32
122 #                       else
123 #                               define UINT32_C(n) n ## U
124 #                       endif
125 #               endif
126
127 #               ifndef UINT64_C
128 #                       if defined(_WIN32) && defined(_MSC_VER)
129 #                               define UINT64_C(n) n ## UI64
130 #                       else
131                                 /* Get ULONG_MAX. */
132 #                               include <limits.h>
133 #                               if ULONG_MAX == 4294967295UL
134 #                                       define UINT64_C(n) n ## ULL
135 #                               else
136 #                                       define UINT64_C(n) n ## UL
137 #                               endif
138 #                       endif
139 #               endif
140
141 #               ifndef UINT32_MAX
142 #                       define UINT32_MAX (UINT32_C(4294967295))
143 #               endif
144
145 #               ifndef UINT64_MAX
146 #                       define UINT64_MAX (UINT64_C(18446744073709551615))
147 #               endif
148 #       endif
149 #endif /* ifdef LZMA_MANUAL_HEADERS */
150
151
152 /******************
153  * LZMA_API macro *
154  ******************/
155
156 /*
157  * Some systems require that the functions are declared specially
158  * in the headers.
159  */
160 #ifndef LZMA_API
161 #       if defined(_WIN32)
162 #               define LZMA_API __cdecl __declspec(dllimport)
163 #       else
164 #               define LZMA_API
165 #       endif
166 #endif
167
168
169 /********************
170  * GNU C extensions *
171  ********************/
172
173 /*
174  * GNU C extensions are used conditionally in the public API. It doesn't
175  * break anything if these are sometimes enabled and sometimes not, only
176  * affects warnings and optimizations.
177  */
178 #if __GNUC__ >= 3
179 #       ifndef lzma_attribute
180 #               define lzma_attribute(attr) __attribute__(attr)
181 #       endif
182
183 #       ifndef lzma_restrict
184 #               define lzma_restrict __restrict__
185 #       endif
186
187         /* warn_unused_result was added in GCC 3.4. */
188 #       ifndef lzma_attr_warn_unused_result
189 #               if __GNUC__ == 3 && __GNUC_MINOR__ < 4
190 #                       define lzma_attr_warn_unused_result
191 #               endif
192 #       endif
193
194 #else
195 #       ifndef lzma_attribute
196 #               define lzma_attribute(attr)
197 #       endif
198
199 #       ifndef lzma_restrict
200 #               if __STDC_VERSION__ >= 199901L
201 #                       define lzma_restrict restrict
202 #               else
203 #                       define lzma_restrict
204 #               endif
205 #       endif
206 #endif
207
208
209 #ifndef lzma_attr_pure
210 #       define lzma_attr_pure lzma_attribute((__pure__))
211 #endif
212
213 #ifndef lzma_attr_const
214 #       define lzma_attr_const lzma_attribute((__const__))
215 #endif
216
217 #ifndef lzma_attr_warn_unused_result
218 #       define lzma_attr_warn_unused_result \
219                 lzma_attribute((__warn_unused_result__))
220 #endif
221
222
223 /**************
224  * Subheaders *
225  **************/
226
227 #ifdef __cplusplus
228 extern "C" {
229 #endif
230
231 /*
232  * Subheaders check that this is defined. It is to prevent including
233  * them directly from applications.
234  */
235 #define LZMA_H_INTERNAL 1
236
237 /* Basic features */
238 #include "lzma/version.h"
239 #include "lzma/base.h"
240 #include "lzma/vli.h"
241 #include "lzma/check.h"
242
243 /* Filters */
244 #include "lzma/filter.h"
245 #include "lzma/subblock.h"
246 #include "lzma/bcj.h"
247 #include "lzma/delta.h"
248 #include "lzma/lzma.h"
249
250 /* Container formats */
251 #include "lzma/container.h"
252
253 /* Advanced features */
254 #include "lzma/stream_flags.h"
255 #include "lzma/block.h"
256 #include "lzma/index.h"
257 #include "lzma/index_hash.h"
258
259 /*
260  * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
261  * re-including the subheaders.
262  */
263 #undef LZMA_H_INTERNAL
264
265 #ifdef __cplusplus
266 }
267 #endif
268
269 #endif /* ifndef LZMA_H */