commit a82b08e791741db37bd3f70b3fc19cd3bf08c24a
parent b2a2fbfa6266e4874ed9849f13f4226f3bd54917
Author: ukai <ukai>
Date:   Tue, 20 Aug 2002 17:49:38 +0000
Debian Bug#157098: wrong file presentation on large files
	  from "Eduard Bloch" <blade@debian.org>
* configure (clen_t): added
		(HAVE_STRTOLL): added
		(HAVE_STRTOQ): added
		(HAVE_ATOLL): added
		(HAVE_ATOQ): added
* config.h.dist: ditto
* file.c (current_content_length): s/int/clen_t/
	(loadGeneralFile): s/atoi/strtoclen/
	(convert_size): s/int/clen_t/
	(convert_size2): s/int/clen_t/
	(showProgress): s/int/clen_t/
	(loadHTMLstream): s/int/clen_t/ linelen, trbyte
	(loadBuffer): ditto
	(getNextPage): s/int/clen_t/ linelen
	(save2tmp): s/int/clen_t/ linelen, trbye
	(_MoveFile): s/int/clen_t/ linelen, trbye
* fm.h (_Buffer): s/int/clen_t/ linelen, trbye
* ftp.c (size_int2str): s/long/clen_t/
	(ex_ftpdir_name_size_date): s/long/clen_t/
* indep.c (strtoclen): added
* indep.h (strtoclen): added
* proto.h (showProgress): s/int/clen_t/
From: Fumitoshi UKAI  <ukai@debian.or.jp>
Diffstat:
9 files changed, 153 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,30 @@
+2002-08-21  Fumitoshi UKAI  <ukai@debian.or.jp>
+
+	* Debian Bug#157098: wrong file presentation on large files
+	  from "Eduard Bloch" <blade@debian.org>
+	* configure (clen_t): added
+			(HAVE_STRTOLL): added
+			(HAVE_STRTOQ): added
+			(HAVE_ATOLL): added
+			(HAVE_ATOQ): added
+	* config.h.dist: ditto
+	* file.c (current_content_length): s/int/clen_t/
+		(loadGeneralFile): s/atoi/strtoclen/
+		(convert_size): s/int/clen_t/
+		(convert_size2): s/int/clen_t/
+		(showProgress): s/int/clen_t/
+		(loadHTMLstream): s/int/clen_t/ linelen, trbyte
+		(loadBuffer): ditto
+		(getNextPage): s/int/clen_t/ linelen
+		(save2tmp): s/int/clen_t/ linelen, trbye
+		(_MoveFile): s/int/clen_t/ linelen, trbye
+	* fm.h (_Buffer): s/int/clen_t/ linelen, trbye
+	* ftp.c (size_int2str): s/long/clen_t/
+		(ex_ftpdir_name_size_date): s/long/clen_t/
+	* indep.c (strtoclen): added
+	* indep.h (strtoclen): added
+	* proto.h (showProgress): s/int/clen_t/
+
 2002-07-31  Fumitoshi UKAI  <ukai@debian.or.jp>
 
 	* Debian Bug#154766: w3m-img: support DirectColor framebuffer visuals?
diff --git a/config.h.dist b/config.h.dist
@@ -179,6 +179,11 @@ MODEL=Linux.i686-monster-ja
 #undef USE_BINMODE_STREAM
 #define HAVE_TERMIOS_H
 #define HAVE_DIRENT_H
+typedef long clen_t;
+#undef HAVE_STRTOLL
+#undef HAVE_STRTOQ
+#undef HAVE_ATOLL
+#undef HAVE_ATOQ
 #define HAVE_STRCASECMP
 #define HAVE_STRCASESTR
 #define HAVE_STRCHR
diff --git a/configure b/configure
@@ -1283,6 +1283,88 @@ fi
 
 def_param use_help_cgi $have_perl
 
+####### long long
+cat > _zmachdep.c <<EOF
+main()
+{
+  int i = sizeof(unsigned long long);
+}
+EOF
+if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+then
+    echo "You have long long"
+    def_have_long_long="typedef long long clen_t;"
+    cat > _zmachdep.c <<EOF
+#include <stdlib.h>
+main()
+{
+    const char *s = "1";
+    long long ll = strtoll(s, NULL, 10);
+}
+EOF
+    if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+    then
+	echo "You have strtoll()"
+	def_have_strtoll="#define HAVE_STRTOLL"
+    else
+	echo "You don't have strtoll()"
+	def_have_strtoll="#undef HAVE_STRTOLL"
+    fi
+    cat > _zmachdep.c <<EOF
+#include <sys/types.h>
+#include <stdlib.h>
+#include <limits.h>
+main()
+{
+    const char *s = "1"
+    quad_t q = strtoq(s, NULL, 10);
+}
+EOF
+    if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+    then
+	echo "You have strtoq()"
+	def_have_strtoq="#define HAVE_STRTOQ"
+    else
+	echo "You don't have strtoq()"
+	def_have_strtoq="#undef HAVE_STRTOQ"
+    fi
+    cat > _zmachdep.c <<EOF
+#include <stdlib.h>
+main()
+{
+    const char *s = "1";
+    long long ll = atoll(s);
+}
+EOF
+    if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+    then
+	echo "You have atoll()"
+	def_have_atoll="#define HAVE_ATOLL"
+    else
+	echo "You don't have atoll()"
+	def_have_atoll="#undef HAVE_ATOLL"
+    fi
+    cat > _zmachdep.c <<EOF
+#include <stdlib.h>
+main()
+{
+    const char *s = "1";
+    long long ll = atoq(s);
+}
+EOF
+    if $cc $cflags -o _zmachdep _zmachdep.c > /dev/null 2>&1
+    then
+	echo "You have atoq()"
+	def_have_atoq="#define HAVE_ATOQ"
+    else
+	echo "You don't have atoq()"
+	def_have_atoq="#undef HAVE_ATOQ"
+    fi
+else
+    echo "You don't have long long"
+    def_have_long_long="typedef long clen_t;"
+fi
+
 ####### strcasecmp
 cat > _zmachdep.c << EOF
 #include <string.h>
@@ -2306,6 +2388,11 @@ $def_use_xface
 $def_use_binstream
 $def_term_if
 $def_dir_if
+$def_have_long_long
+$def_have_strtoll
+$def_have_strtoq
+$def_have_atoll
+$def_have_atoq
 $def_have_strcasecmp
 $def_have_strcasestr
 $def_have_strchr
diff --git a/file.c b/file.c
@@ -120,7 +120,7 @@ static int forms_size = 0;
 #define cur_form_id ((form_sp >= 0)? form_stack[form_sp] : -1)
 static int form_sp = 0;
 
-static int current_content_length;
+static clen_t current_content_length;
 
 static int cur_hseq;
 #ifdef USE_IMAGE
@@ -1950,7 +1950,7 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer,
 
     current_content_length = 0;
     if ((p = checkHeader(t_buf, "Content-Length:")) != NULL)
-	current_content_length = atoi(p);
+	current_content_length = strtoclen(p);
 
     if (flag & RG_FRAME) {
 	t_buf = newBuffer(INIT_BUFFER_WIDTH);
@@ -5777,7 +5777,7 @@ static char *_size_unit[] = { "b", "kb", "Mb", "Gb", "Tb",
 };
 
 char *
-convert_size(int size, int usefloat)
+convert_size(clen_t size, int usefloat)
 {
     float csize;
     int sizepos = 0;
@@ -5793,7 +5793,7 @@ convert_size(int size, int usefloat)
 }
 
 char *
-convert_size2(int size1, int size2, int usefloat)
+convert_size2(clen_t size1, clen_t size2, int usefloat)
 {
     char **sizes = _size_unit;
     float csize, factor = 1;
@@ -5811,7 +5811,7 @@ convert_size2(int size1, int size2, int usefloat)
 }
 
 void
-showProgress(int *linelen, int *trbyte)
+showProgress(clen_t *linelen, clen_t *trbyte)
 {
     int i, j, rate, duration, eta, pos;
     static time_t last_time, start_time;
@@ -6052,8 +6052,8 @@ void
 loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal)
 {
     struct environment envs[MAX_ENV_LEVEL];
-    int linelen = 0;
-    int trbyte = 0;
+    clen_t linelen = 0;
+    clen_t trbyte = 0;
     Str lineBuf2 = Strnew();
     char code;
     struct html_feed_environ htmlenv1;
@@ -6396,7 +6396,7 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf)
     volatile char pre_lbuf = '\0';
     int nlines;
     Str tmpf;
-    int linelen = 0, trbyte = 0;
+    clen_t linelen = 0, trbyte = 0;
 #ifdef USE_ANSI_COLOR
     int check_color;
 #endif
@@ -6776,7 +6776,7 @@ getNextPage(Buffer *buf, int plen)
     Line *l, *fl, *pl = buf->lastLine;
     Line *rl = NULL;
     int len, i, nlines = 0;
-    int linelen = buf->linelen, trbyte = buf->trbyte;
+    clen_t linelen = buf->linelen, trbyte = buf->trbyte;
     Str lineBuf2;
     char pre_lbuf = '\0';
     URLFile uf;
@@ -6920,7 +6920,7 @@ save2tmp(URLFile uf, char *tmpf)
 {
     FILE *ff;
     int check;
-    int linelen = 0, trbyte = 0;
+    clen_t linelen = 0, trbyte = 0;
     MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL;
     static JMP_BUF env_bak;
 
@@ -7073,7 +7073,7 @@ _MoveFile(char *path1, char *path2)
     InputStream f1;
     FILE *f2;
     int is_pipe;
-    int linelen = 0, trbyte = 0;
+    clen_t linelen = 0, trbyte = 0;
     Str buf;
 
     f1 = openIS(path1);
diff --git a/fm.h b/fm.h
@@ -419,8 +419,8 @@ typedef struct _Buffer {
     struct frameset *frameset;
     struct frameset_queue *frameQ;
     int *clone;
-    int linelen;
-    int trbyte;
+    size_t linelen;
+    size_t trbyte;
     char check_url;
 #ifdef JP_CHARSET
     char document_code;
diff --git a/ftp.c b/ftp.c
@@ -711,7 +711,7 @@ ftp_system(FTP ftp)
   }\
 }
 
-static Str size_int2str(unsigned long);
+static Str size_int2str(clen_t);
 
 static int
 ex_ftpdir_name_size_date(char *line, char **name, char **date, char **sizep)
@@ -719,7 +719,7 @@ ex_ftpdir_name_size_date(char *line, char **name, char **date, char **sizep)
     int ftype = FTPDIR_NONE;
     char *cp, *endp;
     Str date_str, name_str, size_str;
-    unsigned long size;
+    clen_t size;
 
     if (strlen(line) < 11) {
 	goto done;
@@ -805,7 +805,7 @@ ex_ftpdir_name_size_date(char *line, char **name, char **date, char **sizep)
 }
 
 static Str
-size_int2str(unsigned long size)
+size_int2str(clen_t size)
 {
     Str size_str;
     int unit;
diff --git a/indep.c b/indep.c
@@ -11,6 +11,22 @@
 #include "myctype.h"
 #include "entity.h"
 
+clen_t
+strtoclen(const char *s)
+{
+#ifdef HAVE_STRTOLL
+    return strtoll(s, NULL, 10);
+#elif HAVE_STRTOQ
+    return strtoq(s, NULL, 10);
+#elif HAVE_ATOLL
+    return atoll(s);
+#elif HAVE_ATOQ
+    return atoq(s);
+#else
+    return atoi(s);
+#endif
+}
+
 #ifndef HAVE_BCOPY
 void
 bcopy(const void *src, void *dest, int len)
diff --git a/indep.h b/indep.h
@@ -16,6 +16,7 @@
 #define HTML_MODE	1
 #define HEADER_MODE	2
 
+extern clen_t strtoclen(const char *s);
 extern char *conv_entity(int ch);
 extern int getescapechar(char **s);
 extern char *getescapecmd(char **s);
diff --git a/proto.h b/proto.h
@@ -176,7 +176,7 @@ extern void HTMLlineproc0(char *istr, struct html_feed_environ *h_env,
 			  int internal);
 #define HTMLlineproc1(x,y) HTMLlineproc0(x,y,TRUE)
 extern Buffer *loadHTMLBuffer(URLFile *f, Buffer *newBuf);
-extern void showProgress(int *linelen, int *trbyte);
+extern void showProgress(clen_t *linelen, clen_t *trbyte);
 extern void init_henv(struct html_feed_environ *, struct readbuffer *,
 		      struct environment *, int, TextLineList *, int, int);
 extern void completeHTMLstream(struct html_feed_environ *,