1 | /* Declarations for windows
|
---|
2 | Copyright (C) 1995, 1997, 1997, 1998, 2004
|
---|
3 | Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | This file is part of GNU Wget.
|
---|
6 |
|
---|
7 | GNU Wget is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | GNU Wget is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with Wget; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
20 |
|
---|
21 | In addition, as a special exception, the Free Software Foundation
|
---|
22 | gives permission to link the code of its release of Wget with the
|
---|
23 | OpenSSL project's "OpenSSL" library (or with modified versions of it
|
---|
24 | that use the same license as the "OpenSSL" library), and distribute
|
---|
25 | the linked executables. You must obey the GNU General Public License
|
---|
26 | in all respects for all of the code used other than "OpenSSL". If you
|
---|
27 | modify this file, you may extend this exception to your version of the
|
---|
28 | file, but you are not obligated to do so. If you do not wish to do
|
---|
29 | so, delete this exception statement from your version. */
|
---|
30 |
|
---|
31 | #ifndef MSWINDOWS_H
|
---|
32 | #define MSWINDOWS_H
|
---|
33 |
|
---|
34 | #ifndef WGET_H
|
---|
35 | #error Include mswindows.h inside or after "wget.h"
|
---|
36 | #endif
|
---|
37 |
|
---|
38 | /* Prevent inclusion of <winsock*.h> in <windows.h>. */
|
---|
39 | #ifndef WIN32_LEAN_AND_MEAN
|
---|
40 | #define WIN32_LEAN_AND_MEAN
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <windows.h>
|
---|
44 |
|
---|
45 | /* Use the correct winsock header; <ws2tcpip.h> includes <winsock2.h> only
|
---|
46 | on Watcom/MingW. We cannot use <winsock.h> for IPv6. Using
|
---|
47 | getaddrinfo() requires <ws2tcpip.h>. */
|
---|
48 | #if defined(ENABLE_IPV6) || defined(HAVE_GETADDRINFO)
|
---|
49 | # include <winsock2.h>
|
---|
50 | # include <ws2tcpip.h>
|
---|
51 | #else
|
---|
52 | # include <winsock.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | #ifndef EAI_SYSTEM
|
---|
56 | # define EAI_SYSTEM -1 /* value doesn't matter */
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | /* Must include <sys/stat.h> because of 'stat' define below. */
|
---|
60 | #include <sys/stat.h>
|
---|
61 |
|
---|
62 | /* Missing in several .c files. Include here. */
|
---|
63 | #include <io.h>
|
---|
64 |
|
---|
65 | /* Apparently needed for alloca(). */
|
---|
66 | #include <malloc.h>
|
---|
67 |
|
---|
68 | #ifndef S_ISDIR
|
---|
69 | # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
|
---|
70 | #endif
|
---|
71 | #ifndef S_ISLNK
|
---|
72 | # define S_ISLNK(a) 0
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | /* We have strcasecmp and strncasecmp, just under a different name. */
|
---|
76 | #define strcasecmp stricmp
|
---|
77 | #define strncasecmp strnicmp
|
---|
78 |
|
---|
79 | /* The same for snprintf() and vsnprintf(). */
|
---|
80 | #define snprintf _snprintf
|
---|
81 | #define vsnprintf _vsnprintf
|
---|
82 |
|
---|
83 | /* Define a wgint type under Windows. */
|
---|
84 | typedef __int64 wgint;
|
---|
85 | #define SIZEOF_WGINT 8
|
---|
86 |
|
---|
87 | #ifdef __GNUC__
|
---|
88 | #define WGINT_MAX 9223372036854775807LL
|
---|
89 | #else
|
---|
90 | #define WGINT_MAX 9223372036854775807I64
|
---|
91 | #endif
|
---|
92 |
|
---|
93 | #if defined __MINGW32__
|
---|
94 | # define str_to_wgint strtoll
|
---|
95 | #elif defined(_MSC_VER) && _MSC_VER >= 1300 && !defined(__BORLANDC__)
|
---|
96 | # define str_to_wgint _strtoi64
|
---|
97 | #else
|
---|
98 | # define str_to_wgint strtoll
|
---|
99 | # define NEED_STRTOLL
|
---|
100 | # define strtoll_return __int64
|
---|
101 | #endif
|
---|
102 |
|
---|
103 | /* Windows has no symlink, therefore no lstat. Without symlinks lstat
|
---|
104 | is equivalent to stat anyway. */
|
---|
105 | #define lstat stat
|
---|
106 |
|
---|
107 | /* Transparently support statting large files, like POSIX's LFS API
|
---|
108 | does. All Windows compilers we support use _stati64 (but have
|
---|
109 | different names for 2nd argument type, see below), so we use
|
---|
110 | that. */
|
---|
111 | #define stat(fname, buf) _stati64 (fname, buf)
|
---|
112 |
|
---|
113 | /* On Windows the 64-bit stat requires an explicitly different type
|
---|
114 | for the 2nd argument, so we define a struct_stat macro that expands
|
---|
115 | to the appropriate type on Windows, and to the regular struct stat
|
---|
116 | on Unix.
|
---|
117 |
|
---|
118 | Note that Borland C 5.5 has 64-bit stat (_stati64), but not a
|
---|
119 | 64-bit fstat! Because of that we also need a struct_fstat that
|
---|
120 | points to struct_stat on Unix and on Windows, except under Borland,
|
---|
121 | where it points to the 32-bit struct stat. */
|
---|
122 |
|
---|
123 | #ifndef __BORLANDC__
|
---|
124 | # define fstat(fd, buf) _fstati64 (fd, buf)
|
---|
125 | # define struct_stat struct _stati64
|
---|
126 | # define struct_fstat struct _stati64
|
---|
127 | #else /* __BORLANDC__ */
|
---|
128 | # define struct_stat struct stati64
|
---|
129 | # define struct_fstat struct stat
|
---|
130 | #endif /* __BORLANDC__ */
|
---|
131 |
|
---|
132 | #define PATH_SEPARATOR '\\'
|
---|
133 |
|
---|
134 | #ifdef HAVE_ISATTY
|
---|
135 | #ifdef _MSC_VER
|
---|
136 | # define isatty _isatty
|
---|
137 | #endif
|
---|
138 | #endif
|
---|
139 |
|
---|
140 | /* #### Do we need this? */
|
---|
141 | #include <direct.h>
|
---|
142 |
|
---|
143 | /* Windows compilers accept only one arg to mkdir. */
|
---|
144 | #define mkdir(a, b) _mkdir(a)
|
---|
145 |
|
---|
146 | #ifndef INHIBIT_WRAP
|
---|
147 |
|
---|
148 | /* Winsock functions don't set errno, so we provide wrappers
|
---|
149 | that do. */
|
---|
150 |
|
---|
151 | #define socket wrapped_socket
|
---|
152 | #define bind wrapped_bind
|
---|
153 | #define connect wrapped_connect
|
---|
154 | #define listen wrapped_listen
|
---|
155 | #define accept wrapped_accept
|
---|
156 | #define recv wrapped_recv
|
---|
157 | #define send wrapped_send
|
---|
158 | #define select wrapped_select
|
---|
159 | #define getsockname wrapped_getsockname
|
---|
160 | #define getpeername wrapped_getpeername
|
---|
161 | #define setsockopt wrapped_setsockopt
|
---|
162 | #define closesocket wrapped_closesocket
|
---|
163 |
|
---|
164 | #endif /* not INHIBIT_WRAP */
|
---|
165 |
|
---|
166 | int wrapped_socket (int, int, int);
|
---|
167 | int wrapped_bind (int, struct sockaddr *, int);
|
---|
168 | int wrapped_connect (int, const struct sockaddr *, int);
|
---|
169 | int wrapped_listen (int s, int backlog);
|
---|
170 | int wrapped_accept (int s, struct sockaddr *a, int *alen);
|
---|
171 | int wrapped_recv (int, void *, int, int);
|
---|
172 | int wrapped_send (int, const void *, int, int);
|
---|
173 | int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
|
---|
174 | int wrapped_getsockname (int, struct sockaddr *, int *);
|
---|
175 | int wrapped_getpeername (int, struct sockaddr *, int *);
|
---|
176 | int wrapped_setsockopt (int, int, int, const void *, int);
|
---|
177 | int wrapped_closesocket (int);
|
---|
178 |
|
---|
179 | /* Finally, provide a private version of strerror that does the
|
---|
180 | right thing with Winsock errors. */
|
---|
181 | #ifndef INHIBIT_WRAP
|
---|
182 | # define strerror windows_strerror
|
---|
183 | #endif
|
---|
184 | const char *windows_strerror (int);
|
---|
185 |
|
---|
186 | /* MingW 3.7 (or older) prototypes gai_strerror(), but is missing
|
---|
187 | from all import libraries. */
|
---|
188 | #if defined(__MINGW32__) && defined(ENABLE_IPV6)
|
---|
189 | # undef gai_strerror
|
---|
190 | # define gai_strerror windows_strerror
|
---|
191 | #endif
|
---|
192 |
|
---|
193 | /* Declarations of various socket errors: */
|
---|
194 |
|
---|
195 | #define EWOULDBLOCK WSAEWOULDBLOCK
|
---|
196 | #define EINPROGRESS WSAEINPROGRESS
|
---|
197 | #define EALREADY WSAEALREADY
|
---|
198 | #define ENOTSOCK WSAENOTSOCK
|
---|
199 | #define EDESTADDRREQ WSAEDESTADDRREQ
|
---|
200 | #define EMSGSIZE WSAEMSGSIZE
|
---|
201 | #define EPROTOTYPE WSAEPROTOTYPE
|
---|
202 | #define ENOPROTOOPT WSAENOPROTOOPT
|
---|
203 | #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
|
---|
204 | #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
|
---|
205 | #define EOPNOTSUPP WSAEOPNOTSUPP
|
---|
206 | #define EPFNOSUPPORT WSAEPFNOSUPPORT
|
---|
207 | #define EAFNOSUPPORT WSAEAFNOSUPPORT
|
---|
208 | #define EADDRINUSE WSAEADDRINUSE
|
---|
209 | #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
|
---|
210 | #define ENETDOWN WSAENETDOWN
|
---|
211 | #define ENETUNREACH WSAENETUNREACH
|
---|
212 | #define ENETRESET WSAENETRESET
|
---|
213 | #define ECONNABORTED WSAECONNABORTED
|
---|
214 | #define ECONNRESET WSAECONNRESET
|
---|
215 | #define ENOBUFS WSAENOBUFS
|
---|
216 | #define EISCONN WSAEISCONN
|
---|
217 | #define ENOTCONN WSAENOTCONN
|
---|
218 | #define ESHUTDOWN WSAESHUTDOWN
|
---|
219 | #define ETOOMANYREFS WSAETOOMANYREFS
|
---|
220 | #define ETIMEDOUT WSAETIMEDOUT
|
---|
221 | #define ECONNREFUSED WSAECONNREFUSED
|
---|
222 | #define ELOOP WSAELOOP
|
---|
223 | #define EHOSTDOWN WSAEHOSTDOWN
|
---|
224 | #define EHOSTUNREACH WSAEHOSTUNREACH
|
---|
225 | #define EPROCLIM WSAEPROCLIM
|
---|
226 | #define EUSERS WSAEUSERS
|
---|
227 | #define EDQUOT WSAEDQUOT
|
---|
228 | #define ESTALE WSAESTALE
|
---|
229 | #define EREMOTE WSAEREMOTE
|
---|
230 |
|
---|
231 | /* Public functions. */
|
---|
232 |
|
---|
233 | void ws_startup (void);
|
---|
234 | void ws_changetitle (const char *);
|
---|
235 | void ws_percenttitle (double);
|
---|
236 | char *ws_mypath (void);
|
---|
237 | void windows_main (int *, char **, char **);
|
---|
238 |
|
---|
239 | /* Things needed for IPv6; missing in <ws2tcpip.h>. */
|
---|
240 | #ifdef ENABLE_IPV6
|
---|
241 | # ifndef HAVE_INET_NTOP
|
---|
242 | extern const char *inet_ntop (int af, const void *src, char *dst, size_t size);
|
---|
243 | # endif
|
---|
244 | #endif /* ENABLE_IPV6 */
|
---|
245 |
|
---|
246 | #endif /* MSWINDOWS_H */
|
---|