X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Futils.c;h=15e3f89ba392b726050e6ba7dccc4af502bca4a7;hb=766df9d4e9392045a4e5c730ed81e599b509557a;hp=f3b4a60c3aa285a85430c22b724c6e953c772d57;hpb=3e34be1c4b963ac120e3758c12a0317c5364fc16;p=wget diff --git a/src/utils.c b/src/utils.c index f3b4a60c..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. */ @@ -1360,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) @@ -2205,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)