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 // Copyright (C) 2007 Lasse Collin
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.
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.
21 ///////////////////////////////////////////////////////////////////////////////
23 #ifndef LZMA_SYSDEFS_H
24 #define LZMA_SYSDEFS_H
37 #ifdef HAVE_INTTYPES_H
38 # include <inttypes.h>
41 // C99 says that inttypes.h always includes stdint.h, but some systems
42 // don't do that, and require including stdint.h separately.
47 // Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
48 // limits are also used to figure out some macros missing from pre-C99 systems.
53 // Be more compatible with systems that have non-conforming inttypes.h.
54 // We assume that int is 32-bit and that long is either 32-bit or 64-bit.
55 // Full Autoconf test could be more correct, but this should work well enough.
56 // Note that this duplicates some code from lzma.h, but this is better since
57 // we can work without inttypes.h thanks to Autoconf tests.
59 # if UINT_MAX != 4294967295U
60 # error UINT32_C is not defined and unsiged int is not 32-bit.
62 # define UINT32_C(n) n ## U
65 # define UINT32_MAX UINT32_C(4294967295)
74 #if ULONG_MAX == 4294967295UL
76 # define UINT64_C(n) n ## ULL
86 # define UINT64_C(n) n ## UL
96 # define UINT64_MAX UINT64_C(18446744073709551615)
99 // The code currently assumes that size_t is either 32-bit or 64-bit.
101 # if SIZEOF_SIZE_T == 4
102 # define SIZE_MAX UINT32_MAX
103 # elif SIZEOF_SIZE_T == 8
104 # define SIZE_MAX UINT64_MAX
106 # error sizeof(size_t) is not 32-bit or 64-bit
109 #if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
110 # error sizeof(size_t) is not 32-bit or 64-bit
116 // Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
117 // so that it works with fake bool type, for example:
119 // bool foo = (flags & 0x100) != 0;
120 // bool bar = !!(flags & 0x100);
122 // This works with the real C99 bool but breaks with fake bool:
124 // bool baz = (flags & 0x100);
126 #ifdef HAVE_STDBOOL_H
127 # include <stdbool.h>
130 typedef unsigned char _Bool;
135 # define __bool_true_false_are_defined 1
138 // string.h should be enough but let's include strings.h and memory.h too if
139 // they exists, since that shouldn't do any harm, but may improve portability.
144 #ifdef HAVE_STRINGS_H
145 # include <strings.h>
158 #define memzero(s, n) memset(s, 0, n)
161 # define MIN(x, y) ((x) < (y) ? (x) : (y))
165 # define MAX(x, y) ((x) > (y) ? (x) : (y))
169 # define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))