2 * This file has been modified for the cdrkit suite.
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).
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.
13 /* @(#)utypes.h 1.15 05/11/06 Copyright 1997 J. Schilling */
15 * Definitions for some user defined types
17 * Copyright (c) 1997 J. Schilling
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.
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.
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.
42 * Include limits.h for CHAR_BIT
45 #ifndef _INCL_LIMITS_H
47 #define _INCL_LIMITS_H
52 * Include sys/param.h for NBBY
54 #ifdef HAVE_SYS_PARAM_H
55 #ifndef _INCL_SYS_PARAM_H
56 #include <sys/param.h>
57 #define _INCL_SYS_PARAM_H
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...
77 * Bits 1's c. 2's complement.
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.
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) \
97 #define TYPE_MAXVAL(t) ((t)(~((t)0) - TYPE_MINVAL(t)))
100 * Let us include system defined types too.
102 #ifndef _INCL_SYS_TYPES_H
103 #include <sys/types.h>
104 #define _INCL_SYS_TYPES_H
108 * Several unsigned cardinal types
110 typedef unsigned long Ulong;
111 typedef unsigned int Uint;
112 typedef unsigned short Ushort;
113 typedef unsigned char Uchar;
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.
121 # if defined(HAVE_LONGLONG)
122 # define USE_LONGLONG
128 typedef long long Llong;
129 typedef unsigned long long Ullong; /* We should avoid this */
130 typedef unsigned long long ULlong;
132 #define SIZEOF_LLONG SIZEOF_LONG_LONG
133 #define SIZEOF_ULLONG SIZEOF_UNSIGNED_LONG_LONG
138 typedef unsigned long Ullong; /* We should avoid this */
139 typedef unsigned long ULlong;
141 #define SIZEOF_LLONG SIZEOF_LONG
142 #define SIZEOF_ULLONG SIZEOF_UNSIGNED_LONG
146 #define LLONG_MIN TYPE_MINVAL(Llong)
149 #define LLONG_MAX TYPE_MAXVAL(Llong)
152 #define ULLONG_MAX TYPE_MAXVAL(Ullong)
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.
161 #if defined(_AIX) && !defined(__GNUC__)
163 typedef unsigned int Ucbit;
167 typedef unsigned char Ucbit;
172 * Start inttypes.h emulation.
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>.
180 #ifdef HAVE_INTTYPES_H
181 # ifndef _INCL_INTTYPES_H
182 # include <inttypes.h>
183 # define _INCL_INTTYPES_H
185 # define HAVE_INT64_T
186 # define HAVE_UINT64_T
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
199 #define Intptr_t intptr_t
200 #define UIntptr_t uintptr_t
202 #else /* !HAVE_INTTYPES_H */
204 #if SIZEOF_CHAR != 1 || SIZEOF_UNSIGNED_CHAR != 1
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.
210 error Sizeof char is not equal 1
213 typedef signed char Int8_t;
215 #if SIZEOF_SHORT_INT == 2
216 typedef short Int16_t;
218 error No int16_t found
224 error No int32_t found
227 #if SIZEOF_LONG_INT == 8
228 typedef long Int64_t;
229 # define HAVE_INT64_T
231 #if SIZEOF_LONG_LONG == 8
232 typedef long long Int64_t;
233 # define HAVE_INT64_T
235 /* error No int64_t found*/
239 #if SIZEOF_CHAR_P == SIZEOF_INT
240 typedef int Intptr_t;
242 #if SIZEOF_CHAR_P == SIZEOF_LONG_INT
243 typedef long Intptr_t;
245 error No intptr_t found
249 typedef unsigned char UInt8_t;
251 #if SIZEOF_UNSIGNED_SHORT_INT == 2
252 typedef unsigned short UInt16_t;
254 error No uint16_t found
257 #if SIZEOF_UNSIGNED_INT == 4
258 typedef unsigned int UInt32_t;
260 error No int32_t found
263 #if SIZEOF_UNSIGNED_LONG_INT == 8
264 typedef unsigned long UInt64_t;
265 # define HAVE_UINT64_T
267 #if SIZEOF_UNSIGNED_LONG_LONG == 8
268 typedef unsigned long long UInt64_t;
269 # define HAVE_UINT64_T
271 /* error No uint64_t found*/
275 #define Intmax_t Llong
276 #define UIntmax_t Ullong
278 #if SIZEOF_CHAR_P == SIZEOF_UNSIGNED_INT
279 typedef unsigned int UIntptr_t;
281 #if SIZEOF_CHAR_P == SIZEOF_UNSIGNED_LONG_INT
282 typedef unsigned long UIntptr_t;
284 error No uintptr_t found
288 #endif /* HAVE_INTTYPES_H */
291 #define CHAR_MIN TYPE_MINVAL(char)
294 #define CHAR_MAX TYPE_MAXVAL(char)
297 #define UCHAR_MAX TYPE_MAXVAL(unsigned char)
301 #define SHRT_MIN TYPE_MINVAL(short)
304 #define SHRT_MAX TYPE_MAXVAL(short)
307 #define USHRT_MAX TYPE_MAXVAL(unsigned short)
311 #define INT_MIN TYPE_MINVAL(int)
314 #define INT_MAX TYPE_MAXVAL(int)
317 #define UINT_MAX TYPE_MAXVAL(unsigned int)
321 #define LONG_MIN TYPE_MINVAL(long)
324 #define LONG_MAX TYPE_MAXVAL(long)
327 #define ULONG_MAX TYPE_MAXVAL(unsigned long)
331 #define INT8_MIN TYPE_MINVAL(Int8_t)
334 #define INT8_MAX TYPE_MAXVAL(Int8_t)
337 #define UINT8_MAX TYPE_MAXVAL(UInt8_t)
341 #define INT16_MIN TYPE_MINVAL(Int16_t)
344 #define INT16_MAX TYPE_MAXVAL(Int16_t)
347 #define UINT16_MAX TYPE_MAXVAL(UInt16_t)
351 #define INT32_MIN TYPE_MINVAL(Int32_t)
354 #define INT32_MAX TYPE_MAXVAL(Int32_t)
357 #define UINT32_MAX TYPE_MAXVAL(UInt32_t)
362 #define INT64_MIN TYPE_MINVAL(Int64_t)
365 #define INT64_MAX TYPE_MAXVAL(Int64_t)
370 #define UINT64_MAX TYPE_MAXVAL(UInt64_t)
375 #define INTMAX_MIN TYPE_MINVAL(Intmax_t)
378 #define INTMAX_MAX TYPE_MAXVAL(Intmax_t)
381 #define UINTMAX_MAX TYPE_MAXVAL(UIntmax_t)
384 #define SIZE_T_MIN TYPE_MINVAL(size_t)
386 #define SIZE_T_MAX TYPE_MAXVAL(size_t)
389 #define SSIZE_T_MIN TYPE_MINVAL(ssize_t)
390 #define SSIZE_T_MAX TYPE_MAXVAL(ssize_t)
392 #define OFF_T_MIN TYPE_MINVAL(off_t)
393 #define OFF_T_MAX TYPE_MAXVAL(off_t)
395 #define UID_T_MIN TYPE_MINVAL(uid_t)
396 #define UID_T_MAX TYPE_MAXVAL(uid_t)
398 #define GID_T_MIN TYPE_MINVAL(gid_t)
399 #define GID_T_MAX TYPE_MAXVAL(gid_t)
401 #define PID_T_MIN TYPE_MINVAL(pid_t)
402 #define PID_T_MAX TYPE_MAXVAL(pid_t)
404 #define MODE_T_MIN TYPE_MINVAL(mode_t)
405 #define MODE_T_MAX TYPE_MAXVAL(mode_t)
407 #define TIME_T_MIN TYPE_MINVAL(time_t)
408 #define TIME_T_MAX TYPE_MAXVAL(time_t)
410 #define CADDR_T_MIN TYPE_MINVAL(caddr_t)
411 #define CADDR_T_MAX TYPE_MAXVAL(caddr_t)
413 #define DADDR_T_MIN TYPE_MINVAL(daddr_t)
414 #define DADDR_T_MAX TYPE_MAXVAL(daddr_t)
416 #define DEV_T_MIN TYPE_MINVAL(dev_t)
417 #define DEV_T_MAX TYPE_MAXVAL(dev_t)
419 #define MAJOR_T_MIN TYPE_MINVAL(major_t)
420 #define MAJOR_T_MAX TYPE_MAXVAL(major_t)
422 #define MINOR_T_MIN TYPE_MINVAL(minor_t)
423 #define MINOR_T_MAX TYPE_MAXVAL(minor_t)
425 #define INO_T_MIN TYPE_MINVAL(ino_t)
426 #define INO_T_MAX TYPE_MAXVAL(ino_t)
428 #define NLINK_T_MIN TYPE_MINVAL(nlink_t)
429 #define NLINK_T_MAX TYPE_MAXVAL(nlink_t)
431 #define BLKCNT_T_MIN TYPE_MINVAL(blkcnt_t)
432 #define BLKCNT_T_MAX TYPE_MAXVAL(blkcnt_t)
434 #define CLOCK_T_MIN TYPE_MINVAL(clock_t)
435 #define CLOCK_T_MAX TYPE_MAXVAL(clock_t)
437 #define SOCKLEN_T_MIN TYPE_MINVAL(socklen_t)
438 #define SOCKLEN_T_MAX TYPE_MAXVAL(socklen_t)
440 #endif /* _UTYPES_H */