]> icculus.org git repositories - icculus/xz.git/blob - src/common/sysdefs.h
Introduced compatibility with systems that have pre-C99
[icculus/xz.git] / src / common / sysdefs.h
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       sysdefs.h
4 /// \brief      Common includes, definitions, system-specific things etc.
5 ///
6 /// This file is used also by the lzma command line tool, that's why this
7 /// file is separate from common.h.
8 //
9 //  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
23 #ifndef LZMA_SYSDEFS_H
24 #define LZMA_SYSDEFS_H
25
26 //////////////
27 // Includes //
28 //////////////
29
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include <sys/types.h>
35
36 #ifdef HAVE_INTTYPES_H
37 #       include <inttypes.h>
38 #endif
39
40 #ifdef HAVE_LIMITS_H
41 #       include <limits.h>
42 #endif
43
44 // Be more compatible with systems that have non-conforming inttypes.h.
45 // We assume that int is 32-bit and that long is either 32-bit or 64-bit.
46 // Full Autoconf test could be more correct, but this should work well enough.
47 #ifndef UINT32_C
48 #       define UINT32_C(n) n ## U
49 #endif
50 #ifndef UINT32_MAX
51 #       define UINT32_MAX UINT32_C(4294967295)
52 #endif
53 #ifndef PRIu32
54 #       define PRIu32 "u"
55 #endif
56 #ifndef PRIX32
57 #       define PRIX32 "X"
58 #endif
59 #if SIZEOF_UNSIGNED_LONG == 4
60 #       ifndef UINT64_C
61 #               define UINT64_C(n) n ## ULL
62 #       endif
63 #       ifndef PRIu64
64 #               define PRIu64 "llu"
65 #       endif
66 #       ifndef PRIX64
67 #               define PRIX64 "llX"
68 #       endif
69 #else
70 #       ifndef UINT64_C
71 #               define UINT64_C(n) n ## UL
72 #       endif
73 #       ifndef PRIu64
74 #               define PRIu64 "lu"
75 #       endif
76 #       ifndef PRIX64
77 #               define PRIX64 "lX"
78 #       endif
79 #endif
80 #ifndef UINT64_MAX
81 #       define UINT64_MAX UINT64_C(18446744073709551615)
82 #endif
83 #ifndef SIZE_MAX
84 #       if SIZEOF_SIZE_T == 4
85 #               define SIZE_MAX UINT32_MAX
86 #       else
87 #               define SIZE_MAX UINT64_MAX
88 #       endif
89 #endif
90
91 #include <stdlib.h>
92
93 #ifdef HAVE_STDBOOL_H
94 #       include <stdbool.h>
95 #else
96 #       if ! HAVE__BOOL
97 typedef unsigned char _Bool;
98 #       endif
99 #       define bool _Bool
100 #       define false 0
101 #       define true 1
102 #       define __bool_true_false_are_defined 1
103 #endif
104
105 #ifdef HAVE_ASSERT_H
106 #       include <assert.h>
107 #else
108 #       ifdef NDEBUG
109 #               define assert(x)
110 #       else
111                 // TODO: Pretty bad assert() macro.
112 #               define assert(x) (!(x) && abort())
113 #       endif
114 #endif
115
116 #ifdef HAVE_STRING_H
117 #       include <string.h>
118 #endif
119
120 #ifdef HAVE_STRINGS_H
121 #       include <strings.h>
122 #endif
123
124 #ifdef HAVE_MEMORY_H
125 #       include <memory.h>
126 #endif
127
128 #include "lzma.h"
129
130
131 ////////////
132 // Macros //
133 ////////////
134
135 #ifndef HAVE_MEMCPY
136 #       define memcpy(dest, src, n) bcopy(src, dest, n)
137 #endif
138
139 #ifndef HAVE_MEMMOVE
140 #       define memmove(dest, src, n) bcopy(src, dest, n)
141 #endif
142
143 #ifdef HAVE_MEMSET
144 #       define memzero(s, n) memset(s, 0, n)
145 #else
146 #       define memzero(s, n) bzero(s, n)
147 #endif
148
149 #ifndef MIN
150 #       define MIN(x, y) ((x) < (y) ? (x) : (y))
151 #endif
152
153 #ifndef MAX
154 #       define MAX(x, y) ((x) > (y) ? (x) : (y))
155 #endif
156
157 #endif