]> sjero.net Git - wget/blob - src/sysdep.h
[svn] Check for timegm and use it where available.
[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 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: */
74 #ifdef __EMX__
75 # ifndef S_ISLNK
76 #  define S_ISLNK(m) 0
77 # endif
78 # ifndef lstat
79 #  define lstat stat
80 # endif
81 #endif /* __EMX__ */
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 /* Used by wget.h to define SIZEOF_WGINT. */
116 #ifndef LONG_MAX
117 # define LONG_MAX ((long) ~((unsigned long)1 << (CHAR_BIT * sizeof (long) - 1)))
118 #endif
119 #ifndef LLONG_MAX
120 # define LLONG_MAX ((long long) ~((unsigned long long)1 << (CHAR_BIT * sizeof (long long) - 1)))
121 #endif
122
123 /* These are defined in cmpt.c if missing, so we must declare
124    them.  */
125 #ifndef HAVE_STRCASECMP
126 int strcasecmp ();
127 #endif
128 #ifndef HAVE_STRNCASECMP
129 int strncasecmp ();
130 #endif
131 #ifndef HAVE_STRPTIME
132 char *strptime ();
133 #endif
134 #ifndef HAVE_TIMEGM
135 # include <time.h>
136 time_t timegm (struct tm *);
137 #endif
138
139 /* These are defined in snprintf.c.  It would be nice to have an
140    snprintf.h, though.  */
141 #ifndef HAVE_SNPRINTF
142 int snprintf ();
143 #endif
144 #ifndef HAVE_VSNPRINTF
145 int vsnprintf ();
146 #endif
147
148 /* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
149    provide MAP_FAILED, a symbolic constant for the value returned by
150    mmap() when it doesn't work.  Usually, this constant should be -1.
151    This only makes sense for files that use mmap() and include
152    sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
153
154 #ifndef MAP_FAILED
155 # define MAP_FAILED ((void *) -1)
156 #endif
157
158 /* Enable system fnmatch only on systems where fnmatch.h is usable and
159    which are known to have a non-broken fnmatch implementation.
160    Currently those include glibc-based systems and Solaris.  One could
161    add more, but fnmatch is not that large, so it might be better to
162    play it safe.  */
163 #ifdef HAVE_WORKING_FNMATCH_H
164 # if defined __GLIBC__ && __GLIBC__ >= 2
165 #  define SYSTEM_FNMATCH
166 # endif
167 # ifdef solaris
168 #  define SYSTEM_FNMATCH
169 # endif
170 #endif /* HAVE_WORKING_FNMATCH_H */
171
172 #ifdef SYSTEM_FNMATCH
173 # include <fnmatch.h>
174 #else  /* not SYSTEM_FNMATCH */
175 /* Define fnmatch flags.  Undef them first to avoid warnings in case
176    an evil library include chose to include system fnmatch.h.  */
177 # undef FNM_PATHNAME
178 # undef FNM_NOESCAPE
179 # undef FNM_PERIOD
180 # undef FNM_NOMATCH
181
182 # define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
183 # define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
184 # define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
185 # define FNM_NOMATCH    1
186
187 /* Declare the function minimally. */
188 int fnmatch ();
189 #endif
190
191 /* Provide sig_atomic_t if the system doesn't.  */
192 #ifndef HAVE_SIG_ATOMIC_T
193 typedef int sig_atomic_t;
194 #endif
195
196 /* Provide uint32_t on the platforms that don't define it.  Although
197    most code should be agnostic about integer sizes, some code really
198    does need a 32-bit integral type.  Such code should use uint32_t.
199    (The exception is gnu-md5.[ch], which uses its own detection for
200    portability across platforms.)  */
201
202 #ifndef HAVE_UINT32_T
203 # if SIZEOF_INT == 4
204 typedef unsigned int uint32_t;
205 # else
206 #  if SIZEOF_LONG == 4
207 typedef unsigned long uint32_t;
208 #  else
209 #   if SIZEOF_SHORT == 4
210 typedef unsigned short uint32_t;
211 #   else
212  #error "Cannot determine a 32-bit unsigned integer type"
213 #   endif
214 #  endif
215 # endif
216 #endif
217
218 #endif /* SYSDEP_H */