]> sjero.net Git - wget/blob - src/sysdep.h
[svn] Remove VERY_LONG_FORMAT. Instead, define function very_long_to_string
[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 (at
9 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 /* Watcom-specific stuff.  In practice this is probably specific to
49    Windows, although Watcom exists under other OS's too.  For that
50    reason, we keep this here.  */
51
52 #ifdef __WATCOMC__
53 /* Watcom has its own alloca() defined in malloc.h malloc.h needs to
54    be included in the sources to prevent 'undefined external' errors
55    at the link phase. */
56 # include <malloc.h>
57 /* io.h defines unlink() and chmod().  We put this here because it's
58    way too obscure to require all the .c files to observe.  */
59 # include <io.h>
60 #endif /* __WATCOMC__ */
61
62 /* Needed for compilation under OS/2: */
63 #ifdef __EMX__
64 #ifndef S_ISLNK
65 # define S_ISLNK(m) 0
66 #endif
67 #ifndef lstat
68 # define lstat stat
69 #endif
70 #endif /* __EMX__ */
71
72 /* Reportedly, stat() macros are broken on some old systems.  Those
73    systems will have to fend for themselves, as I will not introduce
74    new code to handle it.
75
76    However, I will add code for *missing* macros, and the following
77    are missing from many systems.  */
78 #ifndef S_ISLNK
79 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
80 #endif
81 #ifndef S_ISDIR
82 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
83 #endif
84 #ifndef S_ISREG
85 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
86 #endif
87
88 /* Bletch!  SPARC compiler doesn't define sparc (needed by
89    arpa/nameser.h) when in -Xc mode.  Luckily, it always defines
90    __sparc.  */
91 #ifdef __sparc
92 #ifndef sparc
93 #define sparc
94 #endif
95 #endif
96
97 /* mswindows.h defines these.  */
98 #ifndef READ
99 # define READ(fd, buf, cnt) read ((fd), (buf), (cnt))
100 #endif
101 #ifndef WRITE
102 # define WRITE(fd, buf, cnt) write ((fd), (buf), (cnt))
103 #endif
104 #ifndef REALCLOSE
105 # define REALCLOSE(x) close (x)
106 #endif
107
108 #define CLOSE(x)                                \
109 do {                                            \
110   REALCLOSE (x);                                \
111   DEBUGP (("Closing fd %d\n", x));              \
112 } while (0)
113
114 /* Define a large ("very long") type useful for storing large
115    non-negative quantities that exceed sizes of normal download, such
116    as the *total* number of bytes downloaded.  To fit today's needs,
117    this needs to be an integral type at least 64 bits wide.  On the
118    machines where `long' is 64-bit, we use long.  Otherwise, we check
119    whether `long long' is available and if yes, use that.  If long
120    long is unavailable, we give up and just use `long'.
121
122    This check could be smarter and moved to configure, which could
123    check for a bunch of non-standard types such as uint64_t.  But I
124    don't see the need for it -- the current test will work on all
125    modern architectures, and if it fails, nothing bad happens, we just
126    end up with long.
127
128    Note: you cannot use VERY_LONG_TYPE along with printf().  When you
129    need to print it, use very_long_to_string().  */
130
131 #if (SIZEOF_LONG >= 8) || !defined(HAVE_LONG_LONG)
132 /* either long is "big enough", or long long is unavailable which
133    leaves long as the only choice. */ 
134 # define VERY_LONG_TYPE   unsigned long
135 #else  /* use long long */
136 /* long is smaller than 8 bytes, but long long is available. */
137 # define VERY_LONG_TYPE   unsigned long long
138 #endif /* use long long */
139
140 /* Defined in cmpt.c: */
141 #ifndef HAVE_STRERROR
142 char *strerror ();
143 #endif
144 #ifndef HAVE_STRCASECMP
145 int strcasecmp ();
146 #endif
147 #ifndef HAVE_STRNCASECMP
148 int strncasecmp ();
149 #endif
150 #ifndef HAVE_STRSTR
151 char *strstr ();
152 #endif
153 #ifndef HAVE_STRPTIME
154 char *strptime ();
155 #endif
156 #ifndef HAVE_VSNPRINTF
157 int vsnprintf ();
158 #endif
159
160 /* SunOS brain damage -- for some reason, SunOS header files fail to
161    declare the functions below, which causes all kinds of problems
162    (compiling errors) with pointer arithmetic and similar.
163
164    This used to be only within `#ifdef STDC_HEADERS', but it got
165    tripped on other systems (AIX), thus causing havoc.  Fortunately,
166    SunOS appears to be the only system braindamaged that badly, so I
167    added an extra `#ifdef sun' guard.  */
168 #ifndef STDC_HEADERS
169 #ifdef sun
170 #ifndef __cplusplus
171 char *strstr ();
172 char *strchr ();
173 char *strrchr ();
174 char *strtok ();
175 char *strdup ();
176 void *memcpy ();
177 #endif /* not __cplusplus */
178 #endif /* sun */
179 #endif /* STDC_HEADERS */
180
181 #endif /* SYSDEP_H */