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 This file should not be included directly.
38 /* Prevent inclusion of <winsock*.h> in <windows.h>. */
39 #ifndef WIN32_LEAN_AND_MEAN
40 # define WIN32_LEAN_AND_MEAN
45 /* We need winsock2.h for IPv6 and ws2tcpip.h for getaddrinfo, so
46 include both in ENABLE_IPV6 case. (ws2tcpip.h includes winsock2.h
49 # include <winsock2.h>
50 # include <ws2tcpip.h>
56 # define EAI_SYSTEM -1 /* value doesn't matter */
59 /* Declares file access functions, such as open, creat, access, and
60 chmod. Unix declares these in unistd.h and fcntl.h. */
64 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
70 /* We have strcasecmp and strncasecmp, just under a different name. */
71 #define strcasecmp stricmp
72 #define strncasecmp strnicmp
74 /* The same for snprintf() and vsnprintf(). */
75 #define snprintf _snprintf
76 #define vsnprintf _vsnprintf
78 /* Define a wgint type under Windows. */
79 typedef __int64 wgint;
80 #define SIZEOF_WGINT 8
83 #define WGINT_MAX 9223372036854775807LL
85 #define WGINT_MAX 9223372036854775807I64
88 /* str_to_wgint is a function with the semantics of strtol, but which
89 works on wgint. Since wgint is unconditionally 64-bit on Windows,
90 we #define it to str_to_int64, which either calls _strtoi64 or
91 implements the conversion manually. */
92 #define str_to_wgint str_to_int64
93 __int64 str_to_int64 (const char *, char **, int);
95 /* Windows has no symlink, therefore no lstat. Without symlinks lstat
96 is equivalent to stat anyway. */
99 /* Transparently support statting large files, like POSIX's LFS API
100 does. All Windows compilers we support use _stati64 (but have
101 different names for 2nd argument type, see below), so we use
103 #define stat(fname, buf) _stati64 (fname, buf)
105 /* On Windows the 64-bit stat requires an explicitly different type
106 for the 2nd argument, so we define a struct_stat macro that expands
107 to the appropriate type on Windows, and to the regular struct stat
110 Note that Borland C 5.5 has 64-bit stat (_stati64), but not a
111 64-bit fstat! Because of that we also need a struct_fstat that
112 points to struct_stat on Unix and on Windows, except under Borland,
113 where it points to the 32-bit struct stat. */
116 # define fstat(fd, buf) _fstati64 (fd, buf)
117 # define struct_stat struct _stati64
118 # define struct_fstat struct _stati64
119 #else /* __BORLANDC__ */
120 # define struct_stat struct stati64
121 # define struct_fstat struct stat
122 #endif /* __BORLANDC__ */
124 #define PATH_SEPARATOR '\\'
128 # define isatty _isatty
132 /* Win32 doesn't support the MODE argument to mkdir. */
133 #define mkdir(a, b) _mkdir(a)
135 /* Additional declarations needed for IPv6: */
137 /* Missing declaration? */
138 extern const char *inet_ntop (int, const void *, char *, size_t);
139 /* MinGW 3.7 (or older) prototypes gai_strerror(), but is missing
140 from all import libraries. */
143 # define gai_strerror windows_strerror
145 #endif /* ENABLE_IPV6 */
149 /* Winsock functions don't set errno, so we provide wrappers that do. */
151 #define socket wrapped_socket
152 #define bind wrapped_bind
153 #define connect wrapped_connect
154 #define recv wrapped_recv
155 #define send wrapped_send
156 #define select wrapped_select
157 #define getsockname wrapped_getsockname
158 #define getpeername wrapped_getpeername
159 #define setsockopt wrapped_setsockopt
160 #define closesocket wrapped_closesocket
162 #endif /* not INHIBIT_WRAP */
164 int wrapped_socket (int, int, int);
165 int wrapped_bind (int, struct sockaddr *, int);
166 int wrapped_connect (int, const struct sockaddr *, int);
167 int wrapped_recv (int, void *, int, int);
168 int wrapped_send (int, const void *, int, int);
169 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
170 int wrapped_getsockname (int, struct sockaddr *, int *);
171 int wrapped_getpeername (int, struct sockaddr *, int *);
172 int wrapped_setsockopt (int, int, int, const void *, int);
173 int wrapped_closesocket (int);
175 /* Finally, provide a private version of strerror that does the
176 right thing with Winsock errors. */
178 # define strerror windows_strerror
180 const char *windows_strerror (int);
182 /* Declarations of various socket errors: */
184 #define EWOULDBLOCK WSAEWOULDBLOCK
185 #define EINPROGRESS WSAEINPROGRESS
186 #define EALREADY WSAEALREADY
187 #define ENOTSOCK WSAENOTSOCK
188 #define EDESTADDRREQ WSAEDESTADDRREQ
189 #define EMSGSIZE WSAEMSGSIZE
190 #define EPROTOTYPE WSAEPROTOTYPE
191 #define ENOPROTOOPT WSAENOPROTOOPT
192 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
193 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
194 #define EOPNOTSUPP WSAEOPNOTSUPP
195 #define EPFNOSUPPORT WSAEPFNOSUPPORT
196 #define EAFNOSUPPORT WSAEAFNOSUPPORT
197 #define EADDRINUSE WSAEADDRINUSE
198 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
199 #define ENETDOWN WSAENETDOWN
200 #define ENETUNREACH WSAENETUNREACH
201 #define ENETRESET WSAENETRESET
202 #define ECONNABORTED WSAECONNABORTED
203 #define ECONNRESET WSAECONNRESET
204 #define ENOBUFS WSAENOBUFS
205 #define EISCONN WSAEISCONN
206 #define ENOTCONN WSAENOTCONN
207 #define ESHUTDOWN WSAESHUTDOWN
208 #define ETOOMANYREFS WSAETOOMANYREFS
209 #define ETIMEDOUT WSAETIMEDOUT
210 #define ECONNREFUSED WSAECONNREFUSED
211 #define ELOOP WSAELOOP
212 #define EHOSTDOWN WSAEHOSTDOWN
213 #define EHOSTUNREACH WSAEHOSTUNREACH
214 #define EPROCLIM WSAEPROCLIM
215 #define EUSERS WSAEUSERS
216 #define EDQUOT WSAEDQUOT
217 #define ESTALE WSAESTALE
218 #define EREMOTE WSAEREMOTE
220 /* Public functions. */
222 void ws_startup (void);
223 void ws_changetitle (const char *);
224 void ws_percenttitle (double);
225 char *ws_mypath (void);
226 void windows_main (int *, char **, char **);
228 #endif /* MSWINDOWS_H */