xref: /linux/tools/include/nolibc/stdint.h (revision b8e85e6f3a09fc56b0ff574887798962ef8a8f80)
1 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2 /*
3  * Standard definitions and types for NOLIBC
4  * Copyright (C) 2023 Vincent Dagonneau <v@vda.io>
5  */
6 
7 #ifndef _NOLIBC_STDINT_H
8 #define _NOLIBC_STDINT_H
9 
10 typedef unsigned char       uint8_t;
11 typedef   signed char        int8_t;
12 typedef unsigned short     uint16_t;
13 typedef   signed short      int16_t;
14 typedef unsigned int       uint32_t;
15 typedef   signed int        int32_t;
16 typedef unsigned long long uint64_t;
17 typedef   signed long long  int64_t;
18 typedef __SIZE_TYPE__        size_t;
19 typedef   signed long       ssize_t;
20 typedef unsigned long     uintptr_t;
21 typedef   signed long      intptr_t;
22 typedef   signed long     ptrdiff_t;
23 
24 typedef   int8_t       int_least8_t;
25 typedef  uint8_t      uint_least8_t;
26 typedef  int16_t      int_least16_t;
27 typedef uint16_t     uint_least16_t;
28 typedef  int32_t      int_least32_t;
29 typedef uint32_t     uint_least32_t;
30 typedef  int64_t      int_least64_t;
31 typedef uint64_t     uint_least64_t;
32 
33 typedef   int8_t        int_fast8_t;
34 typedef  uint8_t       uint_fast8_t;
35 typedef  ssize_t       int_fast16_t;
36 typedef   size_t      uint_fast16_t;
37 typedef  ssize_t       int_fast32_t;
38 typedef   size_t      uint_fast32_t;
39 typedef  int64_t       int_fast64_t;
40 typedef uint64_t      uint_fast64_t;
41 
42 typedef  int64_t           intmax_t;
43 typedef uint64_t          uintmax_t;
44 
45 /* limits of integral types */
46 
47 #define        INT8_MIN  (-128)
48 #define       INT16_MIN  (-32767-1)
49 #define       INT32_MIN  (-2147483647-1)
50 #define       INT64_MIN  (-9223372036854775807LL-1)
51 
52 #define        INT8_MAX  (127)
53 #define       INT16_MAX  (32767)
54 #define       INT32_MAX  (2147483647)
55 #define       INT64_MAX  (9223372036854775807LL)
56 
57 #define       UINT8_MAX  (255)
58 #define      UINT16_MAX  (65535)
59 #define      UINT32_MAX  (4294967295U)
60 #define      UINT64_MAX  (18446744073709551615ULL)
61 
62 #define  INT_LEAST8_MIN  INT8_MIN
63 #define INT_LEAST16_MIN  INT16_MIN
64 #define INT_LEAST32_MIN  INT32_MIN
65 #define INT_LEAST64_MIN  INT64_MIN
66 
67 #define  INT_LEAST8_MAX  INT8_MAX
68 #define INT_LEAST16_MAX  INT16_MAX
69 #define INT_LEAST32_MAX  INT32_MAX
70 #define INT_LEAST64_MAX  INT64_MAX
71 
72 #define  UINT_LEAST8_MAX UINT8_MAX
73 #define UINT_LEAST16_MAX UINT16_MAX
74 #define UINT_LEAST32_MAX UINT32_MAX
75 #define UINT_LEAST64_MAX UINT64_MAX
76 
77 #define SIZE_MAX         ((size_t)(__LONG_MAX__) * 2 + 1)
78 #define INTPTR_MIN       (-__LONG_MAX__ - 1)
79 #define INTPTR_MAX       __LONG_MAX__
80 #define PTRDIFF_MIN      INTPTR_MIN
81 #define PTRDIFF_MAX      INTPTR_MAX
82 #define UINTPTR_MAX      SIZE_MAX
83 
84 #define  INT_FAST8_MIN   INT8_MIN
85 #define INT_FAST16_MIN   INTPTR_MIN
86 #define INT_FAST32_MIN   INTPTR_MIN
87 #define INT_FAST64_MIN   INT64_MIN
88 
89 #define  INT_FAST8_MAX   INT8_MAX
90 #define INT_FAST16_MAX   INTPTR_MAX
91 #define INT_FAST32_MAX   INTPTR_MAX
92 #define INT_FAST64_MAX   INT64_MAX
93 
94 #define  UINT_FAST8_MAX  UINT8_MAX
95 #define UINT_FAST16_MAX  SIZE_MAX
96 #define UINT_FAST32_MAX  SIZE_MAX
97 #define UINT_FAST64_MAX  UINT64_MAX
98 
99 #ifndef INT_MIN
100 #define INT_MIN          (-__INT_MAX__ - 1)
101 #endif
102 #ifndef INT_MAX
103 #define INT_MAX          __INT_MAX__
104 #endif
105 
106 #ifndef LONG_MIN
107 #define LONG_MIN         (-__LONG_MAX__ - 1)
108 #endif
109 #ifndef LONG_MAX
110 #define LONG_MAX         __LONG_MAX__
111 #endif
112 
113 #endif /* _NOLIBC_STDINT_H */
114