? configure ? doc/sample.wgetrc.munged_for_texi_inclusion ? doc/wget.info ? doc/wget.info-1 ? doc/wget.info-2 ? doc/wget.info-3 ? doc/wget.info-4 ? po/bg.gmo ? po/ca.gmo ? po/cs.gmo ? po/da.gmo ? po/de.gmo ? po/el.gmo ? po/en_GB.gmo ? po/es.gmo ? po/et.gmo ? po/eu.gmo ? po/fi.gmo ? po/fr.gmo ? po/gl.gmo ? po/he.gmo ? po/hr.gmo ? po/hu.gmo ? po/it.gmo ? po/ja.gmo ? po/nl.gmo ? po/no.gmo ? po/pl.gmo ? po/pt_BR.gmo ? po/ro.gmo ? po/ru.gmo ? po/sk.gmo ? po/sl.gmo ? po/sr.gmo ? po/sv.gmo ? po/tr.gmo ? po/uk.gmo ? po/zh_CN.gmo ? po/zh_TW.gmo ? src/config.h.in Index: ChangeLog =================================================================== RCS file: /pack/anoncvs/wget/ChangeLog,v retrieving revision 1.232 diff -u -r1.232 ChangeLog --- ChangeLog 2004/05/09 21:08:37 1.232 +++ ChangeLog 2004/11/14 01:13:54 @@ -1,3 +1,61 @@ +2004-11-13 Leonid Petrov (mail@lpetrov.net) + + * Corrected src/ret.c for the bug in CVS version: the previous + version held a long pause, 1-2 minuts, after http file retrieval + when http-proxy was used. + +2004-09-09 Leonid Petrov (mail@lpetrov.net) + + * Replaced a library call strtoll with wget_strtoull which + is appended to the bottom of ftp-basic.c + strtoll is absent in some flavors of Unix, f.e. HP-UX 11.00, + and apparently fails at some other Unixes. + + Modified files: src/http.c, src/ftp.c, src/ftp-basic.c, + src/utils.c, src/utils.h + +2004-09-08 Leonid Petrov (mail@lpetrov.net) + + * Fixed two small bugs in configure.in + +2004-06-30 Leonid Petrov (mail@lpetrov.net) + + * Fixed bugs related to incorrect printing filesize when files + longer than 10Gb are downloaded. Added three new routines: + legible_off_t, number_to_string_off_t and number_to_string_64 . + Replaced $ld and %llu with legible_off_t when a variable related + to filesize is printed. + + Modified files: src/progress.c, src/retr.c, src/utils.c, + src/ftp-basic.c, src/html-url.c, src/ftp-ls.c, + src/http.c, src/ftp.c, progress.h, utils.h, + configure.h + +2004-06-22 Leonid Petrov (mail@lpetrov.net) + + * Fixed bugs related to an attempt to provide Large File Support + in the 2004-06-05 version: + 1) the previous version incorrectly restarted if connection was + broken the first time and crashed if it was broken the second + time; + 2) Progress in batch mode was incorrect. + 3) If the file larger than 2Gb was already downloaded, wget with + -c option tried to downloaded it the second time and append it + to the file which is already in local disk + Modified files: + progress.h, ftp-basic.c, ftp.c, progress.c, retr.c, utils.c + +2004-06-05 Leonid Petrov (mail@lpetrov.net) + + * configure.in: added support of --disable-LFS configuration option. + + * Enabled ability to restart and correctly retrieve large files + if restart occurred after downloading more than 2Gb of data: + src/ftp.h src/ftp-basic.c, etc/ftp.c, etc/ftp-ls.c, src/html-url.c + Replaced some definitions "long" with "off_t" and format + specifications "%ld" with "%lld" in order to allow restarting + for LFS if _LARGEFILE_SOURCE preprocessor symbol is defined. + 2004-05-09 David Fritz * windows/Makefile.src.bor: Fix broken build rule. Add clean target. @@ -24,6 +82,12 @@ specific Wget version from linker flags. Add missing dependencies. +2004-05-07 Alvaro Lopez Ortega + + * configure.in: Added check for strtol() and strtoll() + * configure.in: Added check for LFS + + 2004-02-09 David Fritz * configure.bat.in: Don't clear the screen. Index: configure.in =================================================================== RCS file: /pack/anoncvs/wget/configure.in,v retrieving revision 1.73 diff -u -r1.73 configure.in --- configure.in 2003/11/26 22:46:13 1.73 +++ configure.in 2004/11/14 01:13:55 @@ -107,6 +107,15 @@ AC_AIX AM_PROG_CC_STDC +dnl +dnl Define Large File support +dnl + +AC_ARG_ENABLE(LFS, [ --disable-LFS disable Large File Support], +ENABLE_LFS=$enableval, ENABLE_LFS=yes) +test x"${ENABLE_LFS}" = xyes && AC_DEFINE([ENABLE_LFS], 1, + [Define if you want the Large File Support compiled in.]) + dnl Turn on optimization by default. Specifically: dnl dnl if the user hasn't specified CFLAGS, then @@ -117,6 +126,9 @@ if test -n "$auto_cflags"; then if test -n "$GCC"; then CFLAGS="$CFLAGS -O2 -Wall -Wno-implicit" + if test x"$ENABLE_LFS" = xyes; then + CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DLFS" + fi else case "$host_os" in *hpux*) CFLAGS="$CFLAGS +O3" ;; @@ -208,6 +220,7 @@ AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk memmove) AC_CHECK_FUNCS(gettimeofday mktime strptime strerror snprintf vsnprintf) AC_CHECK_FUNCS(usleep select sigblock sigsetjmp signal symlink access isatty) +AC_CHECK_FUNCS(strtol strtoll) dnl dnl Call Wget's local macros defined in aclocal. Index: src/ftp-basic.c =================================================================== RCS file: /pack/anoncvs/wget/src/ftp-basic.c,v retrieving revision 1.36 diff -u -r1.36 ftp-basic.c --- src/ftp-basic.c 2003/11/21 01:48:05 1.36 +++ src/ftp-basic.c 2004/11/14 01:14:12 @@ -61,11 +61,15 @@ uerr_t ftp_response (int fd, char **ret_line) { + int bufsize = 40; + while (1) { char *line = fd_read_line (fd); - if (!line) + if (!line) { + *ret_line = (char *)xmalloc (bufsize); return FTPRERR; + } if (opt.server_response) logputs (LOG_NOTQUIET, line); else @@ -897,14 +901,14 @@ /* Sends REST command to the FTP server. */ uerr_t -ftp_rest (int csock, long offset) +ftp_rest (int csock, off_t offset) { char *request, *respline; int nwritten; uerr_t err; static char numbuf[24]; /* Buffer for the number */ - number_to_string (numbuf, offset); + number_to_string_off_t (numbuf, offset); request = ftp_request ("REST", numbuf); nwritten = fd_write (csock, request, strlen (request), -1); if (nwritten < 0) @@ -1114,7 +1118,7 @@ /* Sends the SIZE command to the server, and returns the value in 'size'. * If an error occurs, size is set to zero. */ uerr_t -ftp_size (int csock, const char *file, long int *size) +ftp_size (int csock, const char *file, off_t *size) { char *request, *respline; int nwritten; @@ -1150,7 +1154,11 @@ } errno = 0; - *size = strtol (respline + 4, NULL, 0); +#ifdef LFS + *size = wget_strtoull ( respline + 4, NULL, 10 ); +#else + *size = strtol ( respline + 4, NULL, 10 ); +#endif if (errno) { /* @@ -1181,3 +1189,132 @@ else return 'I'; } + +#ifdef LFS +unsigned long long int wget_strtoull ( const char * str, + char ** endptr, + int base ) +/* *********************************************************************** */ +/* */ +/* These functions shall convert the initial portion of the string */ +/* pointed to by nptr to double, float, and long double representation, */ +/* respectively. First, they decompose the input string into three parts: */ +/* */ +/* An initial, possibly empty, sequence of white-space characters */ +/* (as specified by isspace()) */ +/* A subject sequence interpreted as a floating-point constant or */ +/* representing infinity or NaN */ +/* A final string of one or more unrecognized characters, including the */ +/* terminating null byte of the input string */ +/* */ +/* Then they shall attempt to convert the subject sequence */ +/* to a floating-point number, and return the result. */ +/* */ +/* The expected form of the subject sequence is an optional plus or */ +/* minus sign, then one of the following: */ +/* */ +/* A non-empty sequence of decimal digits optionally containing */ +/* a radix character, then an optional exponent part */ +/* */ +/* A 0x or 0X, then a non-empty sequence of hexadecimal digits optionally */ +/* containing a radix character, then an optional binary exponent part */ +/* */ +/* One of INF or INFINITY, ignoring case */ +/* */ +/* One of NAN or NAN(n-char-sequenceopt), ignoring case */ +/* in the NAN part, where: */ +/* n-char-sequence: -- digit -- nondigit -- n-char-sequence digit */ +/* -- n-char-sequence nondigit */ +/* */ +/* Borrowed from http://www.greatsnakes.com/Sepal/d8/d4/strtoull_8c.html */ +/* on 2004.09.09 */ +/* */ +/* 2003, greatsnakes.com. "Verbatim copying and distribution of this */ +/* entire article is permitted in any medium, provided this notice */ +/* is preserved." -- unless otherwise specified. */ +/* */ +/* *********************************************************************** */ +#define WGET__ULLONG_MAX ( 18446744073709551615ULL ) + +{ + unsigned long long result; + unsigned long long stop; + + const char *cursor = str; + int i_char, sign = 0, track, threshold; + + do + { + i_char = *cursor++; + } while ( isspace( i_char & 0xff ) ); + + if ( i_char == '-' ) + { + sign = 1; + i_char = *cursor++; + } else if ( i_char == '+' ) + { + i_char = *cursor++; + }/* end of if else */ + + if (( base == 0 || base == 16 ) && + ( i_char == '0' ) && ( ( ( *cursor == 'x' ) || ( *cursor == 'X' )))) + { + i_char = cursor[1]; + cursor += 2; + base = 16; + }/* end of if base */ + + if ( base == 0 ) + base = ( ( i_char == '0' ) ? 8 : 10 ); + + stop = ((( unsigned long long ) WGET__ULLONG_MAX) / base); + threshold = ((( unsigned long long ) WGET__ULLONG_MAX) % base); + result = 0; track = 0; + + for ( ;; ( i_char = *cursor++ ), ( i_char &= 0xff ) ) + { + if ( isdigit(i_char) ) + { + i_char -= '0'; + } else if (isalpha(i_char)) + { + i_char -= ( isupper(i_char) ? ('A' - 10) : ('a' - 10) ); + } else + { + break; + }/* if elseif else */ + + if ( i_char >= base ) + break; + if ( ( track < 0 ) || ( result > stop ) || + ( result == stop && ( i_char > threshold ) ) ) + { + track = -1; + } else + { + track = 1; + result *= base; + result += i_char; + }/* end if else */ + }/* for ( ;; ( i_char = *cursor++ ), ( i_char &= 0xff ) ) */ + + if ( track < 0 ) + { + result = (( unsigned long long ) WGET__ULLONG_MAX); + errno = ERANGE; + } else if ( sign ) + { + result = -result; + }/* end of if else */ + + if ( endptr != 0 ) + { + // *endptr = ( track ? ( fixit( str, char * ) - 1 ) + // : fixit( str, char * ) ); + } + + return result; +}/* unsigned long long int wget_strtoull ( const char *str, char **endptr, int base ) */ + +#endif /* ifdef LFS */ Index: src/ftp-ls.c =================================================================== RCS file: /pack/anoncvs/wget/src/ftp-ls.c,v retrieving revision 1.27 diff -u -r1.27 ftp-ls.c --- src/ftp-ls.c 2003/12/14 13:35:27 1.27 +++ src/ftp-ls.c 2004/11/14 01:14:14 @@ -213,7 +213,7 @@ if (i != 12) { char *t = tok - 2; - long mul = 1; + off_t mul = 1; for (cur.size = 0; t > line && ISDIGIT (*t); mul *= 10, t--) cur.size += mul * (*t - '0'); @@ -512,7 +512,7 @@ cur.type = FT_PLAINFILE; cur.size = atoi(tok); cur.perms = 0644; - DEBUGP(("File, size %ld bytes\n", cur.size)); + DEBUGP(("File, size %s bytes\n", legible_off_t(cur.size))); } cur.linkto = NULL; @@ -912,7 +912,7 @@ putc ('/', fp); fprintf (fp, " "); if (f->type == FT_PLAINFILE) - fprintf (fp, _(" (%s bytes)"), legible (f->size)); + fprintf (fp, _(" (%s bytes)"), legible_off_t (f->size)); else if (f->type == FT_SYMLINK) fprintf (fp, "-> %s", f->linkto ? f->linkto : "(nil)"); putc ('\n', fp); Index: src/ftp.c =================================================================== RCS file: /pack/anoncvs/wget/src/ftp.c,v retrieving revision 1.88 diff -u -r1.88 ftp.c --- src/ftp.c 2004/02/25 23:45:24 1.88 +++ src/ftp.c 2004/11/14 01:14:17 @@ -85,10 +85,10 @@ /* Look for regexp "( *[0-9]+ *byte" (literal parenthesis) anywhere in the string S, and return the number converted to long, if found, 0 otherwise. */ -static long +static off_t ftp_expected_bytes (const char *s) { - long res; + off_t res; while (1) { @@ -234,19 +234,20 @@ connection to the server. It always closes the data connection, and closes the control connection in case of error. */ static uerr_t -getftp (struct url *u, long *len, long restval, ccon *con) +getftp (struct url *u, off_t *len, off_t restval, ccon *con) { int csock, dtsock, local_sock, res; - uerr_t err; + uerr_t err = 0; FILE *fp; char *user, *passwd, *respline; char *tms, *tmrate; int cmd = con->cmd; int pasv_mode_open = 0; - long expected_bytes = 0L; + off_t expected_bytes = 0; int rest_failed = 0; int flags; - long rd_size; + int flush_res; + off_t rd_size; assert (con != NULL); assert (con->target != NULL); @@ -626,6 +627,7 @@ return err; break; case FTPOK: + logprintf (LOG_VERBOSE, " %s bytes ... ", legible_off_t(*len) ); /* Everything is OK. */ break; default: @@ -770,7 +772,7 @@ if (restval && (cmd & DO_RETR)) { if (!opt.server_response) - logprintf (LOG_VERBOSE, "==> REST %ld ... ", restval); + logprintf (LOG_VERBOSE, "==> REST %s ... ", legible_off_t(restval)); err = ftp_rest (csock, restval); /* FTPRERR, WRITEFAILED, FTPRESTFAIL */ @@ -982,20 +984,33 @@ if (*len) { - logprintf (LOG_VERBOSE, _("Length: %s"), legible (*len)); + logprintf (LOG_VERBOSE, _("Length: %s"), legible_off_t (*len)); if (restval) - logprintf (LOG_VERBOSE, _(" [%s to go]"), legible (*len - restval)); + logprintf (LOG_VERBOSE, _(" [%s to go]"), legible_off_t (*len - restval)); logputs (LOG_VERBOSE, "\n"); expected_bytes = *len; /* for get_contents/show_progress */ } else if (expected_bytes) { - logprintf (LOG_VERBOSE, _("Length: %s"), legible (expected_bytes)); + logprintf (LOG_VERBOSE, _("Length: %s"), legible_off_t (expected_bytes)); if (restval) logprintf (LOG_VERBOSE, _(" [%s to go]"), - legible (expected_bytes - restval)); + legible_off_t (expected_bytes - restval)); logputs (LOG_VERBOSE, _(" (unauthoritative)\n")); } + if (*len > 2147483647 && (*len - restval) <= 0 ) + { + logputs (LOG_VERBOSE, _("File has already been downloaded. Nothing to do.\n")); + /* Close data connection socket. */ + fd_close (dtsock); + fd_close (local_sock); + /* Close the local file. */ + if (!output_stream || con->cmd & DO_LIST) + flush_res = fclose (fp); + else + flush_res = fflush (fp); + return RETRFINISHED; + } /* Get the contents of the document. */ flags = 0; @@ -1004,7 +1019,7 @@ *len = restval; rd_size = 0; res = fd_read_body (dtsock, fp, - expected_bytes ? expected_bytes - restval : 0, + expected_bytes ? expected_bytes - restval : 0, restval, &rd_size, len, &con->dltime, flags); tms = time_str (NULL); @@ -1017,7 +1032,6 @@ /* Close or flush the file. We have to be careful to check for error here. Checking the result of fwrite() is not enough -- errors could go unnoticed! */ - int flush_res; if (!output_stream || con->cmd & DO_LIST) flush_res = fclose (fp); else @@ -1123,7 +1137,7 @@ ftp_loop_internal (struct url *u, struct fileinfo *f, ccon *con) { int count, orig_lp; - long restval, len = 0; + off_t restval, len = 0; char *tms, *locf; char *tmrate = NULL; uerr_t err; @@ -1263,16 +1277,16 @@ con->csock = -1; } if (!opt.spider) - logprintf (LOG_VERBOSE, _("%s (%s) - `%s' saved [%ld]\n\n"), - tms, tmrate, locf, len); + logprintf (LOG_VERBOSE, _("%s (%s) - `%s' saved [%s]\n\n"), + tms, tmrate, locf, legible_off_t(len)); if (!opt.verbose && !opt.quiet) { /* Need to hide the password from the URL. The `if' is here so that we don't do the needless allocation every time. */ char *hurl = url_string (u, 1); - logprintf (LOG_NONVERBOSE, "%s URL: %s [%ld] -> \"%s\" [%d]\n", - tms, hurl, len, locf, count); + logprintf (LOG_NONVERBOSE, "%s URL: %s [%s] -> \"%s\" [%d]\n", + tms, hurl, legible_off_t(len), locf, count); xfree (hurl); } @@ -1389,7 +1403,7 @@ static int depth = 0; uerr_t err; struct fileinfo *orig; - long local_size; + off_t local_size; time_t tml; int dlthis; @@ -1482,7 +1496,7 @@ { /* Sizes do not match */ logprintf (LOG_VERBOSE, _("\ -The sizes do not match (local %ld) -- retrieving.\n\n"), local_size); +The sizes do not match (local %s) -- retrieving.\n\n"), legible_off_t(local_size)); } } } /* opt.timestamping && f->type == FT_PLAINFILE */ @@ -1843,14 +1857,14 @@ if (!opt.output_document) { struct stat st; - long sz; + off_t sz; if (stat (filename, &st) == 0) sz = st.st_size; else sz = -1; logprintf (LOG_NOTQUIET, - _("Wrote HTML-ized index to `%s' [%ld].\n"), - filename, sz); + _("Wrote HTML-ized index to `%s' [%s].\n"), + filename, legible_off_t(sz)); } else logprintf (LOG_NOTQUIET, Index: src/ftp.h =================================================================== RCS file: /pack/anoncvs/wget/src/ftp.h,v retrieving revision 1.23 diff -u -r1.23 ftp.h --- src/ftp.h 2003/11/30 23:39:04 1.23 +++ src/ftp.h 2004/11/14 01:14:17 @@ -56,11 +56,11 @@ uerr_t ftp_type PARAMS ((int, int)); uerr_t ftp_cwd PARAMS ((int, const char *)); uerr_t ftp_retr PARAMS ((int, const char *)); -uerr_t ftp_rest PARAMS ((int, long)); +uerr_t ftp_rest PARAMS ((int, off_t)); uerr_t ftp_list PARAMS ((int, const char *)); uerr_t ftp_syst PARAMS ((int, enum stype *)); uerr_t ftp_pwd PARAMS ((int, char **)); -uerr_t ftp_size PARAMS ((int, const char *, long int *)); +uerr_t ftp_size PARAMS ((int, const char *, off_t *)); #ifdef USE_OPIE const char *skey_response PARAMS ((int, const char *, const char *)); @@ -89,7 +89,7 @@ { enum ftype type; /* file type */ char *name; /* file name */ - long size; /* file size */ + off_t size; /* file size */ long tstamp; /* time-stamp */ int perms; /* file permissions */ char *linkto; /* link to which file points */ Index: src/html-url.c =================================================================== RCS file: /pack/anoncvs/wget/src/html-url.c,v retrieving revision 1.41 diff -u -r1.41 html-url.c --- src/html-url.c 2003/11/26 16:37:04 1.41 +++ src/html-url.c 2004/11/14 01:14:18 @@ -599,7 +599,7 @@ logprintf (LOG_NOTQUIET, "%s: %s\n", file, strerror (errno)); return NULL; } - DEBUGP (("Loaded %s (size %ld).\n", file, fm->length)); + DEBUGP (("Loaded %s (size %s).\n", file, legible_off_t(fm->length))); ctx.text = fm->content; ctx.head = ctx.tail = NULL; @@ -651,7 +651,7 @@ logprintf (LOG_NOTQUIET, "%s: %s\n", file, strerror (errno)); return NULL; } - DEBUGP (("Loaded %s (size %ld).\n", file, fm->length)); + DEBUGP (("Loaded %s (size %s).\n", file, legible_off_t(fm->length))); head = tail = NULL; text = fm->content; Index: src/http.c =================================================================== RCS file: /pack/anoncvs/wget/src/http.c,v retrieving revision 1.143 diff -u -r1.143 http.c --- src/http.c 2004/03/31 19:14:05 1.143 +++ src/http.c 2004/11/14 01:14:23 @@ -219,8 +219,13 @@ request_set_header (req, "Referer", opt.referer, rel_none); // Value freshly allocated, free it when done. +#ifdef LFS + request_set_header (req, "Range", aprintf ("bytes=%llu-", hs->restval), + rel_value); +#else request_set_header (req, "Range", aprintf ("bytes=%ld-", hs->restval), rel_value); +#endif */ static void @@ -359,10 +364,10 @@ longer, read only that much; if the file is shorter, report an error. */ static int -post_file (int sock, const char *file_name, long promised_size) +post_file (int sock, const char *file_name, off_t promised_size) { static char chunk[8192]; - long written = 0; + off_t written = 0; int write_error; FILE *fp; @@ -705,10 +710,10 @@ /* Parse the `Content-Range' header and extract the information it contains. Returns 1 if successful, -1 otherwise. */ static int -parse_content_range (const char *hdr, long *first_byte_ptr, - long *last_byte_ptr, long *entity_length_ptr) +parse_content_range (const char *hdr, off_t *first_byte_ptr, + off_t *last_byte_ptr, off_t *entity_length_ptr) { - long num; + off_t num; /* Ancient versions of Netscape proxy server, presumably predating rfc2068, sent out `Content-Range' without the "bytes" @@ -751,7 +756,7 @@ which need to be read anyway. */ static void -skip_short_body (int fd, long contlen) +skip_short_body (int fd, off_t contlen) { /* Skipping the body doesn't make sense if the content length is unknown because, in that case, persistent connections cannot be @@ -759,7 +764,7 @@ still be used with the magic of the "chunked" transfer!) */ if (contlen == -1) return; - DEBUGP (("Skipping %ld bytes of body data... ", contlen)); + DEBUGP (("Skipping %s bytes of body data... ", legible_off_t(contlen))); while (contlen > 0) { @@ -974,15 +979,15 @@ struct http_stat { - long len; /* received length */ - long contlen; /* expected length */ - long restval; /* the restart value */ + off_t len; /* received length */ + off_t contlen; /* expected length */ + off_t restval; /* the restart value */ int res; /* the result of last read */ char *newloc; /* new location (redirection) */ char *remote_time; /* remote time-stamp string */ char *error; /* textual HTTP error */ int statcode; /* status code */ - long rd_size; /* amount of data read from socket */ + off_t rd_size; /* amount of data read from socket */ double dltime; /* time it took to download the data */ const char *referer; /* value of the referer header. */ char **local_file; /* local file. */ @@ -1034,7 +1039,7 @@ char *proxyauth; int statcode; int write_error; - long contlen, contrange; + off_t contlen, contrange; struct url *conn; FILE *fp; @@ -1060,7 +1065,7 @@ int inhibit_keep_alive = !opt.http_keep_alive || opt.ignore_length; /* Headers sent when using POST. */ - long post_data_size = 0; + off_t post_data_size = 0; int host_lookup_failed = 0; @@ -1133,8 +1138,13 @@ if (*dt & SEND_NOCACHE) request_set_header (req, "Pragma", "no-cache", rel_none); if (hs->restval) +#ifdef LFS request_set_header (req, "Range", + aprintf ("bytes=%llu-", hs->restval), rel_value); +#else + request_set_header (req, "Range", aprintf ("bytes=%ld-", hs->restval), rel_value); +#endif if (opt.useragent) request_set_header (req, "User-Agent", opt.useragent, rel_none); else @@ -1258,8 +1268,13 @@ post_data_size = 0; } } +#ifdef LFS request_set_header (req, "Content-Length", + aprintf ("%llu", post_data_size), rel_value); +#else + request_set_header (req, "Content-Length", aprintf ("%ld", post_data_size), rel_value); +#endif } /* Add the user headers. */ @@ -1463,7 +1478,11 @@ if (!opt.ignore_length && response_header_copy (resp, "Content-Length", hdrval, sizeof (hdrval))) - contlen = strtol (hdrval, NULL, 10); +#ifdef LFS + contlen = wget_strtoull ( hdrval, NULL, 10 ); +#else + contlen = strtol ( hdrval, NULL, 10 ); +#endif /* Check for keep-alive related responses. */ if (!inhibit_keep_alive && contlen != -1) @@ -1562,7 +1581,7 @@ } if (response_header_copy (resp, "Content-Range", hdrval, sizeof (hdrval))) { - long first_byte_pos, last_byte_pos, entity_length; + off_t first_byte_pos, last_byte_pos, entity_length; if (parse_content_range (hdrval, &first_byte_pos, &last_byte_pos, &entity_length)) contrange = first_byte_pos; @@ -1666,9 +1685,9 @@ logputs (LOG_VERBOSE, _("Length: ")); if (contlen != -1) { - logputs (LOG_VERBOSE, legible (contlen + contrange)); + logputs (LOG_VERBOSE, legible_off_t (contlen + contrange)); if (contrange) - logprintf (LOG_VERBOSE, _(" (%s to go)"), legible (contlen)); + logprintf (LOG_VERBOSE, _(" (%s to go)"), legible_off_t (contlen)); } else logputs (LOG_VERBOSE, @@ -1768,7 +1787,7 @@ char *tms, *locf, *tmrate; uerr_t err; time_t tml = -1, tmr = -1; /* local and remote time-stamps */ - long local_size = 0; /* the size of the local file */ + off_t local_size = 0; /* the size of the local file */ size_t filename_len; struct http_stat hstat; /* HTTP status */ struct stat st; @@ -2096,7 +2115,7 @@ } else if (tml >= tmr) logprintf (LOG_VERBOSE, _("\ -The sizes do not match (local %ld) -- retrieving.\n"), local_size); +The sizes do not match (local %s) -- retrieving.\n"), legible_off_t(local_size)); else logputs (LOG_VERBOSE, _("Remote file is newer, retrieving.\n")); @@ -2140,11 +2159,13 @@ if (*dt & RETROKF) { logprintf (LOG_VERBOSE, - _("%s (%s) - `%s' saved [%ld/%ld]\n\n"), - tms, tmrate, locf, hstat.len, hstat.contlen); + _("%s (%s) - `%s' saved [%s/%s]\n\n"), + tms, tmrate, locf, legible_off_t(hstat.len), + legible_off_t(hstat.contlen)); logprintf (LOG_NONVERBOSE, - "%s URL:%s [%ld/%ld] -> \"%s\" [%d]\n", - tms, u->url, hstat.len, hstat.contlen, locf, count); + "%s URL:%s [%s/%s] -> \"%s\" [%d]\n", + tms, u->url, legible_off_t(hstat.len), + legible_off_t(hstat.contlen), locf, count); } ++opt.numurls; total_downloaded_bytes += hstat.len; @@ -2167,11 +2188,11 @@ if (*dt & RETROKF) { logprintf (LOG_VERBOSE, - _("%s (%s) - `%s' saved [%ld]\n\n"), - tms, tmrate, locf, hstat.len); + _("%s (%s) - `%s' saved [%s]\n\n"), + tms, tmrate, locf, legible_off_t(hstat.len)); logprintf (LOG_NONVERBOSE, - "%s URL:%s [%ld] -> \"%s\" [%d]\n", - tms, u->url, hstat.len, locf, count); + "%s URL:%s [%s] -> \"%s\" [%d]\n", + tms, u->url, legible_off_t(hstat.len), locf, count); } ++opt.numurls; total_downloaded_bytes += hstat.len; @@ -2190,8 +2211,8 @@ connection too soon */ { logprintf (LOG_VERBOSE, - _("%s (%s) - Connection closed at byte %ld. "), - tms, tmrate, hstat.len); + _("%s (%s) - Connection closed at byte %s. "), + tms, tmrate, legible(hstat.len)); printwhat (count, opt.ntry); free_hstat (&hstat); continue; @@ -2199,11 +2220,13 @@ else if (!opt.kill_longer) /* meaning we got more than expected */ { logprintf (LOG_VERBOSE, - _("%s (%s) - `%s' saved [%ld/%ld])\n\n"), - tms, tmrate, locf, hstat.len, hstat.contlen); + _("%s (%s) - `%s' saved [%s/%s])\n\n"), + tms, tmrate, locf, legible_off_t(hstat.len), + legible_off_t(hstat.contlen)); logprintf (LOG_NONVERBOSE, - "%s URL:%s [%ld/%ld] -> \"%s\" [%d]\n", - tms, u->url, hstat.len, hstat.contlen, locf, count); + "%s URL:%s [%s/%s] -> \"%s\" [%d]\n", + tms, u->url, legible_off_t(hstat.len), + legible_off_t(hstat.contlen), locf, count); ++opt.numurls; total_downloaded_bytes += hstat.len; @@ -2220,8 +2243,9 @@ else /* the same, but not accepted */ { logprintf (LOG_VERBOSE, - _("%s (%s) - Connection closed at byte %ld/%ld. "), - tms, tmrate, hstat.len, hstat.contlen); + _("%s (%s) - Connection closed at byte %s/%s. "), + tms, tmrate, legible_off_t(hstat.len), + legible_off_t(hstat.contlen)); printwhat (count, opt.ntry); free_hstat (&hstat); continue; @@ -2232,8 +2256,9 @@ if (hstat.contlen == -1) { logprintf (LOG_VERBOSE, - _("%s (%s) - Read error at byte %ld (%s)."), - tms, tmrate, hstat.len, strerror (errno)); + _("%s (%s) - Read error at byte %s (%s)."), + tms, tmrate, legible_off_t(hstat.len), + strerror (errno)); printwhat (count, opt.ntry); free_hstat (&hstat); continue; @@ -2241,8 +2266,9 @@ else /* hstat.res == -1 and contlen is given */ { logprintf (LOG_VERBOSE, - _("%s (%s) - Read error at byte %ld/%ld (%s). "), - tms, tmrate, hstat.len, hstat.contlen, + _("%s (%s) - Read error at byte %s/%s (%s). "), + tms, tmrate, legible_off_t(hstat.len), + legible_off_t(hstat.contlen), strerror (errno)); printwhat (count, opt.ntry); free_hstat (&hstat); Index: src/progress.c =================================================================== RCS file: /pack/anoncvs/wget/src/progress.c,v retrieving revision 1.43 diff -u -r1.43 progress.c --- src/progress.c 2004/01/28 01:02:26 1.43 +++ src/progress.c 2004/11/14 01:14:27 @@ -52,21 +52,21 @@ struct progress_implementation { const char *name; int interactive; - void *(*create) PARAMS ((long, long)); - void (*update) PARAMS ((void *, long, double)); + void *(*create) PARAMS ((off_t, off_t)); + void (*update) PARAMS ((void *, off_t, double)); void (*finish) PARAMS ((void *, double)); void (*set_params) PARAMS ((const char *)); }; /* Necessary forward declarations. */ -static void *dot_create PARAMS ((long, long)); -static void dot_update PARAMS ((void *, long, double)); +static void *dot_create PARAMS ((off_t, off_t)); +static void dot_update PARAMS ((void *, off_t, double)); static void dot_finish PARAMS ((void *, double)); static void dot_set_params PARAMS ((const char *)); -static void *bar_create PARAMS ((long, long)); -static void bar_update PARAMS ((void *, long, double)); +static void *bar_create PARAMS ((off_t, off_t)); +static void bar_update PARAMS ((void *, off_t, double)); static void bar_finish PARAMS ((void *, double)); static void bar_set_params PARAMS ((const char *)); @@ -156,7 +156,7 @@ advance. */ void * -progress_create (long initial, long total) +progress_create (off_t initial, off_t total) { /* Check if the log status has changed under our feet. */ if (output_redirected) @@ -184,7 +184,7 @@ time in milliseconds since the beginning of the download. */ void -progress_update (void *progress, long howmuch, double dltime) +progress_update (void *progress, off_t howmuch, double dltime) { current_impl->update (progress, howmuch, dltime); } @@ -201,12 +201,12 @@ /* Dot-printing. */ struct dot_progress { - long initial_length; /* how many bytes have been downloaded + off_t initial_length; /* how many bytes have been downloaded previously. */ - long total_length; /* expected total byte count when the + off_t total_length; /* expected total byte count when the download finishes */ - int accumulated; + off_t accumulated; int rows; /* number of rows printed so far */ int dots; /* number of dots printed in this row */ @@ -216,7 +216,7 @@ /* Dot-progress backend for progress_create. */ static void * -dot_create (long initial, long total) +dot_create (off_t initial, off_t total) { struct dot_progress *dp = xnew0 (struct dot_progress); dp->initial_length = initial; @@ -224,11 +224,35 @@ if (dp->initial_length) { +#ifdef LFS /* 64-bit off_t */ + long long int dot_bytes = opt.dot_bytes; + long row_bytes = opt.dot_bytes * opt.dots_in_line; + + long long int remainder = (long long int) (dp->initial_length % row_bytes); + off_t skipped = dp->initial_length - remainder; + + if (skipped) + { + long long int skipped_k = (skipped / 1024ULL); /* skipped amount in K */ + int skipped_k_len = numdigit_64 (skipped_k); + if (skipped_k_len < 5) + skipped_k_len = 5; + + /* Align the [ skipping ... ] line with the dots. To do + that, insert the number of spaces equal to the number of + digits in the skipped amount in K. */ + DEBUGP ( ("Skipped bytes: %llu", skipped )); + logprintf (LOG_VERBOSE, _("\n%*s[ skipping %lluK ]"), + 2 + skipped_k_len, "", skipped_k); + } + + logprintf (LOG_VERBOSE, "\n%5lluK", (skipped / 1024ULL) ); +#else int dot_bytes = opt.dot_bytes; long row_bytes = opt.dot_bytes * opt.dots_in_line; int remainder = (int) (dp->initial_length % row_bytes); - long skipped = dp->initial_length - remainder; + off_t skipped = dp->initial_length - remainder; if (skipped) { @@ -240,11 +264,13 @@ /* Align the [ skipping ... ] line with the dots. To do that, insert the number of spaces equal to the number of digits in the skipped amount in K. */ + DEBUGP ( ("Skipped bytes: %ld", skipped )); logprintf (LOG_VERBOSE, _("\n%*s[ skipping %dK ]"), 2 + skipped_k_len, "", skipped_k); } - logprintf (LOG_VERBOSE, "\n%5ldK", skipped / 1024); + logprintf (LOG_VERBOSE, "\n%5luK", skipped / 1024); +#endif for (; remainder >= dot_bytes; remainder -= dot_bytes) { if (dp->dots % opt.dot_spacing == 0) @@ -262,14 +288,14 @@ } static void -print_percentage (long bytes, long expected) +print_percentage (off_t bytes, off_t expected) { int percentage = (int)(100.0 * bytes / expected); logprintf (LOG_VERBOSE, "%3d%%", percentage); } static void -print_download_speed (struct dot_progress *dp, long bytes, double dltime) +print_download_speed (struct dot_progress *dp, off_t bytes, double dltime) { logprintf (LOG_VERBOSE, " %s", retr_rate (bytes, dltime - dp->last_timer_value, 1)); @@ -279,7 +305,7 @@ /* Dot-progress backend for progress_update. */ static void -dot_update (void *progress, long howmuch, double dltime) +dot_update (void *progress, off_t howmuch, double dltime) { struct dot_progress *dp = progress; int dot_bytes = opt.dot_bytes; @@ -291,7 +317,12 @@ for (; dp->accumulated >= dot_bytes; dp->accumulated -= dot_bytes) { if (dp->dots == 0) +#ifdef LFS + logprintf (LOG_VERBOSE, "\n%5lluK", + (long long)dp->rows * (long long)row_bytes / 1024ULL ); +#else logprintf (LOG_VERBOSE, "\n%5ldK", dp->rows * row_bytes / 1024); +#endif if (dp->dots % opt.dot_spacing == 0) logputs (LOG_VERBOSE, " "); @@ -308,7 +339,12 @@ dp->dots = 0; if (dp->total_length) +#ifdef LFS + print_percentage ( (long long)dp->rows * (long long)row_bytes, + dp->total_length); +#else print_percentage (dp->rows * row_bytes, dp->total_length); +#endif print_download_speed (dp, row_qty, dltime); } } @@ -329,7 +365,12 @@ log_set_flush (0); if (dp->dots == 0) +#ifdef LFS + logprintf (LOG_VERBOSE, "\n%5lluK", + (long long)dp->rows * (long long)(row_bytes) / 1024ULL ); +#else logprintf (LOG_VERBOSE, "\n%5ldK", dp->rows * row_bytes / 1024); +#endif for (i = dp->dots; i < opt.dots_in_line; i++) { if (i % opt.dot_spacing == 0) @@ -338,14 +379,26 @@ } if (dp->total_length) { +#ifdef LFS + print_percentage ( (long long)dp->rows * (long long)row_bytes + + (long long)dp->dots * (long long)dot_bytes + + dp->accumulated, + dp->total_length); +#else print_percentage (dp->rows * row_bytes + dp->dots * dot_bytes + dp->accumulated, dp->total_length); +#endif } { +#ifdef LFS + long long row_qty = (long long)dp->dots * (long long)dot_bytes + + dp->accumulated; +#else long row_qty = dp->dots * dot_bytes + dp->accumulated; +#endif if (dp->rows == dp->initial_length / row_bytes) row_qty -= dp->initial_length % row_bytes; print_download_speed (dp, row_qty, dltime); @@ -443,11 +496,11 @@ #define STALL_START_TIME 5000 struct bar_progress { - long initial_length; /* how many bytes have been downloaded + off_t initial_length; /* how many bytes have been downloaded previously. */ - long total_length; /* expected total byte count when the + off_t total_length; /* expected total byte count when the download finishes */ - long count; /* bytes downloaded so far */ + off_t count; /* bytes downloaded so far */ double last_screen_update; /* time of the last screen update, measured since the beginning of @@ -470,18 +523,18 @@ details. */ struct bar_progress_hist { int pos; - long times[DLSPEED_HISTORY_SIZE]; - long bytes[DLSPEED_HISTORY_SIZE]; + off_t times[DLSPEED_HISTORY_SIZE]; + off_t bytes[DLSPEED_HISTORY_SIZE]; /* The sum of times and bytes respectively, maintained for efficiency. */ - long total_time; - long total_bytes; + off_t total_time; + off_t total_bytes; } hist; double recent_start; /* timestamp of beginning of current position. */ - long recent_bytes; /* bytes downloaded so far. */ + off_t recent_bytes; /* bytes downloaded so far. */ int stalled; /* set when no data arrives for longer than STALL_START_TIME, then reset @@ -499,7 +552,7 @@ static void display_image PARAMS ((char *)); static void * -bar_create (long initial, long total) +bar_create (off_t initial, off_t total) { struct bar_progress *bp = xnew0 (struct bar_progress); @@ -536,10 +589,10 @@ return bp; } -static void update_speed_ring PARAMS ((struct bar_progress *, long, double)); +static void update_speed_ring PARAMS ((struct bar_progress *, off_t, double)); static void -bar_update (void *progress, long howmuch, double dltime) +bar_update (void *progress, off_t howmuch, double dltime) { struct bar_progress *bp = progress; int force_screen_update = 0; @@ -622,7 +675,7 @@ 3-second average would be too erratic. */ static void -update_speed_ring (struct bar_progress *bp, long howmuch, double dltime) +update_speed_ring (struct bar_progress *bp, off_t howmuch, double dltime) { struct bar_progress_hist *hist = &bp->hist; double recent_age = dltime - bp->recent_start; @@ -719,9 +772,9 @@ create_image (struct bar_progress *bp, double dl_total_time) { char *p = bp->buffer; - long size = bp->initial_length + bp->count; + off_t size = bp->initial_length + bp->count; - char *size_legible = legible (size); + char *size_legible = legible_off_t (size); int size_legible_len = strlen (size_legible); struct bar_progress_hist *hist = &bp->hist; @@ -828,7 +881,7 @@ } /* " 234,567,890" */ - sprintf (p, " %-11s", legible (size)); + sprintf (p, " %-11s", legible_off_t (size)); p += strlen (p); /* " 1012.45K/s" */ @@ -838,7 +891,7 @@ int units = 0; /* Calculate the download speed using the history ring and recent data that hasn't made it to the ring yet. */ - long dlquant = hist->total_bytes + bp->recent_bytes; + off_t dlquant = hist->total_bytes + bp->recent_bytes; double dltime = hist->total_time + (dl_total_time - bp->recent_start); double dlspeed = calc_rate (dlquant, dltime, &units); sprintf (p, " %7.2f%s", dlspeed, short_units[units]); @@ -871,7 +924,7 @@ I found that doing that results in a very jerky and ultimately unreliable ETA. */ double time_sofar = (double)dl_total_time / 1000; - long bytes_remaining = bp->total_length - size; + off_t bytes_remaining = bp->total_length - size; eta = (long) (time_sofar * bytes_remaining / bp->count); bp->last_eta_value = eta; bp->last_eta_time = dl_total_time; Index: src/progress.h =================================================================== RCS file: /pack/anoncvs/wget/src/progress.h,v retrieving revision 1.7 diff -u -r1.7 progress.h --- src/progress.h 2003/11/08 16:56:52 1.7 +++ src/progress.h 2004/11/14 01:14:27 @@ -34,9 +34,9 @@ void set_progress_implementation PARAMS ((const char *)); void progress_schedule_redirect PARAMS ((void)); -void *progress_create PARAMS ((long, long)); +void *progress_create PARAMS ((off_t, off_t)); int progress_interactive_p PARAMS ((void *)); -void progress_update PARAMS ((void *, long, double)); +void progress_update PARAMS ((void *, off_t, double)); void progress_finish PARAMS ((void *, double)); RETSIGTYPE progress_handle_sigwinch PARAMS ((int)); Index: src/retr.c =================================================================== RCS file: /pack/anoncvs/wget/src/retr.c,v retrieving revision 1.85 diff -u -r1.85 retr.c --- src/retr.c 2004/03/04 00:05:26 1.85 +++ src/retr.c 2004/11/14 01:14:29 @@ -75,7 +75,7 @@ int output_stream_regular; static struct { - long chunk_bytes; + off_t chunk_bytes; double chunk_start; double sleep_adjust; } limit_data; @@ -92,7 +92,7 @@ is the timer that started at the beginning of download. */ static void -limit_bandwidth (long bytes, struct wget_timer *timer) +limit_bandwidth (off_t bytes, struct wget_timer *timer) { double delta_t = wtimer_read (timer) - limit_data.chunk_start; double expected; @@ -110,12 +110,13 @@ double t0, t1; if (slp < 200) { - DEBUGP (("deferring a %.2f ms sleep (%ld/%.2f).\n", - slp, limit_data.chunk_bytes, delta_t)); + DEBUGP (("deferring a %.2f ms sleep (%s/%.2f).\n", + slp, legible_off_t(limit_data.chunk_bytes), delta_t)); return; } - DEBUGP (("\nsleeping %.2f ms for %ld bytes, adjust %.2f ms\n", - slp, limit_data.chunk_bytes, limit_data.sleep_adjust)); + DEBUGP (("\nsleeping %.2f ms for %s bytes, adjust %.2f ms\n", + slp, legible_off_t(limit_data.chunk_bytes), + limit_data.sleep_adjust)); t0 = wtimer_read (timer); xsleep (slp / 1000); @@ -142,8 +143,8 @@ of data written. */ static int -write_data (FILE *out, const char *buf, int bufsize, long *skip, - long *written) +write_data (FILE *out, const char *buf, int bufsize, off_t *skip, + off_t *written) { if (!out) return 1; @@ -192,8 +193,8 @@ writing data, -2 is returned. */ int -fd_read_body (int fd, FILE *out, long toread, long startpos, - long *qtyread, long *qtywritten, double *elapsed, int flags) +fd_read_body (int fd, FILE *out, off_t toread, off_t startpos, + off_t *qtyread, off_t *qtywritten, double *elapsed, int flags) { int ret = 0; @@ -213,11 +214,11 @@ int progress_interactive = 0; int exact = flags & rb_read_exactly; - long skip = 0; + off_t skip = 0; /* How much data we've read/written. */ - long sum_read = 0; - long sum_written = 0; + off_t sum_read = 0; + off_t sum_written = 0; if (flags & rb_skip_startpos) skip = startpos; @@ -256,7 +257,7 @@ should be read. */ while (!exact || (sum_read < toread)) { - int rdsize = exact ? MIN (toread - sum_read, dlbufsize) : dlbufsize; + off_t rdsize = exact ? MIN (toread - sum_read, dlbufsize) : dlbufsize; double tmout = opt.read_timeout; if (progress_interactive) { @@ -283,6 +284,8 @@ } ret = fd_read (fd, dlbuf, rdsize, tmout); + if ( ret == -1 && errno == ETIMEDOUT && sum_read == toread && toread > 0 ) break; + if (ret == 0 || (ret < 0 && errno != ETIMEDOUT)) break; /* read error */ else if (ret < 0) @@ -482,7 +485,7 @@ appropriate for the speed. If PAD is non-zero, strings will be padded to the width of 7 characters (xxxx.xx). */ char * -retr_rate (long bytes, double msecs, int pad) +retr_rate (off_t bytes, double msecs, int pad) { static char res[20]; static const char *rate_names[] = {"B/s", "KB/s", "MB/s", "GB/s" }; @@ -502,7 +505,7 @@ UNITS is zero for B/s, one for KB/s, two for MB/s, and three for GB/s. */ double -calc_rate (long bytes, double msecs, int *units) +calc_rate (off_t bytes, double msecs, int *units) { double dlrate; Index: src/retr.h =================================================================== RCS file: /pack/anoncvs/wget/src/retr.h,v retrieving revision 1.19 diff -u -r1.19 retr.h --- src/retr.h 2003/12/06 02:32:57 1.19 +++ src/retr.h 2004/11/14 01:14:29 @@ -36,8 +36,8 @@ rb_skip_startpos = 2 }; -int fd_read_body PARAMS ((int, FILE *, long, long, long *, long *, double *, - int)); +int fd_read_body PARAMS ((int, FILE *, off_t, off_t, off_t *, off_t *, + double *, int)); typedef const char *(*hunk_terminator_t) PARAMS ((const char *, int, int)); @@ -48,8 +48,8 @@ const char *, int *)); uerr_t retrieve_from_file PARAMS ((const char *, int, int *)); -char *retr_rate PARAMS ((long, double, int)); -double calc_rate PARAMS ((long, double, int *)); +char *retr_rate PARAMS ((off_t, double, int)); +double calc_rate PARAMS ((off_t, double, int *)); void printwhat PARAMS ((int, int)); void sleep_between_retrievals PARAMS ((int)); Index: src/utils.c =================================================================== RCS file: /pack/anoncvs/wget/src/utils.c,v retrieving revision 1.77 diff -u -r1.77 utils.c --- src/utils.c 2004/01/29 12:38:52 1.77 +++ src/utils.c 2004/11/14 01:14:32 @@ -383,10 +383,10 @@ /* Return the size of file named by FILENAME, or -1 if it cannot be opened or seeked into. */ -long +off_t file_size (const char *filename) { - long size; + off_t size; /* We use fseek rather than stat to determine the file size because that way we can also verify whether the file is readable. Inspired by the POST patch by Arnaud Wylie. */ @@ -799,7 +799,7 @@ { int fd; struct file_memory *fm; - long size; + off_t size; int inhibit_close = 0; /* Some magic in the finest tradition of Perl and its kin: if FILE @@ -851,7 +851,7 @@ fm->content = xmalloc (size); while (1) { - long nread; + off_t nread; if (fm->length > size / 2) { /* #### I'm not sure whether the whole exponential-growth @@ -1151,7 +1151,7 @@ /* Legible -- return a static pointer to the legibly printed long. */ char * -legible (long l) +legible (unsigned long int l) { char inbuf[24]; /* Print the number into the buffer. */ @@ -1187,7 +1187,7 @@ /* Count the digits in a (long) integer. */ int -numdigit (long number) +numdigit (unsigned long int number) { int cnt = 1; if (number < 0) @@ -1200,6 +1200,24 @@ return cnt; } +#ifdef LFS +int +numdigit_64 (unsigned long long int number) +{ + int cnt = 1; + if (number < 0) + { + number = -number; + ++cnt; + } + while ((number /= 10ULL) > 0) + ++cnt; + return cnt; +} + +#endif + + /* Attempt to calculate INT_MAX on machines that don't bother to define it. */ #ifndef INT_MAX @@ -1254,10 +1272,10 @@ terminating '\0'. */ char * -number_to_string (char *buffer, long number) +number_to_string (char *buffer, unsigned long int number) { char *p = buffer; - long n = number; + unsigned long int n = number; #if (SIZEOF_LONG != 4) && (SIZEOF_LONG != 8) /* We are running in a strange or misconfigured environment. Let @@ -1988,3 +2006,88 @@ } #endif /* not WINDOWS */ + +#ifdef LFS +char * +number_to_string_off_t (char *buffer, off_t number) +{ + if ( sizeof(number) == 8 ) + return number_to_string_64 (buffer, number); + else + return number_to_string (buffer, number); + return number_to_string (buffer, number); +} + + +/* Legible_off_t -- return a static pointer to the legibly printed long. */ +/* the same as legible, but it interprete the argument */ +/* either as 32-bits unsigned long or as 64-bits unsigned */ +/* long according to the size of off_t */ + +char * +legible_off_t ( off_t l) +{ + char inbuf[28]; + /* Print the number into the buffer. */ + + number_to_string_off_t (inbuf, l); + return legible_1 (inbuf); +} + +/* number_to_string_64 -- is the same as number_to_string, but it it */ +/* assumes that its argukent is a 64-bits unsigned */ +/* long */ + +char * +number_to_string_64 (char *buffer, unsigned long long int number) +{ + char *p = buffer; + unsigned long long int n = number; + +#define ONE_DIGIT(figure) *p++ = n / (figure) + '0' +#define ONE_DIGIT_ADVANCE(figure) (ONE_DIGIT (figure), n %= (figure)) + +#define DIGITS_1(figure) ONE_DIGIT (figure) +#define DIGITS_2(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_1 ((figure) / 10) +#define DIGITS_3(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_2 ((figure) / 10) +#define DIGITS_4(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_3 ((figure) / 10) +#define DIGITS_5(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_4 ((figure) / 10) +#define DIGITS_6(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_5 ((figure) / 10) +#define DIGITS_7(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_6 ((figure) / 10) +#define DIGITS_8(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_7 ((figure) / 10) +#define DIGITS_9(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_8 ((figure) / 10) +#define DIGITS_10(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_9 ((figure) / 10) +#define DIGITS_11(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_10 ((figure) / 10) +#define DIGITS_12(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_11 ((figure) / 10) +#define DIGITS_13(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_12 ((figure) / 10) +#define DIGITS_14(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_13 ((figure) / 10) +#define DIGITS_15(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_14 ((figure) / 10) +#define DIGITS_16(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_15 ((figure) / 10) +#define DIGITS_17(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_16 ((figure) / 10) +#define DIGITS_18(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_17 ((figure) / 10) +#define DIGITS_19(figure) ONE_DIGIT_ADVANCE (figure); DIGITS_18 ((figure) / 10) + + if (n < 10ULL) { DIGITS_1 (1ULL); } + else if (n < 100ULL) { DIGITS_2 (10ULL); } + else if (n < 1000ULL) { DIGITS_3 (100ULL); } + else if (n < 10000ULL) { DIGITS_4 (1000ULL); } + else if (n < 100000ULL) { DIGITS_5 (10000ULL); } + else if (n < 1000000ULL) { DIGITS_6 (100000ULL); } + else if (n < 10000000ULL) { DIGITS_7 (1000000ULL); } + else if (n < 100000000ULL) { DIGITS_8 (10000000ULL); } + else if (n < 1000000000ULL) { DIGITS_9 (100000000ULL); } + else if (n < 10000000000ULL) { DIGITS_10 (1000000000ULL); } + else if (n < 100000000000ULL) { DIGITS_11 (10000000000ULL); } + else if (n < 1000000000000ULL) { DIGITS_12 (100000000000ULL); } + else if (n < 10000000000000ULL) { DIGITS_13 (1000000000000ULL); } + else if (n < 100000000000000ULL) { DIGITS_14 (10000000000000ULL); } + else if (n < 1000000000000000ULL) { DIGITS_15 (100000000000000ULL); } + else if (n < 10000000000000000ULL) { DIGITS_16 (1000000000000000ULL); } + else if (n < 100000000000000000ULL) { DIGITS_17 (10000000000000000ULL); } + else if (n < 1000000000000000000ULL) { DIGITS_18 (100000000000000000ULL); } + else { DIGITS_19 (1000000000000000000ULL); } + + *p = '\0'; + return p; +} +#endif /* LFS */ Index: src/utils.h =================================================================== RCS file: /pack/anoncvs/wget/src/utils.h,v retrieving revision 1.32 diff -u -r1.32 utils.h --- src/utils.h 2003/11/29 18:40:01 1.32 +++ src/utils.h 2004/11/14 01:14:33 @@ -45,7 +45,7 @@ struct file_memory { char *content; - long length; + off_t length; int mmap_p; }; @@ -79,7 +79,7 @@ int remove_link PARAMS ((const char *)); int file_exists_p PARAMS ((const char *)); int file_non_directory_p PARAMS ((const char *)); -long file_size PARAMS ((const char *)); +off_t file_size PARAMS ((const char *)); int make_directory PARAMS ((const char *)); char *unique_name PARAMS ((const char *, int)); char *file_merge PARAMS ((const char *, const char *)); @@ -109,10 +109,21 @@ void string_set_free PARAMS ((struct hash_table *)); void free_keys_and_values PARAMS ((struct hash_table *)); -char *legible PARAMS ((long)); +char *legible PARAMS ((unsigned long int)); char *legible_large_int PARAMS ((LARGE_INT)); -int numdigit PARAMS ((long)); -char *number_to_string PARAMS ((char *, long)); +int numdigit PARAMS ((unsigned long int)); +char *number_to_string PARAMS ((char *, unsigned long int)); + +#ifdef LFS +char *legible_off_t PARAMS ((off_t)); +char *number_to_string_off_t PARAMS ((char *, off_t )); +char *number_to_string_64 PARAMS ((char *, unsigned long long int)); +int numdigit_64 PARAMS ((unsigned long long int)); +unsigned long long int wget_strtoull ( const char *ptr, char **endptr, int base ); +#else +#define number_to_string_off_t number_to_string +#define legible_off_t legible +#endif struct wget_timer *wtimer_allocate PARAMS ((void)); struct wget_timer *wtimer_new PARAMS ((void));