~ubuntu-branches/ubuntu/trusty/cmake3/trusty-updates

« back to all changes in this revision

Viewing changes to Utilities/cmliblzma/common/sysdefs.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2017-02-23 17:55:24 UTC
  • Revision ID: package-import@ubuntu.com-20170223175524-5nh7s4pu97fsa0t7
Tags: upstream-3.5.1
ImportĀ upstreamĀ versionĀ 3.5.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
//  Author:     Lasse Collin
 
10
//
 
11
//  This file has been put into the public domain.
 
12
//  You can do whatever you want with this file.
 
13
//
 
14
///////////////////////////////////////////////////////////////////////////////
 
15
 
 
16
#ifndef LZMA_SYSDEFS_H
 
17
#define LZMA_SYSDEFS_H
 
18
 
 
19
#if defined(_MSC_VER)
 
20
# pragma warning(push,1)
 
21
# pragma warning(disable: 4142) /* benign redefinition of type */
 
22
# pragma warning(disable: 4761) /* integral size mismatch in argument */
 
23
#endif
 
24
 
 
25
//////////////
 
26
// Includes //
 
27
//////////////
 
28
 
 
29
#include "config.h"
 
30
 
 
31
// Get standard-compliant stdio functions under MinGW and MinGW-w64.
 
32
#ifdef __MINGW32__
 
33
#       define __USE_MINGW_ANSI_STDIO 1
 
34
#endif
 
35
 
 
36
// size_t and NULL
 
37
#include <stddef.h>
 
38
 
 
39
#ifdef HAVE_INTTYPES_H
 
40
#       include <inttypes.h>
 
41
#endif
 
42
 
 
43
// C99 says that inttypes.h always includes stdint.h, but some systems
 
44
// don't do that, and require including stdint.h separately.
 
45
#ifdef HAVE_STDINT_H
 
46
#       include <stdint.h>
 
47
#endif
 
48
 
 
49
// Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
 
50
// limits are also used to figure out some macros missing from pre-C99 systems.
 
51
#ifdef HAVE_LIMITS_H
 
52
#       include <limits.h>
 
53
#endif
 
54
 
 
55
 
 
56
#if defined(_MSC_VER) && (_MSC_VER < 1310)
 
57
#  define UINT64_C(n) n ## ui64
 
58
#endif
 
59
 
 
60
 
 
61
// Be more compatible with systems that have non-conforming inttypes.h.
 
62
// We assume that int is 32-bit and that long is either 32-bit or 64-bit.
 
63
// Full Autoconf test could be more correct, but this should work well enough.
 
64
// Note that this duplicates some code from lzma.h, but this is better since
 
65
// we can work without inttypes.h thanks to Autoconf tests.
 
66
#ifndef UINT32_C
 
67
#       if UINT_MAX != 4294967295U
 
68
#               error UINT32_C is not defined and unsigned int is not 32-bit.
 
69
#       endif
 
70
#       define UINT32_C(n) n ## U
 
71
#endif
 
72
#ifndef UINT32_MAX
 
73
#       define UINT32_MAX UINT32_C(4294967295)
 
74
#endif
 
75
#ifndef PRIu32
 
76
#       define PRIu32 "u"
 
77
#endif
 
78
#ifndef PRIx32
 
79
#       define PRIx32 "x"
 
80
#endif
 
81
#ifndef PRIX32
 
82
#       define PRIX32 "X"
 
83
#endif
 
84
 
 
85
#if ULONG_MAX == 4294967295UL
 
86
#       ifndef UINT64_C
 
87
#               define UINT64_C(n) n ## ULL
 
88
#       endif
 
89
#       ifndef PRIu64
 
90
#               define PRIu64 "llu"
 
91
#       endif
 
92
#       ifndef PRIx64
 
93
#               define PRIx64 "llx"
 
94
#       endif
 
95
#       ifndef PRIX64
 
96
#               define PRIX64 "llX"
 
97
#       endif
 
98
#else
 
99
#       ifndef UINT64_C
 
100
#               define UINT64_C(n) n ## UL
 
101
#       endif
 
102
#       ifndef PRIu64
 
103
#               define PRIu64 "lu"
 
104
#       endif
 
105
#       ifndef PRIx64
 
106
#               define PRIx64 "lx"
 
107
#       endif
 
108
#       ifndef PRIX64
 
109
#               define PRIX64 "lX"
 
110
#       endif
 
111
#endif
 
112
#ifndef UINT64_MAX
 
113
#       define UINT64_MAX UINT64_C(18446744073709551615)
 
114
#endif
 
115
 
 
116
// Incorrect(?) SIZE_MAX:
 
117
//   - Interix headers typedef size_t to unsigned long,
 
118
//     but a few lines later define SIZE_MAX to INT32_MAX.
 
119
//   - SCO OpenServer (x86) headers typedef size_t to unsigned int
 
120
//     but define SIZE_MAX to INT32_MAX.
 
121
#if defined(__INTERIX) || defined(_SCO_DS)
 
122
#       undef SIZE_MAX
 
123
#endif
 
124
 
 
125
// The code currently assumes that size_t is either 32-bit or 64-bit.
 
126
#ifndef SIZE_MAX
 
127
#       if SIZE_OF_SIZE_T == 4
 
128
#               define SIZE_MAX UINT32_MAX
 
129
#       elif SIZE_OF_SIZE_T == 8
 
130
#               define SIZE_MAX UINT64_MAX
 
131
#       else
 
132
#               error size_t is not 32-bit or 64-bit
 
133
#       endif
 
134
#endif
 
135
#if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
 
136
#       error size_t is not 32-bit or 64-bit
 
137
#endif
 
138
 
 
139
#include <stdlib.h>
 
140
#include <assert.h>
 
141
 
 
142
// Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
 
143
// so that it works with fake bool type, for example:
 
144
//
 
145
//    bool foo = (flags & 0x100) != 0;
 
146
//    bool bar = !!(flags & 0x100);
 
147
//
 
148
// This works with the real C99 bool but breaks with fake bool:
 
149
//
 
150
//    bool baz = (flags & 0x100);
 
151
//
 
152
#ifdef HAVE_STDBOOL_H
 
153
#       include <stdbool.h>
 
154
#else
 
155
#       if ! HAVE__BOOL
 
156
typedef unsigned char _Bool;
 
157
#       endif
 
158
#       define bool _Bool
 
159
#       define false 0
 
160
#       define true 1
 
161
#       define __bool_true_false_are_defined 1
 
162
#endif
 
163
 
 
164
// string.h should be enough but let's include strings.h and memory.h too if
 
165
// they exists, since that shouldn't do any harm, but may improve portability.
 
166
#ifdef HAVE_STRING_H
 
167
#       include <string.h>
 
168
#endif
 
169
 
 
170
#ifdef HAVE_STRINGS_H
 
171
#       include <strings.h>
 
172
#endif
 
173
 
 
174
#ifdef HAVE_MEMORY_H
 
175
#       include <memory.h>
 
176
#endif
 
177
 
 
178
 
 
179
////////////
 
180
// Macros //
 
181
////////////
 
182
 
 
183
#undef memzero
 
184
#define memzero(s, n) memset(s, 0, n)
 
185
 
 
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))
 
191
 
 
192
#ifndef ARRAY_SIZE
 
193
#       define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
 
194
#endif
 
195
 
 
196
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
 
197
#       define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x)))
 
198
#else
 
199
#       define lzma_attr_alloc_size(x)
 
200
#endif
 
201
 
 
202
#endif