Since Vim can now open “largefiles” on 32-bit systems, there are some
changes necessary to properly store/access the size of those files.
This is easy to see as when you open a largefile, the status message
showing the number of lines and characters in the file will have a
negative number of characters for largefiles since the 32-bit long was
overflowed.

The attached patch (generated against 7d3cf4693a8f) changes the relevant
buffer size pieces of the code to use off_t instead of long.
Unfortunately, there isn't a standard way to format off_t for
printf-style functions, so that required some preprocessor checks for
what to use.  There may be a better way to do that, but it worked for
me.

I've tested this on Windows with VS Express 2008 and Linux (both 32-bit
and 64-bit environments).

-- 
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[email protected]>
diff --git a/src/config.h.in b/src/config.h.in
--- a/src/config.h.in
+++ b/src/config.h.in
@@ -39,6 +39,12 @@
 /* Defined to the size of an int */
 #undef SIZEOF_INT
 
+/* Defined to the size of an off_t */
+#undef SIZEOF_OFF_T
+
+/* Defined to the size of a long */
+#undef SIZEOF_LONG
+
 /* Define when wchar_t is only 2 bytes. */
 #undef SMALL_WCHAR_T
 
@@ -248,6 +254,7 @@
 #undef HAVE_SYS_SYSINFO_H
 #undef HAVE_SYS_SYSTEMINFO_H
 #undef HAVE_SYS_TIME_H
+#undef HAVE_SYS_TYPES_H
 #undef HAVE_SYS_UTSNAME_H
 #undef HAVE_WCHAR_H
 #undef HAVE_WCTYPE_H
diff --git a/src/configure.in b/src/configure.in
--- a/src/configure.in
+++ b/src/configure.in
@@ -2964,29 +2964,9 @@
 	AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYSCONF),
 	AC_MSG_RESULT(not usable))
 
-dnl Our own version of AC_CHECK_SIZEOF(int); fixes a bug when sizeof() can't
-dnl be printed with "%d", and avoids a warning for cross-compiling.
-
-AC_MSG_CHECKING(size of int)
-AC_CACHE_VAL(ac_cv_sizeof_int,
-	[AC_TRY_RUN([
-#include <stdio.h>
-#if STDC_HEADERS
-# include <stdlib.h>
-# include <stddef.h>
-#endif
-main()
-{
-  FILE *f=fopen("conftestval", "w");
-  if (!f) exit(1);
-  fprintf(f, "%d\n", (int)sizeof(int));
-  exit(0);
-}],
-	    ac_cv_sizeof_int=`cat conftestval`,
-	    AC_MSG_ERROR([failed to determine sizeof(int)]),
-	    AC_MSG_ERROR([failed to compile test program]))])
-AC_MSG_RESULT($ac_cv_sizeof_int)
-AC_DEFINE_UNQUOTED(SIZEOF_INT, $ac_cv_sizeof_int)
+AC_CHECK_SIZEOF([int])
+AC_CHECK_SIZEOF([off_t])
+AC_CHECK_SIZEOF([long])
 
 dnl Make sure that uint32_t is really 32 bits unsigned.
 AC_MSG_CHECKING([uint32_t is 32 bits])
diff --git a/src/fileio.c b/src/fileio.c
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -59,7 +59,7 @@
 #endif
 #ifdef FEAT_CRYPT
 static int get_crypt_method __ARGS((char *ptr, int len));
-static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, long *filesizep, int newfile, int *did_ask));
+static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *sizep, off_t *filesizep, int newfile, int *did_ask));
 #endif
 #ifdef UNIX
 static void set_file_time __ARGS((char_u *fname, time_t atime, time_t mtime));
@@ -247,7 +247,7 @@
     colnr_T	len;
     long	size = 0;
     char_u	*p;
-    long	filesize = 0;
+    off_t	filesize = 0;
     int		skip_read = FALSE;
 #ifdef FEAT_CRYPT
     char_u	*cryptkey = NULL;
@@ -2829,7 +2829,7 @@
     char_u	*cryptkey;	/* previous encryption key or NULL */
     char_u	*ptr;		/* pointer to read bytes */
     long	*sizep;		/* length of read bytes */
-    long	*filesizep;	/* nr of bytes used from file */
+    off_t	*filesizep;	/* nr of bytes used from file */
     int		newfile;	/* editing a new buffer */
     int		*did_ask;	/* flag: whether already asked for key */
 {
@@ -5042,7 +5042,7 @@
 msg_add_lines(insert_space, lnum, nchars)
     int	    insert_space;
     long    lnum;
-    long    nchars;
+    off_t    nchars;
 {
     char_u  *p;
 
@@ -5051,7 +5051,7 @@
     if (insert_space)
 	*p++ = ' ';
     if (shortmess(SHM_LINES))
-	sprintf((char *)p, "%ldL, %ldC", lnum, nchars);
+	sprintf((char *)p, "%ldL, "PRINTF_OFF_T"C", lnum, nchars);
     else
     {
 	if (lnum == 1)
@@ -5062,7 +5062,7 @@
 	if (nchars == 1)
 	    STRCPY(p, _("1 character"));
 	else
-	    sprintf((char *)p, _("%ld characters"), nchars);
+	    sprintf((char *)p, _(PRINTF_OFF_T" characters"), nchars);
     }
 }
 
@@ -6630,7 +6630,7 @@
 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
     int		can_reload = FALSE;
 #endif
-    size_t	orig_size = buf->b_orig_size;
+    off_t	orig_size = buf->b_orig_size;
     int		orig_mode = buf->b_orig_mode;
 #ifdef FEAT_GUI
     int		save_mouse_correct = need_mouse_correct;
@@ -7030,7 +7030,7 @@
     char_u	*fname UNUSED;
 {
     buf->b_mtime = (long)st->st_mtime;
-    buf->b_orig_size = (size_t)st->st_size;
+    buf->b_orig_size = st->st_size;
 #ifdef HAVE_ST_MODE
     buf->b_orig_mode = (int)st->st_mode;
 #else
diff --git a/src/memline.c b/src/memline.c
--- a/src/memline.c
+++ b/src/memline.c
@@ -1979,7 +1979,7 @@
 	     */
 	    if (mch_stat((char *)buf->b_ffname, &st) == -1
 		    || st.st_mtime != buf->b_mtime_read
-		    || (size_t)st.st_size != buf->b_orig_size)
+		    || st.st_size != buf->b_orig_size)
 	    {
 		ml_preserve(buf, FALSE);
 		did_check_timestamps = FALSE;
diff --git a/src/netbeans.c b/src/netbeans.c
--- a/src/netbeans.c
+++ b/src/netbeans.c
@@ -934,7 +934,7 @@
 			char_u *tooltip, char_u *glyphfile,
 			char_u *fg, char_u *bg));
 static void print_read_msg __ARGS((nbbuf_T *buf));
-static void print_save_msg __ARGS((nbbuf_T *buf, long nchars));
+static void print_save_msg __ARGS((nbbuf_T *buf, off_t nchars));
 
 static int curPCtype = -1;
 
@@ -3831,7 +3831,7 @@
     nbbuf_T	*buf;
 {
     int	    lnum = buf->bufp->b_ml.ml_line_count;
-    long    nchars = (long)buf->bufp->b_orig_size;
+    off_t   nchars = buf->bufp->b_orig_size;
     char_u  c;
 
     msg_add_fname(buf->bufp, buf->bufp->b_ffname);
@@ -3867,7 +3867,7 @@
     static void
 print_save_msg(buf, nchars)
     nbbuf_T	*buf;
-    long	nchars;
+    off_t	nchars;
 {
     char_u	c;
     char_u	*p;
@@ -3879,7 +3879,7 @@
 	c = FALSE;
 
 	msg_add_lines(c, buf->bufp->b_ml.ml_line_count,
-						(long)buf->bufp->b_orig_size);
+						buf->bufp->b_orig_size);
 
 	vim_free(keep_msg);
 	keep_msg = NULL;
diff --git a/src/os_win32.h b/src/os_win32.h
--- a/src/os_win32.h
+++ b/src/os_win32.h
@@ -93,6 +93,7 @@
 
 #include <stdlib.h>
 #include <time.h>
+#include <sys/types.h>
 
 #ifndef STRICT
 # define STRICT
diff --git a/src/proto/fileio.pro b/src/proto/fileio.pro
--- a/src/proto/fileio.pro
+++ b/src/proto/fileio.pro
@@ -5,7 +5,7 @@
 int check_file_readonly __ARGS((char_u *fname, int perm));
 int buf_write __ARGS((buf_T *buf, char_u *fname, char_u *sfname, linenr_T start, linenr_T end, exarg_T *eap, int append, int forceit, int reset_changed, int filtering));
 void msg_add_fname __ARGS((buf_T *buf, char_u *fname));
-void msg_add_lines __ARGS((int insert_space, long lnum, long nchars));
+void msg_add_lines __ARGS((int insert_space, long lnum, off_t nchars));
 char_u *shorten_fname1 __ARGS((char_u *full_path));
 char_u *shorten_fname __ARGS((char_u *full_path, char_u *dir_name));
 void shorten_fnames __ARGS((int force));
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -1212,7 +1212,7 @@
 
     long	b_mtime;	/* last change time of original file */
     long	b_mtime_read;	/* last change time when reading */
-    size_t	b_orig_size;	/* size of original file in bytes */
+    off_t	b_orig_size;	/* size of original file in bytes */
     int		b_orig_mode;	/* mode of original file */
 
     pos_T	b_namedm[NMARKS]; /* current named marks (mark.c) */
diff --git a/src/vim.h b/src/vim.h
--- a/src/vim.h
+++ b/src/vim.h
@@ -411,6 +411,18 @@
 #define PRINTF_DECIMAL_LONG_U SCANF_DECIMAL_LONG_U
 
 /*
+ * Only systems which use configure will have SIZEOF_OFF_T/SIZEOF_LONG
+ * defined, which is ok since those are the same systems which can have
+ * varying sizes for off_t.  The other systems will continue to use "%ld" to
+ * print off_t since off_t is simply a typedef to long for them.
+ */
+#if defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T > SIZEOF_LONG)
+# define PRINTF_OFF_T "%lld"
+#else
+# define PRINTF_OFF_T "%ld"
+#endif
+
+/*
  * The characters and attributes cached for the screen.
  */
 typedef char_u schar_T;

Attachment: signature.asc
Description: Digital signature

Raspunde prin e-mail lui