]> sjero.net Git - wget/blobdiff - src/main.c
Reopen stdout in binary mode for -O -.
[wget] / src / main.c
index 228bb27fe2ef00dc2171b4e94ec9cebd1e382415..28b04b30114f66bd876a5280846956f9583dff46 100644 (file)
@@ -294,7 +294,7 @@ static void
 init_switches (void)
 {
   char *p = short_options;
-  int i, o = 0;
+  size_t i, o = 0;
   for (i = 0; i < countof (option_data); i++)
     {
       struct cmdline_option *opt = &option_data[i];
@@ -640,7 +640,7 @@ Recursive accept/reject:\n"),
     N_("Mail bug reports and suggestions to <bug-wget@gnu.org>.\n")
   };
 
-  int i;
+  size_t i;
 
   printf (_("GNU Wget %s, a non-interactive network retriever.\n"),
           version_string);
@@ -947,6 +947,14 @@ for details.\n\n"));
       exit (1);
     }
 
+  if (opt.ask_passwd)
+    {
+      opt.passwd = prompt_for_password ();
+
+      if (opt.passwd == NULL || opt.passwd[0] == '\0')
+        exit (1);
+    }
+
 #ifdef MSDOS
   if (opt.wdebug)
      dbug_init();
@@ -983,7 +991,19 @@ for details.\n\n"));
   if (opt.output_document)
     {
       if (HYPHENP (opt.output_document))
-        output_stream = stdout;
+        {
+#ifdef WINDOWS
+          FILE *result;
+          result = freopen (NULL, "wb", stdout);
+          if (result == NULL)
+            {
+              logputs (LOG_NOTQUIET, _("\
+WARNING: Can't reopen standard output in binary mode;\n\
+         downloaded file may contain inappropriate line endings.\n"));
+            }
+#endif
+          output_stream = stdout;
+        }
       else
         {
           struct_fstat st;
@@ -1030,14 +1050,6 @@ for details.\n\n"));
       char *filename = NULL, *redirected_URL = NULL;
       int dt;
 
-      if (opt.ask_passwd)
-        {
-          opt.passwd = prompt_for_password ();
-
-          if (opt.passwd == NULL || opt.passwd[0] == '\0')
-              exit (1);
-        }
-
       if ((opt.recursive || opt.page_requisites)
           && (url_scheme (*t) != SCHEME_FTP || url_uses_proxy (*t)))
         {