1 /* Dirty system-dependent hacks.
2 Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
4 This file is part of GNU Wget.
6 GNU Wget is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at
9 your option) any later version.
11 GNU Wget is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Wget; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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. */
30 /* This file is included by wget.h. Random .c files need not include
36 /* We need these to be playing with various stuff. */
37 #ifdef TIME_WITH_SYS_TIME
38 # include <sys/time.h>
40 #else /* not TIME_WITH_SYS_TIME_H */
41 #ifdef HAVE_SYS_TIME_H
42 # include <sys/time.h>
43 #else /* not HAVE_SYS_TIME_H */
45 #endif /* HAVE_SYS_TIME_H */
46 #endif /* TIME_WITH_SYS_TIME_H */
48 #include <sys/types.h>
52 /* Windows doesn't have some functions. Include mswindows.h so we get
53 their declarations, as well as some additional declarations and
54 macros. This must come first, so it can set things up. */
55 #include <mswindows.h>
58 /* Watcom-specific stuff. In practice this is probably specific to
59 Windows, although Watcom exists under other OS's too. For that
60 reason, we keep this here. */
63 /* Watcom has its own alloca() defined in malloc.h malloc.h needs to
64 be included in the sources to prevent 'undefined external' errors
67 /* io.h defines unlink() and chmod(). We put this here because it's
68 way too obscure to require all the .c files to observe. */
70 #endif /* __WATCOMC__ */
72 /* Needed for compilation under OS/2: */
82 /* Reportedly, stat() macros are broken on some old systems. Those
83 systems will have to fend for themselves, as I will not introduce
84 new code to handle it.
86 However, I will add code for *missing* macros, and the following
87 are missing from many systems. */
89 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
92 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
95 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
98 /* Bletch! SPARC compiler doesn't define sparc (needed by
99 arpa/nameser.h) when in -Xc mode. Luckily, it always defines
110 # define READ(fd, buf, cnt) recv((fd), (buf), (cnt), 0)
111 # define WRITE(fd, buf, cnt) send((fd), (buf), (cnt), 0)
114 /* mswindows.h defines these. */
116 # define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
119 # define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
122 # define REALCLOSE(x) close (x)
128 DEBUGP (("Closing fd %d\n", x)); \
131 /* Define a large integral type useful for storing large sizes that
132 exceed sizes of one download, such as when printing the sum of all
133 downloads. Note that this has nothing to do with large file
136 We use a 64-bit integral type where available, `double' otherwise.
137 It's hard to print LARGE_INT's portably, but fortunately it's
141 /* Long is large enough: use it. */
142 typedef long LARGE_INT;
143 # define LARGE_INT_FMT "%ld"
145 # if SIZEOF_LONG_LONG == 8
146 /* Long long is large enough: use it. */
147 typedef long long LARGE_INT;
148 # define LARGE_INT_FMT "%lld"
151 typedef double LARGE_INT;
152 # define LARGE_INT_FMT "%.0f"
156 /* These are defined in cmpt.c if missing, therefore it's generally
157 safe to declare their parameters. */
158 #ifndef HAVE_STRERROR
161 #ifndef HAVE_STRCASECMP
164 #ifndef HAVE_STRNCASECMP
170 #ifndef HAVE_STRPTIME
173 #ifndef HAVE_SNPRINTF
176 #ifndef HAVE_VSNPRINTF
180 int usleep PARAMS ((unsigned long));
186 /* SunOS brain damage -- for some reason, SunOS header files fail to
187 declare the functions below, which causes all kinds of problems,
188 most notably compilation errors when using pointer arithmetic on
191 This used to be only within `#ifdef STDC_HEADERS', but it got
192 tripped on other systems (AIX), thus causing havoc. Fortunately,
193 SunOS appears to be the only system braindamaged that badly, so I
194 added an extra `#ifdef sun' guard. */
197 #ifndef __SVR4 /* exclude Solaris */
204 #endif /* not __SVR4 */
206 #endif /* not STDC_HEADERS */
208 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
209 provide MAP_FAILED, a symbolic constant for the value returned by
210 mmap() when it doesn't work. Usually, this constant should be -1.
211 This only makes sense for files that use mmap() and include
212 sys/mman.h *before* sysdep.h, but doesn't hurt others. */
215 # define MAP_FAILED ((void *) -1)
218 /* Enable system fnmatch only on systems where we know it works:
219 currently glibc-based systems and Solaris. One could add more, but
220 fnmatch is not that large, so it might be better to play it
222 #if defined __GLIBC__ && __GLIBC__ >= 2
223 # define SYSTEM_FNMATCH
226 # define SYSTEM_FNMATCH
229 #ifdef SYSTEM_FNMATCH
230 # include <fnmatch.h>
231 #else /* not SYSTEM_FNMATCH */
232 /* Define fnmatch flags. Undef them first to avoid warnings in case
233 an evil library include chose to include system fnmatch.h. */
239 # define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
240 # define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
241 # define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
242 # define FNM_NOMATCH 1
244 /* Declare the function minimally. */
248 /* Provide 32-bit types. Most code shouldn't care, but there is code
249 that really needs a 32-bit integral type. If int32_t and u_int32_t
250 are present, we use them, otherwise we pick one of int/short/long,
251 and throw an error if none of them works. */
257 # if SIZEOF_LONG == 4
258 typedef long int32_t;
260 # if SIZEOF_SHORT == 4
261 typedef short int32_t;
263 #error "Cannot determine a 32-bit type"
269 #ifndef HAVE_U_INT32_T
271 typedef unsigned int u_int32_t;
273 # if SIZEOF_LONG == 4
274 typedef unsigned long u_int32_t;
276 # if SIZEOF_SHORT == 4
277 typedef unsigned short u_int32_t;
279 #error "Cannot determine a 32-bit type"
285 #endif /* SYSDEP_H */