/* mswindows.c -- Windows-specific support
- Copyright (C) 1995, 1996, 1997, 1998, 2004
- Free Software Foundation, Inc.
+ Copyright (C) 1996-2005 Free Software Foundation, Inc.
This file is part of GNU Wget.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with Wget; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+along with Wget; if not, write to the Free Software Foundation, Inc.,
+51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
In addition, as a special exception, the Free Software Foundation
gives permission to link the code of its release of Wget with the
#include "utils.h"
#include "url.h"
-#ifndef errno
-extern int errno;
-#endif
-
#ifndef ES_SYSTEM_REQUIRED
#define ES_SYSTEM_REQUIRED 0x00000001
#endif
/* Defined in log.c. */
-void log_request_redirect_output PARAMS ((const char *));
+void log_request_redirect_output (const char *);
/* Windows version of xsleep in utils.c. */
__int64
str_to_int64 (const char *nptr, char **endptr, int base)
{
-#define OVERFLOW 9223372036854775807I64
-#define UNDERFLOW (-OVERFLOW - 1)
+#define INT64_OVERFLOW 9223372036854775807I64
+#define INT64_UNDERFLOW (-INT64_OVERFLOW - 1)
__int64 result = 0;
- int negative;
+ bool negative;
if (base != 0 && (base < 2 || base > 36))
{
++nptr;
if (*nptr == '-')
{
- negative = 1;
+ negative = true;
++nptr;
}
else if (*nptr == '+')
{
- negative = 0;
+ negative = false;
++nptr;
}
else
- negative = 0;
+ negative = false;
/* If base is 0, determine the real base based on the beginning on
the number; octal numbers begin with "0", hexadecimal with "0x",
__int64 newresult = base * result + val;
if (newresult < result)
{
- result = OVERFLOW;
+ result = INT64_OVERFLOW;
errno = ERANGE;
break;
}
__int64 newresult = base * result - val;
if (newresult > result)
{
- result = UNDERFLOW;
+ result = INT64_UNDERFLOW;
errno = ERANGE;
break;
}
struct fake_fork_info
{
HANDLE event;
- int logfile_changed;
+ bool logfile_changed;
char lfilename[MAX_PATH + 1];
};
event = info->event;
- info->logfile_changed = 0;
+ info->logfile_changed = false;
if (!opt.lfilename)
{
/* See utils:fork_to_background for explanation. */
- FILE *new_log_fp = unique_create (DEFAULT_LOGFILE, 0, &opt.lfilename);
+ FILE *new_log_fp = unique_create (DEFAULT_LOGFILE, false, &opt.lfilename);
if (new_log_fp)
{
- info->logfile_changed = 1;
+ info->logfile_changed = true;
strncpy (info->lfilename, opt.lfilename, sizeof (info->lfilename));
info->lfilename[sizeof (info->lfilename) - 1] = '\0';
fclose (new_log_fp);
{
xfree_null (title_buf);
xfree_null (curr_url);
- title_buf = (char *)xmalloc (strlen (url) + 20);
+ title_buf = xmalloc (strlen (url) + 20);
curr_url = xstrdup (url);
old_percentage = -1;
sprintf (title_buf, "Wget %s", curr_url);
}
/* Call FUN(ARG), but don't allow it to run for more than TIMEOUT
- seconds. Returns non-zero if the function was interrupted with a
- timeout, zero otherwise.
+ seconds. Returns true if the function was interrupted with a
+ timeout, false otherwise.
This works by running FUN in a separate thread and terminating the
thread if it doesn't finish in the specified time. */
-int
+bool
run_with_timeout (double seconds, void (*fun) (void *), void *arg)
{
static HANDLE thread_hnd = NULL;
struct thread_data thread_arg;
DWORD thread_id;
- int rc;
+ bool rc;
DEBUGP (("seconds %.2f, ", seconds));
{
blocking_fallback:
fun (arg);
- return 0;
+ return false;
}
/* Should never happen, but test for recursivety anyway. */
so the caller can inspect it. */
WSASetLastError (thread_arg.ws_error);
DEBUGP (("Winsock error: %d\n", WSAGetLastError ()));
- rc = 0;
+ rc = false;
}
else
{
TerminateThread (thread_hnd, 1);
- rc = 1;
+ rc = true;
}
CloseHandle (thread_hnd); /* Clear-up after TerminateThread(). */
return buf;
}
}
+\f
+#ifdef ENABLE_IPV6
+/* An IPv6-only inet_ntop that prints with WSAAddressToString. (Wget
+ uses inet_ntoa for IPv4 addresses -- see print_address.) Prototype
+ complies with POSIX 1003.1-2004. */
+
+const char *
+inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
+{
+ struct sockaddr_in6 sin6;
+ DWORD dstlen = cnt;
+
+ assert (af == AF_INET6);
+ xzero (sin6);
+ sin6.sin6_family = AF_INET6;
+ sin6.sin6_addr = *(struct in6_addr *) src;
+ if (WSAAddressToString ((struct sockaddr *) &sin6, sizeof (sin6),
+ NULL, dst, &dstlen) != 0)
+ {
+ errno = WSAGetLastError();
+ return NULL;
+ }
+ return (const char *) dst;
+}
+#endif