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
30 #ifdef HAVE_INTTYPES_H
31 # include <inttypes.h>
34 // C99 says that inttypes.h always includes stdint.h, but some systems
35 // don't do that, and require including stdint.h separately.
40 // Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
41 // limits are also used to figure out some macros missing from pre-C99 systems.
46 // Be more compatible with systems that have non-conforming inttypes.h.
47 // We assume that int is 32-bit and that long is either 32-bit or 64-bit.
48 // Full Autoconf test could be more correct, but this should work well enough.
49 // Note that this duplicates some code from lzma.h, but this is better since
50 // we can work without inttypes.h thanks to Autoconf tests.
52 # if UINT_MAX != 4294967295U
53 # error UINT32_C is not defined and unsiged int is not 32-bit.
55 # define UINT32_C(n) n ## U
58 # define UINT32_MAX UINT32_C(4294967295)
67 #if ULONG_MAX == 4294967295UL
69 # define UINT64_C(n) n ## ULL
79 # define UINT64_C(n) n ## UL
89 # define UINT64_MAX UINT64_C(18446744073709551615)
92 // The code currently assumes that size_t is either 32-bit or 64-bit.
94 # if SIZEOF_SIZE_T == 4
95 # define SIZE_MAX UINT32_MAX
96 # elif SIZEOF_SIZE_T == 8
97 # define SIZE_MAX UINT64_MAX
99 # error sizeof(size_t) is not 32-bit or 64-bit
102 #if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
103 # error sizeof(size_t) is not 32-bit or 64-bit
109 // Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
110 // so that it works with fake bool type, for example:
112 // bool foo = (flags & 0x100) != 0;
113 // bool bar = !!(flags & 0x100);
115 // This works with the real C99 bool but breaks with fake bool:
117 // bool baz = (flags & 0x100);
119 #ifdef HAVE_STDBOOL_H
120 # include <stdbool.h>
123 typedef unsigned char _Bool;
128 # define __bool_true_false_are_defined 1
131 // string.h should be enough but let's include strings.h and memory.h too if
132 // they exists, since that shouldn't do any harm, but may improve portability.
137 #ifdef HAVE_STRINGS_H
138 # include <strings.h>
150 #if defined(_WIN32) || defined(__MSDOS__) || defined(__OS2__)
155 #define memzero(s, n) memset(s, 0, n)
158 # define MIN(x, y) ((x) < (y) ? (x) : (y))
162 # define MAX(x, y) ((x) > (y) ? (x) : (y))
166 # define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))