1 /* Declarations for windows
2 Copyright (C) 1996-2005 Free Software Foundation, Inc.
4 This file is part of GNU Wget.
6 GNU Wget 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.
11 GNU Wget 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.
16 You should have received a copy of the GNU General Public License
17 along with Wget; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 In addition, as a special exception, the Free Software Foundation
21 gives permission to link the code of its release of Wget with the
22 OpenSSL project's "OpenSSL" library (or with modified versions of it
23 that use the same license as the "OpenSSL" library), and distribute
24 the linked executables. You must obey the GNU General Public License
25 in all respects for all of the code used other than "OpenSSL". If you
26 modify this file, you may extend this exception to your version of the
27 file, but you are not obligated to do so. If you do not wish to do
28 so, delete this exception statement from your version. */
34 # error This file should not be included directly.
37 /* Prevent inclusion of <winsock*.h> in <windows.h>. */
38 #ifndef WIN32_LEAN_AND_MEAN
39 # define WIN32_LEAN_AND_MEAN
44 /* We need winsock2.h for IPv6 and ws2tcpip.h for getaddrinfo, so
45 include both in ENABLE_IPV6 case. (ws2tcpip.h includes winsock2.h
48 # include <winsock2.h>
49 # include <ws2tcpip.h>
55 # define EAI_SYSTEM -1 /* value doesn't matter */
58 /* Declares file access functions, such as open, creat, access, and
59 chmod. Unix declares these in unistd.h and fcntl.h. */
63 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
69 /* We have strcasecmp and strncasecmp, just under a different name. */
70 #define strcasecmp stricmp
71 #define strncasecmp strnicmp
73 /* The same for snprintf() and vsnprintf(). */
74 #define snprintf _snprintf
75 #define vsnprintf _vsnprintf
77 /* Define a wgint type under Windows. */
78 typedef __int64 wgint;
79 #define SIZEOF_WGINT 8
82 #define WGINT_MAX 9223372036854775807LL
84 #define WGINT_MAX 9223372036854775807I64
87 /* str_to_wgint is a function with the semantics of strtol, but which
88 works on wgint. Since wgint is unconditionally 64-bit on Windows,
89 we #define it to str_to_int64, which either calls _strtoi64 or
90 implements the conversion manually. */
91 #define str_to_wgint str_to_int64
92 __int64 str_to_int64 (const char *, char **, int);
94 /* Windows has no symlink, therefore no lstat. Without symlinks lstat
95 is equivalent to stat anyway. */
98 /* Transparently support statting large files, like POSIX's LFS API
99 does. All Windows compilers we support use _stati64 (but have
100 different names for 2nd argument type, see below), so we use
102 #define stat(fname, buf) _stati64 (fname, buf)
104 /* On Windows the 64-bit stat requires an explicitly different type
105 for the 2nd argument, so we define a struct_stat macro that expands
106 to the appropriate type on Windows, and to the regular struct stat
109 Note that Borland C 5.5 has 64-bit stat (_stati64), but not a
110 64-bit fstat! Because of that we also need a struct_fstat that
111 points to struct_stat on Unix and on Windows, except under Borland,
112 where it points to the 32-bit struct stat. */
115 # define fstat(fd, buf) _fstati64 (fd, buf)
116 # define struct_stat struct _stati64
117 # define struct_fstat struct _stati64
118 #else /* __BORLANDC__ */
119 # define struct_stat struct stati64
120 # define struct_fstat struct stat
121 #endif /* __BORLANDC__ */
123 #define PATH_SEPARATOR '\\'
127 # define isatty _isatty
131 /* Win32 doesn't support the MODE argument to mkdir. */
132 #define mkdir(a, b) _mkdir(a)
134 /* Additional declarations needed for IPv6: */
136 const char *inet_ntop (int, const void *, char *, socklen_t);
137 /* MinGW 3.7 (or older) prototypes gai_strerror(), but is missing
138 from all import libraries. */
141 # define gai_strerror windows_strerror
143 #endif /* ENABLE_IPV6 */
147 /* Winsock functions don't set errno, so we provide wrappers that do. */
149 #define socket wrapped_socket
150 #define bind wrapped_bind
151 #define connect wrapped_connect
152 #define recv wrapped_recv
153 #define send wrapped_send
154 #define select wrapped_select
155 #define getsockname wrapped_getsockname
156 #define getpeername wrapped_getpeername
157 #define setsockopt wrapped_setsockopt
158 #define closesocket wrapped_closesocket
160 #endif /* not INHIBIT_WRAP */
162 int wrapped_socket (int, int, int);
163 int wrapped_bind (int, struct sockaddr *, int);
164 int wrapped_connect (int, const struct sockaddr *, int);
165 int wrapped_recv (int, void *, int, int);
166 int wrapped_send (int, const void *, int, int);
167 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
168 int wrapped_getsockname (int, struct sockaddr *, int *);
169 int wrapped_getpeername (int, struct sockaddr *, int *);
170 int wrapped_setsockopt (int, int, int, const void *, int);
171 int wrapped_closesocket (int);
173 /* Finally, provide a private version of strerror that does the
174 right thing with Winsock errors. */
176 # define strerror windows_strerror
178 const char *windows_strerror (int);
180 /* Declarations of various socket errors: */
182 #define EWOULDBLOCK WSAEWOULDBLOCK
183 #define EINPROGRESS WSAEINPROGRESS
184 #define EALREADY WSAEALREADY
185 #define ENOTSOCK WSAENOTSOCK
186 #define EDESTADDRREQ WSAEDESTADDRREQ
187 #define EMSGSIZE WSAEMSGSIZE
188 #define EPROTOTYPE WSAEPROTOTYPE
189 #define ENOPROTOOPT WSAENOPROTOOPT
190 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
191 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
192 #define EOPNOTSUPP WSAEOPNOTSUPP
193 #define EPFNOSUPPORT WSAEPFNOSUPPORT
194 #define EAFNOSUPPORT WSAEAFNOSUPPORT
195 #define EADDRINUSE WSAEADDRINUSE
196 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
197 #define ENETDOWN WSAENETDOWN
198 #define ENETUNREACH WSAENETUNREACH
199 #define ENETRESET WSAENETRESET
200 #define ECONNABORTED WSAECONNABORTED
201 #define ECONNRESET WSAECONNRESET
202 #define ENOBUFS WSAENOBUFS
203 #define EISCONN WSAEISCONN
204 #define ENOTCONN WSAENOTCONN
205 #define ESHUTDOWN WSAESHUTDOWN
206 #define ETOOMANYREFS WSAETOOMANYREFS
207 #define ETIMEDOUT WSAETIMEDOUT
208 #define ECONNREFUSED WSAECONNREFUSED
209 #define ELOOP WSAELOOP
210 #define EHOSTDOWN WSAEHOSTDOWN
211 #define EHOSTUNREACH WSAEHOSTUNREACH
212 #define EPROCLIM WSAEPROCLIM
213 #define EUSERS WSAEUSERS
214 #define EDQUOT WSAEDQUOT
215 #define ESTALE WSAESTALE
216 #define EREMOTE WSAEREMOTE
218 /* Public functions. */
220 void ws_startup (void);
221 void ws_changetitle (const char *);
222 void ws_percenttitle (double);
223 char *ws_mypath (void);
224 void windows_main (int *, char **, char **);
226 #endif /* MSWINDOWS_H */