]> sjero.net Git - wget/blob - src/sysdep.h
[svn] snprintf.c addition.
[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 Wget.
5
6 This program 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
9 (at your option) any later version.
10
11 This program 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 this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 /* This file is included by wget.h.  Random .c files need not include
21    it.  */
22
23 #ifndef SYSDEP_H
24 #define SYSDEP_H
25
26 /* We need these to be playing with various stuff.  */
27 #ifdef TIME_WITH_SYS_TIME
28 # include <sys/time.h>
29 # include <time.h>
30 #else /* not TIME_WITH_SYS_TIME_H */
31 #ifdef HAVE_SYS_TIME_H
32 # include <sys/time.h>
33 #else /* not HAVE_SYS_TIME_H */
34 # include <time.h>
35 #endif /* HAVE_SYS_TIME_H */
36 #endif /* TIME_WITH_SYS_TIME_H */
37
38 #include <sys/types.h>
39 #include <sys/stat.h>
40
41 #ifdef WINDOWS
42 /* Windows doesn't have some functions.  Include mswindows.h so we get
43    their declarations, as well as some additional declarations and
44    macros.  This must come first, so it can set things up.  */
45 #include <mswindows.h>
46 #endif /* WINDOWS */
47
48 /* Allegedly needed for compilation under OS/2: */
49 #ifdef EMXOS2
50 #ifndef S_ISLNK
51 # define S_ISLNK(m) 0
52 #endif
53 #ifndef lstat
54 # define lstat stat
55 #endif
56 #endif /* EMXOS2 */
57
58 /* Reportedly, stat() macros are broken on some old systems.  Those
59    systems will have to fend for themselves, as I will not introduce
60    new code to handle it.
61
62    However, I will add code for *missing* macros, and the following
63    are missing from many systems.  */
64 #ifndef S_ISLNK
65 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
66 #endif
67 #ifndef S_ISDIR
68 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
69 #endif
70 #ifndef S_ISREG
71 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
72 #endif
73
74 /* Bletch!  SPARC compiler doesn't define sparc (needed by
75    arpa/nameser.h) when in -Xc mode.  Luckily, it always defines
76    __sparc.  */
77 #ifdef __sparc
78 #ifndef sparc
79 #define sparc
80 #endif
81 #endif
82
83 /* mswindows.h defines these.  */
84 #ifndef READ
85 # define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
86 #endif
87 #ifndef WRITE
88 # define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
89 #endif
90 #ifndef REALCLOSE
91 # define REALCLOSE(x) close (x)
92 #endif
93
94 #define CLOSE(x)                                \
95 do {                                            \
96   REALCLOSE (x);                                \
97   DEBUGP (("Closing fd %d\n", x));              \
98 } while (0)
99
100 /* Define a "very long" type useful for storing large non-negative
101    integers, e.g. the total number of bytes downloaded.  This needs to
102    be an integral type at least 64 bits wide.  On the machines where
103    `long' is 64-bit, we use long.  Otherwise, we check whether `long
104    long' is available and if yes, use that.  Otherwise, we give up and
105    just use `long'.  */
106 #if (SIZEOF_LONG >= 8) || !defined(HAVE_LONG_LONG)
107 # define VERY_LONG_TYPE   unsigned long
108 # define VERY_LONG_FORMAT "%lu"
109 #else  /* long is smaller than 8 bytes, but long long is available. */
110 # define VERY_LONG_TYPE   unsigned long long
111 # define VERY_LONG_FORMAT "%llu"
112 #endif /* use long long */
113
114 /* OK, now define a decent interface to ctype macros.  The regular
115    ones misfire when you feed them chars > 127, as they understand
116    them as "negative", which results in out-of-bound access at
117    table-lookup, yielding random results.  This is, of course, totally
118    bogus.  One way to "solve" this is to use `unsigned char'
119    everywhere, but it is nearly impossible to do that cleanly, because
120    all of the library functions and system calls accept `char'.
121
122    Thus we define our wrapper macros which simply cast the argument to
123    unsigned char before passing it to the <ctype.h> macro.  These
124    versions are used consistently across the code.  */
125 #define ISASCII(x)  isascii ((unsigned char)(x))
126 #define ISALPHA(x)  isalpha ((unsigned char)(x))
127 #define ISALNUM(x)  isalnum ((unsigned char)(x))
128 #define ISSPACE(x)  isspace ((unsigned char)(x))
129 #define ISDIGIT(x)  isdigit ((unsigned char)(x))
130 #define ISXDIGIT(x) isxdigit ((unsigned char)(x))
131 #define TOUPPER(x)  toupper ((unsigned char)(x))
132 #define TOLOWER(x)  tolower ((unsigned char)(x))
133
134 /* Defined in cmpt.c: */
135 #ifndef HAVE_STRERROR
136 char *strerror ();
137 #endif
138 #ifndef HAVE_STRCASECMP
139 int strcasecmp ();
140 #endif
141 #ifndef HAVE_STRNCASECMP
142 int strncasecmp ();
143 #endif
144 #ifndef HAVE_STRSTR
145 char *strstr ();
146 #endif
147 #ifndef HAVE_STRPTIME
148 char *strptime ();
149 #endif
150 #ifndef HAVE_VSNPRINTF
151 int vsnprintf ();
152 #endif
153
154 /* SunOS brain damage -- for some reason, SunOS header files fail to
155    declare the functions below, which causes all kinds of problems
156    (compiling errors) with pointer arithmetic and similar.
157
158    This used to be only within `#ifdef STDC_HEADERS', but it got
159    tripped on other systems (AIX), thus causing havoc.  Fortunately,
160    SunOS appears to be the only system braindamaged that badly, so I
161    added an extra `#ifdef sun' guard.  */
162 #ifndef STDC_HEADERS
163 #ifdef sun
164 #ifndef __cplusplus
165 char *strstr ();
166 char *strchr ();
167 char *strrchr ();
168 char *strtok ();
169 char *strdup ();
170 void *memcpy ();
171 #endif /* not __cplusplus */
172 #endif /* sun */
173 #endif /* STDC_HEADERS */
174
175 #endif /* SYSDEP_H */