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// HP-UX has a function named memorymap() that prints out the contents of the
10// memory allocator for 32-bit HP-UX systems. It's depreceated in 11.11 and
11// obsolete in 11.21+. However, its existence confuses code that uses the
12// memorymap class. It's defined in malloc.h, and one of the includes below
13// ends up pulling it in. Since this header gets included by any code that
14// uses rudiments, we'll use the trick below to effectively rename memorymap()
15// to _memorymap(), then undef it after the includes. Hopefully no code
16// that uses rudiments actually tries to call memorymap().
17#define memorymap _memorymap
18
19// define NULL...
20
21// NULL is typically defined in stddef.h
22#include <stddef.h>
23
24// Certain versions of gcc define NULL as ((void *)0) and then complain when
25// you set a const pointer to it. Work around that.
26#ifdef RUDIMENTS_REDEFINE_NULL
27#undef NULL
28#define NULL 0
29#endif
30
31// some platforms define types like char16_t in their new or new.h
32// (some firstworks C code uses inttypes.h to make sure types are defined
33// though, and we don't want that code to include new.h)
34#ifdef __cplusplus
35 #include <rudiments/private/new.h>
36#endif
37
38#if defined(RUDIMENTS_HAVE_STDINT_H)
39 #include <stdint.h>
40#elif defined(RUDIMENTS_HAVE_SYS_BITYPES_H)
41 // Tru64 needs __arch64__ for int64_t and uint64_t typedefs
42 #ifndef __arch64__
43 #define __arch64__
44 #endif
45 #include <sys/bitypes.h>
46#elif defined(RUDIMENTS_HAVE_INTTYPES_H)
47 #if defined(RUDIMENTS_HAVE_VARARGS_H) && \
48 !defined(RUDIMENTS_HAVE_STDARG_H)
49 #include <varargs.h>
50 #endif
51 #include <inttypes.h>
52#endif
53
54#if defined(RUDIMENTS_HAVE_UCHAR_H)
55 #include <uchar.h>
56#endif
57
58// see HP-UX note above for why we're doing this
59#undef memorymap
60
61// define bool and true/false
62#ifndef RUDIMENTS_HAVE_BOOL
63 class bool {
64 public:
65 bool(const bool &b) {
66 value=b.value;
67 }
68 bool(const long long &b) {
69 value=b;
70 }
71 bool(const long &b) {
72 value=b;
73 }
74 bool(const int &b) {
75 value=b;
76 }
77 bool(const short &b) {
78 value=b;
79 }
80 bool(const char &b) {
81 value=b;
82 }
83 bool(const unsigned long long &b) {
84 value=b;
85 }
86 bool(const unsigned long &b) {
87 value=b;
88 }
89 bool(const unsigned int &b) {
90 value=b;
91 }
92 bool(const unsigned short &b) {
93 value=b;
94 }
95 bool(const unsigned char &b) {
96 value=b;
97 }
98 bool &operator=(const bool &b) {
99 value=b.value;
100 return *this;
101 }
102 bool &operator=(const long long &b) {
103 value=b;
104 return *this;
105 }
106 bool &operator=(const long &b) {
107 value=b;
108 return *this;
109 }
110 bool &operator=(const int &b) {
111 value=b;
112 return *this;
113 }
114 bool &operator=(const short &b) {
115 value=b;
116 return *this;
117 }
118 bool &operator=(const char &b) {
119 value=b;
120 return *this;
121 }
122 bool &operator=(const unsigned long long &b) {
123 value=b;
124 return *this;
125 }
126 bool &operator=(const unsigned long &b) {
127 value=b;
128 return *this;
129 }
130 bool &operator=(const unsigned int &b) {
131 value=b;
132 return *this;
133 }
134 bool &operator=(const unsigned short &b) {
135 value=b;
136 return *this;
137 }
138 bool &operator=(const unsigned char &b) {
139 value=b;
140 return *this;
141 }
142 operator long() {
143 return value;
144 }
145 int operator!() {
146 return !value;
147 }
148 int operator==(const bool &b) {
149 return value==b.value;
150 }
151 int operator!=(const bool &b) {
152 return value!=b.value;
153 }
154 private:
155 long value;
156 };
157#endif
158#ifndef RUDIMENTS_HAVE_TRUE_FALSE
159 #define true 1
160 #define false 0
161#endif
162
163// define [u]int(8|16|32|64)_t...
164#ifndef RUDIMENTS_HAVE_INT8_T
165 typedef signed char int8_t;
166#endif
167#ifndef RUDIMENTS_HAVE_UINT8_T
168 typedef unsigned char uint8_t;
169#endif
170#ifndef RUDIMENTS_HAVE_INT16_T
171 typedef signed short int16_t;
172#endif
173#ifndef RUDIMENTS_HAVE_UINT16_T
174 typedef unsigned short uint16_t;
175#endif
176#ifndef RUDIMENTS_HAVE_INT32_T
177 typedef signed int int32_t;
178#endif
179#ifndef RUDIMENTS_HAVE_UINT32_T
180 typedef unsigned int uint32_t;
181 // older versions of solaris require this to prevent a pthreads conflict
182 #define _UINT32_T 1
183#endif
184#ifndef RUDIMENTS_HAVE_INT64_T
185 #ifdef RUDIMENTS_HAVE_LONG_LONG
186 typedef signed long long int64_t;
187 #else
188 typedef signed long int64_t;
189 #endif
190#endif
191#ifndef RUDIMENTS_HAVE_UINT64_T
192 #ifdef RUDIMENTS_HAVE_LONG_LONG
193 typedef unsigned long long uint64_t;
194 #else
195 typedef unsigned long uint64_t;
196 #endif
197#endif
198
199// define byte_t
200#ifndef RUDIMENTS_HAVE_BYTE_T
201 typedef uint8_t byte_t;
202#endif
203
204// define char(8|16|32)_t
205#ifndef RUDIMENTS_HAVE_CHAR8_T
206 typedef uint8_t char8_t;
207#endif
208#if !defined(RUDIMENTS_HAVE_CHAR16_T) && \
209 defined(__cplusplus) && (__cplusplus<201103L)
210 typedef uint16_t char16_t;
211#endif
212#ifndef RUDIMENTS_HAVE_CHAR32_T
213 typedef uint32_t char32_t;
214#endif
215
216// define ucs2_t and utf(8|16)_t
217typedef uint16_t ucs2_t;
218typedef uint8_t utf8_t;
219typedef uint16_t utf16_t;
220
221#endif
Definition avltree.h:11
Definition inttypes.h:63