Rudiments: /home/dmuse/temp/rudiments/include/rudiments/private/inttypes.h Source File

Rudiments

inttypes.h
1 // Copyright (c) 1999-2018 David Muse
2 // See the COPYING file for more information.
3
4 #ifndef RUDIMENTS_INTTYPES_H
5 #define RUDIMENTS_INTTYPES_H
6
7 #include <rudiments/private/config.h>
8
9 #ifdef RUDIMENTS_HAVE_SYS_CDEFS_H
10 #include <sys/cdefs.h>
11 #endif
12
13 // define NULL...
14
15 // NULL is typically defined in stddef.h
16 #include <stddef.h>
17
18 // Certain versions of gcc define NULL as ((void *)0) and then complain when
19 // you set a const pointer to it. Work around that.
20 #ifdef RUDIMENTS_REDEFINE_NULL
21 #undef NULL
22 #define NULL 0
23 #endif
24
25
26 // some platforms define types like char16_t in their new or new.h
27 // (some firstworks C code uses inttypes.h to make sure types are defined
28 // though, and we don't want that code to include new.h)
29 #ifdef __cplusplus
30 #include <rudiments/private/new.h>
31 #endif
32
33
34 // define [u]int(8|16|32|64)_t...
35
36 #if defined(RUDIMENTS_HAVE_STDINT_H)
37 #include <stdint.h>
38 #elif defined(RUDIMENTS_HAVE_SYS_BITYPES_H)
39 // Tru64 needs __arch64__ for int64_t and uint64_t typedefs
40 #ifndef __arch64__
41 #define __arch64__
42 #endif
43 #include <sys/bitypes.h>
44 #elif defined(RUDIMENTS_HAVE_INTTYPES_H)
45 #include <inttypes.h>
46 #endif
47
48 #if defined(RUDIMENTS_HAVE_UCHAR_H)
49 #include <uchar.h>
50 #endif
51
52 #ifndef RUDIMENTS_HAVE_INT8_T
53 typedef signed char int8_t;
54 #endif
55 #ifndef RUDIMENTS_HAVE_UINT8_T
56 typedef unsigned char uint8_t;
57 #endif
58 #ifndef RUDIMENTS_HAVE_INT16_T
59 typedef signed short int16_t;
60 #endif
61 #ifndef RUDIMENTS_HAVE_UINT16_T
62 typedef unsigned short uint16_t;
63 #endif
64 #if !defined(RUDIMENTS_HAVE_CHAR16_T) && \
65 defined(__cplusplus) && (__cplusplus<201103L)
66 typedef unsigned short char16_t;
67 #endif
68 #ifndef RUDIMENTS_HAVE_INT32_T
69 typedef signed int int32_t;
70 #endif
71 #ifndef RUDIMENTS_HAVE_UINT32_T
72 typedef unsigned int uint32_t;
73 // older versions of solaris require this to prevent a pthreads conflict
74 #define _UINT32_T 1
75 #endif
76 #ifndef RUDIMENTS_HAVE_INT64_T
77 #ifdef RUDIMENTS_HAVE_LONG_LONG
78 typedef signed long long int64_t;
79 #else
80 typedef signed long int64_t;
81 #endif
82 #endif
83 #ifndef RUDIMENTS_HAVE_UINT64_T
84 #ifdef RUDIMENTS_HAVE_LONG_LONG
85 typedef unsigned long long uint64_t;
86 #else
87 typedef unsigned long uint64_t;
88 #endif
89 #endif
90
91 #ifndef RUDIMENTS_HAVE_BOOL
92 class bool {
93 public:
94 bool(const bool &b) {
95 value=b.value;
96 }
97 bool(const long &b) {
98 value=b;
99 }
100 bool(const int &b) {
101 value=b;
102 }
103 bool(const short &b) {
104 value=b;
105 }
106 bool(const char &b) {
107 value=b;
108 }
109 bool(const unsigned long &b) {
110 value=b;
111 }
112 bool(const unsigned int &b) {
113 value=b;
114 }
115 bool(const unsigned short &b) {
116 value=b;
117 }
118 bool(const unsigned char &b) {
119 value=b;
120 }
121 bool &operator=(const bool &b) {
122 value=b.value;
123 return *this;
124 }
125 bool &operator=(const long &b) {
126 value=b;
127 return *this;
128 }
129 bool &operator=(const int &b) {
130 value=b;
131 return *this;
132 }
133 bool &operator=(const short &b) {
134 value=b;
135 return *this;
136 }
137 bool &operator=(const char &b) {
138 value=b;
139 return *this;
140 }
141 bool &operator=(const unsigned long &b) {
142 value=b;
143 return *this;
144 }
145 bool &operator=(const unsigned int &b) {
146 value=b;
147 return *this;
148 }
149 bool &operator=(const unsigned short &b) {
150 value=b;
151 return *this;
152 }
153 bool &operator=(const unsigned char &b) {
154 value=b;
155 return *this;
156 }
157 operator long() const {
158 return value;
159 }
160 int operator!() {
161 value=!value;
162 return value;
163 }
164 int operator==(const bool &b) {
165 return value==b.value;
166 }
167 int operator!=(const bool &b) {
168 return value!=b.value;
169 }
170 private:
171 long value;
172 };
173 #endif
174 #ifndef RUDIMENTS_HAVE_TRUE_FALSE
175 #define true 1
176 #define false 0
177 #endif
178
179 #endif
bool
Definition: inttypes.h:92