]> sjero.net Git - wget/blobdiff - src/mswindows.c
[svn] Fix a possible race condition when opening files.
[wget] / src / mswindows.c
index 93bf0c6967192be79c3a9ea4ae2b83a1e17b5910..22605a95d8fa6b345824c28e6681a43c090117d5 100644 (file)
@@ -86,7 +86,7 @@ xsleep (double seconds)
 #endif /* not HAVE_USLEEP */
 }
 
-#if defined(_MSC_VER) && _MSC_VER < 1300
+#if defined(__BORLANDC__) || (defined(_MSC_VER) && _MSC_VER < 1300)
 
 static inline int
 char_value (char c, int base)
@@ -195,7 +195,7 @@ str_to_int64 (const char *nptr, char **endptr, int base)
   return result;
 }
 
-#else  /* !defined(_MSC_VER) || _MSC_VER >= 1300 */
+#else  /* !defined(__BORLANDC__) && (!defined(_MSC_VER) || _MSC_VER >= 1300) */
 
 __int64
 str_to_int64 (const char *nptr, char **endptr, int base)
@@ -207,24 +207,7 @@ str_to_int64 (const char *nptr, char **endptr, int base)
 #endif
 }
 
-#endif /* !defined(_MSC_VER) || _MSC_VER >= 1300 */
-
-/* A simple clone of ftello.  The normal ftell doesn't work for large
-   files, so this is needed, and used by file_size(), which is itself
-   used for the --post-file option.
-
-   This function uses fgetpos incorrectly and should be considered a
-   hack until a better way to tell the stream position is found.  */
-
-__int64
-wget_ftello (FILE *fp)
-{
-  fpos_t pos;
-  if (fgetpos (fp, &pos) != 0)
-    return -1;
-  else
-    return pos;
-}
+#endif /* !defined(__BORLANDC__) && (!defined(_MSC_VER) || _MSC_VER >= 1300) */
 
 void
 windows_main_junk (int *argc, char **argv, char **exec_name)
@@ -247,18 +230,7 @@ ws_cleanup (void)
 static void
 ws_hangup (const char *reason)
 {
-  /* Whether we arrange our own version of opt.lfilename here.  */
-  int changedp = 0;
-
-  if (!opt.lfilename)
-    {
-      opt.lfilename = unique_name (DEFAULT_LOGFILE, 0);
-      changedp = 1;
-    }
-  printf (_("Continuing in background.\n"));
-  if (changedp)
-    printf (_("Output will be written to `%s'.\n"), opt.lfilename);
-
+  fprintf (stderr, _("Continuing in background.\n"));
   log_request_redirect_output (reason);
 
   /* Detach process from the current console.  Under Windows 9x, if we
@@ -282,7 +254,7 @@ make_section_name (DWORD pid)
 struct fake_fork_info
 {
   HANDLE event;
-  int changedp;
+  int logfile_changed;
   char lfilename[MAX_PATH + 1];
 };
 
@@ -317,15 +289,19 @@ fake_fork_child (void)
 
   event = info->event;
 
+  info->logfile_changed = 0;
   if (!opt.lfilename)
     {
-      opt.lfilename = unique_name (DEFAULT_LOGFILE, 0);
-      info->changedp = 1;
-      strncpy (info->lfilename, opt.lfilename, sizeof (info->lfilename));
-      info->lfilename[sizeof (info->lfilename) - 1] = '\0';
+      /* See utils:fork_to_background for explanation. */
+      FILE *new_log_fp = unique_create (DEFAULT_LOGFILE, 0, &opt.lfilename);
+      if (new_log_fp)
+       {
+         info->logfile_changed = 1;
+         strncpy (info->lfilename, opt.lfilename, sizeof (info->lfilename));
+         info->lfilename[sizeof (info->lfilename) - 1] = '\0';
+         fclose (new_log_fp);
+       }
     }
-  else
-    info->changedp = 0;
 
   UnmapViewOfFile (info);
   CloseHandle (section);
@@ -439,7 +415,7 @@ fake_fork (void)
     }
 
   /* Ensure string is properly terminated.  */
-  if (info->changedp &&
+  if (info->logfile_changed &&
       !memchr (info->lfilename, '\0', sizeof (info->lfilename)))
     {
       rv = FALSE;
@@ -447,7 +423,7 @@ fake_fork (void)
     }
 
   printf (_("Continuing in background, pid %lu.\n"), pi.dwProcessId);
-  if (info->changedp)
+  if (info->logfile_changed)
     printf (_("Output will be written to `%s'.\n"), info->lfilename);
 
   UnmapViewOfFile (info);