X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Futils.c;h=15e3f89ba392b726050e6ba7dccc4af502bca4a7;hb=123f5c39669abc055987d69a311785c861494c87;hp=df4ce20858849a5ba2b3db9ad754a1a97c1d1471;hpb=1a41bc067c118fe0cbc8a632e9716102bc357b13;p=wget diff --git a/src/utils.c b/src/utils.c index df4ce208..15e3f89b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -88,6 +88,32 @@ as that of the covered work. */ #include "test.h" #endif +static void +memfatal (const char *context, long attempted_size) +{ + /* Make sure we don't try to store part of the log line, and thus + call malloc. */ + log_set_save_context (false); + + /* We have different log outputs in different situations: + 1) output without bytes information + 2) output with bytes information */ + if (attempted_size == UNKNOWN_ATTEMPTED_SIZE) + { + logprintf (LOG_ALWAYS, + _("%s: %s: Failed to allocate enough memory; memory exhausted.\n"), + exec_name, context); + } + else + { + logprintf (LOG_ALWAYS, + _("%s: %s: Failed to allocate %ld bytes; memory exhausted.\n"), + exec_name, context, attempted_size); + } + + exit (1); +} + /* Utility function: like xstrdup(), but also lowercases S. */ char * @@ -241,7 +267,7 @@ concat_strings (const char *str0, ...) const char *next_str; int total_length = 0; - int argcount; + size_t argcount; /* Calculate the length of and allocate the resulting string. */ @@ -322,14 +348,7 @@ fork_to_background (void) /* Whether we arrange our own version of opt.lfilename here. */ bool logfile_changed = false; - if (opt.quiet && !opt.server_response) - { - /* Don't bother with a logfile, there are virtually no logs we - issue in quiet mode. (Server responses in FTP are the - exception, when enabled.) */ - log_close (); - } - 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 @@ -353,10 +372,9 @@ fork_to_background (void) else if (pid != 0) { /* parent, no error */ - if (!quiet) - printf (_("Continuing in background, pid %d.\n"), (int) pid); + 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()? */ } @@ -402,8 +420,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; } @@ -1368,7 +1386,7 @@ human_readable (HR_NUMTYPE n) 'E', /* exabyte, 2^60 bytes */ }; static char buf[8]; - int i; + size_t i; /* If the quantity is smaller than 1K, just print it. */ if (n < 1024) @@ -2213,6 +2231,8 @@ test_dir_matches_p() { { "*/*COMPLETE", NULL, NULL }, "foo/!COMPLETE", true }, { { "/dir with spaces", NULL, NULL }, "dir with spaces", true }, { { "/dir*with*spaces", NULL, NULL }, "dir with spaces", true }, + { { "/Tmp/has", NULL, NULL }, "/Tmp/has space", false }, + { { "/Tmp/has", NULL, NULL }, "/Tmp/has,comma", false }, }; for (i = 0; i < countof(test_array); ++i)