]> sjero.net Git - wget/blob - src/mswindows.h
[svn] Merge of fix for bugs 20341 and 20410.
[wget] / src / mswindows.h
1 /* Declarations for windows
2    Copyright (C) 1996-2006 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 3 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, see <http://www.gnu.org/licenses/>.
18
19 In addition, as a special exception, the Free Software Foundation
20 gives permission to link the code of its release of Wget with the
21 OpenSSL project's "OpenSSL" library (or with modified versions of it
22 that use the same license as the "OpenSSL" library), and distribute
23 the linked executables.  You must obey the GNU General Public License
24 in all respects for all of the code used other than "OpenSSL".  If you
25 modify this file, you may extend this exception to your version of the
26 file, but you are not obligated to do so.  If you do not wish to do
27 so, delete this exception statement from your version.  */
28
29 #ifndef MSWINDOWS_H
30 #define MSWINDOWS_H
31
32 #ifndef WGET_H
33 # error This file should not be included directly.
34 #endif
35
36 /* Prevent inclusion of <winsock*.h> in <windows.h>.  */
37 #ifndef WIN32_LEAN_AND_MEAN
38 # define WIN32_LEAN_AND_MEAN
39 #endif
40
41 #include <windows.h>
42
43 /* We need winsock2.h for IPv6 and ws2tcpip.h for getaddrinfo, so
44   include both in ENABLE_IPV6 case.  (ws2tcpip.h includes winsock2.h
45   only on MinGW.) */
46 #ifdef ENABLE_IPV6
47 # include <winsock2.h>
48 # include <ws2tcpip.h>
49 #else
50 # include <winsock.h>
51 #endif
52
53 #ifndef EAI_SYSTEM
54 # define EAI_SYSTEM -1   /* value doesn't matter */
55 #endif
56
57 /* Declares file access functions, such as open, creat, access, and
58    chmod.  Unix declares these in unistd.h and fcntl.h.  */
59 #include <io.h>
60
61 /* Declares getpid(). */
62 #include <process.h>
63
64 #ifndef S_ISDIR
65 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
66 #endif
67 #ifndef S_ISLNK
68 # define S_ISLNK(a) 0
69 #endif
70
71 /* We have strcasecmp and strncasecmp, just under different names.  */
72 #ifndef HAVE_STRCASECMP
73 # define strcasecmp stricmp
74 #endif
75 #ifndef HAVE_STRNCASECMP
76 # define strncasecmp strnicmp
77 #endif
78
79 /* The same for snprintf() and vsnprintf().  */
80 #define snprintf _snprintf
81 #define vsnprintf _vsnprintf
82
83 /* Define a wgint type under Windows. */
84 typedef __int64 wgint;
85 #define SIZEOF_WGINT 8
86
87 /* str_to_wgint is a function with the semantics of strtol[l], but
88    which works on wgint.  */
89 #if defined HAVE_STRTOLL
90 # define str_to_wgint strtoll
91 #elif defined HAVE__STRTOI64
92 # define str_to_wgint _strtoi64
93 #else
94 # define str_to_wgint strtoll
95 # define NEED_STRTOLL
96 # define strtoll_type __int64
97 #endif
98
99 /* Windows has no symlink, therefore no lstat.  Without symlinks lstat
100    is equivalent to stat anyway.  */
101 #define lstat stat
102
103 /* Define LFS aliases for stat and fstat. */
104 #ifdef stat_alias
105 # define stat(f, b) stat_alias (f, b)
106 #endif
107 #ifdef fstat_alias
108 # define fstat(f, b) fstat_alias (f, b)
109 #endif
110
111 #define PATH_SEPARATOR '\\'
112
113 /* Win32 doesn't support the MODE argument to mkdir.  */
114 #include <direct.h>
115 #define mkdir(a, b) (mkdir) (a)
116
117 /* Additional declarations needed for IPv6: */
118 #ifdef ENABLE_IPV6
119 const char *inet_ntop (int, const void *, char *, socklen_t);
120 #endif
121
122 #ifdef NEED_GAI_STRERROR
123 # undef gai_strerror
124 # define gai_strerror windows_strerror
125 #endif
126
127 #ifndef INHIBIT_WRAP
128
129 /* Winsock functions don't set errno, so we provide wrappers that do. */
130
131 #define socket wrapped_socket
132 #define bind wrapped_bind
133 #define connect wrapped_connect
134 #define listen wrapped_listen
135 #define accept wrapped_accept
136 #define recv wrapped_recv
137 #define send wrapped_send
138 #define select wrapped_select
139 #define getsockname wrapped_getsockname
140 #define getpeername wrapped_getpeername
141 #define setsockopt wrapped_setsockopt
142 #define closesocket wrapped_closesocket
143
144 #endif /* not INHIBIT_WRAP */
145
146 int wrapped_socket (int, int, int);
147 int wrapped_bind (int, struct sockaddr *, int);
148 int wrapped_connect (int, const struct sockaddr *, int);
149 int wrapped_listen (int s, int backlog);
150 int wrapped_accept (int s, struct sockaddr *a, int *alen);
151 int wrapped_recv (int, void *, int, int);
152 int wrapped_send (int, const void *, int, int);
153 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
154 int wrapped_getsockname (int, struct sockaddr *, int *);
155 int wrapped_getpeername (int, struct sockaddr *, int *);
156 int wrapped_setsockopt (int, int, int, const void *, int);
157 int wrapped_closesocket (int);
158
159 /* Finally, provide a private version of strerror that does the
160    right thing with Winsock errors. */
161 #ifndef INHIBIT_WRAP
162 # define strerror windows_strerror
163 #endif
164 const char *windows_strerror (int);
165
166 /* Declarations of various socket errors:  */
167
168 #define EWOULDBLOCK             WSAEWOULDBLOCK
169 #define EINPROGRESS             WSAEINPROGRESS
170 #define EALREADY                WSAEALREADY
171 #define ENOTSOCK                WSAENOTSOCK
172 #define EDESTADDRREQ            WSAEDESTADDRREQ
173 #define EMSGSIZE                WSAEMSGSIZE
174 #define EPROTOTYPE              WSAEPROTOTYPE
175 #define ENOPROTOOPT             WSAENOPROTOOPT
176 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
177 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
178 #define EOPNOTSUPP              WSAEOPNOTSUPP
179 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
180 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
181 #define EADDRINUSE              WSAEADDRINUSE
182 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
183 #define ENETDOWN                WSAENETDOWN
184 #define ENETUNREACH             WSAENETUNREACH
185 #define ENETRESET               WSAENETRESET
186 #define ECONNABORTED            WSAECONNABORTED
187 #define ECONNRESET              WSAECONNRESET
188 #define ENOBUFS                 WSAENOBUFS
189 #define EISCONN                 WSAEISCONN
190 #define ENOTCONN                WSAENOTCONN
191 #define ESHUTDOWN               WSAESHUTDOWN
192 #define ETOOMANYREFS            WSAETOOMANYREFS
193 #define ETIMEDOUT               WSAETIMEDOUT
194 #define ECONNREFUSED            WSAECONNREFUSED
195 #define ELOOP                   WSAELOOP
196 #define EHOSTDOWN               WSAEHOSTDOWN
197 #define EHOSTUNREACH            WSAEHOSTUNREACH
198 #define EPROCLIM                WSAEPROCLIM
199 #define EUSERS                  WSAEUSERS
200 #define EDQUOT                  WSAEDQUOT
201 #define ESTALE                  WSAESTALE
202 #define EREMOTE                 WSAEREMOTE
203
204 /* Public functions.  */
205
206 void ws_startup (void);
207 void ws_changetitle (const char *);
208 void ws_percenttitle (double);
209 char *ws_mypath (void);
210 void windows_main (int *, char **, char **);
211
212 #endif /* MSWINDOWS_H */