1 ///////////////////////////////////////////////////////////////////////////////
4 /// \brief Common includes, definitions, system-specific things etc.
6 /// This file is used also by the lzma command line tool, that's why this
7 /// file is separate from common.h.
9 // Author: Lasse Collin
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
14 ///////////////////////////////////////////////////////////////////////////////
16 #ifndef LZMA_SYSDEFS_H
17 #define LZMA_SYSDEFS_H
27 // Get standard-compliant stdio functions under MinGW and MinGW-w64.
29 # define __USE_MINGW_ANSI_STDIO 1
35 #ifdef HAVE_INTTYPES_H
36 # include <inttypes.h>
39 // C99 says that inttypes.h always includes stdint.h, but some systems
40 // don't do that, and require including stdint.h separately.
45 // Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
46 // limits are also used to figure out some macros missing from pre-C99 systems.
51 // Be more compatible with systems that have non-conforming inttypes.h.
52 // We assume that int is 32-bit and that long is either 32-bit or 64-bit.
53 // Full Autoconf test could be more correct, but this should work well enough.
54 // Note that this duplicates some code from lzma.h, but this is better since
55 // we can work without inttypes.h thanks to Autoconf tests.
57 # if UINT_MAX != 4294967295U
58 # error UINT32_C is not defined and unsigned int is not 32-bit.
60 # define UINT32_C(n) n ## U
63 # define UINT32_MAX UINT32_C(4294967295)
75 #if ULONG_MAX == 4294967295UL
77 # define UINT64_C(n) n ## ULL
90 # define UINT64_C(n) n ## UL
103 # define UINT64_MAX UINT64_C(18446744073709551615)
106 // Incorrect(?) SIZE_MAX:
107 // - Interix headers typedef size_t to unsigned long,
108 // but a few lines later define SIZE_MAX to INT32_MAX.
109 // - SCO OpenServer (x86) headers typedef size_t to unsigned int
110 // but define SIZE_MAX to INT32_MAX.
111 #if defined(__INTERIX) || defined(_SCO_DS)
115 // The code currently assumes that size_t is either 32-bit or 64-bit.
117 # if SIZEOF_SIZE_T == 4
118 # define SIZE_MAX UINT32_MAX
119 # elif SIZEOF_SIZE_T == 8
120 # define SIZE_MAX UINT64_MAX
122 # error size_t is not 32-bit or 64-bit
125 #if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
126 # error size_t is not 32-bit or 64-bit
132 // Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
133 // so that it works with fake bool type, for example:
135 // bool foo = (flags & 0x100) != 0;
136 // bool bar = !!(flags & 0x100);
138 // This works with the real C99 bool but breaks with fake bool:
140 // bool baz = (flags & 0x100);
142 #ifdef HAVE_STDBOOL_H
143 # include <stdbool.h>
146 typedef unsigned char _Bool
;
151 # define __bool_true_false_are_defined 1
154 // string.h should be enough but let's include strings.h and memory.h too if
155 // they exists, since that shouldn't do any harm, but may improve portability.
160 #ifdef HAVE_STRINGS_H
161 # include <strings.h>
168 // As of MSVC 2013, inline and restrict are supported with
169 // non-standard keywords.
170 #if defined(_WIN32) && defined(_MSC_VER)
172 # define inline __inline
175 # define restrict __restrict
184 #define memzero(s, n) memset(s, 0, n)
186 // NOTE: Avoid using MIN() and MAX(), because even conditionally defining
187 // those macros can cause some portability trouble, since on some systems
188 // the system headers insist defining their own versions.
189 #define my_min(x, y) ((x) < (y) ? (x) : (y))
190 #define my_max(x, y) ((x) > (y) ? (x) : (y))
193 # define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
196 #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
197 # define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x)))
199 # define lzma_attr_alloc_size(x)