]> sjero.net Git - wget/blob - src/sysdep.h
Gisle's MS-DOS support
[wget] / src / sysdep.h
1 /* Dirty system-dependent hacks.
2    Copyright (C) 1996-2006 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 3 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, see <http://www.gnu.org/licenses/>.
18
19 In addition, as a special exception, the Free Software Foundation
20 gives permission to link the code of its release of Wget with the
21 OpenSSL project's "OpenSSL" library (or with modified versions of it
22 that use the same license as the "OpenSSL" library), and distribute
23 the linked executables.  You must obey the GNU General Public License
24 in all respects for all of the code used other than "OpenSSL".  If you
25 modify this file, you may extend this exception to your version of the
26 file, but you are not obligated to do so.  If you do not wish to do
27 so, delete this exception statement from your version.  */
28
29 /* This file is included by wget.h.  Random .c files need not include
30    it.  */
31
32 #ifndef SYSDEP_H
33 #define SYSDEP_H
34
35 /* Must include these, so we can test for the missing stat macros and
36    define them as necessary.  */
37 #include <sys/types.h>
38 #include <sys/stat.h>
39
40 #ifdef HAVE_INTTYPES_H
41 # include <inttypes.h>
42 #endif
43
44 #ifdef WINDOWS
45 /* Windows doesn't have some functions normally found on Unix-like
46    systems, such as strcasecmp, strptime, etc.  Include mswindows.h so
47    we get the declarations for their replacements in mswindows.c, as
48    well as to pick up Windows-specific includes and constants.  To be
49    able to test for such features, the file must be included as early
50    as possible.  */
51 # include "mswindows.h"
52 #endif
53
54 /* Provide support for C99-type boolean type "bool".  This blurb comes
55    straight from the Autoconf 2.59 manual. */
56 #if HAVE_STDBOOL_H
57 # include <stdbool.h>
58 #else
59 # if ! HAVE__BOOL
60 #  ifdef __cplusplus
61 typedef bool _Bool;
62 #  else
63 typedef unsigned char _Bool;
64 #  endif
65 # endif
66 # define bool _Bool
67 # define false 0
68 # define true 1
69 # define __bool_true_false_are_defined 1
70 #endif
71
72 /* Needed for compilation under OS/2 and MSDOS */
73 #if defined(__EMX__) || defined(MSDOS)
74 # ifndef S_ISLNK
75 #  define S_ISLNK(m) 0
76 # endif
77 # ifndef lstat
78 #  define lstat stat
79 # endif
80 #endif /* __EMX__ || MSDOS */
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 reportedly 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 /* These are needed so we can #define struct_stat to struct _stati64
99    under Windows. */
100 #ifndef struct_stat
101 # define struct_stat struct stat
102 #endif
103 #ifndef struct_fstat
104 # define struct_fstat struct stat
105 #endif
106
107 /* For CHAR_BIT, LONG_MAX, etc. */
108 #include <limits.h>
109
110 #ifndef CHAR_BIT
111 # define CHAR_BIT 8
112 #endif
113
114 /* From gnulib, simplified to assume a signed type. */
115 #define TYPE_MAXIMUM(t) ((t) (~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
116
117 /* These are defined in cmpt.c if missing, so we must declare
118    them.  */
119 #ifndef HAVE_STRCASECMP
120 int strcasecmp ();
121 #endif
122 #ifndef HAVE_STRNCASECMP
123 int strncasecmp ();
124 #endif
125 #ifndef HAVE_STRPTIME
126 char *strptime ();
127 #endif
128 #ifndef HAVE_TIMEGM
129 # include <time.h>
130 time_t timegm (struct tm *);
131 #endif
132 #ifndef HAVE_MEMRCHR
133 void *memrchr (const void *, int, size_t);
134 #endif
135
136 /* These are defined in snprintf.c.  It would be nice to have an
137    snprintf.h, though.  */
138 #ifndef HAVE_SNPRINTF
139 int snprintf ();
140 #endif
141 #ifndef HAVE_VSNPRINTF
142 int vsnprintf ();
143 #endif
144
145 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
146    provide MAP_FAILED, a symbolic constant for the value returned by
147    mmap() when it doesn't work.  Usually, this constant should be -1.
148    This only makes sense for files that use mmap() and include
149    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
150
151 #ifndef MAP_FAILED
152 # define MAP_FAILED ((void *) -1)
153 #endif
154
155 /* Enable system fnmatch only on systems where fnmatch.h is usable.
156    If the fnmatch on your system is buggy, undef this symbol and a
157    replacement implementation will be used instead.  */
158 #ifdef HAVE_WORKING_FNMATCH_H
159 # define SYSTEM_FNMATCH
160 #endif
161
162 #ifdef SYSTEM_FNMATCH
163 # include <fnmatch.h>
164 #else  /* not SYSTEM_FNMATCH */
165 /* Define fnmatch flags.  Undef them first to avoid warnings in case
166    an evil library include chose to include system fnmatch.h.  */
167 # undef FNM_PATHNAME
168 # undef FNM_NOESCAPE
169 # undef FNM_PERIOD
170 # undef FNM_NOMATCH
171
172 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
173 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
174 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
175 # define FNM_NOMATCH    1
176
177 int fnmatch (const char *, const char *, int);
178 #endif
179
180 /* Provide sig_atomic_t if the system doesn't.  */
181 #ifndef HAVE_SIG_ATOMIC_T
182 typedef int sig_atomic_t;
183 #endif
184
185 /* Provide uint32_t on the platforms that don't define it.  Although
186    most code should be agnostic about integer sizes, some code really
187    does need a 32-bit integral type.  Such code should use uint32_t.
188    (The exception is gnu-md5.[ch], which uses its own detection for
189    portability across platforms.)  */
190
191 #ifndef HAVE_UINT32_T
192 # if SIZEOF_INT == 4
193 typedef unsigned int uint32_t;
194 # else
195 #  if SIZEOF_LONG == 4
196 typedef unsigned long uint32_t;
197 #  else
198 #   if SIZEOF_SHORT == 4
199 typedef unsigned short uint32_t;
200 #   else
201  #error "Cannot determine a 32-bit unsigned integer type"
202 #   endif
203 #  endif
204 # endif
205 #endif
206
207 /* If uintptr_t isn't defined, simply typedef it to unsigned long. */
208 #ifndef HAVE_UINTPTR_T
209 typedef unsigned long uintptr_t;
210 #endif
211
212 /* If intptr_t isn't defined, simply typedef it to long. */
213 #ifndef HAVE_INTPTR_T
214 typedef long intptr_t;
215 #endif
216
217 #endif /* SYSDEP_H */