~ubuntu-branches/ubuntu/hardy/wget/hardy-updates

« back to all changes in this revision

Viewing changes to src/sysdep.h

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2004-02-13 20:26:44 UTC
  • Revision ID: james.westby@ubuntu.com-20040213202644-skxj93qs15sskqfy
Tags: upstream-1.9.1
Import upstream version 1.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/* We need these to be playing with various stuff.  */
 
37
#ifdef TIME_WITH_SYS_TIME
 
38
# include <sys/time.h>
 
39
# include <time.h>
 
40
#else /* not TIME_WITH_SYS_TIME_H */
 
41
#ifdef HAVE_SYS_TIME_H
 
42
# include <sys/time.h>
 
43
#else /* not HAVE_SYS_TIME_H */
 
44
# include <time.h>
 
45
#endif /* HAVE_SYS_TIME_H */
 
46
#endif /* TIME_WITH_SYS_TIME_H */
 
47
 
 
48
#include <sys/types.h>
 
49
#include <sys/stat.h>
 
50
 
 
51
#ifdef HAVE_INTTYPES_H
 
52
# include <inttypes.h>
 
53
#endif
 
54
 
 
55
#ifdef WINDOWS
 
56
/* Windows doesn't have some functions.  Include mswindows.h so we get
 
57
   their declarations, as well as some additional declarations and
 
58
   macros.  This must come first, so it can set things up.  */
 
59
#include <mswindows.h>
 
60
#endif /* WINDOWS */
 
61
 
 
62
/* Watcom-specific stuff.  In practice this is probably specific to
 
63
   Windows, although Watcom exists under other OS's too.  For that
 
64
   reason, we keep this here.  */
 
65
 
 
66
#ifdef __WATCOMC__
 
67
/* Watcom has its own alloca() defined in malloc.h malloc.h needs to
 
68
   be included in the sources to prevent 'undefined external' errors
 
69
   at the link phase. */
 
70
# include <malloc.h>
 
71
/* io.h defines unlink() and chmod().  We put this here because it's
 
72
   way too obscure to require all the .c files to observe.  */
 
73
# include <io.h>
 
74
#endif /* __WATCOMC__ */
 
75
 
 
76
/* Needed for compilation under OS/2: */
 
77
#ifdef __EMX__
 
78
#ifndef S_ISLNK
 
79
# define S_ISLNK(m) 0
 
80
#endif
 
81
#ifndef lstat
 
82
# define lstat stat
 
83
#endif
 
84
#endif /* __EMX__ */
 
85
 
 
86
/* Reportedly, stat() macros are broken on some old systems.  Those
 
87
   systems will have to fend for themselves, as I will not introduce
 
88
   new code to handle it.
 
89
 
 
90
   However, I will add code for *missing* macros, and the following
 
91
   are missing from many systems.  */
 
92
#ifndef S_ISLNK
 
93
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
 
94
#endif
 
95
#ifndef S_ISDIR
 
96
# define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
 
97
#endif
 
98
#ifndef S_ISREG
 
99
# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
 
100
#endif
 
101
 
 
102
/* Bletch!  SPARC compiler doesn't define sparc (needed by
 
103
   arpa/nameser.h) when in -Xc mode.  Luckily, it always defines
 
104
   __sparc.  */
 
105
#ifdef __sparc
 
106
#ifndef sparc
 
107
#define sparc
 
108
#endif
 
109
#endif
 
110
 
 
111
#ifdef __BEOS__
 
112
# undef READ
 
113
# undef WRITE
 
114
# define READ(fd, buf, cnt) recv((fd), (buf), (cnt), 0)
 
115
# define WRITE(fd, buf, cnt) send((fd), (buf), (cnt), 0)
 
116
#endif
 
117
 
 
118
/* mswindows.h defines these.  */
 
119
#ifndef READ
 
120
# define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
 
121
#endif
 
122
#ifndef WRITE
 
123
# define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
 
124
#endif
 
125
#ifndef REALCLOSE
 
126
# define REALCLOSE(x) close (x)
 
127
#endif
 
128
 
 
129
#define CLOSE(x)                                \
 
130
do {                                            \
 
131
  REALCLOSE (x);                                \
 
132
  DEBUGP (("Closing fd %d\n", x));              \
 
133
} while (0)
 
134
 
 
135
/* Define a large integral type useful for storing large sizes that
 
136
   exceed sizes of one download, such as when printing the sum of all
 
137
   downloads.  Note that this has nothing to do with large file
 
138
   support, yet.
 
139
 
 
140
   We use a 64-bit integral type where available, `double' otherwise.
 
141
   It's hard to print LARGE_INT's portably, but fortunately it's
 
142
   rarely needed.  */
 
143
 
 
144
#if SIZEOF_LONG >= 8
 
145
/* Long is large enough: use it.  */
 
146
typedef long LARGE_INT;
 
147
# define LARGE_INT_FMT "%ld"
 
148
#else
 
149
# if SIZEOF_LONG_LONG >= 8
 
150
/* Long long is large enough: use it.  */
 
151
typedef long long LARGE_INT;
 
152
#  define LARGE_INT_FMT "%lld"
 
153
# else
 
154
/* Large integer type unavailable; use `double' instead.  */
 
155
typedef double LARGE_INT;
 
156
#  define LARGE_INT_FMT "%.0f"
 
157
# endif
 
158
#endif
 
159
 
 
160
/* These are defined in cmpt.c if missing, therefore it's generally
 
161
   safe to declare their parameters.  */
 
162
#ifndef HAVE_STRERROR
 
163
char *strerror ();
 
164
#endif
 
165
#ifndef HAVE_STRCASECMP
 
166
int strcasecmp ();
 
167
#endif
 
168
#ifndef HAVE_STRNCASECMP
 
169
int strncasecmp ();
 
170
#endif
 
171
#ifndef HAVE_STRSTR
 
172
char *strstr ();
 
173
#endif
 
174
#ifndef HAVE_STRPTIME
 
175
char *strptime ();
 
176
#endif
 
177
#ifndef HAVE_SNPRINTF
 
178
int snprintf ();
 
179
#endif
 
180
#ifndef HAVE_VSNPRINTF
 
181
int vsnprintf ();
 
182
#endif
 
183
#ifndef HAVE_USLEEP
 
184
int usleep PARAMS ((unsigned long));
 
185
#endif
 
186
#ifndef HAVE_MEMMOVE
 
187
void *memmove ();
 
188
#endif
 
189
 
 
190
/* SunOS brain damage -- for some reason, SunOS header files fail to
 
191
   declare the functions below, which causes all kinds of problems,
 
192
   most notably compilation errors when using pointer arithmetic on
 
193
   their return values.
 
194
 
 
195
   This used to be only within `#ifdef STDC_HEADERS', but it got
 
196
   tripped on other systems (AIX), thus causing havoc.  Fortunately,
 
197
   SunOS appears to be the only system braindamaged that badly, so I
 
198
   added an extra `#ifdef sun' guard.  */
 
199
#ifndef STDC_HEADERS
 
200
#ifdef sun
 
201
#ifndef __SVR4                  /* exclude Solaris */
 
202
char *strstr ();
 
203
char *strchr ();
 
204
char *strrchr ();
 
205
char *strtok ();
 
206
char *strdup ();
 
207
void *memcpy ();
 
208
#endif /* not __SVR4 */
 
209
#endif /* sun */
 
210
#endif /* not STDC_HEADERS */
 
211
 
 
212
/* Some systems (Linux libc5, "NCR MP-RAS 3.0", and others) don't
 
213
   provide MAP_FAILED, a symbolic constant for the value returned by
 
214
   mmap() when it doesn't work.  Usually, this constant should be -1.
 
215
   This only makes sense for files that use mmap() and include
 
216
   sys/mman.h *before* sysdep.h, but doesn't hurt others.  */
 
217
 
 
218
#ifndef MAP_FAILED
 
219
# define MAP_FAILED ((void *) -1)
 
220
#endif
 
221
 
 
222
/* Enable system fnmatch only on systems where fnmatch.h is usable and
 
223
   which are known to have a non-broken fnmatch implementation.
 
224
   Currently those include glibc-based systems and Solaris.  One could
 
225
   add more, but fnmatch is not that large, so it might be better to
 
226
   play it safe.  */
 
227
#ifdef HAVE_WORKING_FNMATCH_H
 
228
# if defined __GLIBC__ && __GLIBC__ >= 2
 
229
#  define SYSTEM_FNMATCH
 
230
# endif
 
231
# ifdef solaris
 
232
#  define SYSTEM_FNMATCH
 
233
# endif
 
234
#endif /* HAVE_FNMATCH_H */
 
235
 
 
236
#ifdef SYSTEM_FNMATCH
 
237
# include <fnmatch.h>
 
238
#else  /* not SYSTEM_FNMATCH */
 
239
/* Define fnmatch flags.  Undef them first to avoid warnings in case
 
240
   an evil library include chose to include system fnmatch.h.  */
 
241
# undef FNM_PATHNAME
 
242
# undef FNM_NOESCAPE
 
243
# undef FNM_PERIOD
 
244
# undef FNM_NOMATCH
 
245
 
 
246
# define FNM_PATHNAME   (1 << 0) /* No wildcard can ever match `/'.  */
 
247
# define FNM_NOESCAPE   (1 << 1) /* Backslashes don't quote special chars.  */
 
248
# define FNM_PERIOD     (1 << 2) /* Leading `.' is matched only explicitly.  */
 
249
# define FNM_NOMATCH    1
 
250
 
 
251
/* Declare the function minimally. */
 
252
int fnmatch ();
 
253
#endif
 
254
 
 
255
/* Provide uint32_t on the platforms that don't define it.  Although
 
256
   most code should be agnostic about integer sizes, some code really
 
257
   does need a 32-bit integral type.  Such code should use uint32_t.
 
258
   (The exception is gnu-md5.[ch], which uses its own detection for
 
259
   portability across platforms.)  */
 
260
 
 
261
#ifndef HAVE_UINT32_T
 
262
# if SIZEOF_INT == 4
 
263
typedef unsigned int uint32_t;
 
264
# else
 
265
#  if SIZEOF_LONG == 4
 
266
typedef unsigned long uint32_t;
 
267
#  else
 
268
#   if SIZEOF_SHORT == 4
 
269
typedef unsigned short uint32_t;
 
270
#   else
 
271
 #error "Cannot determine a 32-bit unsigned integer type"
 
272
#   endif
 
273
#  endif
 
274
# endif
 
275
#endif
 
276
 
 
277
#endif /* SYSDEP_H */