]> sjero.net Git - wget/blob - src/sysdep.h
Workaround for broken Tru64 inttypes.h.
[wget] / src / sysdep.h
1 /* Dirty system-dependent hacks.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3    2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GNU Wget.
6
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at
10 your option) any later version.
11
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Wget.  If not, see <http://www.gnu.org/licenses/>.
19
20 In addition, as a special exception, the Free Software Foundation
21 gives permission to link the code of its release of Wget with the
22 OpenSSL project's "OpenSSL" library (or with modified versions of it
23 that use the same license as the "OpenSSL" library), and distribute
24 the linked executables.  You must obey the GNU General Public License
25 in all respects for all of the code used other than "OpenSSL".  If you
26 modify this file, you may extend this exception to your version of the
27 file, but you are not obligated to do so.  If you do not wish to do
28 so, delete this exception statement from your version.  */
29
30 /* This file is included by wget.h.  Random .c files need not include
31    it.  */
32
33 #ifndef SYSDEP_H
34 #define SYSDEP_H
35
36 /* Testing for __sun is not enough because it's also defined on SunOS.  */
37 #ifdef __sun
38 # ifdef __SVR4
39 #  define solaris
40 # endif
41 #endif
42
43 /* The "namespace tweaks" below attempt to set a friendly "compilation
44    environment" under popular operating systems.  Default compilation
45    environment often means that some functions that are "extensions"
46    are not declared -- `strptime' is one example.
47
48    But non-default environments can expose bugs in the system header
49    files, crippling compilation in _very_ non-obvious ways.  Because
50    of that, we define them only on well-tested architectures where we
51    know they will work.  */
52
53 #undef NAMESPACE_TWEAKS
54
55 #ifdef solaris
56 # define NAMESPACE_TWEAKS
57 #endif
58
59 #ifdef __linux__
60 # define NAMESPACE_TWEAKS
61 #endif
62
63 #ifdef NAMESPACE_TWEAKS
64
65 /* Request the "Unix 98 compilation environment". */
66 #define _XOPEN_SOURCE 500
67
68 /* For Solaris: request everything else that is available and doesn't
69    conflict with the above.  */
70 #define __EXTENSIONS__
71
72 /* For Linux: request features of 4.3BSD and SVID (System V Interface
73    Definition). */
74 #define _SVID_SOURCE
75 #define _BSD_SOURCE
76
77 /* Under glibc-based systems we want all GNU extensions as well.  This
78    declares some unnecessary cruft, but also useful functions such as
79    timegm, FNM_CASEFOLD extension to fnmatch, memrchr, etc.  */
80 #define _GNU_SOURCE
81
82 #endif /* NAMESPACE_TWEAKS */
83
84
85 /* Alloca declaration, based on recommendation in the Autoconf manual.
86    These have to be after the above namespace tweaks, but before any
87    non-preprocessor code.  */
88
89 #if HAVE_ALLOCA_H
90 # include <alloca.h>
91 #elif defined WINDOWS
92 # include <malloc.h>
93 # ifndef alloca
94 #  define alloca _alloca
95 # endif
96 #elif defined __GNUC__
97 # define alloca __builtin_alloca
98 #elif defined _AIX
99 # define alloca __alloca
100 #else
101 # include <stddef.h>
102 # ifdef  __cplusplus
103 extern "C"
104 # endif
105 void *alloca (size_t);
106 #endif
107
108 /* Must include these, so we can test for the missing stat macros and
109    define them as necessary.  */
110 #include <sys/types.h>
111 #include <sys/stat.h>
112
113 #ifdef HAVE_INTTYPES_H
114   /* Compaq C V6.5-303 (dtk) on HP Tru64 UNIX V5.1B (Rev. 2650) needs: */
115 # include <stdint.h>
116 # include <inttypes.h>
117 #endif
118
119 #ifdef WINDOWS
120 /* Windows doesn't have some functions normally found on Unix-like
121    systems, such as strcasecmp, strptime, etc.  Include mswindows.h so
122    we get the declarations for their replacements in mswindows.c, as
123    well as to pick up Windows-specific includes and constants.  To be
124    able to test for such features, the file must be included as early
125    as possible.  */
126 # include "mswindows.h"
127 #endif
128
129 /* Provide support for C99-type boolean type "bool".  This blurb comes
130    straight from the Autoconf 2.59 manual. */
131 #if HAVE_STDBOOL_H
132 # include <stdbool.h>
133 #else
134 # if ! HAVE__BOOL
135 #  ifdef __cplusplus
136 typedef bool _Bool;
137 #  else
138 typedef unsigned char _Bool;
139 #  endif
140 # endif
141 # define bool _Bool
142 # define false 0
143 # define true 1
144 # define __bool_true_false_are_defined 1
145 #endif
146
147 /* Needed for compilation under OS/2 and MSDOS */
148 #if defined(__EMX__) || defined(MSDOS)
149 # ifndef S_ISLNK
150 #  define S_ISLNK(m) 0
151 # endif
152 # ifndef lstat
153 #  define lstat stat
154 # endif
155 #endif /* __EMX__ || MSDOS */
156
157 /* Reportedly, stat() macros are broken on some old systems.  Those
158    systems will have to fend for themselves, as I will not introduce
159    new code to handle it.
160
161    However, I will add code for *missing* macros, and the following
162    are reportedly missing from many systems.  */
163 #ifndef S_ISLNK
164 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
165 #endif
166 #ifndef S_ISDIR
167 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
168 #endif
169 #ifndef S_ISREG
170 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
171 #endif
172
173 /* These are needed so we can #define struct_stat to struct _stati64
174    under Windows. */
175 #ifndef struct_stat
176 # define struct_stat struct stat
177 #endif
178 #ifndef struct_fstat
179 # define struct_fstat struct stat
180 #endif
181
182 /* For CHAR_BIT, LONG_MAX, etc. */
183 #include <limits.h>
184
185 #ifndef CHAR_BIT
186 # define CHAR_BIT 8
187 #endif
188
189 /* From gnulib, simplified to assume a signed type. */
190 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
191
192 /* These are defined in cmpt.c if missing, so we must declare
193    them.  */
194 #ifndef HAVE_STRCASECMP
195 int strcasecmp ();
196 #endif
197 #ifndef HAVE_STRNCASECMP
198 int strncasecmp ();
199 #endif
200 #ifndef HAVE_STRPTIME
201 char *strptime ();
202 #endif
203 #ifndef HAVE_TIMEGM
204 # include <time.h>
205 time_t timegm (struct tm *);
206 #endif
207 #ifndef HAVE_MEMRCHR
208 void *memrchr (const void *, int, size_t);
209 #endif
210
211 /* These are defined in snprintf.c.  It would be nice to have an
212    snprintf.h, though.  */
213 #ifndef HAVE_SNPRINTF
214 int snprintf ();
215 #endif
216 #ifndef HAVE_VSNPRINTF
217 int vsnprintf ();
218 #endif
219
220 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
221    provide MAP_FAILED, a symbolic constant for the value returned by
222    mmap() when it doesn't work.  Usually, this constant should be -1.
223    This only makes sense for files that use mmap() and include
224    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
225
226 #ifndef MAP_FAILED
227 # define MAP_FAILED ((void *) -1)
228 #endif
229
230 /* Enable system fnmatch only on systems where fnmatch.h is usable.
231    If the fnmatch on your system is buggy, undef this symbol and a
232    replacement implementation will be used instead.  */
233 #ifdef HAVE_WORKING_FNMATCH_H
234 # define SYSTEM_FNMATCH
235 #endif
236
237 #ifdef SYSTEM_FNMATCH
238 # include <fnmatch.h>
239 #else  /* not SYSTEM_FNMATCH */
240 /* Define fnmatch flags.  Undef them first to avoid warnings in case
241    an evil library include chose to include system fnmatch.h.  */
242 # undef FNM_PATHNAME
243 # undef FNM_NOESCAPE
244 # undef FNM_PERIOD
245 # undef FNM_NOMATCH
246
247 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
248 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
249 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
250 # define FNM_NOMATCH    1
251
252 int fnmatch (const char *, const char *, int);
253 #endif
254
255 /* Provide sig_atomic_t if the system doesn't.  */
256 #ifndef HAVE_SIG_ATOMIC_T
257 typedef int sig_atomic_t;
258 #endif
259
260 /* Provide uint32_t on the platforms that don't define it.  Although
261    most code should be agnostic about integer sizes, some code really
262    does need a 32-bit integral type.  Such code should use uint32_t.
263    (The exception is gnu-md5.[ch], which uses its own detection for
264    portability across platforms.)  */
265
266 #ifndef HAVE_UINT32_T
267 # if SIZEOF_INT == 4
268 typedef unsigned int uint32_t;
269 # else
270 #  if SIZEOF_LONG == 4
271 typedef unsigned long uint32_t;
272 #  else
273 #   if SIZEOF_SHORT == 4
274 typedef unsigned short uint32_t;
275 #   else
276  #error "Cannot determine a 32-bit unsigned integer type"
277 #   endif
278 #  endif
279 # endif
280 #endif
281
282 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
283 #ifndef HAVE_UINTPTR_T
284 typedef unsigned long uintptr_t;
285 #endif
286
287 /* If intptr_t isn't defined, simply typedef it to long. */
288 #ifndef HAVE_INTPTR_T
289 typedef long intptr_t;
290 #endif
291
292 #endif /* SYSDEP_H */