]> sjero.net Git - wget/blob - src/sysdep.h
[svn] Also check for short for int32_t.
[wget] / src / sysdep.h
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 WINDOWS
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>
56 #endif /* WINDOWS */
57
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.  */
61
62 #ifdef __WATCOMC__
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
65    at the link phase. */
66 # include <malloc.h>
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.  */
69 # include <io.h>
70 #endif /* __WATCOMC__ */
71
72 /* Needed for compilation under OS/2: */
73 #ifdef __EMX__
74 #ifndef S_ISLNK
75 # define S_ISLNK(m) 0
76 #endif
77 #ifndef lstat
78 # define lstat stat
79 #endif
80 #endif /* __EMX__ */
81
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.
85
86    However, I will add code for *missing* macros, and the following
87    are missing from many systems.  */
88 #ifndef S_ISLNK
89 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
90 #endif
91 #ifndef S_ISDIR
92 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
93 #endif
94 #ifndef S_ISREG
95 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
96 #endif
97
98 /* Bletch!  SPARC compiler doesn't define sparc (needed by
99    arpa/nameser.h) when in -Xc mode.  Luckily, it always defines
100    __sparc.  */
101 #ifdef __sparc
102 #ifndef sparc
103 #define sparc
104 #endif
105 #endif
106
107 #ifdef __BEOS__
108 # undef READ
109 # undef WRITE
110 # define READ(fd, buf, cnt) recv((fd), (buf), (cnt), 0)
111 # define WRITE(fd, buf, cnt) send((fd), (buf), (cnt), 0)
112 #endif
113
114 /* mswindows.h defines these.  */
115 #ifndef READ
116 # define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
117 #endif
118 #ifndef WRITE
119 # define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
120 #endif
121 #ifndef REALCLOSE
122 # define REALCLOSE(x) close (x)
123 #endif
124
125 #define CLOSE(x)                                \
126 do {                                            \
127   REALCLOSE (x);                                \
128   DEBUGP (("Closing fd %d\n", x));              \
129 } while (0)
130
131 /* Define a large ("very long") type useful for storing large
132    non-negative quantities that exceed sizes of normal download.  Note
133    that this has nothing to do with large file support.  For example,
134    one should be able to say `--quota=10G', large files
135    notwithstanding.
136
137    On the machines where `long' is 64-bit, we use long.  Otherwise, we
138    check whether `long long' is available and if yes, use that.  If
139    long long is unavailable, we give up and just use `long'.
140
141    Note: you cannot use VERY_LONG_TYPE along with printf().  When you
142    need to print it, use very_long_to_string().  */
143
144 #if SIZEOF_LONG >= 8 || SIZEOF_LONG_LONG == 0
145 /* either long is "big enough", or long long is unavailable which
146    leaves long as the only choice. */ 
147 # define VERY_LONG_TYPE   unsigned long
148 #else  /* use long long */
149 /* long is smaller than 8 bytes, but long long is available. */
150 # define VERY_LONG_TYPE   unsigned long long
151 #endif /* use long long */
152
153 /* These are defined in cmpt.c if missing, therefore it's generally
154    safe to declare their parameters.  */
155 #ifndef HAVE_STRERROR
156 char *strerror ();
157 #endif
158 #ifndef HAVE_STRCASECMP
159 int strcasecmp ();
160 #endif
161 #ifndef HAVE_STRNCASECMP
162 int strncasecmp ();
163 #endif
164 #ifndef HAVE_STRSTR
165 char *strstr ();
166 #endif
167 #ifndef HAVE_STRPTIME
168 char *strptime ();
169 #endif
170 #ifndef HAVE_VSNPRINTF
171 int vsnprintf ();
172 #endif
173 #ifndef HAVE_USLEEP
174 int usleep PARAMS ((unsigned long));
175 #endif
176 #ifndef HAVE_MEMMOVE
177 void *memmove ();
178 #endif
179
180 /* SunOS brain damage -- for some reason, SunOS header files fail to
181    declare the functions below, which causes all kinds of problems,
182    most notably compilation errors when using pointer arithmetic on
183    their return values.
184
185    This used to be only within `#ifdef STDC_HEADERS', but it got
186    tripped on other systems (AIX), thus causing havoc.  Fortunately,
187    SunOS appears to be the only system braindamaged that badly, so I
188    added an extra `#ifdef sun' guard.  */
189 #ifndef STDC_HEADERS
190 #ifdef sun
191 #ifndef __SVR4                  /* exclude Solaris */
192 char *strstr ();
193 char *strchr ();
194 char *strrchr ();
195 char *strtok ();
196 char *strdup ();
197 void *memcpy ();
198 #endif /* not __SVR4 */
199 #endif /* sun */
200 #endif /* not STDC_HEADERS */
201
202 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
203    provide MAP_FAILED, a symbolic constant for the value returned by
204    mmap() when it doesn't work.  Usually, this constant should be -1.
205    This only makes sense for files that use mmap() and include
206    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
207
208 #ifndef MAP_FAILED
209 # define MAP_FAILED ((void *) -1)
210 #endif
211
212 /* Enable system fnmatch only on systems where we know it works:
213    currently glibc-based systems and Solaris.  One could add more, but
214    fnmatch is not that large, so it might be better to play it
215    safe.  */
216 #if defined __GLIBC__ && __GLIBC__ >= 2
217 # define SYSTEM_FNMATCH
218 #endif
219 #ifdef solaris
220 # define SYSTEM_FNMATCH
221 #endif
222
223 #ifdef SYSTEM_FNMATCH
224 # include <fnmatch.h>
225 #else  /* not SYSTEM_FNMATCH */
226 /* Define fnmatch flags.  Undef them first to avoid warnings in case
227    an evil library include chose to include system fnmatch.h.  */
228 # undef FNM_PATHNAME
229 # undef FNM_NOESCAPE
230 # undef FNM_PERIOD
231 # undef FNM_NOMATCH
232
233 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
234 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
235 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
236 # define FNM_NOMATCH    1
237
238 /* Declare the function minimally. */
239 int fnmatch ();
240 #endif
241
242 /* Provide 32-bit types.  Most code shouldn't care, but there is code
243    that really needs a 32-bit integral type.  If int32_t and u_int32_t
244    are present, we use them, otherwise we pick one of int/short/long,
245    and throw an error if none of them works.  */
246
247 #ifndef HAVE_INT32_T
248 # if SIZEOF_INT == 4
249 typedef int int32_t;
250 # else
251 #  if SIZEOF_LONG == 4
252 typedef long int32_t;
253 #  else
254 #   if SIZEOF_SHORT == 4
255 typedef short int32_t;
256 #   else
257  #error "Cannot determine a 32-bit type"
258 #   endif
259 #  endif
260 # endif
261 #endif
262
263 #ifndef HAVE_U_INT32_T
264 # if SIZEOF_INT == 4
265 typedef unsigned int u_int32_t;
266 # else
267 #  if SIZEOF_LONG == 4
268 typedef unsigned long u_int32_t;
269 #  else
270 #   if SIZEOF_SHORT == 4
271 typedef unsigned short u_int32_t;
272 #   else
273  #error "Cannot determine a 32-bit type"
274 #   endif
275 #  endif
276 # endif
277 #endif
278
279 #endif /* SYSDEP_H */