]> sjero.net Git - wget/blob - src/sysdep.h
mass change: update copyright years.
[wget] / src / sysdep.h
1 /* Dirty system-dependent hacks.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3    2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
4    Inc.
5
6 This file is part of GNU Wget.
7
8 GNU Wget is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at
11 your option) any later version.
12
13 GNU Wget is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Wget.  If not, see <http://www.gnu.org/licenses/>.
20
21 Additional permission under GNU GPL version 3 section 7
22
23 If you modify this program, or any covered work, by linking or
24 combining it with the OpenSSL project's OpenSSL library (or a
25 modified version of that library), containing parts covered by the
26 terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
27 grants you additional permission to convey the resulting work.
28 Corresponding Source for a non-source form of such a combination
29 shall include the source code for the parts of OpenSSL used as well
30 as that of the covered work.  */
31
32 /* This file is included by wget.h.  Random .c files need not include
33    it.  */
34
35 #ifndef SYSDEP_H
36 #define SYSDEP_H
37
38 /* Testing for __sun is not enough because it's also defined on SunOS.  */
39 #ifdef __sun
40 # ifdef __SVR4
41 #  define solaris
42 # endif
43 #endif
44
45 #if defined(__INTERIX) && !defined(_ALL_SOURCE)
46 # define _ALL_SOURCE
47 #endif
48
49 /* The "namespace tweaks" below attempt to set a friendly "compilation
50    environment" under popular operating systems.  Default compilation
51    environment often means that some functions that are "extensions"
52    are not declared -- `strptime' is one example.
53
54    But non-default environments can expose bugs in the system header
55    files, crippling compilation in _very_ non-obvious ways.  Because
56    of that, we define them only on well-tested architectures where we
57    know they will work.  */
58
59 #undef NAMESPACE_TWEAKS
60
61 #ifdef solaris
62 # define NAMESPACE_TWEAKS
63 #endif
64
65 #if defined(__linux__) || defined(__GLIBC__)
66 # define NAMESPACE_TWEAKS
67 #endif
68
69 #ifdef NAMESPACE_TWEAKS
70
71 /* Request the "Unix 98 compilation environment". */
72 #define _XOPEN_SOURCE 500
73
74 #endif /* NAMESPACE_TWEAKS */
75
76
77 /* Alloca declaration, based on recommendation in the Autoconf manual.
78    These have to be after the above namespace tweaks, but before any
79    non-preprocessor code.  */
80
81 #if HAVE_ALLOCA_H
82 # include <alloca.h>
83 #elif defined WINDOWS
84 # include <malloc.h>
85 # ifndef alloca
86 #  define alloca _alloca
87 # endif
88 #elif defined __GNUC__
89 # define alloca __builtin_alloca
90 #elif defined _AIX
91 # define alloca __alloca
92 #else
93 # include <stddef.h>
94 # ifdef  __cplusplus
95 extern "C"
96 # endif
97 void *alloca (size_t);
98 #endif
99
100 /* Must include these, so we can test for the missing stat macros and
101    define them as necessary.  */
102 #include <sys/types.h>
103 #include <sys/stat.h>
104
105 #ifdef HAVE_INTTYPES_H
106   /* Compaq C V6.5-303 (dtk) on HP Tru64 UNIX V5.1B (Rev. 2650) needs: */
107 # include <stdint.h>
108 # include <inttypes.h>
109 #endif
110
111 #ifdef WINDOWS
112 /* Windows doesn't have some functions normally found on Unix-like
113    systems, such as strcasecmp, strptime, etc.  Include mswindows.h so
114    we get the declarations for their replacements in mswindows.c, as
115    well as to pick up Windows-specific includes and constants.  To be
116    able to test for such features, the file must be included as early
117    as possible.  */
118 # include "mswindows.h"
119 #endif
120
121 /* Provided by gnulib on systems that don't have it: */
122 # include <stdbool.h>
123
124 /* Needed for compilation under OS/2 and MSDOS */
125 #if defined(__EMX__) || defined(MSDOS)
126 # ifndef S_ISLNK
127 #  define S_ISLNK(m) 0
128 # endif
129 # ifndef lstat
130 #  define lstat stat
131 # endif
132 #endif /* __EMX__ || MSDOS */
133
134 /* Reportedly, stat() macros are broken on some old systems.  Those
135    systems will have to fend for themselves, as I will not introduce
136    new code to handle it.
137
138    However, I will add code for *missing* macros, and the following
139    are reportedly missing from many systems.  */
140 #ifndef S_ISLNK
141 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
142 #endif
143 #ifndef S_ISDIR
144 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
145 #endif
146 #ifndef S_ISREG
147 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
148 #endif
149
150 /* These are needed so we can #define struct_stat to struct _stati64
151    under Windows. */
152 #ifndef struct_stat
153 # define struct_stat struct stat
154 #endif
155 #ifndef struct_fstat
156 # define struct_fstat struct stat
157 #endif
158
159 /* For CHAR_BIT, LONG_MAX, etc. */
160 #include <limits.h>
161
162 #ifndef CHAR_BIT
163 # define CHAR_BIT 8
164 #endif
165
166 /* From gnulib, simplified to assume a signed type. */
167 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
168
169 /* These are defined in cmpt.c if missing, so we must declare
170    them.  */
171 #ifndef HAVE_STRCASECMP
172 int strcasecmp ();
173 #endif
174 #ifndef HAVE_STRNCASECMP
175 int strncasecmp ();
176 #endif
177 #ifndef HAVE_STRPTIME
178 char *strptime ();
179 #endif
180 #ifndef HAVE_TIMEGM
181 # include <time.h>
182 time_t timegm (struct tm *);
183 #endif
184 #ifndef HAVE_MEMRCHR
185 void *memrchr (const void *, int, size_t);
186 #endif
187
188 /* These are defined in snprintf.c.  It would be nice to have an
189    snprintf.h, though.  */
190 #ifndef HAVE_SNPRINTF
191 int snprintf (char *str, size_t count, const char *fmt, ...);
192 #endif
193 #ifndef HAVE_VSNPRINTF
194 #include <stdarg.h>
195 int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
196 #endif
197
198 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
199    provide MAP_FAILED, a symbolic constant for the value returned by
200    mmap() when it doesn't work.  Usually, this constant should be -1.
201    This only makes sense for files that use mmap() and include
202    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
203
204 #ifndef MAP_FAILED
205 # define MAP_FAILED ((void *) -1)
206 #endif
207
208 /* Enable system fnmatch only on systems where fnmatch.h is usable.
209    If the fnmatch on your system is buggy, undef this symbol and a
210    replacement implementation will be used instead.  */
211 #ifdef HAVE_WORKING_FNMATCH_H
212 # define SYSTEM_FNMATCH
213 #endif
214
215 #ifdef SYSTEM_FNMATCH
216 # include <fnmatch.h>
217 #else  /* not SYSTEM_FNMATCH */
218 /* Define fnmatch flags.  Undef them first to avoid warnings in case
219    an evil library include chose to include system fnmatch.h.  */
220 # undef FNM_PATHNAME
221 # undef FNM_NOESCAPE
222 # undef FNM_PERIOD
223 # undef FNM_NOMATCH
224
225 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
226 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
227 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
228 # define FNM_NOMATCH    1
229
230 int fnmatch (const char *, const char *, int);
231 #endif
232
233 /* Provide sig_atomic_t if the system doesn't.  */
234 #ifndef HAVE_SIG_ATOMIC_T
235 typedef int sig_atomic_t;
236 #endif
237
238 /* Provide uint32_t on the platforms that don't define it.  Although
239    most code should be agnostic about integer sizes, some code really
240    does need a 32-bit integral type.  Such code should use uint32_t.
241    (The exception is gnu-md5.[ch], which uses its own detection for
242    portability across platforms.)  */
243
244 #ifndef HAVE_UINT32_T
245 # if SIZEOF_INT == 4
246 typedef unsigned int uint32_t;
247 # else
248 #  if SIZEOF_LONG == 4
249 typedef unsigned long uint32_t;
250 #  else
251 #   if SIZEOF_SHORT == 4
252 typedef unsigned short uint32_t;
253 #   else
254  #error "Cannot determine a 32-bit unsigned integer type"
255 #   endif
256 #  endif
257 # endif
258 #endif
259
260 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
261 #ifndef HAVE_UINTPTR_T
262 typedef unsigned long uintptr_t;
263 #endif
264
265 /* If intptr_t isn't defined, simply typedef it to long. */
266 #ifndef HAVE_INTPTR_T
267 typedef long intptr_t;
268 #endif
269
270 #endif /* SYSDEP_H */