]> sjero.net Git - wget/blobdiff - src/mswindows.c
[svn] Update FSF's address and copyright years.
[wget] / src / mswindows.c
index 0d083e2982b8bf1c2033dc73850f00fb236edca3..245114fe5280d70b048947f613438fbd18ceb08e 100644 (file)
@@ -1,6 +1,5 @@
 /* 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.
 
@@ -15,8 +14,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 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
@@ -54,10 +53,6 @@ so, delete this exception statement from your version.  */
 #include "utils.h"
 #include "url.h"
 
-#ifndef errno
-extern int errno;
-#endif
-
 #ifndef ES_SYSTEM_REQUIRED
 #define ES_SYSTEM_REQUIRED  0x00000001
 #endif
@@ -68,7 +63,7 @@ extern int errno;
 
 
 /* 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.  */
 
@@ -115,11 +110,11 @@ char_value (char c, int base)
 __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))
     {
@@ -131,16 +126,16 @@ str_to_int64 (const char *nptr, char **endptr, int base)
     ++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",
@@ -169,7 +164,7 @@ str_to_int64 (const char *nptr, char **endptr, int base)
          __int64 newresult = base * result + val;
          if (newresult < result)
            {
-             result = OVERFLOW;
+             result = INT64_OVERFLOW;
              errno = ERANGE;
              break;
            }
@@ -185,7 +180,7 @@ str_to_int64 (const char *nptr, char **endptr, int base)
          __int64 newresult = base * result - val;
          if (newresult > result)
            {
-             result = UNDERFLOW;
+             result = INT64_UNDERFLOW;
              errno = ERANGE;
              break;
            }
@@ -256,7 +251,7 @@ make_section_name (DWORD pid)
 struct fake_fork_info
 {
   HANDLE event;
-  int logfile_changed;
+  bool logfile_changed;
   char lfilename[MAX_PATH + 1];
 };
 
@@ -291,14 +286,14 @@ fake_fork_child (void)
 
   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);
@@ -503,7 +498,7 @@ ws_changetitle (const char *url)
 {
   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);
@@ -681,19 +676,19 @@ thread_helper (void *arg)
 }
 
 /* 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));
 
@@ -701,7 +696,7 @@ run_with_timeout (double seconds, void (*fun) (void *), void *arg)
     {
     blocking_fallback:
       fun (arg);
-      return 0;
+      return false;
     }
 
   /* Should never happen, but test for recursivety anyway.  */
@@ -725,12 +720,12 @@ run_with_timeout (double seconds, void (*fun) (void *), void *arg)
         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().  */
@@ -852,3 +847,28 @@ windows_strerror (int err)
       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