]> sjero.net Git - wget/blob - src/sysdep.h
[svn] Check for the C99 bool type and define it if missing.
[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 /* Must include these, so we can test for the missing stat macros and
37    define them as necessary.  */
38 #include <sys/types.h>
39 #include <sys/stat.h>
40
41 #ifdef HAVE_INTTYPES_H
42 # include <inttypes.h>
43 #endif
44
45 #ifdef WINDOWS
46 /* Windows doesn't have some functions.  Include mswindows.h so we get
47    their declarations, as well as some additional declarations and
48    macros.  This must come first, so it can set things up.  */
49 #include <mswindows.h>
50 #endif /* WINDOWS */
51
52 /* Watcom-specific stuff.  In practice this is probably specific to
53    Windows, although Watcom exists under other OS's too.  For that
54    reason, we keep this here.  */
55
56 #ifdef __WATCOMC__
57 /* Watcom has its own alloca() defined in malloc.h malloc.h needs to
58    be included in the sources to prevent 'undefined external' errors
59    at the link phase. */
60 # include <malloc.h>
61 /* io.h defines unlink() and chmod().  We put this here because it's
62    way too obscure to require all the .c files to observe.  */
63 # include <io.h>
64 #endif /* __WATCOMC__ */
65
66 /* Provide support for C99-type boolean type "bool".  This blurb comes
67    straight from the Autoconf 2.59 manual. */
68 #if HAVE_STDBOOL_H
69 # include <stdbool.h>
70 #else
71 # if ! HAVE__BOOL
72 #  ifdef __cplusplus
73 typedef bool _Bool;
74 #  else
75 typedef unsigned char _Bool;
76 #  endif
77 # endif
78 # define bool _Bool
79 # define false 0
80 # define true 1
81 # define __bool_true_false_are_defined 1
82 #endif
83
84 /* Needed for compilation under OS/2: */
85 #ifdef __EMX__
86 # ifndef S_ISLNK
87 #  define S_ISLNK(m) 0
88 # endif
89 # ifndef lstat
90 #  define lstat stat
91 # endif
92 #endif /* __EMX__ */
93
94 /* Reportedly, stat() macros are broken on some old systems.  Those
95    systems will have to fend for themselves, as I will not introduce
96    new code to handle it.
97
98    However, I will add code for *missing* macros, and the following
99    are reportedly missing from many systems.  */
100 #ifndef S_ISLNK
101 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
102 #endif
103 #ifndef S_ISDIR
104 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
105 #endif
106 #ifndef S_ISREG
107 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
108 #endif
109
110 /* Define a large integral type useful for storing large sizes that
111    exceed sizes of one download, such as when printing the sum of all
112    downloads.  Note that this has nothing to do with large file
113    support, which determines the wgint type.  This should be as large
114    as possible even on systems where when wgint is 32-bit; also,
115    unlike wgint, this can be a floating point type.
116
117    We use a 64-bit integral type where available, `double' otherwise.
118    It's hard to print LARGE_INT's portably, but fortunately it's
119    rarely needed.  */
120
121 #if SIZEOF_LONG >= 8
122 /* Long is large enough: use it.  */
123 typedef long LARGE_INT;
124 # define LARGE_INT_FMT "%ld"
125 #elif SIZEOF_LONG_LONG >= 8
126 /* Long long is large enough: use it.  */
127 typedef long long LARGE_INT;
128 # define LARGE_INT_FMT "%lld"
129 #elif _MSC_VER
130 /* Use __int64 under Windows. */
131 typedef __int64 LARGE_INT;
132 # define LARGE_INT_FMT "%I64"
133 #else
134 /* Large integer type unavailable; fake it with `double'.  */
135 typedef double LARGE_INT;
136 # define LARGE_INT_FMT "%.0f"
137 #endif
138
139 /* Under Windows we #define struct_stat to struct _stati64. */
140 #ifndef struct_stat
141 # define struct_stat struct stat
142 #endif
143
144 /* For CHAR_BIT, LONG_MAX, etc. */
145 #include <limits.h>
146
147 #ifndef CHAR_BIT
148 # define CHAR_BIT 8
149 #endif
150
151 /* Used by wget.h to define SIZEOF_WGINT. */
152 #ifndef LONG_MAX
153 # define LONG_MAX ((long) ~((unsigned long)1 << (CHAR_BIT * sizeof (long) - 1)))
154 #endif
155 #ifndef LLONG_MAX
156 # define LLONG_MAX ((long long) ~((unsigned long long)1 << (CHAR_BIT * sizeof (long long) - 1)))
157 #endif
158
159 /* These are defined in cmpt.c if missing, so we must declare
160    them.  */
161 #ifndef HAVE_STRCASECMP
162 int strcasecmp ();
163 #endif
164 #ifndef HAVE_STRNCASECMP
165 int strncasecmp ();
166 #endif
167 #ifndef HAVE_STRPTIME
168 char *strptime ();
169 #endif
170
171 /* These are defined in snprintf.c.  It would be nice to have an
172    snprintf.h, though.  */
173 #ifndef HAVE_SNPRINTF
174 int snprintf ();
175 #endif
176 #ifndef HAVE_VSNPRINTF
177 int vsnprintf ();
178 #endif
179
180 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
181    provide MAP_FAILED, a symbolic constant for the value returned by
182    mmap() when it doesn't work.  Usually, this constant should be -1.
183    This only makes sense for files that use mmap() and include
184    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
185
186 #ifndef MAP_FAILED
187 # define MAP_FAILED ((void *) -1)
188 #endif
189
190 /* Enable system fnmatch only on systems where fnmatch.h is usable and
191    which are known to have a non-broken fnmatch implementation.
192    Currently those include glibc-based systems and Solaris.  One could
193    add more, but fnmatch is not that large, so it might be better to
194    play it safe.  */
195 #ifdef HAVE_WORKING_FNMATCH_H
196 # if defined __GLIBC__ && __GLIBC__ >= 2
197 #  define SYSTEM_FNMATCH
198 # endif
199 # ifdef solaris
200 #  define SYSTEM_FNMATCH
201 # endif
202 #endif /* HAVE_WORKING_FNMATCH_H */
203
204 #ifdef SYSTEM_FNMATCH
205 # include <fnmatch.h>
206 #else  /* not SYSTEM_FNMATCH */
207 /* Define fnmatch flags.  Undef them first to avoid warnings in case
208    an evil library include chose to include system fnmatch.h.  */
209 # undef FNM_PATHNAME
210 # undef FNM_NOESCAPE
211 # undef FNM_PERIOD
212 # undef FNM_NOMATCH
213
214 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
215 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
216 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
217 # define FNM_NOMATCH    1
218
219 /* Declare the function minimally. */
220 int fnmatch ();
221 #endif
222
223 /* Provide sig_atomic_t if the system doesn't.  */
224 #ifndef HAVE_SIG_ATOMIC_T
225 typedef int sig_atomic_t;
226 #endif
227
228 /* Provide uint32_t on the platforms that don't define it.  Although
229    most code should be agnostic about integer sizes, some code really
230    does need a 32-bit integral type.  Such code should use uint32_t.
231    (The exception is gnu-md5.[ch], which uses its own detection for
232    portability across platforms.)  */
233
234 #ifndef HAVE_UINT32_T
235 # if SIZEOF_INT == 4
236 typedef unsigned int uint32_t;
237 # else
238 #  if SIZEOF_LONG == 4
239 typedef unsigned long uint32_t;
240 #  else
241 #   if SIZEOF_SHORT == 4
242 typedef unsigned short uint32_t;
243 #   else
244  #error "Cannot determine a 32-bit unsigned integer type"
245 #   endif
246 #  endif
247 # endif
248 #endif
249
250 #endif /* SYSDEP_H */