1 | /* Dirty system-dependent hacks.
|
---|
2 | Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
---|
3 |
|
---|
4 | This file is part of GNU Wget.
|
---|
5 |
|
---|
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.
|
---|
10 |
|
---|
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.
|
---|
15 |
|
---|
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.
|
---|
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 | /* We need these to be playing with various stuff. */
|
---|
37 | #ifdef TIME_WITH_SYS_TIME
|
---|
38 | # include <sys/time.h>
|
---|
39 | # include <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 */
|
---|
44 | # include <time.h>
|
---|
45 | #endif /* HAVE_SYS_TIME_H */
|
---|
46 | #endif /* TIME_WITH_SYS_TIME_H */
|
---|
47 |
|
---|
48 | #include <sys/types.h>
|
---|
49 | #include <sys/stat.h>
|
---|
50 |
|
---|
51 | #ifdef HAVE_INTTYPES_H
|
---|
52 | # include <inttypes.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | #ifdef WINDOWS
|
---|
56 | /* Windows doesn't have some functions. Include mswindows.h so we get
|
---|
57 | their declarations, as well as some additional declarations and
|
---|
58 | macros. This must come first, so it can set things up. */
|
---|
59 | #include <mswindows.h>
|
---|
60 | #endif /* WINDOWS */
|
---|
61 |
|
---|
62 | /* Watcom-specific stuff. In practice this is probably specific to
|
---|
63 | Windows, although Watcom exists under other OS's too. For that
|
---|
64 | reason, we keep this here. */
|
---|
65 |
|
---|
66 | #ifdef __WATCOMC__
|
---|
67 | /* Watcom has its own alloca() defined in malloc.h malloc.h needs to
|
---|
68 | be included in the sources to prevent 'undefined external' errors
|
---|
69 | at the link phase. */
|
---|
70 | # include <malloc.h>
|
---|
71 | /* io.h defines unlink() and chmod(). We put this here because it's
|
---|
72 | way too obscure to require all the .c files to observe. */
|
---|
73 | # include <io.h>
|
---|
74 | #endif /* __WATCOMC__ */
|
---|
75 |
|
---|
76 | /* Needed for compilation under OS/2: */
|
---|
77 | #ifdef __EMX__
|
---|
78 | #ifndef S_ISLNK
|
---|
79 | # define S_ISLNK(m) 0
|
---|
80 | #endif
|
---|
81 | #ifndef lstat
|
---|
82 | # define lstat stat
|
---|
83 | #endif
|
---|
84 | #endif /* __EMX__ */
|
---|
85 |
|
---|
86 | /* Reportedly, stat() macros are broken on some old systems. Those
|
---|
87 | systems will have to fend for themselves, as I will not introduce
|
---|
88 | new code to handle it.
|
---|
89 |
|
---|
90 | However, I will add code for *missing* macros, and the following
|
---|
91 | are missing from many systems. */
|
---|
92 | #ifndef S_ISLNK
|
---|
93 | # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
---|
94 | #endif
|
---|
95 | #ifndef S_ISDIR
|
---|
96 | # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
|
---|
97 | #endif
|
---|
98 | #ifndef S_ISREG
|
---|
99 | # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | /* Bletch! SPARC compiler doesn't define sparc (needed by
|
---|
103 | arpa/nameser.h) when in -Xc mode. Luckily, it always defines
|
---|
104 | __sparc. */
|
---|
105 | #ifdef __sparc
|
---|
106 | #ifndef sparc
|
---|
107 | #define sparc
|
---|
108 | #endif
|
---|
109 | #endif
|
---|
110 |
|
---|
111 | /* These are needed so we can #define struct_stat to struct _stati64
|
---|
112 | under Windows. */
|
---|
113 | #ifndef struct_stat
|
---|
114 | # define struct_stat struct stat
|
---|
115 | #endif
|
---|
116 | #ifndef struct_fstat
|
---|
117 | # define struct_fstat struct stat
|
---|
118 | #endif
|
---|
119 |
|
---|
120 | #ifdef HAVE_LIMITS_H
|
---|
121 | # include <limits.h>
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | #ifndef CHAR_BIT
|
---|
125 | # define CHAR_BIT 8
|
---|
126 | #endif
|
---|
127 |
|
---|
128 | #ifndef LONG_MAX
|
---|
129 | # define LONG_MAX ((long) ~((unsigned long)1 << (CHAR_BIT * sizeof (long) - 1)))
|
---|
130 | #endif
|
---|
131 | #ifndef LLONG_MAX
|
---|
132 | # define LLONG_MAX ((long long) ~((unsigned long long)1 << (CHAR_BIT * sizeof (long long) - 1)))
|
---|
133 | #endif
|
---|
134 |
|
---|
135 | /* These are defined in cmpt.c if missing, therefore it's generally
|
---|
136 | safe to declare their parameters. */
|
---|
137 | #ifndef HAVE_STRERROR
|
---|
138 | char *strerror ();
|
---|
139 | #endif
|
---|
140 | #ifndef HAVE_STRCASECMP
|
---|
141 | int strcasecmp ();
|
---|
142 | #endif
|
---|
143 | #ifndef HAVE_STRNCASECMP
|
---|
144 | int strncasecmp ();
|
---|
145 | #endif
|
---|
146 | #ifndef HAVE_STRSTR
|
---|
147 | char *strstr ();
|
---|
148 | #endif
|
---|
149 | #ifndef HAVE_STRPTIME
|
---|
150 | char *strptime ();
|
---|
151 | #endif
|
---|
152 | #ifndef HAVE_SNPRINTF
|
---|
153 | int snprintf ();
|
---|
154 | #endif
|
---|
155 | #ifndef HAVE_VSNPRINTF
|
---|
156 | int vsnprintf ();
|
---|
157 | #endif
|
---|
158 | #ifndef HAVE_MEMMOVE
|
---|
159 | void *memmove ();
|
---|
160 | #endif
|
---|
161 | #ifndef HAVE_TIMEGM
|
---|
162 | time_t timegm (struct tm *);
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | /* SunOS brain damage -- for some reason, SunOS header files fail to
|
---|
166 | declare the functions below, which causes all kinds of problems,
|
---|
167 | most notably compilation errors when using pointer arithmetic on
|
---|
168 | their return values.
|
---|
169 |
|
---|
170 | This used to be only within `#ifdef STDC_HEADERS', but it got
|
---|
171 | tripped on other systems (AIX), thus causing havoc. Fortunately,
|
---|
172 | SunOS appears to be the only system braindamaged that badly, so I
|
---|
173 | added an extra `#ifdef sun' guard. */
|
---|
174 | #ifndef STDC_HEADERS
|
---|
175 | #ifdef sun
|
---|
176 | #ifndef __SVR4 /* exclude Solaris */
|
---|
177 | char *strstr ();
|
---|
178 | char *strchr ();
|
---|
179 | char *strrchr ();
|
---|
180 | char *strtok ();
|
---|
181 | char *strdup ();
|
---|
182 | void *memcpy ();
|
---|
183 | #endif /* not __SVR4 */
|
---|
184 | #endif /* sun */
|
---|
185 | #endif /* not STDC_HEADERS */
|
---|
186 |
|
---|
187 | /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
|
---|
188 | provide MAP_FAILED, a symbolic constant for the value returned by
|
---|
189 | mmap() when it doesn't work. Usually, this constant should be -1.
|
---|
190 | This only makes sense for files that use mmap() and include
|
---|
191 | sys/mman.h *before* sysdep.h, but doesn't hurt others. */
|
---|
192 |
|
---|
193 | #ifndef MAP_FAILED
|
---|
194 | # define MAP_FAILED ((void *) -1)
|
---|
195 | #endif
|
---|
196 |
|
---|
197 | /* Enable system fnmatch only on systems where fnmatch.h is usable and
|
---|
198 | which are known to have a non-broken fnmatch implementation.
|
---|
199 | Currently those include glibc-based systems and Solaris. One could
|
---|
200 | add more, but fnmatch is not that large, so it might be better to
|
---|
201 | play it safe. */
|
---|
202 | #ifdef HAVE_WORKING_FNMATCH_H
|
---|
203 | # if defined __GLIBC__ && __GLIBC__ >= 2
|
---|
204 | # define SYSTEM_FNMATCH
|
---|
205 | # endif
|
---|
206 | # ifdef solaris
|
---|
207 | # define SYSTEM_FNMATCH
|
---|
208 | # endif
|
---|
209 | #endif /* HAVE_WORKING_FNMATCH_H */
|
---|
210 |
|
---|
211 | #ifdef SYSTEM_FNMATCH
|
---|
212 | # include <fnmatch.h>
|
---|
213 | #else /* not SYSTEM_FNMATCH */
|
---|
214 | /* Define fnmatch flags. Undef them first to avoid warnings in case
|
---|
215 | an evil library include chose to include system fnmatch.h. */
|
---|
216 | # undef FNM_PATHNAME
|
---|
217 | # undef FNM_NOESCAPE
|
---|
218 | # undef FNM_PERIOD
|
---|
219 | # undef FNM_NOMATCH
|
---|
220 |
|
---|
221 | # define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
|
---|
222 | # define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
|
---|
223 | # define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
|
---|
224 | # define FNM_NOMATCH 1
|
---|
225 |
|
---|
226 | /* Declare the function minimally. */
|
---|
227 | int fnmatch ();
|
---|
228 | #endif
|
---|
229 |
|
---|
230 | /* Provide sig_atomic_t if the system doesn't. */
|
---|
231 | #ifndef HAVE_SIG_ATOMIC_T
|
---|
232 | typedef int sig_atomic_t;
|
---|
233 | #endif
|
---|
234 |
|
---|
235 | /* Provide uint32_t on the platforms that don't define it. Although
|
---|
236 | most code should be agnostic about integer sizes, some code really
|
---|
237 | does need a 32-bit integral type. Such code should use uint32_t.
|
---|
238 | (The exception is gnu-md5.[ch], which uses its own detection for
|
---|
239 | portability across platforms.) */
|
---|
240 |
|
---|
241 | #ifndef HAVE_UINT32_T
|
---|
242 | # if SIZEOF_INT == 4
|
---|
243 | typedef unsigned int uint32_t;
|
---|
244 | # else
|
---|
245 | # if SIZEOF_LONG == 4
|
---|
246 | typedef unsigned long uint32_t;
|
---|
247 | # else
|
---|
248 | # if SIZEOF_SHORT == 4
|
---|
249 | typedef unsigned short uint32_t;
|
---|
250 | # else
|
---|
251 | #error "Cannot determine a 32-bit unsigned integer type"
|
---|
252 | # endif
|
---|
253 | # endif
|
---|
254 | # endif
|
---|
255 | #endif
|
---|
256 |
|
---|
257 | #endif /* SYSDEP_H */
|
---|