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 listen wrapped_listen
153 #define accept wrapped_accept
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_listen (int s, int backlog);
168 int wrapped_accept (int s, struct sockaddr *a, int *alen);
169 int wrapped_recv (int, void *, int, int);
170 int wrapped_send (int, const void *, int, int);
171 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
172 int wrapped_getsockname (int, struct sockaddr *, int *);
173 int wrapped_getpeername (int, struct sockaddr *, int *);
174 int wrapped_setsockopt (int, int, int, const void *, int);
175 int wrapped_closesocket (int);
177 /* Finally, provide a private version of strerror that does the
178 right thing with Winsock errors. */
180 # define strerror windows_strerror
182 const char *windows_strerror (int);
184 /* Declarations of various socket errors: */
186 #define EWOULDBLOCK WSAEWOULDBLOCK
187 #define EINPROGRESS WSAEINPROGRESS
188 #define EALREADY WSAEALREADY
189 #define ENOTSOCK WSAENOTSOCK
190 #define EDESTADDRREQ WSAEDESTADDRREQ
191 #define EMSGSIZE WSAEMSGSIZE
192 #define EPROTOTYPE WSAEPROTOTYPE
193 #define ENOPROTOOPT WSAENOPROTOOPT
194 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
195 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
196 #define EOPNOTSUPP WSAEOPNOTSUPP
197 #define EPFNOSUPPORT WSAEPFNOSUPPORT
198 #define EAFNOSUPPORT WSAEAFNOSUPPORT
199 #define EADDRINUSE WSAEADDRINUSE
200 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
201 #define ENETDOWN WSAENETDOWN
202 #define ENETUNREACH WSAENETUNREACH
203 #define ENETRESET WSAENETRESET
204 #define ECONNABORTED WSAECONNABORTED
205 #define ECONNRESET WSAECONNRESET
206 #define ENOBUFS WSAENOBUFS
207 #define EISCONN WSAEISCONN
208 #define ENOTCONN WSAENOTCONN
209 #define ESHUTDOWN WSAESHUTDOWN
210 #define ETOOMANYREFS WSAETOOMANYREFS
211 #define ETIMEDOUT WSAETIMEDOUT
212 #define ECONNREFUSED WSAECONNREFUSED
213 #define ELOOP WSAELOOP
214 #define EHOSTDOWN WSAEHOSTDOWN
215 #define EHOSTUNREACH WSAEHOSTUNREACH
216 #define EPROCLIM WSAEPROCLIM
217 #define EUSERS WSAEUSERS
218 #define EDQUOT WSAEDQUOT
219 #define ESTALE WSAESTALE
220 #define EREMOTE WSAEREMOTE
222 /* Public functions. */
224 void ws_startup (void);
225 void ws_changetitle (const char *);
226 void ws_percenttitle (double);
227 char *ws_mypath (void);
228 void windows_main (int *, char **, char **);
230 #endif /* MSWINDOWS_H */