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