]> sjero.net Git - wget/blob - src/mswindows.h
[svn] Also wrap accept() and listen() on Windows.
[wget] / src / mswindows.h
1 /* Declarations for windows
2    Copyright (C) 1996-2005 Free Software Foundation, Inc.
3
4 This file is part of GNU Wget.
5
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.
10
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.
15
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.
19
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.  */
29
30 #ifndef MSWINDOWS_H
31 #define MSWINDOWS_H
32
33 #ifndef WGET_H
34 # error This file should not be included directly.
35 #endif
36
37 /* Prevent inclusion of <winsock*.h> in <windows.h>.  */
38 #ifndef WIN32_LEAN_AND_MEAN
39 # define WIN32_LEAN_AND_MEAN
40 #endif
41
42 #include <windows.h>
43
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
46   only on MinGW.) */
47 #ifdef ENABLE_IPV6
48 # include <winsock2.h>
49 # include <ws2tcpip.h>
50 #else
51 # include <winsock.h>
52 #endif
53
54 #ifndef EAI_SYSTEM
55 # define EAI_SYSTEM -1   /* value doesn't matter */
56 #endif
57
58 /* Declares file access functions, such as open, creat, access, and
59    chmod.  Unix declares these in unistd.h and fcntl.h.  */
60 #include <io.h>
61
62 #ifndef S_ISDIR
63 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
64 #endif
65 #ifndef S_ISLNK
66 # define S_ISLNK(a) 0
67 #endif
68
69 /* We have strcasecmp and strncasecmp, just under a different name.  */
70 #define strcasecmp stricmp
71 #define strncasecmp strnicmp
72
73 /* The same for snprintf() and vsnprintf().  */
74 #define snprintf _snprintf
75 #define vsnprintf _vsnprintf
76
77 /* Define a wgint type under Windows. */
78 typedef __int64 wgint;
79 #define SIZEOF_WGINT 8
80
81 #ifdef __GNUC__
82 #define WGINT_MAX 9223372036854775807LL
83 #else
84 #define WGINT_MAX 9223372036854775807I64
85 #endif
86
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);
93
94 /* Windows has no symlink, therefore no lstat.  Without symlinks lstat
95    is equivalent to stat anyway.  */
96 #define lstat stat
97
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
101    that.  */
102 #define stat(fname, buf) _stati64 (fname, buf)
103
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
107    on Unix.
108
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.  */
113
114 #ifndef __BORLANDC__
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__ */
122
123 #define PATH_SEPARATOR '\\'
124
125 #ifdef HAVE_ISATTY
126 #ifdef _MSC_VER
127 # define isatty _isatty
128 #endif
129 #endif
130
131 /* Win32 doesn't support the MODE argument to mkdir.  */
132 #define mkdir(a, b) _mkdir(a)
133
134 /* Additional declarations needed for IPv6: */
135 #ifdef ENABLE_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. */
139 # ifdef __MINGW32__
140 #  undef gai_strerror
141 #  define gai_strerror windows_strerror
142 # endif
143 #endif /* ENABLE_IPV6 */
144
145 #ifndef INHIBIT_WRAP
146
147 /* Winsock functions don't set errno, so we provide wrappers that do. */
148
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
161
162 #endif /* not INHIBIT_WRAP */
163
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);
176
177 /* Finally, provide a private version of strerror that does the
178    right thing with Winsock errors. */
179 #ifndef INHIBIT_WRAP
180 # define strerror windows_strerror
181 #endif
182 const char *windows_strerror (int);
183
184 /* Declarations of various socket errors:  */
185
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
221
222 /* Public functions.  */
223
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 **);
229
230 #endif /* MSWINDOWS_H */