]> sjero.net Git - wget/blob - src/mswindows.h
34f909a44ce208544e6865ca493f258f84964f0d
[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 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 /* Declares getpid(). */
63 #include <process.h>
64
65 #ifndef S_ISDIR
66 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
67 #endif
68 #ifndef S_ISLNK
69 # define S_ISLNK(a) 0
70 #endif
71
72 /* We have strcasecmp and strncasecmp, just under different names.  */
73 #ifndef HAVE_STRCASECMP
74 # define strcasecmp stricmp
75 #endif
76 #ifndef HAVE_STRNCASECMP
77 # define strncasecmp strnicmp
78 #endif
79
80 /* The same for snprintf() and vsnprintf().  */
81 #define snprintf _snprintf
82 #define vsnprintf _vsnprintf
83
84 /* Define a wgint type under Windows. */
85 typedef __int64 wgint;
86 #define SIZEOF_WGINT 8
87
88 /* str_to_wgint is a function with the semantics of strtol[l], but
89    which works on wgint.  */
90 #if defined HAVE_STRTOLL
91 # define str_to_wgint strtoll
92 #elif defined HAVE__STRTOI64
93 # define str_to_wgint _strtoi64
94 #else
95 # define str_to_wgint strtoll
96 # define NEED_STRTOLL
97 # define strtoll_type __int64
98 #endif
99
100 /* Windows has no symlink, therefore no lstat.  Without symlinks lstat
101    is equivalent to stat anyway.  */
102 #define lstat stat
103
104 /* Define LFS aliases for stat and fstat. */
105 #ifdef stat_alias
106 # define stat(f, b) stat_alias (f, b)
107 #endif
108 #ifdef fstat_alias
109 # define fstat(f, b) fstat_alias (f, b)
110 #endif
111
112 #define PATH_SEPARATOR '\\'
113
114 /* Win32 doesn't support the MODE argument to mkdir.  */
115 #include <direct.h>
116 #define mkdir(a, b) (mkdir) (a)
117
118 /* Additional declarations needed for IPv6: */
119 #ifdef ENABLE_IPV6
120 const char *inet_ntop (int, const void *, char *, socklen_t);
121 #endif
122
123 #ifdef NEED_GAI_STRERROR
124 # undef gai_strerror
125 # define gai_strerror windows_strerror
126 #endif
127
128 #ifndef INHIBIT_WRAP
129
130 /* Winsock functions don't set errno, so we provide wrappers that do. */
131
132 #define socket wrapped_socket
133 #define bind wrapped_bind
134 #define connect wrapped_connect
135 #define listen wrapped_listen
136 #define accept wrapped_accept
137 #define recv wrapped_recv
138 #define send wrapped_send
139 #define select wrapped_select
140 #define getsockname wrapped_getsockname
141 #define getpeername wrapped_getpeername
142 #define setsockopt wrapped_setsockopt
143 #define closesocket wrapped_closesocket
144
145 #endif /* not INHIBIT_WRAP */
146
147 int wrapped_socket (int, int, int);
148 int wrapped_bind (int, struct sockaddr *, int);
149 int wrapped_connect (int, const struct sockaddr *, int);
150 int wrapped_listen (int s, int backlog);
151 int wrapped_accept (int s, struct sockaddr *a, int *alen);
152 int wrapped_recv (int, void *, int, int);
153 int wrapped_send (int, const void *, int, int);
154 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
155 int wrapped_getsockname (int, struct sockaddr *, int *);
156 int wrapped_getpeername (int, struct sockaddr *, int *);
157 int wrapped_setsockopt (int, int, int, const void *, int);
158 int wrapped_closesocket (int);
159
160 /* Finally, provide a private version of strerror that does the
161    right thing with Winsock errors. */
162 #ifndef INHIBIT_WRAP
163 # define strerror windows_strerror
164 #endif
165 const char *windows_strerror (int);
166
167 /* Declarations of various socket errors:  */
168
169 #define EWOULDBLOCK             WSAEWOULDBLOCK
170 #define EINPROGRESS             WSAEINPROGRESS
171 #define EALREADY                WSAEALREADY
172 #define ENOTSOCK                WSAENOTSOCK
173 #define EDESTADDRREQ            WSAEDESTADDRREQ
174 #define EMSGSIZE                WSAEMSGSIZE
175 #define EPROTOTYPE              WSAEPROTOTYPE
176 #define ENOPROTOOPT             WSAENOPROTOOPT
177 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
178 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
179 #define EOPNOTSUPP              WSAEOPNOTSUPP
180 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
181 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
182 #define EADDRINUSE              WSAEADDRINUSE
183 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
184 #define ENETDOWN                WSAENETDOWN
185 #define ENETUNREACH             WSAENETUNREACH
186 #define ENETRESET               WSAENETRESET
187 #define ECONNABORTED            WSAECONNABORTED
188 #define ECONNRESET              WSAECONNRESET
189 #define ENOBUFS                 WSAENOBUFS
190 #define EISCONN                 WSAEISCONN
191 #define ENOTCONN                WSAENOTCONN
192 #define ESHUTDOWN               WSAESHUTDOWN
193 #define ETOOMANYREFS            WSAETOOMANYREFS
194 #define ETIMEDOUT               WSAETIMEDOUT
195 #define ECONNREFUSED            WSAECONNREFUSED
196 #define ELOOP                   WSAELOOP
197 #define EHOSTDOWN               WSAEHOSTDOWN
198 #define EHOSTUNREACH            WSAEHOSTUNREACH
199 #define EPROCLIM                WSAEPROCLIM
200 #define EUSERS                  WSAEUSERS
201 #define EDQUOT                  WSAEDQUOT
202 #define ESTALE                  WSAESTALE
203 #define EREMOTE                 WSAEREMOTE
204
205 /* Public functions.  */
206
207 void ws_startup (void);
208 void ws_changetitle (const char *);
209 void ws_percenttitle (double);
210 char *ws_mypath (void);
211 void windows_main (int *, char **, char **);
212
213 #endif /* MSWINDOWS_H */