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 for 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 /* No lstat on Windows. */
103 /* On Windows the 64-bit stat requires a different version of struct
104 stat. (On Unix too, but it happens transparently when stat is
105 remapped to stat64.) */
107 #if defined(_MSC_VER) || defined(__MINGW32__)
108 # define struct_stat struct _stati64
109 #elif defined(__BORLANDC__)
110 # define struct_stat struct stati64
112 # define struct_stat struct stat
115 /* Transparently support statting large files, like POSIX's LFS API
117 #define stat(fname, buf) _stati64 (fname, buf)
120 # define fstat(fd, buf) _fstati64 (fd, buf)
123 #define PATH_SEPARATOR '\\'
127 # define isatty _isatty
131 /* #### Do we need this? */
134 /* Windows compilers accept only one arg to mkdir. */
135 #define mkdir(a, b) _mkdir(a)
139 /* Winsock functions don't set errno, so we provide wrappers
142 #define socket wrapped_socket
143 #define bind wrapped_bind
144 #define connect wrapped_connect
145 #define recv wrapped_recv
146 #define send wrapped_send
147 #define select wrapped_select
148 #define getsockname wrapped_getsockname
149 #define getpeername wrapped_getpeername
150 #define setsockopt wrapped_setsockopt
151 #define closesocket wrapped_closesocket
153 #endif /* not INHIBIT_WRAP */
155 int wrapped_socket (int, int, int);
156 int wrapped_bind (int, struct sockaddr *, int);
157 int wrapped_connect (int, const struct sockaddr *, int);
158 int wrapped_recv (int, void *, int, int);
159 int wrapped_send (int, const void *, int, int);
160 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
161 int wrapped_getsockname (int, struct sockaddr *, int *);
162 int wrapped_getpeername (int, struct sockaddr *, int *);
163 int wrapped_setsockopt (int, int, int, const void *, int);
164 int wrapped_closesocket (int);
166 /* Finally, provide a private version of strerror that does the
167 right thing with Winsock errors. */
169 # define strerror windows_strerror
171 const char *windows_strerror (int);
173 /* Declarations of various socket errors: */
175 #define EWOULDBLOCK WSAEWOULDBLOCK
176 #define EINPROGRESS WSAEINPROGRESS
177 #define EALREADY WSAEALREADY
178 #define ENOTSOCK WSAENOTSOCK
179 #define EDESTADDRREQ WSAEDESTADDRREQ
180 #define EMSGSIZE WSAEMSGSIZE
181 #define EPROTOTYPE WSAEPROTOTYPE
182 #define ENOPROTOOPT WSAENOPROTOOPT
183 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT
184 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT
185 #define EOPNOTSUPP WSAEOPNOTSUPP
186 #define EPFNOSUPPORT WSAEPFNOSUPPORT
187 #define EAFNOSUPPORT WSAEAFNOSUPPORT
188 #define EADDRINUSE WSAEADDRINUSE
189 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL
190 #define ENETDOWN WSAENETDOWN
191 #define ENETUNREACH WSAENETUNREACH
192 #define ENETRESET WSAENETRESET
193 #define ECONNABORTED WSAECONNABORTED
194 #define ECONNRESET WSAECONNRESET
195 #define ENOBUFS WSAENOBUFS
196 #define EISCONN WSAEISCONN
197 #define ENOTCONN WSAENOTCONN
198 #define ESHUTDOWN WSAESHUTDOWN
199 #define ETOOMANYREFS WSAETOOMANYREFS
200 #define ETIMEDOUT WSAETIMEDOUT
201 #define ECONNREFUSED WSAECONNREFUSED
202 #define ELOOP WSAELOOP
203 #define EHOSTDOWN WSAEHOSTDOWN
204 #define EHOSTUNREACH WSAEHOSTUNREACH
205 #define EPROCLIM WSAEPROCLIM
206 #define EUSERS WSAEUSERS
207 #define EDQUOT WSAEDQUOT
208 #define ESTALE WSAESTALE
209 #define EREMOTE WSAEREMOTE
211 /* Public functions. */
213 void ws_startup (void);
214 void ws_changetitle (const char *);
215 void ws_percenttitle (double);
216 char *ws_mypath (void);
217 void windows_main (int *, char **, char **);
219 /* Things needed for IPv6; missing in <ws2tcpip.h>. */
221 # ifndef HAVE_INET_NTOP
222 extern const char *inet_ntop (int af, const void *src, char *dst, size_t size);
224 #endif /* ENABLE_IPV6 */
226 #endif /* MSWINDOWS_H */