]> sjero.net Git - wget/blob - src/mswindows.h
6750934b2c6b1221246180a7f051da743daf1a83
[wget] / src / mswindows.h
1 /* Declarations for windows
2    Copyright (C) 1995, 1997, 1997, 1998, 2004
3    Free Software Foundation, Inc.
4
5 This file is part of GNU Wget.
6
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.
11
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.
16
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.
20
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.  */
30
31 #ifndef MSWINDOWS_H
32 #define MSWINDOWS_H
33
34 #ifndef WGET_H
35 #error Include mswindows.h inside or after "wget.h"
36 #endif
37
38 /* Prevent inclusion of <winsock*.h> in <windows.h>.  */
39 #ifndef WIN32_LEAN_AND_MEAN
40 #define WIN32_LEAN_AND_MEAN
41 #endif
42
43 #include <windows.h>
44
45 /* Use the correct winsock header; <ws2tcpip.h> includes <winsock2.h> only
46    on Watcom/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>
51 #else
52 # include <winsock.h>
53 #endif
54
55 #ifndef EAI_SYSTEM
56 # define EAI_SYSTEM -1   /* value doesn't matter */
57 #endif
58
59 /* Must include <sys/stat.h> because of 'stat' define below.  */
60 #include <sys/stat.h>
61
62 /* Missing in several .c files.  Include here.  */
63 #include <io.h>
64
65 /* Apparently needed for alloca().  */
66 #include <malloc.h>
67
68 #ifndef S_ISDIR
69 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
70 #endif
71 #ifndef S_ISLNK
72 # define S_ISLNK(a) 0
73 #endif
74
75 /* We have strcasecmp and strncasecmp, just under a different name.  */
76 #define strcasecmp stricmp
77 #define strncasecmp strnicmp
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 #ifdef __GNUC__
88 #define WGINT_MAX 9223372036854775807LL
89 #else
90 #define WGINT_MAX 9223372036854775807I64
91 #endif
92
93 #define str_to_wgint str_to_int64
94 __int64 str_to_int64 (const char *, char **, int);
95
96 /* No lstat on Windows.  */
97 #define lstat stat
98
99 /* Transparently support large files, in spirit similar to the POSIX
100    LFS API.  */
101 #define stat(fname, buf) _stati64 (fname, buf)
102
103 #ifndef __BORLANDC__
104 # define fstat(fd, buf) _fstati64 (fd, buf)
105 #endif
106
107 #if defined(_MSC_VER) || defined(__MINGW32__)
108 # define struct_stat struct _stati64
109 #elif defined(__BORLANDC__)
110 # define struct_stat struct stati64
111 #else
112 # define struct_stat struct stat
113 #endif
114
115 #define PATH_SEPARATOR '\\'
116
117 #ifdef HAVE_ISATTY
118 #ifdef _MSC_VER
119 # define isatty _isatty
120 #endif
121 #endif
122
123 /* #### Do we need this?  */
124 #include <direct.h>
125
126 /* Windows compilers accept only one arg to mkdir.  */
127 #define mkdir(a, b) _mkdir(a)
128
129 #ifndef INHIBIT_WRAP
130
131 /* Winsock functions don't set errno, so we provide wrappers
132    that do. */
133
134 #define socket wrapped_socket
135 #define bind wrapped_bind
136 #define connect wrapped_connect
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_recv (int, void *, int, int);
151 int wrapped_send (int, const void *, int, int);
152 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
153 int wrapped_getsockname (int, struct sockaddr *, int *);
154 int wrapped_getpeername (int, struct sockaddr *, int *);
155 int wrapped_setsockopt (int, int, int, const void *, int);
156 int wrapped_closesocket (int);
157
158 /* Finally, provide a private version of strerror that does the
159    right thing with Winsock errors. */
160 #ifndef INHIBIT_WRAP
161 # define strerror windows_strerror
162 #endif
163 const char *windows_strerror (int);
164
165 /* Declarations of various socket errors:  */
166
167 #define EWOULDBLOCK             WSAEWOULDBLOCK
168 #define EINPROGRESS             WSAEINPROGRESS
169 #define EALREADY                WSAEALREADY
170 #define ENOTSOCK                WSAENOTSOCK
171 #define EDESTADDRREQ            WSAEDESTADDRREQ
172 #define EMSGSIZE                WSAEMSGSIZE
173 #define EPROTOTYPE              WSAEPROTOTYPE
174 #define ENOPROTOOPT             WSAENOPROTOOPT
175 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
176 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
177 #define EOPNOTSUPP              WSAEOPNOTSUPP
178 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
179 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
180 #define EADDRINUSE              WSAEADDRINUSE
181 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
182 #define ENETDOWN                WSAENETDOWN
183 #define ENETUNREACH             WSAENETUNREACH
184 #define ENETRESET               WSAENETRESET
185 #define ECONNABORTED            WSAECONNABORTED
186 #define ECONNRESET              WSAECONNRESET
187 #define ENOBUFS                 WSAENOBUFS
188 #define EISCONN                 WSAEISCONN
189 #define ENOTCONN                WSAENOTCONN
190 #define ESHUTDOWN               WSAESHUTDOWN
191 #define ETOOMANYREFS            WSAETOOMANYREFS
192 #define ETIMEDOUT               WSAETIMEDOUT
193 #define ECONNREFUSED            WSAECONNREFUSED
194 #define ELOOP                   WSAELOOP
195 #define EHOSTDOWN               WSAEHOSTDOWN
196 #define EHOSTUNREACH            WSAEHOSTUNREACH
197 #define EPROCLIM                WSAEPROCLIM
198 #define EUSERS                  WSAEUSERS
199 #define EDQUOT                  WSAEDQUOT
200 #define ESTALE                  WSAESTALE
201 #define EREMOTE                 WSAEREMOTE
202
203 /* Public functions.  */
204
205 void ws_startup (void);
206 void ws_changetitle (const char *);
207 void ws_percenttitle (double);
208 char *ws_mypath (void);
209 void windows_main (int *, char **, char **);
210
211 /* Things needed for IPv6; missing in <ws2tcpip.h>.  */
212 #ifdef ENABLE_IPV6
213 # ifndef HAVE_INET_NTOP
214 extern const char *inet_ntop (int af, const void *src, char *dst, size_t size);
215 # endif
216 #endif /* ENABLE_IPV6 */
217
218 #endif /* MSWINDOWS_H */