Subversion Repositories Kolibri OS

Rev

Rev 4872 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/*
2
 * Copyright (c) 2004, 2005 by
3
 * Ralf Corsepius, Ulm/Germany. All rights reserved.
4
 *
5
 * Permission to use, copy, modify, and distribute this software
6
 * is freely granted, provided that this notice is preserved.
7
 */
8
 
9
#ifndef _STDINT_H
10
#define _STDINT_H
11
 
12
#ifdef __cplusplus
13
extern "C" {
14
#endif
15
 
16
#if defined(__GNUC__) && \
17
  ( (__GNUC__ >= 4) || \
18
    ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ > 2) ) )
19
/* gcc > 3.2 implicitly defines the values we are interested */
20
#define __STDINT_EXP(x) __##x##__
21
#else
22
#define __STDINT_EXP(x) x
23
#include 
24
#endif
25
 
26
/* Check if "long long" is 64bit wide */
27
/* Modern GCCs provide __LONG_LONG_MAX__, SUSv3 wants LLONG_MAX */
28
#if ( defined(__LONG_LONG_MAX__) && (__LONG_LONG_MAX__ > 0x7fffffff) ) \
29
  || ( defined(LLONG_MAX) && (LLONG_MAX > 0x7fffffff) )
30
#define __have_longlong64 1
31
#endif
32
 
33
/* Check if "long" is 64bit or 32bit wide */
34
#if __STDINT_EXP(LONG_MAX) > 0x7fffffff
35
#define __have_long64 1
36
#elif __STDINT_EXP(LONG_MAX) == 0x7fffffff && !defined(__SPU__)
37
#define __have_long32 1
38
#define __have_long64 0
39
#endif
40
 
41
#if __STDINT_EXP(SCHAR_MAX) == 0x7f
42
typedef signed char int8_t ;
43
typedef unsigned char uint8_t ;
44
#define __int8_t_defined 1
45
#endif
46
 
47
#if __int8_t_defined
48
typedef signed char int_least8_t;
49
typedef unsigned char uint_least8_t;
50
#define __int_least8_t_defined 1
51
#endif
52
 
53
#if __STDINT_EXP(SHRT_MAX) == 0x7fff
54
typedef signed short int16_t;
55
typedef unsigned short uint16_t;
56
#define __int16_t_defined 1
57
#elif __STDINT_EXP(INT_MAX) == 0x7fff
58
typedef signed int int16_t;
59
typedef unsigned int uint16_t;
60
#define __int16_t_defined 1
61
#elif __STDINT_EXP(SCHAR_MAX) == 0x7fff
62
typedef signed char int16_t;
63
typedef unsigned char uint16_t;
64
#define __int16_t_defined 1
65
#endif
66
 
67
#if __int16_t_defined
68
typedef int16_t   	int_least16_t;
69
typedef uint16_t 	uint_least16_t;
70
#define __int_least16_t_defined 1
71
 
72
#if !__int_least8_t_defined
73
typedef int16_t	   	int_least8_t;
74
typedef uint16_t  	uint_least8_t;
75
#define __int_least8_t_defined 1
76
#endif
77
#endif
78
 
79
//#if __have_long32
80
//typedef signed long int32_t;
81
//typedef unsigned long uint32_t;
82
//#define __int32_t_defined 1
83
//#elif __STDINT_EXP(INT_MAX) == 0x7fffffffL
84
typedef signed int int32_t;
85
typedef unsigned int uint32_t;
86
#define __int32_t_defined 1
87
//#elif __STDINT_EXP(SHRT_MAX) == 0x7fffffffL
88
//typedef signed short int32_t;
89
//typedef unsigned short uint32_t;
90
//#define __int32_t_defined 1
91
//#elif __STDINT_EXP(SCHAR_MAX) == 0x7fffffffL
92
//typedef signed char int32_t;
93
//typedef unsigned char uint32_t;
94
//#define __int32_t_defined 1
95
//#endif
96
 
97
#if __int32_t_defined
98
typedef int32_t   	int_least32_t;
99
typedef uint32_t 	uint_least32_t;
100
#define __int_least32_t_defined 1
101
 
102
#if !__int_least8_t_defined
103
typedef int32_t	   	int_least8_t;
104
typedef uint32_t  	uint_least8_t;
105
#define __int_least8_t_defined 1
106
#endif
107
 
108
#if !__int_least16_t_defined
109
typedef int32_t	   	int_least16_t;
110
typedef uint32_t  	uint_least16_t;
111
#define __int_least16_t_defined 1
112
#endif
113
#endif
114
 
115
#if __have_long64
116
typedef signed long int64_t;
117
typedef unsigned long uint64_t;
118
#define __int64_t_defined 1
119
#elif __have_longlong64
120
typedef signed long long int64_t;
121
typedef unsigned long long uint64_t;
122
#define __int64_t_defined 1
123
#elif  __STDINT_EXP(INT_MAX) > 0x7fffffff
124
typedef signed int int64_t;
125
typedef unsigned int uint64_t;
126
#define __int64_t_defined 1
127
#endif
128
 
129
#if __int64_t_defined
130
typedef int64_t   	int_least64_t;
131
typedef uint64_t 	uint_least64_t;
132
#define __int_least64_t_defined 1
133
 
134
#if !__int_least8_t_defined
135
typedef int64_t	   	int_least8_t;
136
typedef uint64_t  	uint_least8_t;
137
#define __int_least8_t_defined 1
138
#endif
139
 
140
#if !__int_least16_t_defined
141
typedef int64_t	   	int_least16_t;
142
typedef uint64_t  	uint_least16_t;
143
#define __int_least16_t_defined 1
144
#endif
145
 
146
#if !__int_least32_t_defined
147
typedef int64_t	   	int_least32_t;
148
typedef uint64_t  	uint_least32_t;
149
#define __int_least32_t_defined 1
150
#endif
151
#endif
152
 
153
/*
154
 * Fastest minimum-width integer types
155
 *
156
 * Assume int to be the fastest type for all types with a width
157
 * less than __INT_MAX__ rsp. INT_MAX
158
 */
159
#if __STDINT_EXP(INT_MAX) >= 0x7f
160
  typedef signed int int_fast8_t;
161
  typedef unsigned int uint_fast8_t;
162
#define __int_fast8_t_defined 1
163
#endif
164
 
165
#if __STDINT_EXP(INT_MAX) >= 0x7fff
166
  typedef signed int int_fast16_t;
167
  typedef unsigned int uint_fast16_t;
168
#define __int_fast16_t_defined 1
169
#endif
170
 
171
#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
172
  typedef signed int int_fast32_t;
173
  typedef unsigned int uint_fast32_t;
174
#define __int_fast32_t_defined 1
175
#endif
176
 
177
#if __STDINT_EXP(INT_MAX) > 0x7fffffff
178
  typedef signed int int_fast64_t;
179
  typedef unsigned int uint_fast64_t;
180
#define __int_fast64_t_defined 1
181
#else
182
#define __int_fast64_t_defined 0
183
#endif
184
 
185
/*
186
 * Fall back to [u]int_least_t for [u]int_fast_t types
187
 * not having been defined, yet.
188
 * Leave undefined, if [u]int_least_t should not be available.
189
 */
190
#if !__int_fast8_t_defined
191
#if __int_least8_t_defined
192
  typedef int_least8_t int_fast8_t;
193
  typedef uint_least8_t uint_fast8_t;
194
#define __int_fast8_t_defined 1
195
#endif
196
#endif
197
 
198
#if !__int_fast16_t_defined
199
#if __int_least16_t_defined
200
  typedef int_least16_t int_fast16_t;
201
  typedef uint_least16_t uint_fast16_t;
202
#define __int_fast16_t_defined 1
203
#endif
204
#endif
205
 
206
#if !__int_fast32_t_defined
207
#if __int_least32_t_defined
208
  typedef int_least32_t int_fast32_t;
209
  typedef uint_least32_t uint_fast32_t;
210
#define __int_fast32_t_defined 1
211
#endif
212
#endif
213
 
214
#if !__int_fast64_t_defined
215
#if __int_least64_t_defined
216
  typedef int_least64_t int_fast64_t;
217
  typedef uint_least64_t uint_fast64_t;
218
#undef  __int_fast64_t_defined
219
#define __int_fast64_t_defined 1
220
#endif
221
#endif
222
 
223
/* Greatest-width integer types */
224
/* Modern GCCs provide __INTMAX_TYPE__ */
225
#if defined(__INTMAX_TYPE__)
226
  typedef __INTMAX_TYPE__ intmax_t;
227
#elif __have_longlong64
228
  typedef signed long long intmax_t;
229
#else
230
  typedef signed long intmax_t;
231
#endif
232
 
233
/* Modern GCCs provide __UINTMAX_TYPE__ */
234
#if defined(__UINTMAX_TYPE__)
235
  typedef __UINTMAX_TYPE__ uintmax_t;
236
#elif __have_longlong64
237
  typedef unsigned long long uintmax_t;
238
#else
239
  typedef unsigned long uintmax_t;
240
#endif
241
 
242
/*
243
 * GCC doesn't provide an appropriate macro for [u]intptr_t
244
 * For now, use __PTRDIFF_TYPE__
245
 */
246
#if defined(__PTRDIFF_TYPE__)
247
typedef signed __PTRDIFF_TYPE__ intptr_t;
248
typedef unsigned __PTRDIFF_TYPE__ uintptr_t;
249
#define INTPTR_MAX PTRDIFF_MAX
250
#define INTPTR_MIN PTRDIFF_MIN
251
#ifdef __UINTPTR_MAX__
252
#define UINTPTR_MAX __UINTPTR_MAX__
253
#else
254
#define UINTPTR_MAX (2UL * PTRDIFF_MAX + 1)
255
#endif
256
#else
257
/*
258
 * Fallback to hardcoded values,
259
 * should be valid on cpu's with 32bit int/32bit void*
260
 */
261
typedef signed long intptr_t;
262
typedef unsigned long uintptr_t;
263
#define INTPTR_MAX __STDINT_EXP(LONG_MAX)
264
#define INTPTR_MIN (-__STDINT_EXP(LONG_MAX) - 1)
265
#define UINTPTR_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
266
#endif
267
 
268
/* Limits of Specified-Width Integer Types */
269
 
270
#if __int8_t_defined
271
#define INT8_MIN 	-128
272
#define INT8_MAX 	 127
273
#define UINT8_MAX 	 255
274
#endif
275
 
276
#if __int_least8_t_defined
277
#define INT_LEAST8_MIN 	-128
278
#define INT_LEAST8_MAX 	 127
279
#define UINT_LEAST8_MAX	 255
280
#else
281
#error required type int_least8_t missing
282
#endif
283
 
284
#if __int16_t_defined
285
#define INT16_MIN 	-32768
286
#define INT16_MAX 	 32767
287
#define UINT16_MAX 	 65535
288
#endif
289
 
290
#if __int_least16_t_defined
291
#define INT_LEAST16_MIN	-32768
292
#define INT_LEAST16_MAX	 32767
293
#define UINT_LEAST16_MAX 65535
294
#else
295
#error required type int_least16_t missing
296
#endif
297
 
298
#if __int32_t_defined
299
#if __have_long32
300
#define INT32_MIN 	 (-2147483647L-1)
301
#define INT32_MAX 	 2147483647L
302
#define UINT32_MAX       4294967295UL
303
#else
304
#define INT32_MIN 	 (-2147483647-1)
305
#define INT32_MAX 	 2147483647
306
#define UINT32_MAX       4294967295U
307
#endif
308
#endif
309
 
310
#if __int_least32_t_defined
311
#if __have_long32
312
#define INT_LEAST32_MIN  (-2147483647L-1)
313
#define INT_LEAST32_MAX  2147483647L
314
#define UINT_LEAST32_MAX 4294967295UL
315
#else
316
#define INT_LEAST32_MIN  (-2147483647-1)
317
#define INT_LEAST32_MAX  2147483647
318
#define UINT_LEAST32_MAX 4294967295U
319
#endif
320
#else
321
#error required type int_least32_t missing
322
#endif
323
 
324
#if __int64_t_defined
325
#if __have_long64
326
#define INT64_MIN 	(-9223372036854775807L-1L)
327
#define INT64_MAX 	 9223372036854775807L
328
#define UINT64_MAX 	18446744073709551615U
329
#elif __have_longlong64
330
#define INT64_MIN 	(-9223372036854775807LL-1LL)
331
#define INT64_MAX 	 9223372036854775807LL
332
#define UINT64_MAX 	18446744073709551615ULL
333
#endif
334
#endif
335
 
336
#if __int_least64_t_defined
337
#if __have_long64
338
#define INT_LEAST64_MIN  (-9223372036854775807L-1L)
339
#define INT_LEAST64_MAX  9223372036854775807L
340
#define UINT_LEAST64_MAX 18446744073709551615U
341
#elif __have_longlong64
342
#define INT_LEAST64_MIN  (-9223372036854775807LL-1LL)
343
#define INT_LEAST64_MAX  9223372036854775807LL
344
#define UINT_LEAST64_MAX 18446744073709551615ULL
345
#endif
346
#endif
347
 
348
#if __int_fast8_t_defined
349
#if __STDINT_EXP(INT_MAX) >= 0x7f
350
#define INT_FAST8_MIN	(-__STDINT_EXP(INT_MAX)-1)
351
#define INT_FAST8_MAX	__STDINT_EXP(INT_MAX)
352
#define UINT_FAST8_MAX	(__STDINT_EXP(INT_MAX)*2U+1U)
353
#else
354
#define INT_FAST8_MIN	INT_LEAST8_MIN
355
#define INT_FAST8_MAX	INT_LEAST8_MAX
356
#define UINT_FAST8_MAX	UINT_LEAST8_MAX
357
#endif
358
#endif
359
 
360
#if __int_fast16_t_defined
361
#if __STDINT_EXP(INT_MAX) >= 0x7fff
362
#define INT_FAST16_MIN	(-__STDINT_EXP(INT_MAX)-1)
363
#define INT_FAST16_MAX	__STDINT_EXP(INT_MAX)
364
#define UINT_FAST16_MAX	(__STDINT_EXP(INT_MAX)*2U+1U)
365
#else
366
#define INT_FAST16_MIN	INT_LEAST16_MIN
367
#define INT_FAST16_MAX	INT_LEAST16_MAX
368
#define UINT_FAST16_MAX	UINT_LEAST16_MAX
369
#endif
370
#endif
371
 
372
#if __int_fast32_t_defined
373
#if __STDINT_EXP(INT_MAX) >= 0x7fffffff
374
#define INT_FAST32_MIN	(-__STDINT_EXP(INT_MAX)-1)
375
#define INT_FAST32_MAX	__STDINT_EXP(INT_MAX)
376
#define UINT_FAST32_MAX	(__STDINT_EXP(INT_MAX)*2U+1U)
377
#else
378
#define INT_FAST32_MIN	INT_LEAST32_MIN
379
#define INT_FAST32_MAX	INT_LEAST32_MAX
380
#define UINT_FAST32_MAX	UINT_LEAST32_MAX
381
#endif
382
#endif
383
 
384
#if __int_fast64_t_defined
385
#if __STDINT_EXP(INT_MAX) > 0x7fffffff
386
#define INT_FAST64_MIN	(-__STDINT_EXP(INT_MAX)-1)
387
#define INT_FAST64_MAX	__STDINT_EXP(INT_MAX)
388
#define UINT_FAST64_MAX	(__STDINT_EXP(INT_MAX)*2U+1U)
389
#else
390
#define INT_FAST64_MIN	INT_LEAST64_MIN
391
#define INT_FAST64_MAX	INT_LEAST64_MAX
392
#define UINT_FAST64_MAX	UINT_LEAST64_MAX
393
#endif
394
#endif
395
 
396
#ifdef __INTMAX_MAX__
397
#define INTMAX_MAX __INTMAX_MAX__
398
#define INTMAX_MIN (-INTMAX_MAX - 1)
399
#elif defined(__INTMAX_TYPE__)
400
/* All relevant GCC versions prefer long to long long for intmax_t.  */
401
#define INTMAX_MAX INT64_MAX
402
#define INTMAX_MIN INT64_MIN
403
#endif
404
 
405
#ifdef __UINTMAX_MAX__
406
#define UINTMAX_MAX __UINTMAX_MAX__
407
#elif defined(__UINTMAX_TYPE__)
408
/* All relevant GCC versions prefer long to long long for intmax_t.  */
409
#define UINTMAX_MAX UINT64_MAX
410
#endif
411
 
412
/* This must match size_t in stddef.h, currently long unsigned int */
413
#ifdef __SIZE_MAX__
414
#define SIZE_MAX __SIZE_MAX__
415
#else
416
#define SIZE_MAX (__STDINT_EXP(LONG_MAX) * 2UL + 1)
417
#endif
418
 
419
/* This must match sig_atomic_t in  (currently int) */
420
#define SIG_ATOMIC_MIN (-__STDINT_EXP(INT_MAX) - 1)
421
#define SIG_ATOMIC_MAX __STDINT_EXP(INT_MAX)
422
 
423
/* This must match ptrdiff_t  in  (currently long int) */
424
#ifdef __PTRDIFF_MAX__
425
#define PTRDIFF_MAX __PTRDIFF_MAX__
426
#else
427
#define PTRDIFF_MAX __STDINT_EXP(LONG_MAX)
428
#endif
429
#define PTRDIFF_MIN (-PTRDIFF_MAX - 1)
430
 
431
#ifdef __WCHAR_MAX__
432
#define WCHAR_MAX __WCHAR_MAX__
433
#endif
434
#ifdef __WCHAR_MIN__
435
#define WCHAR_MIN __WCHAR_MIN__
436
#endif
437
 
438
/* wint_t is unsigned int on almost all GCC targets.  */
439
#ifdef __WINT_MAX__
440
#define WINT_MAX __WINT_MAX__
441
#else
442
#define WINT_MAX (__STDINT_EXP(INT_MAX) * 2U + 1U)
443
#endif
444
#ifdef __WINT_MIN__
445
#define WINT_MIN __WINT_MIN__
446
#else
447
#define WINT_MIN 0U
448
#endif
449
 
450
/** Macros for minimum-width integer constant expressions */
451
#define INT8_C(x)	x
452
#if __STDINT_EXP(INT_MAX) > 0x7f
453
#define UINT8_C(x)	x
454
#else
455
#define UINT8_C(x)	x##U
456
#endif
457
 
458
#define INT16_C(x)	x
459
#if __STDINT_EXP(INT_MAX) > 0x7fff
460
#define UINT16_C(x)	x
461
#else
462
#define UINT16_C(x)	x##U
463
#endif
464
 
465
#if __have_long32
466
#define INT32_C(x)	x##L
467
#define UINT32_C(x)	x##UL
468
#else
469
#define INT32_C(x)	x
470
#define UINT32_C(x)	x##U
471
#endif
472
 
473
#if __int64_t_defined
474
#if __have_long64
475
#define INT64_C(x)	x##L
476
#define UINT64_C(x)	x##UL
477
#else
478
#define INT64_C(x)	x##LL
479
#define UINT64_C(x)	x##ULL
480
#endif
481
#endif
482
 
483
/** Macros for greatest-width integer constant expression */
484
#if __have_long64
485
#define INTMAX_C(x)	x##L
486
#define UINTMAX_C(x)	x##UL
487
#else
488
#define INTMAX_C(x)	x##LL
489
#define UINTMAX_C(x)	x##ULL
490
#endif
491
 
492
 
493
#ifdef __cplusplus
494
}
495
#endif
496
 
497
#endif /* _STDINT_H */