]> sjero.net Git - wget/blob - src/mswindows.h
[svn] Implement inet_ntop on Windows.
[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 This file should not be included directly.
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 /* We need winsock2.h for IPv6 and ws2tcpip.h for getaddrinfo, so
46   include both in ENABLE_IPV6 case.  (ws2tcpip.h includes winsock2.h
47   only on MinGW.) */
48 #ifdef ENABLE_IPV6
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 /* Declares file access functions, such as open, creat, access, and
60    chmod.  Unix declares these in unistd.h and fcntl.h.  */
61 #include <io.h>
62
63 #ifndef S_ISDIR
64 # define S_ISDIR(m) (((m) & (_S_IFMT)) == (_S_IFDIR))
65 #endif
66 #ifndef S_ISLNK
67 # define S_ISLNK(a) 0
68 #endif
69
70 /* We have strcasecmp and strncasecmp, just under a different name.  */
71 #define strcasecmp stricmp
72 #define strncasecmp strnicmp
73
74 /* The same for snprintf() and vsnprintf().  */
75 #define snprintf _snprintf
76 #define vsnprintf _vsnprintf
77
78 /* Define a wgint type under Windows. */
79 typedef __int64 wgint;
80 #define SIZEOF_WGINT 8
81
82 #ifdef __GNUC__
83 #define WGINT_MAX 9223372036854775807LL
84 #else
85 #define WGINT_MAX 9223372036854775807I64
86 #endif
87
88 /* str_to_wgint is a function with the semantics of strtol, but which
89    works on wgint.  Since wgint is unconditionally 64-bit on Windows,
90    we #define it to str_to_int64, which either calls _strtoi64 or
91    implements the conversion manually.  */
92 #define str_to_wgint str_to_int64
93 __int64 str_to_int64 (const char *, char **, int);
94
95 /* Windows has no symlink, therefore no lstat.  Without symlinks lstat
96    is equivalent to stat anyway.  */
97 #define lstat stat
98
99 /* Transparently support statting large files, like POSIX's LFS API
100    does.  All Windows compilers we support use _stati64 (but have
101    different names for 2nd argument type, see below), so we use
102    that.  */
103 #define stat(fname, buf) _stati64 (fname, buf)
104
105 /* On Windows the 64-bit stat requires an explicitly different type
106    for the 2nd argument, so we define a struct_stat macro that expands
107    to the appropriate type on Windows, and to the regular struct stat
108    on Unix.
109
110    Note that Borland C 5.5 has 64-bit stat (_stati64), but not a
111    64-bit fstat!  Because of that we also need a struct_fstat that
112    points to struct_stat on Unix and on Windows, except under Borland,
113    where it points to the 32-bit struct stat.  */
114
115 #ifndef __BORLANDC__
116 # define fstat(fd, buf) _fstati64 (fd, buf)
117 # define struct_stat  struct _stati64
118 # define struct_fstat struct _stati64
119 #else  /* __BORLANDC__ */
120 # define struct_stat  struct stati64
121 # define struct_fstat struct stat
122 #endif /* __BORLANDC__ */
123
124 #define PATH_SEPARATOR '\\'
125
126 #ifdef HAVE_ISATTY
127 #ifdef _MSC_VER
128 # define isatty _isatty
129 #endif
130 #endif
131
132 /* Win32 doesn't support the MODE argument to mkdir.  */
133 #define mkdir(a, b) _mkdir(a)
134
135 /* Additional declarations needed for IPv6: */
136 #ifdef ENABLE_IPV6
137 const char *inet_ntop (int, const void *, char *, socklen_t);
138 /* MinGW 3.7 (or older) prototypes gai_strerror(), but is missing
139    from all import libraries. */
140 # ifdef __MINGW32__
141 #  undef gai_strerror
142 #  define gai_strerror windows_strerror
143 # endif
144 #endif /* ENABLE_IPV6 */
145
146 #ifndef INHIBIT_WRAP
147
148 /* Winsock functions don't set errno, so we provide wrappers that do. */
149
150 #define socket wrapped_socket
151 #define bind wrapped_bind
152 #define connect wrapped_connect
153 #define recv wrapped_recv
154 #define send wrapped_send
155 #define select wrapped_select
156 #define getsockname wrapped_getsockname
157 #define getpeername wrapped_getpeername
158 #define setsockopt wrapped_setsockopt
159 #define closesocket wrapped_closesocket
160
161 #endif /* not INHIBIT_WRAP */
162
163 int wrapped_socket (int, int, int);
164 int wrapped_bind (int, struct sockaddr *, int);
165 int wrapped_connect (int, const struct sockaddr *, int);
166 int wrapped_recv (int, void *, int, int);
167 int wrapped_send (int, const void *, int, int);
168 int wrapped_select (int, fd_set *, fd_set *, fd_set *, const struct timeval *);
169 int wrapped_getsockname (int, struct sockaddr *, int *);
170 int wrapped_getpeername (int, struct sockaddr *, int *);
171 int wrapped_setsockopt (int, int, int, const void *, int);
172 int wrapped_closesocket (int);
173
174 /* Finally, provide a private version of strerror that does the
175    right thing with Winsock errors. */
176 #ifndef INHIBIT_WRAP
177 # define strerror windows_strerror
178 #endif
179 const char *windows_strerror (int);
180
181 /* Declarations of various socket errors:  */
182
183 #define EWOULDBLOCK             WSAEWOULDBLOCK
184 #define EINPROGRESS             WSAEINPROGRESS
185 #define EALREADY                WSAEALREADY
186 #define ENOTSOCK                WSAENOTSOCK
187 #define EDESTADDRREQ            WSAEDESTADDRREQ
188 #define EMSGSIZE                WSAEMSGSIZE
189 #define EPROTOTYPE              WSAEPROTOTYPE
190 #define ENOPROTOOPT             WSAENOPROTOOPT
191 #define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
192 #define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
193 #define EOPNOTSUPP              WSAEOPNOTSUPP
194 #define EPFNOSUPPORT            WSAEPFNOSUPPORT
195 #define EAFNOSUPPORT            WSAEAFNOSUPPORT
196 #define EADDRINUSE              WSAEADDRINUSE
197 #define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
198 #define ENETDOWN                WSAENETDOWN
199 #define ENETUNREACH             WSAENETUNREACH
200 #define ENETRESET               WSAENETRESET
201 #define ECONNABORTED            WSAECONNABORTED
202 #define ECONNRESET              WSAECONNRESET
203 #define ENOBUFS                 WSAENOBUFS
204 #define EISCONN                 WSAEISCONN
205 #define ENOTCONN                WSAENOTCONN
206 #define ESHUTDOWN               WSAESHUTDOWN
207 #define ETOOMANYREFS            WSAETOOMANYREFS
208 #define ETIMEDOUT               WSAETIMEDOUT
209 #define ECONNREFUSED            WSAECONNREFUSED
210 #define ELOOP                   WSAELOOP
211 #define EHOSTDOWN               WSAEHOSTDOWN
212 #define EHOSTUNREACH            WSAEHOSTUNREACH
213 #define EPROCLIM                WSAEPROCLIM
214 #define EUSERS                  WSAEUSERS
215 #define EDQUOT                  WSAEDQUOT
216 #define ESTALE                  WSAESTALE
217 #define EREMOTE                 WSAEREMOTE
218
219 /* Public functions.  */
220
221 void ws_startup (void);
222 void ws_changetitle (const char *);
223 void ws_percenttitle (double);
224 char *ws_mypath (void);
225 void windows_main (int *, char **, char **);
226
227 #endif /* MSWINDOWS_H */