]> icculus.org git repositories - icculus/xz.git/blob - src/liblzma/api/lzma.h
Remove lzma_init() and other init functions from liblzma API.
[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 #               ifdef __cplusplus
77                         /*
78                          * C99 sections 7.18.2 and 7.18.4 specify that in C++
79                          * implementations define the limit and constant
80                          * macros only if specifically requested. Note that
81                          * if you want the format macros (PRIu64 etc.) too,
82                          * you need to define __STDC_FORMAT_MACROS before
83                          * including lzma.h, since re-including inttypes.h
84                          * with __STDC_FORMAT_MACROS defined doesn't
85                          * necessarily work.
86                          */
87 #                       ifndef __STDC_LIMIT_MACROS
88 #                               define __STDC_LIMIT_MACROS 1
89 #                       endif
90 #                       ifndef __STDC_CONSTANT_MACROS
91 #                               define __STDC_CONSTANT_MACROS 1
92 #                       endif
93 #               endif
94
95 #               include <inttypes.h>
96
97                 /*
98                  * Some old systems have only the typedefs in inttypes.h, and
99                  * lack all the macros. For those systems, we need a few more
100                  * hacks. We assume that unsigned int is 32-bit and unsigned
101                  * long is either 32-bit or 64-bit. If these hacks aren't
102                  * enough, the application has to setup the types manually
103                  * before including lzma.h.
104                  */
105 #               ifndef UINT32_C
106 #                       define UINT32_C(n) n # U
107 #               endif
108
109 #               ifndef UINT64_C
110                         /* Get ULONG_MAX. */
111 #                       include <limits.h>
112 #                       if ULONG_MAX == 4294967295UL
113 #                               define UINT64_C(n) n ## ULL
114 #                       else
115 #                               define UINT64_C(n) n ## UL
116 #                       endif
117 #               endif
118
119 #               ifndef UINT32_MAX
120 #                       define UINT32_MAX (UINT32_C(4294967295))
121 #               endif
122
123 #               ifndef UINT64_MAX
124 #                       define UINT64_MAX (UINT64_C(18446744073709551615))
125 #               endif
126 #       endif
127 #endif /* ifdef LZMA_MANUAL_HEADERS */
128
129
130 /********************
131  * GNU C extensions *
132  ********************/
133
134 /*
135  * GNU C extensions are used conditionally in the public API. It doesn't
136  * break anything if these are sometimes enabled and sometimes not, only
137  * affects warnings and optimizations.
138  */
139 #if __GNUC__ >= 3
140 #       ifndef lzma_attribute
141 #               define lzma_attribute(attr) __attribute__(attr)
142 #       endif
143
144 #       ifndef lzma_restrict
145 #               define lzma_restrict __restrict__
146 #       endif
147
148         /* warn_unused_result was added in GCC 3.4. */
149 #       ifndef lzma_attr_warn_unused_result
150 #               if __GNUC__ == 3 && __GNUC_MINOR__ < 4
151 #                       define lzma_attr_warn_unused_result
152 #               endif
153 #       endif
154
155 #else
156 #       ifndef lzma_attribute
157 #               define lzma_attribute(attr)
158 #       endif
159
160 #       ifndef lzma_restrict
161 #               if __STDC_VERSION__ >= 199901L
162 #                       define lzma_restrict restrict
163 #               else
164 #                       define lzma_restrict
165 #               endif
166 #       endif
167 #endif
168
169
170 #ifndef lzma_attr_pure
171 #       define lzma_attr_pure lzma_attribute((__pure__))
172 #endif
173
174 #ifndef lzma_attr_const
175 #       define lzma_attr_const lzma_attribute((__const__))
176 #endif
177
178 #ifndef lzma_attr_warn_unused_result
179 #       define lzma_attr_warn_unused_result \
180                 lzma_attribute((__warn_unused_result__))
181 #endif
182
183
184 /**************
185  * Subheaders *
186  **************/
187
188 #ifdef __cplusplus
189 extern "C" {
190 #endif
191
192 /*
193  * Subheaders check that this is defined. It is to prevent including
194  * them directly from applications.
195  */
196 #define LZMA_H_INTERNAL 1
197
198 /* Basic features */
199 #include "lzma/version.h"
200 #include "lzma/base.h"
201 #include "lzma/vli.h"
202 #include "lzma/check.h"
203
204 /* Filters */
205 #include "lzma/filter.h"
206 #include "lzma/subblock.h"
207 #include "lzma/simple.h"
208 #include "lzma/delta.h"
209 #include "lzma/lzma.h"
210
211 /* Container formats */
212 #include "lzma/container.h"
213
214 /* Advanced features */
215 #include "lzma/stream_flags.h"
216 #include "lzma/block.h"
217 #include "lzma/index.h"
218 #include "lzma/index_hash.h"
219
220 /*
221  * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
222  * re-including the subheaders.
223  */
224 #undef LZMA_H_INTERNAL
225
226 #ifdef __cplusplus
227 }
228 #endif
229
230 #endif /* ifndef LZMA_H */