1 /* Declarations for windows
2 Copyright (C) 1995, 1997, 1997, 1998, 2004
3 Free Software Foundation, Inc.
5 This file is part of GNU Wget.
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.
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.
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.
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. */
35 #error Include mswindows.h inside or after "wget.h"
38 /* Prevent inclusion of <winsock*.h> in <windows.h>. */
39 #ifndef WIN32_LEAN_AND_MEAN
40 #define WIN32_LEAN_AND_MEAN
45 /* Use the correct winsock header; <ws2tcpip.h> includes <winsock2.h>
46 only on 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>
56 # define EAI_SYSTEM -1 /* value doesn't matter */
59 /* Must include <sys/stat.h> because of 'stat' define below. */
62 /* Missing in several .c files. Include here. */
65 /* Apparently needed to get alloca(). */
69 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
75 /* We have strcasecmp and strncasecmp, just under a different name. */
76 #define strcasecmp stricmp
77 #define strncasecmp strnicmp
79 /* The same for snprintf() and vsnprintf(). */
80 #define snprintf _snprintf
81 #define vsnprintf _vsnprintf
83 /* Define a wgint type under Windows. */
84 typedef __int64 wgint;
85 #define SIZEOF_WGINT 8
88 #define WGINT_MAX 9223372036854775807LL
90 #define WGINT_MAX 9223372036854775807I64
93 /* str_to_wgint is a function with the semantics of strtol, but which
94 works on wgint. Since wgint is unconditionally 64-bit on Windows,
95 we #define it to str_to_int64, which either calls _strtoi64 or
96 implements the conversion manually. */
97 #define str_to_wgint str_to_int64
98 __int64 str_to_int64 (const char *, char **, int);
100 /* Windows has no symlink, therefore no lstat. Without symlinks lstat
101 is equivalent to stat anyway. */
104 /* Transparently support statting large files, like POSIX's LFS API
105 does. All Windows compilers we support use _stati64 (but have
106 different names for 2nd argument type, see below), so we use
108 #define stat(fname, buf) _stati64 (fname, buf)
110 /* On Windows the 64-bit stat requires an explicitly different type
111 for the 2nd argument, so we define a struct_stat macro that expands
112 to the appropriate type on Windows, and to the regular struct stat
115 Note that Borland C 5.5 has 64-bit stat (_stati64), but not a
116 64-bit fstat! Because of that we also need a struct_fstat that
117 points to struct_stat on Unix and on Windows, except under Borland,
118 where it points to the 32-bit struct stat. */
121 # define fstat(fd, buf) _fstati64 (fd, buf)
122 # define struct_stat struct _stati64
123 # define struct_fstat struct _stati64
124 #else /* __BORLANDC__ */
125 # define struct_stat struct stati64
126 # define struct_fstat struct stat
127 #endif /* __BORLANDC__ */
129 #define PATH_SEPARATOR '\\'
133 # define isatty _isatty
137 /* #### Do we need this? */
140 /* Windows compilers accept only one arg to mkdir. */
141 #define mkdir(a, b) _mkdir(a)
145 /* Winsock functions don't set errno, so we provide wrappers
148 #define socket wrapped_socket
149 #define bind wrapped_bind
150 #define connect wrapped_connect
151 #define recv wrapped_recv
152 #define send wrapped_send
153 #define select wrapped_select
154 #define getsockname wrapped_getsockname
155 #define getpeername wrapped_getpeername
156 #define setsockopt wrapped_setsockopt
157 #define closesocket wrapped_closesocket
159 #endif /* not INHIBIT_WRAP */
161 int wrapped_socket (int, int, int);
162 int wrapped_bind (int, struct sockaddr *, int);
163 int wrapped_connect (int, const struct sockaddr *, int);
164 int wrapped_recv (int, void *, int, int);
165 int wrapped_send (int, const void *, int, int);
166 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
167 int wrapped_getsockname (int, struct sockaddr *, int *);
168 int wrapped_getpeername (int, struct sockaddr *, int *);
169 int wrapped_setsockopt (int, int, int, const void *, int);
170 int wrapped_closesocket (int);
172 /* Finally, provide a private version of strerror that does the
173 right thing with Winsock errors. */
175 # define strerror windows_strerror
177 const char *windows_strerror (int);
179 /* MingW 3.7 (or older) prototypes gai_strerror(), but is missing
180 from all import libraries. */
181 #if defined(__MINGW32__) && defined(ENABLE_IPV6)
183 # define gai_strerror windows_strerror
186 /* Declarations of various socket errors: */
188 #define EWOULDBLOCK WSAEWOULDBLOCK
189 #define EINPROGRESS WSAEINPROGRESS
190 #define EALREADY WSAEALREADY
191 #define ENOTSOCK WSAENOTSOCK
192 #define EDESTADDRREQ WSAEDESTADDRREQ
193 #define EMSGSIZE WSAEMSGSIZE
194 #define EPROTOTYPE WSAEPROTOTYPE
195 #define ENOPROTOOPT WSAENOPROTOOPT
196 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
197 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
198 #define EOPNOTSUPP WSAEOPNOTSUPP
199 #define EPFNOSUPPORT WSAEPFNOSUPPORT
200 #define EAFNOSUPPORT WSAEAFNOSUPPORT
201 #define EADDRINUSE WSAEADDRINUSE
202 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
203 #define ENETDOWN WSAENETDOWN
204 #define ENETUNREACH WSAENETUNREACH
205 #define ENETRESET WSAENETRESET
206 #define ECONNABORTED WSAECONNABORTED
207 #define ECONNRESET WSAECONNRESET
208 #define ENOBUFS WSAENOBUFS
209 #define EISCONN WSAEISCONN
210 #define ENOTCONN WSAENOTCONN
211 #define ESHUTDOWN WSAESHUTDOWN
212 #define ETOOMANYREFS WSAETOOMANYREFS
213 #define ETIMEDOUT WSAETIMEDOUT
214 #define ECONNREFUSED WSAECONNREFUSED
215 #define ELOOP WSAELOOP
216 #define EHOSTDOWN WSAEHOSTDOWN
217 #define EHOSTUNREACH WSAEHOSTUNREACH
218 #define EPROCLIM WSAEPROCLIM
219 #define EUSERS WSAEUSERS
220 #define EDQUOT WSAEDQUOT
221 #define ESTALE WSAESTALE
222 #define EREMOTE WSAEREMOTE
224 /* Public functions. */
226 void ws_startup (void);
227 void ws_changetitle (const char *);
228 void ws_percenttitle (double);
229 char *ws_mypath (void);
230 void windows_main (int *, char **, char **);
232 /* Things needed for IPv6; missing in <ws2tcpip.h>. */
234 # ifndef HAVE_INET_NTOP
235 extern const char *inet_ntop (int af, const void *src, char *dst, size_t size);
237 #endif /* ENABLE_IPV6 */
239 #endif /* MSWINDOWS_H */