]> sjero.net Git - wget/blob - src/sysdep.h
Update copyright lists, conforming to maintainer guidelines
[wget] / src / sysdep.h
1 /* Dirty system-dependent hacks.
2    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3    2004, 2005, 2006, 2007 Free Software Foundation, Inc.
4
5 This file is part of GNU Wget.
6
7 GNU Wget is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at
10 your option) any later version.
11
12 GNU Wget is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Wget.  If not, see <http://www.gnu.org/licenses/>.
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 normally found on Unix-like
47    systems, such as strcasecmp, strptime, etc.  Include mswindows.h so
48    we get the declarations for their replacements in mswindows.c, as
49    well as to pick up Windows-specific includes and constants.  To be
50    able to test for such features, the file must be included as early
51    as possible.  */
52 # include "mswindows.h"
53 #endif
54
55 /* Provide support for C99-type boolean type "bool".  This blurb comes
56    straight from the Autoconf 2.59 manual. */
57 #if HAVE_STDBOOL_H
58 # include <stdbool.h>
59 #else
60 # if ! HAVE__BOOL
61 #  ifdef __cplusplus
62 typedef bool _Bool;
63 #  else
64 typedef unsigned char _Bool;
65 #  endif
66 # endif
67 # define bool _Bool
68 # define false 0
69 # define true 1
70 # define __bool_true_false_are_defined 1
71 #endif
72
73 /* Needed for compilation under OS/2 and MSDOS */
74 #if defined(__EMX__) || defined(MSDOS)
75 # ifndef S_ISLNK
76 #  define S_ISLNK(m) 0
77 # endif
78 # ifndef lstat
79 #  define lstat stat
80 # endif
81 #endif /* __EMX__ || MSDOS */
82
83 /* Reportedly, stat() macros are broken on some old systems.  Those
84    systems will have to fend for themselves, as I will not introduce
85    new code to handle it.
86
87    However, I will add code for *missing* macros, and the following
88    are reportedly missing from many systems.  */
89 #ifndef S_ISLNK
90 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
91 #endif
92 #ifndef S_ISDIR
93 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
94 #endif
95 #ifndef S_ISREG
96 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
97 #endif
98
99 /* These are needed so we can #define struct_stat to struct _stati64
100    under Windows. */
101 #ifndef struct_stat
102 # define struct_stat struct stat
103 #endif
104 #ifndef struct_fstat
105 # define struct_fstat struct stat
106 #endif
107
108 /* For CHAR_BIT, LONG_MAX, etc. */
109 #include <limits.h>
110
111 #ifndef CHAR_BIT
112 # define CHAR_BIT 8
113 #endif
114
115 /* From gnulib, simplified to assume a signed type. */
116 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
117
118 /* These are defined in cmpt.c if missing, so we must declare
119    them.  */
120 #ifndef HAVE_STRCASECMP
121 int strcasecmp ();
122 #endif
123 #ifndef HAVE_STRNCASECMP
124 int strncasecmp ();
125 #endif
126 #ifndef HAVE_STRPTIME
127 char *strptime ();
128 #endif
129 #ifndef HAVE_TIMEGM
130 # include <time.h>
131 time_t timegm (struct tm *);
132 #endif
133 #ifndef HAVE_MEMRCHR
134 void *memrchr (const void *, int, size_t);
135 #endif
136
137 /* These are defined in snprintf.c.  It would be nice to have an
138    snprintf.h, though.  */
139 #ifndef HAVE_SNPRINTF
140 int snprintf ();
141 #endif
142 #ifndef HAVE_VSNPRINTF
143 int vsnprintf ();
144 #endif
145
146 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
147    provide MAP_FAILED, a symbolic constant for the value returned by
148    mmap() when it doesn't work.  Usually, this constant should be -1.
149    This only makes sense for files that use mmap() and include
150    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
151
152 #ifndef MAP_FAILED
153 # define MAP_FAILED ((void *) -1)
154 #endif
155
156 /* Enable system fnmatch only on systems where fnmatch.h is usable.
157    If the fnmatch on your system is buggy, undef this symbol and a
158    replacement implementation will be used instead.  */
159 #ifdef HAVE_WORKING_FNMATCH_H
160 # define SYSTEM_FNMATCH
161 #endif
162
163 #ifdef SYSTEM_FNMATCH
164 # include <fnmatch.h>
165 #else  /* not SYSTEM_FNMATCH */
166 /* Define fnmatch flags.  Undef them first to avoid warnings in case
167    an evil library include chose to include system fnmatch.h.  */
168 # undef FNM_PATHNAME
169 # undef FNM_NOESCAPE
170 # undef FNM_PERIOD
171 # undef FNM_NOMATCH
172
173 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
174 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
175 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
176 # define FNM_NOMATCH    1
177
178 int fnmatch (const char *, const char *, int);
179 #endif
180
181 /* Provide sig_atomic_t if the system doesn't.  */
182 #ifndef HAVE_SIG_ATOMIC_T
183 typedef int sig_atomic_t;
184 #endif
185
186 /* Provide uint32_t on the platforms that don't define it.  Although
187    most code should be agnostic about integer sizes, some code really
188    does need a 32-bit integral type.  Such code should use uint32_t.
189    (The exception is gnu-md5.[ch], which uses its own detection for
190    portability across platforms.)  */
191
192 #ifndef HAVE_UINT32_T
193 # if SIZEOF_INT == 4
194 typedef unsigned int uint32_t;
195 # else
196 #  if SIZEOF_LONG == 4
197 typedef unsigned long uint32_t;
198 #  else
199 #   if SIZEOF_SHORT == 4
200 typedef unsigned short uint32_t;
201 #   else
202  #error "Cannot determine a 32-bit unsigned integer type"
203 #   endif
204 #  endif
205 # endif
206 #endif
207
208 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
209 #ifndef HAVE_UINTPTR_T
210 typedef unsigned long uintptr_t;
211 #endif
212
213 /* If intptr_t isn't defined, simply typedef it to long. */
214 #ifndef HAVE_INTPTR_T
215 typedef long intptr_t;
216 #endif
217
218 #endif /* SYSDEP_H */