Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / include / utypes.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)utypes.h 1.15 05/11/06 Copyright 1997 J. Schilling */
14 /*
15  *      Definitions for some user defined types
16  *
17  *      Copyright (c) 1997 J. Schilling
18  */
19 /*
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License version 2
22  * as published by the Free Software Foundation.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along with
30  * this program; see the file COPYING.  If not, write to the Free Software
31  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32  */
33
34 #ifndef _UTYPES_H
35 #define _UTYPES_H
36
37 #ifndef _MCONFIG_H
38 #include <mconfig.h>
39 #endif
40
41 /*
42  * Include limits.h for CHAR_BIT
43  */
44 #ifdef  HAVE_LIMITS_H
45 #ifndef _INCL_LIMITS_H
46 #include <limits.h>
47 #define _INCL_LIMITS_H
48 #endif
49 #endif
50
51 /*
52  * Include sys/param.h for NBBY
53  */
54 #ifdef  HAVE_SYS_PARAM_H
55 #ifndef _INCL_SYS_PARAM_H
56 #include        <sys/param.h>
57 #define _INCL_SYS_PARAM_H
58 #endif
59 #endif
60
61 #ifndef CHAR_BIT
62 #ifdef  NBBY
63 #define CHAR_BIT        NBBY 
64 #endif
65 #endif
66
67 #ifndef CHAR_BIT
68 #define CHAR_BIT        8
69 #endif
70
71 /*
72  * These macros may not work on all platforms but as we depend
73  * on two's complement in many places, they do not reduce portability.
74  * The macros below work with 2s complement and ones complement machines.
75  * Verify with this table...
76  *
77  *      Bits    1's c.  2's complement.
78  *      100     -3      -4
79  *      101     -2      -3
80  *      110     -1      -2
81  *      111     -0      -1
82  *      000     +0       0
83  *      001     +1      +1
84  *      010     +2      +2
85  *      011     +3      +3
86  *
87  * Computing -TYPE_MINVAL(type) will not work on 2's complement machines
88  * if 'type' is int or more. Use -(UIntmax_t)TYPE_MINVAL(type), it works
89  * for both 1's complement and 2's complement machines.
90  */
91 #define TYPE_ISSIGNED(t)        (((t)-1) < ((t)0))
92 #define TYPE_ISUNSIGNED(t)      (!TYPE_ISSIGNED(t))
93 #define TYPE_MSBVAL(t)          ((t)(~((t)0) << (sizeof (t)*CHAR_BIT - 1)))
94 #define TYPE_MINVAL(t)          (TYPE_ISSIGNED(t)                       \
95                                     ? TYPE_MSBVAL(t)                    \
96                                     : ((t)0))
97 #define TYPE_MAXVAL(t)          ((t)(~((t)0) - TYPE_MINVAL(t)))
98
99 /*
100  * Let us include system defined types too.
101  */
102 #ifndef _INCL_SYS_TYPES_H
103 #include <sys/types.h>
104 #define _INCL_SYS_TYPES_H
105 #endif
106
107 /*
108  * Several unsigned cardinal types
109  */
110 typedef unsigned long   Ulong;
111 typedef unsigned int    Uint;
112 typedef unsigned short  Ushort;
113 typedef unsigned char   Uchar;
114
115 /*
116  * This is a definition for a compiler dependant 64 bit type.
117  * It currently is silently a long if the compiler does not
118  * support it. Check if this is the right way.
119  */
120 #ifndef NO_LONGLONG
121 #       if      defined(HAVE_LONGLONG)
122 #               define  USE_LONGLONG
123 #       endif
124 #endif
125
126 #ifdef  USE_LONGLONG
127
128 typedef long long               Llong;
129 typedef unsigned long long      Ullong; /* We should avoid this */
130 typedef unsigned long long      ULlong;
131
132 #define SIZEOF_LLONG            SIZEOF_LONG_LONG
133 #define SIZEOF_ULLONG           SIZEOF_UNSIGNED_LONG_LONG
134
135 #else
136
137 typedef long                    Llong;
138 typedef unsigned long           Ullong; /* We should avoid this */
139 typedef unsigned long           ULlong;
140
141 #define SIZEOF_LLONG            SIZEOF_LONG
142 #define SIZEOF_ULLONG           SIZEOF_UNSIGNED_LONG
143
144 #endif
145 #ifndef LLONG_MIN
146 #define LLONG_MIN       TYPE_MINVAL(Llong)
147 #endif
148 #ifndef LLONG_MAX
149 #define LLONG_MAX       TYPE_MAXVAL(Llong)
150 #endif
151 #ifndef ULLONG_MAX
152 #define ULLONG_MAX      TYPE_MAXVAL(Ullong)
153 #endif
154
155 /*
156  * The IBM AIX C-compiler seems to be the only compiler on the world
157  * which does not allow to use unsigned char bit fields as a hint
158  * for packed bit fields. Define a pesical type to avoid warnings.
159  * The packed attribute is honored wit unsigned int in this case too.
160  */
161 #if     defined(_AIX) && !defined(__GNUC__)
162
163 typedef unsigned int    Ucbit;
164
165 #else
166
167 typedef unsigned char   Ucbit;
168
169 #endif
170
171 /*
172  * Start inttypes.h emulation.
173  *
174  * Thanks to Solaris 2.4 and even recent 1999 Linux versions, we
175  * cannot use the official UNIX-98 names here. Old Solaris versions
176  * define parts of the types in some exotic include files.
177  * Linux even defines incompatible types in <sys/types.h>.
178  */
179
180 #ifdef  HAVE_INTTYPES_H
181 #       ifndef  _INCL_INTTYPES_H
182 #       include <inttypes.h>
183 #       define  _INCL_INTTYPES_H
184 #       endif
185 #       define  HAVE_INT64_T
186 #       define  HAVE_UINT64_T
187
188 #define Int8_t                  int8_t
189 #define Int16_t                 int16_t
190 #define Int32_t                 int32_t
191 #define Int64_t                 int64_t
192 #define Intmax_t                intmax_t
193 #define UInt8_t                 uint8_t
194 #define UInt16_t                uint16_t
195 #define UInt32_t                uint32_t
196 #define UInt64_t                uint64_t
197 #define UIntmax_t               uintmax_t
198
199 #define Intptr_t                intptr_t
200 #define UIntptr_t               uintptr_t
201
202 #else   /* !HAVE_INTTYPES_H */
203
204 #if SIZEOF_CHAR != 1 || SIZEOF_UNSIGNED_CHAR != 1
205 /*
206  * #error will not work for all compilers (e.g. sunos4)
207  * The following line will abort compilation on all compilers
208  * if the above is true. And that's what we want.
209  */
210 error  Sizeof char is not equal 1
211 #endif
212
213 typedef signed char                     Int8_t;
214
215 #if SIZEOF_SHORT_INT == 2
216         typedef short                   Int16_t;
217 #else
218         error           No int16_t found
219 #endif
220
221 #if SIZEOF_INT == 4
222         typedef int                     Int32_t;
223 #else
224         error           No int32_t found
225 #endif
226
227 #if SIZEOF_LONG_INT == 8
228         typedef         long            Int64_t;
229 #       define  HAVE_INT64_T
230 #else
231 #if SIZEOF_LONG_LONG == 8
232         typedef         long long       Int64_t;
233 #       define  HAVE_INT64_T
234 #else
235 /*      error           No int64_t found*/
236 #endif
237 #endif
238
239 #if SIZEOF_CHAR_P == SIZEOF_INT
240         typedef         int             Intptr_t;
241 #else
242 #if SIZEOF_CHAR_P == SIZEOF_LONG_INT
243         typedef         long            Intptr_t;
244 #else
245         error           No intptr_t found
246 #endif
247 #endif
248
249 typedef unsigned char           UInt8_t;
250
251 #if SIZEOF_UNSIGNED_SHORT_INT == 2
252         typedef unsigned short          UInt16_t;
253 #else
254         error           No uint16_t found
255 #endif
256
257 #if SIZEOF_UNSIGNED_INT == 4
258         typedef unsigned int            UInt32_t;
259 #else
260         error           No int32_t found
261 #endif
262
263 #if SIZEOF_UNSIGNED_LONG_INT == 8
264         typedef unsigned long           UInt64_t;
265 #       define  HAVE_UINT64_T
266 #else
267 #if SIZEOF_UNSIGNED_LONG_LONG == 8
268         typedef unsigned long long      UInt64_t;
269 #       define  HAVE_UINT64_T
270 #else
271 /*      error           No uint64_t found*/
272 #endif
273 #endif
274
275 #define Intmax_t        Llong
276 #define UIntmax_t       Ullong
277
278 #if SIZEOF_CHAR_P == SIZEOF_UNSIGNED_INT
279         typedef         unsigned int    UIntptr_t;
280 #else
281 #if SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG_INT
282         typedef         unsigned long   UIntptr_t;
283 #else
284         error           No uintptr_t found
285 #endif
286 #endif
287
288 #endif  /* HAVE_INTTYPES_H */
289
290 #ifndef CHAR_MIN
291 #define CHAR_MIN        TYPE_MINVAL(char)
292 #endif
293 #ifndef CHAR_MAX
294 #define CHAR_MAX        TYPE_MAXVAL(char)
295 #endif
296 #ifndef UCHAR_MAX
297 #define UCHAR_MAX       TYPE_MAXVAL(unsigned char)
298 #endif
299
300 #ifndef SHRT_MIN
301 #define SHRT_MIN        TYPE_MINVAL(short)
302 #endif
303 #ifndef SHRT_MAX
304 #define SHRT_MAX        TYPE_MAXVAL(short)
305 #endif
306 #ifndef USHRT_MAX
307 #define USHRT_MAX       TYPE_MAXVAL(unsigned short)
308 #endif
309
310 #ifndef INT_MIN
311 #define INT_MIN         TYPE_MINVAL(int)
312 #endif
313 #ifndef INT_MAX
314 #define INT_MAX         TYPE_MAXVAL(int)
315 #endif
316 #ifndef UINT_MAX
317 #define UINT_MAX        TYPE_MAXVAL(unsigned int)
318 #endif
319
320 #ifndef LONG_MIN
321 #define LONG_MIN        TYPE_MINVAL(long)
322 #endif
323 #ifndef LONG_MAX
324 #define LONG_MAX        TYPE_MAXVAL(long)
325 #endif
326 #ifndef ULONG_MAX
327 #define ULONG_MAX       TYPE_MAXVAL(unsigned long)
328 #endif
329
330 #ifndef INT8_MIN
331 #define INT8_MIN        TYPE_MINVAL(Int8_t)
332 #endif
333 #ifndef INT8_MAX
334 #define INT8_MAX        TYPE_MAXVAL(Int8_t)
335 #endif
336 #ifndef UINT8_MAX
337 #define UINT8_MAX       TYPE_MAXVAL(UInt8_t)
338 #endif
339
340 #ifndef INT16_MIN
341 #define INT16_MIN       TYPE_MINVAL(Int16_t)
342 #endif
343 #ifndef INT16_MAX
344 #define INT16_MAX       TYPE_MAXVAL(Int16_t)
345 #endif
346 #ifndef UINT16_MAX
347 #define UINT16_MAX      TYPE_MAXVAL(UInt16_t)
348 #endif
349
350 #ifndef INT32_MIN
351 #define INT32_MIN       TYPE_MINVAL(Int32_t)
352 #endif
353 #ifndef INT32_MAX
354 #define INT32_MAX       TYPE_MAXVAL(Int32_t)
355 #endif
356 #ifndef UINT32_MAX
357 #define UINT32_MAX      TYPE_MAXVAL(UInt32_t)
358 #endif
359
360 #ifdef  HAVE_INT64_T
361 #ifndef INT64_MIN
362 #define INT64_MIN       TYPE_MINVAL(Int64_t)
363 #endif
364 #ifndef INT64_MAX
365 #define INT64_MAX       TYPE_MAXVAL(Int64_t)
366 #endif
367 #endif
368 #ifdef  HAVE_UINT64_T
369 #ifndef UINT64_MAX
370 #define UINT64_MAX      TYPE_MAXVAL(UInt64_t)
371 #endif
372 #endif
373
374 #ifndef INTMAX_MIN
375 #define INTMAX_MIN      TYPE_MINVAL(Intmax_t)
376 #endif
377 #ifndef INTMAX_MAX
378 #define INTMAX_MAX      TYPE_MAXVAL(Intmax_t)
379 #endif
380 #ifndef UINTMAX_MAX
381 #define UINTMAX_MAX     TYPE_MAXVAL(UIntmax_t)
382 #endif
383
384 #define SIZE_T_MIN      TYPE_MINVAL(size_t)
385 #ifndef SIZE_T_MAX
386 #define SIZE_T_MAX      TYPE_MAXVAL(size_t)
387 #endif
388
389 #define SSIZE_T_MIN     TYPE_MINVAL(ssize_t)
390 #define SSIZE_T_MAX     TYPE_MAXVAL(ssize_t)
391
392 #define OFF_T_MIN       TYPE_MINVAL(off_t)
393 #define OFF_T_MAX       TYPE_MAXVAL(off_t)
394
395 #define UID_T_MIN       TYPE_MINVAL(uid_t)
396 #define UID_T_MAX       TYPE_MAXVAL(uid_t)
397
398 #define GID_T_MIN       TYPE_MINVAL(gid_t)
399 #define GID_T_MAX       TYPE_MAXVAL(gid_t)
400
401 #define PID_T_MIN       TYPE_MINVAL(pid_t)
402 #define PID_T_MAX       TYPE_MAXVAL(pid_t)
403
404 #define MODE_T_MIN      TYPE_MINVAL(mode_t)
405 #define MODE_T_MAX      TYPE_MAXVAL(mode_t)
406
407 #define TIME_T_MIN      TYPE_MINVAL(time_t)
408 #define TIME_T_MAX      TYPE_MAXVAL(time_t)
409
410 #define CADDR_T_MIN     TYPE_MINVAL(caddr_t)
411 #define CADDR_T_MAX     TYPE_MAXVAL(caddr_t)
412
413 #define DADDR_T_MIN     TYPE_MINVAL(daddr_t)
414 #define DADDR_T_MAX     TYPE_MAXVAL(daddr_t)
415
416 #define DEV_T_MIN       TYPE_MINVAL(dev_t)
417 #define DEV_T_MAX       TYPE_MAXVAL(dev_t)
418
419 #define MAJOR_T_MIN     TYPE_MINVAL(major_t)
420 #define MAJOR_T_MAX     TYPE_MAXVAL(major_t)
421
422 #define MINOR_T_MIN     TYPE_MINVAL(minor_t)
423 #define MINOR_T_MAX     TYPE_MAXVAL(minor_t)
424
425 #define INO_T_MIN       TYPE_MINVAL(ino_t)
426 #define INO_T_MAX       TYPE_MAXVAL(ino_t)
427
428 #define NLINK_T_MIN     TYPE_MINVAL(nlink_t)
429 #define NLINK_T_MAX     TYPE_MAXVAL(nlink_t)
430
431 #define BLKCNT_T_MIN    TYPE_MINVAL(blkcnt_t)
432 #define BLKCNT_T_MAX    TYPE_MAXVAL(blkcnt_t)
433
434 #define CLOCK_T_MIN     TYPE_MINVAL(clock_t)
435 #define CLOCK_T_MAX     TYPE_MAXVAL(clock_t)
436
437 #define SOCKLEN_T_MIN   TYPE_MINVAL(socklen_t)
438 #define SOCKLEN_T_MAX   TYPE_MAXVAL(socklen_t)
439
440 #endif  /* _UTYPES_H */