1 /* Dirty system-dependent hacks.
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
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.
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.
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/>.
20 Additional permission under GNU GPL version 3 section 7
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. */
31 /* This file is included by wget.h. Random .c files need not include
37 /* Testing for __sun is not enough because it's also defined on SunOS. */
44 #if defined(__INTERIX) && !defined(_ALL_SOURCE)
48 /* The "namespace tweaks" below attempt to set a friendly "compilation
49 environment" under popular operating systems. Default compilation
50 environment often means that some functions that are "extensions"
51 are not declared -- `strptime' is one example.
53 But non-default environments can expose bugs in the system header
54 files, crippling compilation in _very_ non-obvious ways. Because
55 of that, we define them only on well-tested architectures where we
56 know they will work. */
58 #undef NAMESPACE_TWEAKS
61 # define NAMESPACE_TWEAKS
64 #if defined(__linux__) || defined(__GLIBC__)
65 # define NAMESPACE_TWEAKS
68 #ifdef NAMESPACE_TWEAKS
70 /* Request the "Unix 98 compilation environment". */
71 #define _XOPEN_SOURCE 500
73 #endif /* NAMESPACE_TWEAKS */
76 /* Alloca declaration, based on recommendation in the Autoconf manual.
77 These have to be after the above namespace tweaks, but before any
78 non-preprocessor code. */
85 # define alloca _alloca
87 #elif defined __GNUC__
88 # define alloca __builtin_alloca
90 # define alloca __alloca
96 void *alloca (size_t);
99 /* Must include these, so we can test for the missing stat macros and
100 define them as necessary. */
101 #include <sys/types.h>
102 #include <sys/stat.h>
104 #ifdef HAVE_INTTYPES_H
105 /* Compaq C V6.5-303 (dtk) on HP Tru64 UNIX V5.1B (Rev. 2650) needs: */
107 # include <inttypes.h>
111 /* Windows doesn't have some functions normally found on Unix-like
112 systems, such as strcasecmp, strptime, etc. Include mswindows.h so
113 we get the declarations for their replacements in mswindows.c, as
114 well as to pick up Windows-specific includes and constants. To be
115 able to test for such features, the file must be included as early
117 # include "mswindows.h"
120 /* Provided by gnulib on systems that don't have it: */
121 # include <stdbool.h>
123 /* Needed for compilation under OS/2 and MSDOS */
124 #if defined(__EMX__) || defined(MSDOS)
126 # define S_ISLNK(m) 0
131 #endif /* __EMX__ || MSDOS */
133 /* Reportedly, stat() macros are broken on some old systems. Those
134 systems will have to fend for themselves, as I will not introduce
135 new code to handle it.
137 However, I will add code for *missing* macros, and the following
138 are reportedly missing from many systems. */
140 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
143 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
146 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
149 /* These are needed so we can #define struct_stat to struct _stati64
152 # define struct_stat struct stat
155 # define struct_fstat struct stat
158 /* For CHAR_BIT, LONG_MAX, etc. */
165 /* From gnulib, simplified to assume a signed type. */
166 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
168 /* These are defined in cmpt.c if missing, so we must declare
170 #ifndef HAVE_STRCASECMP
173 #ifndef HAVE_STRNCASECMP
176 #ifndef HAVE_STRPTIME
181 time_t timegm (struct tm *);
184 void *memrchr (const void *, int, size_t);
187 /* These are defined in snprintf.c. It would be nice to have an
188 snprintf.h, though. */
189 #ifndef HAVE_SNPRINTF
190 int snprintf (char *str, size_t count, const char *fmt, ...);
192 #ifndef HAVE_VSNPRINTF
194 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
197 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
198 provide MAP_FAILED, a symbolic constant for the value returned by
199 mmap() when it doesn't work. Usually, this constant should be -1.
200 This only makes sense for files that use mmap() and include
201 sys/mman.h *before* sysdep.h, but doesn't hurt others. */
204 # define MAP_FAILED ((void *) -1)
207 /* Enable system fnmatch only on systems where fnmatch.h is usable.
208 If the fnmatch on your system is buggy, undef this symbol and a
209 replacement implementation will be used instead. */
210 #ifdef HAVE_WORKING_FNMATCH_H
211 # define SYSTEM_FNMATCH
214 #ifdef SYSTEM_FNMATCH
215 # include <fnmatch.h>
216 #else /* not SYSTEM_FNMATCH */
217 /* Define fnmatch flags. Undef them first to avoid warnings in case
218 an evil library include chose to include system fnmatch.h. */
224 # define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
225 # define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
226 # define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
227 # define FNM_NOMATCH 1
229 int fnmatch (const char *, const char *, int);
232 /* Provide sig_atomic_t if the system doesn't. */
233 #ifndef HAVE_SIG_ATOMIC_T
234 typedef int sig_atomic_t;
237 /* Provide uint32_t on the platforms that don't define it. Although
238 most code should be agnostic about integer sizes, some code really
239 does need a 32-bit integral type. Such code should use uint32_t.
240 (The exception is gnu-md5.[ch], which uses its own detection for
241 portability across platforms.) */
243 #ifndef HAVE_UINT32_T
245 typedef unsigned int uint32_t;
247 # if SIZEOF_LONG == 4
248 typedef unsigned long uint32_t;
250 # if SIZEOF_SHORT == 4
251 typedef unsigned short uint32_t;
253 #error "Cannot determine a 32-bit unsigned integer type"
259 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
260 #ifndef HAVE_UINTPTR_T
261 typedef unsigned long uintptr_t;
264 /* If intptr_t isn't defined, simply typedef it to long. */
265 #ifndef HAVE_INTPTR_T
266 typedef long intptr_t;
269 #endif /* SYSDEP_H */