X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fretr.c;h=5f9327a3d75f292166f3dba3243f42e4282813b4;hp=71017761bfa85731279c929dbf3e276eb35296dc;hb=b7a8c6d3f5d6555f323523c3b87507eebc1df3eb;hpb=28293eafd09e41d1cea22ebea291e669c7a8e8d9 diff --git a/src/retr.c b/src/retr.c index 71017761..5f9327a3 100644 --- a/src/retr.c +++ b/src/retr.c @@ -534,7 +534,7 @@ retrieve_from_file (const char *file, int html, int *count) char *filename, *new_file; int dt; - if (opt.quota && opt.downloaded > opt.quota) + if (downloaded_exceeds_quota ()) { status = QUOTEXC; break; @@ -571,3 +571,37 @@ printwhat (int n1, int n2) { logputs (LOG_VERBOSE, (n1 == n2) ? _("Giving up.\n\n") : _("Retrying.\n\n")); } + +/* Increment opt.downloaded by BY_HOW_MUCH. If an overflow occurs, + set opt.downloaded_overflow to 1. */ +void +downloaded_increase (unsigned long by_how_much) +{ + VERY_LONG_TYPE old; + if (opt.downloaded_overflow) + return; + old = opt.downloaded; + opt.downloaded += by_how_much; + if (opt.downloaded < old) /* carry flag, where are you when I + need you? */ + { + /* Overflow. */ + opt.downloaded_overflow = 1; + opt.downloaded = ~((VERY_LONG_TYPE)0); + } +} + +/* Return non-zero if the downloaded amount of bytes exceeds the + desired quota. If quota is not set or if the amount overflowed, 0 + is returned. */ +int +downloaded_exceeds_quota (void) +{ + if (!opt.quota) + return 0; + if (opt.downloaded_overflow) + /* We don't really no. (Wildly) assume not. */ + return 0; + + return opt.downloaded > opt.quota; +}