xref: /optee_os/lib/libutils/isoc/include/stdint.h (revision bc420748bfc44a9e09000a3966fc59e9e0219df4)
1 /*
2  * Copyright (c) 2014, STMicroelectronics International N.V.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 /*
29  * This file provides what C99 standard requires in
30  * 7.18 interger types <stdint.h>
31  * with the exception of:
32  * o Minimum-width integer types
33  * o Fastest minimum-width integer types
34  * o Geatest-width integer types
35  */
36 
37 #ifndef STDINT_H
38 #define STDINT_H
39 #define _STDINT_H
40 
41 /*
42  * If compiler supplies neither __ILP32__ or __LP64__, try to figure it out
43  * here.
44  */
45 #if !defined(__ILP32__) && !defined(__LP64__)
46 #if defined(__SIZEOF_INT__) && defined(__SIZEOF_POINTER__) && \
47 	defined(__SIZEOF_LONG__)
48 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 4 && __SIZEOF_LONG__ == 4
49 #define __ILP32__ 1
50 #endif
51 #if __SIZEOF_INT__ == 4 && __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 8
52 #define __LP64__ 1
53 #endif
54 #endif
55 #endif /* !defined(__ILP32__) && !defined(__LP64__) */
56 
57 #if !defined(__ILP32__) && !defined(__LP64__)
58 #error Neither __ILP32__ nor __LP64__ is defined
59 #endif
60 
61 /* 7.18.1.1 Exact-width interger types */
62 #ifndef __int8_t_defined
63 # define __int8_t_defined
64 typedef signed char             int8_t;
65 typedef short int               int16_t;
66 typedef int                     int32_t;
67 #ifdef __ILP32__
68 __extension__
69 typedef long long int           int64_t;
70 #endif /*__ILP32__*/
71 #ifdef __LP64__
72 typedef long int		int64_t;
73 #endif /*__LP64__*/
74 #endif
75 
76 /* Unsigned.  */
77 typedef unsigned char           uint8_t;
78 typedef unsigned short int      uint16_t;
79 #ifndef __uint32_t_defined
80 typedef unsigned int            uint32_t;
81 # define __uint32_t_defined
82 #endif
83 #ifdef __ILP32__
84 __extension__
85 typedef unsigned long long int  uint64_t;
86 #endif /*__ILP32__*/
87 #ifdef __LP64__
88 typedef unsigned long int	uint64_t;
89 #endif /*__LP64__*/
90 
91 /* 7.18.1.4 Integer types capable of holding object pointers */
92 typedef long intptr_t;
93 typedef unsigned long uintptr_t;
94 
95 typedef int64_t intmax_t;
96 typedef uint64_t uintmax_t;
97 
98 /*
99  * 7.18.2 Limits of specified-width integer types
100  */
101 
102 /* 7.18.2.1 Limits of exact-width interger types */
103 
104 #define INT8_MIN    (-0x7f-1)
105 #define INT16_MIN   (-0x7fff-1)
106 #define INT32_MIN   (-0x7fffffff-1)
107 #define INT64_MIN   (-0x7fffffffffffffffL-1)
108 
109 #define INT8_MAX    0x7f
110 #define INT16_MAX   0x7fff
111 #define INT32_MAX   0x7fffffff
112 #define INT64_MAX   0x7fffffffffffffffL
113 
114 #define UINT8_MAX    0xff
115 #define UINT16_MAX   0xffff
116 #define UINT32_MAX   0xffffffffU
117 #define UINT64_MAX   0xffffffffffffffffUL
118 
119 /* 7.18.2.4 Limits of integer types capable of holding object pointers */
120 
121 #define INTPTR_MIN  LONG_MIN
122 #define INTPTR_MAX  LONG_MAX
123 #define UINTPTR_MAX ULONG_MAX
124 
125 #define INTMAX_MAX  INT64_MAX
126 #define INTMAX_MIN  INT64_MIN
127 #define UINTMAX_MAX UINT64_MAX
128 
129 #endif /* STDINT_H */
130