Compilation fix on Mingw32.
[elinks.git] / src / osdep / types.h
blobf1c42f83ccf46a3a7ae7581ae2772fbca67a85fa
1 #ifndef EL__OSDEP_TYPES_H
2 #define EL__OSDEP_TYPES_H
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
8 #ifdef HAVE_SYS_TYPES_H
9 #include <sys/types.h>
10 #endif
12 #ifdef HAVE_LIMITS_H
13 #include <limits.h>
14 #endif
16 #ifdef HAVE_STDINT_H
17 #include <stdint.h>
18 #endif
20 #ifdef HAVE_INTTYPES_H
21 #include <inttypes.h>
22 #endif
24 #ifndef SHRT_MAX
25 #define SHRT_MAX 0x7fff
26 #endif
28 #ifndef USHRT_MAX
29 #define USHRT_MAX 0xffff
30 #endif
32 #ifndef INT_MAX
33 #ifdef MAXINT
34 #define INT_MAX MAXINT
35 #else
36 #define INT_MAX 0x7fffffff
37 #endif
38 #endif
40 #ifndef UINT_MAX
41 #ifdef MAXUINT
42 #define UINT_MAX MAXUINT
43 #else
44 #define UINT_MAX 0xffffffff
45 #endif
46 #endif
48 #ifndef LONG_MAX
49 #ifdef MAXLONG
50 #define LONG_MAX MAXLONG
51 #else
52 #define LONG_MAX 0x7fffffff
53 #endif
54 #endif
56 #if defined(HAVE_LONG_LONG) && !defined(LLONG_MAX)
57 #ifdef MAXLLONG
58 #define LLONG_MAX MAXLLONG
59 #elif SIZEOF_LONG_LONG == 8
60 #define LLONG_MAX 9223372036854775807LL
61 #elif SIZEOF_LONG_LONG == 4
62 #define LLONG_MAX LONG_MAX
63 #endif
64 #endif
66 #ifndef OFFT_MAX
67 #if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T == SIZEOF_LONG_LONG
68 #define OFFT_MAX LLONG_MAX
69 #elif SIZEOF_OFF_T == SIZEOF_LONG
70 #define OFFT_MAX LONG_MAX
71 #elif SIZEOF_OFF_T == SIZEOF_INT
72 #define OFFT_MAX INT_MAX
73 #elif SIZEOF_OFF_T == SIZEOF_SHORT
74 #define OFFT_MAX SHRT_MAX
75 #endif
76 #endif
78 #ifndef HAVE_UINT16_T
79 #if SIZEOF_CHAR == 2
80 typedef unsigned char uint16_t;
81 #elif SIZEOF_SHORT == 2
82 typedef unsigned short uint16_t;
83 #elif SIZEOF_INT == 2
84 typedef unsigned int uint16_t;
85 #elif SIZEOF_LONG == 2
86 typedef unsigned long uint16_t;
87 #elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 2
88 typedef unsigned long long uint16_t;
89 #else
90 #error You have no 16-bit integer type. Get in touch with reality.
91 #endif
92 #endif
94 #ifndef HAVE_INT32_T
95 #if SIZEOF_CHAR == 4
96 typedef char int32_t;
97 #elif SIZEOF_SHORT == 4
98 typedef short int32_t;
99 #elif SIZEOF_INT == 4
100 typedef int int32_t;
101 #elif SIZEOF_LONG == 4
102 typedef long int32_t;
103 #elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 4
104 typedef long long int32_t;
105 #else
106 #error You have no 32-bit integer type. Get in touch with reality.
107 #endif
108 #endif
110 #ifndef HAVE_UINT32_T
111 #if SIZEOF_CHAR == 4
112 typedef unsigned char uint32_t;
113 #elif SIZEOF_SHORT == 4
114 typedef unsigned short uint32_t;
115 #elif SIZEOF_INT == 4
116 typedef unsigned int uint32_t;
117 #elif SIZEOF_LONG == 4
118 typedef unsigned long uint32_t;
119 #elif defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG == 4
120 typedef unsigned long long uint32_t;
121 #else
122 #error You have no 32-bit integer type. Get in touch with reality.
123 #endif
124 #endif
126 #ifdef HAVE_LONG_LONG
127 #define longlong long long
128 #else
129 #define longlong long
130 #endif
132 /* These are mostly for shutting up sparse warnings. */
133 #ifndef __INT_MAX__
134 #define __INT_MAX__ 0x7fffffff
135 #endif
136 #ifndef __LONG_MAX__
137 #define __LONG_MAX__ 0x7fffffff
138 #endif
139 #ifndef __SHRT_MAX__
140 #define __SHRT_MAX__ 0x7fff
141 #endif
144 * long l; (long) (longptr_T) l == l
145 * void *p; (void *) (longptr_T) p == p
147 typedef long longptr_T;
149 /* To print off_t offset, ELinks does:
151 * printf("%" OFF_PRINT_FORMAT, (off_print_T) offset);
153 * The cast is necessary because it is not possible to guess
154 * a printf format for off_t itself based on what we have here.
155 * The off_t type might be either long or long long, and the format
156 * string must match even if both types have the same representation,
157 * because GCC warns about mismatches and --enable-debug adds -Werror
158 * to $CFLAGS. */
159 #if !HAVE_OFF_T || SIZEOF_OFF_T <= SIZEOF_LONG
160 typedef long off_print_T;
161 # define OFF_PRINT_FORMAT "ld"
162 #elif HAVE_LONG_LONG && SIZEOF_OFF_T <= SIZEOF_LONG_LONG
163 typedef long long off_print_T;
164 # define OFF_PRINT_FORMAT "lld"
165 #else
166 # error "cannot figure out how to print off_t values"
167 #endif
169 #endif