]> sjero.net Git - wget/blobdiff - src/utils.c
Use Gnulib's alloc functions throughout the source.
[wget] / src / utils.c
index af621402caa4d1c5d4f3d39d4e84e69ba5f30f04..d1366ef9e1ee84a1b8b98e21e935a454ed168e37 100644 (file)
@@ -28,6 +28,8 @@ Corresponding Source for a non-source form of such a combination
 shall include the source code for the parts of OpenSSL used as well
 as that of the covered work.  */
 
+#define USE_GNULIB_ALLOC
+
 #include "wget.h"
 
 #include <stdio.h>
@@ -178,7 +180,8 @@ aprintf (const char *fmt, ...)
   ret = vasprintf (&str, fmt, args);
   va_end (args);
   if (ret < 0 && errno == ENOMEM)
-    memfatal ("aprintf", UNKNOWN_ATTEMPTED_SIZE);  /* for consistency with xmalloc/xrealloc */
+    memfatal ("aprintf", UNKNOWN_ATTEMPTED_SIZE);  /* for consistency
+                                                      with xmalloc/xrealloc */
   else if (ret < 0)
     return NULL;
   return str;
@@ -208,19 +211,20 @@ aprintf (const char *fmt, ...)
       /* Else try again with a larger buffer. */
       if (n > -1)               /* C99 */
         size = n + 1;           /* precisely what is needed */
+      else if (size >= FMT_MAX_LENGTH)  /* We have a huge buffer, */
+        {                               /* maybe we have some wrong
+                                           format string? */
+          logprintf (LOG_ALWAYS, 
+                     _("%s: aprintf: text buffer is too big (%ld bytes), "
+                       "aborting.\n"),
+                     exec_name, size);  /* printout a log message */
+          abort ();                     /* and abort... */
+        }
       else
         {
-          if (size >= FMT_MAX_LENGTH)  /* We have a huge buffer, */
-            {                          /* maybe we have some wrong format string? */
-              free (str);              /* In this case we must free already allocated memory, */
-              logprintf (LOG_ALWAYS, 
-                         _("%s: aprintf: text buffer is too big (%ld bytes), \
-free already allocated memory and abort.\n"),
-                         exec_name, size);  /* printout a log message */
-              abort ();             /* and abort... */
-            }
-                                       /* else, we continue to grow our buffer. */
-          size <<= 1;                  /* twice the old size */
+          /* else, we continue to grow our
+           * buffer: Twice the old size. */
+          size <<= 1;
         }
       str = xrealloc (str, size);
     }
@@ -320,7 +324,7 @@ fork_to_background (void)
   /* Whether we arrange our own version of opt.lfilename here.  */
   bool logfile_changed = false;
 
-  if (!opt.lfilename)
+  if (!opt.lfilename && (!opt.quiet || opt.server_response))
     {
       /* We must create the file immediately to avoid either a race
          condition (which arises from using unique_name and failing to
@@ -346,7 +350,7 @@ fork_to_background (void)
       /* parent, no error */
       printf (_("Continuing in background, pid %d.\n"), (int) pid);
       if (logfile_changed)
-        printf (_("Output will be written to `%s'.\n"), opt.lfilename);
+        printf (_("Output will be written to %s.\n"), quote (opt.lfilename));
       exit (0);                 /* #### should we use _exit()? */
     }
 
@@ -392,8 +396,8 @@ remove_link (const char *file)
       DEBUGP (("Unlinking %s (symlink).\n", file));
       err = unlink (file);
       if (err != 0)
-        logprintf (LOG_VERBOSE, _("Failed to unlink symlink `%s': %s\n"),
-                   file, strerror (errno));
+        logprintf (LOG_VERBOSE, _("Failed to unlink symlink %s: %s\n"),
+                   quote (file), strerror (errno));
     }
   return err;
 }