]> sjero.net Git - wget/blob - src/sysdep.h
Eschew config-post.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 # include <inttypes.h>
115 #endif
116
117 #ifdef WINDOWS
118 /* Windows doesn't have some functions normally found on Unix-like
119    systems, such as strcasecmp, strptime, etc.  Include mswindows.h so
120    we get the declarations for their replacements in mswindows.c, as
121    well as to pick up Windows-specific includes and constants.  To be
122    able to test for such features, the file must be included as early
123    as possible.  */
124 # include "mswindows.h"
125 #endif
126
127 /* Provide support for C99-type boolean type "bool".  This blurb comes
128    straight from the Autoconf 2.59 manual. */
129 #if HAVE_STDBOOL_H
130 # include <stdbool.h>
131 #else
132 # if ! HAVE__BOOL
133 #  ifdef __cplusplus
134 typedef bool _Bool;
135 #  else
136 typedef unsigned char _Bool;
137 #  endif
138 # endif
139 # define bool _Bool
140 # define false 0
141 # define true 1
142 # define __bool_true_false_are_defined 1
143 #endif
144
145 /* Needed for compilation under OS/2 and MSDOS */
146 #if defined(__EMX__) || defined(MSDOS)
147 # ifndef S_ISLNK
148 #  define S_ISLNK(m) 0
149 # endif
150 # ifndef lstat
151 #  define lstat stat
152 # endif
153 #endif /* __EMX__ || MSDOS */
154
155 /* Reportedly, stat() macros are broken on some old systems.  Those
156    systems will have to fend for themselves, as I will not introduce
157    new code to handle it.
158
159    However, I will add code for *missing* macros, and the following
160    are reportedly missing from many systems.  */
161 #ifndef S_ISLNK
162 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
163 #endif
164 #ifndef S_ISDIR
165 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
166 #endif
167 #ifndef S_ISREG
168 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
169 #endif
170
171 /* These are needed so we can #define struct_stat to struct _stati64
172    under Windows. */
173 #ifndef struct_stat
174 # define struct_stat struct stat
175 #endif
176 #ifndef struct_fstat
177 # define struct_fstat struct stat
178 #endif
179
180 /* For CHAR_BIT, LONG_MAX, etc. */
181 #include <limits.h>
182
183 #ifndef CHAR_BIT
184 # define CHAR_BIT 8
185 #endif
186
187 /* From gnulib, simplified to assume a signed type. */
188 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
189
190 /* These are defined in cmpt.c if missing, so we must declare
191    them.  */
192 #ifndef HAVE_STRCASECMP
193 int strcasecmp ();
194 #endif
195 #ifndef HAVE_STRNCASECMP
196 int strncasecmp ();
197 #endif
198 #ifndef HAVE_STRPTIME
199 char *strptime ();
200 #endif
201 #ifndef HAVE_TIMEGM
202 # include <time.h>
203 time_t timegm (struct tm *);
204 #endif
205 #ifndef HAVE_MEMRCHR
206 void *memrchr (const void *, int, size_t);
207 #endif
208
209 /* These are defined in snprintf.c.  It would be nice to have an
210    snprintf.h, though.  */
211 #ifndef HAVE_SNPRINTF
212 int snprintf ();
213 #endif
214 #ifndef HAVE_VSNPRINTF
215 int vsnprintf ();
216 #endif
217
218 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
219    provide MAP_FAILED, a symbolic constant for the value returned by
220    mmap() when it doesn't work.  Usually, this constant should be -1.
221    This only makes sense for files that use mmap() and include
222    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
223
224 #ifndef MAP_FAILED
225 # define MAP_FAILED ((void *) -1)
226 #endif
227
228 /* Enable system fnmatch only on systems where fnmatch.h is usable.
229    If the fnmatch on your system is buggy, undef this symbol and a
230    replacement implementation will be used instead.  */
231 #ifdef HAVE_WORKING_FNMATCH_H
232 # define SYSTEM_FNMATCH
233 #endif
234
235 #ifdef SYSTEM_FNMATCH
236 # include <fnmatch.h>
237 #else  /* not SYSTEM_FNMATCH */
238 /* Define fnmatch flags.  Undef them first to avoid warnings in case
239    an evil library include chose to include system fnmatch.h.  */
240 # undef FNM_PATHNAME
241 # undef FNM_NOESCAPE
242 # undef FNM_PERIOD
243 # undef FNM_NOMATCH
244
245 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
246 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
247 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
248 # define FNM_NOMATCH    1
249
250 int fnmatch (const char *, const char *, int);
251 #endif
252
253 /* Provide sig_atomic_t if the system doesn't.  */
254 #ifndef HAVE_SIG_ATOMIC_T
255 typedef int sig_atomic_t;
256 #endif
257
258 /* Provide uint32_t on the platforms that don't define it.  Although
259    most code should be agnostic about integer sizes, some code really
260    does need a 32-bit integral type.  Such code should use uint32_t.
261    (The exception is gnu-md5.[ch], which uses its own detection for
262    portability across platforms.)  */
263
264 #ifndef HAVE_UINT32_T
265 # if SIZEOF_INT == 4
266 typedef unsigned int uint32_t;
267 # else
268 #  if SIZEOF_LONG == 4
269 typedef unsigned long uint32_t;
270 #  else
271 #   if SIZEOF_SHORT == 4
272 typedef unsigned short uint32_t;
273 #   else
274  #error "Cannot determine a 32-bit unsigned integer type"
275 #   endif
276 #  endif
277 # endif
278 #endif
279
280 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
281 #ifndef HAVE_UINTPTR_T
282 typedef unsigned long uintptr_t;
283 #endif
284
285 /* If intptr_t isn't defined, simply typedef it to long. */
286 #ifndef HAVE_INTPTR_T
287 typedef long intptr_t;
288 #endif
289
290 #endif /* SYSDEP_H */