<<< Date Index >>>     <<< Thread Index >>>

[patch] Solved problems with file size >2GB



Now anywhere file > 2.5GB appear correctly;
even at attach list we will have the file in MegaBytes correct.

This really closes bug report 2191

All problems were with off_t types, some times used to use 'long' other
'unsigned long', that's why we had file size in negative value.

The patch is attached

ps: Now we begin to think. It's time to show GB instead of MB for some files
=) , but that's another patch

-- 
Bruno Ribas - ribas@xxxxxxx
? patch.diff
Index: browser.c
===================================================================
RCS file: /cvsroots/mutt/browser.c,v
retrieving revision 3.19
diff -u -r3.19 browser.c
--- browser.c   6 Oct 2005 06:15:00 -0000       3.19
+++ browser.c   21 Apr 2006 23:21:45 -0000
@@ -40,6 +40,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <errno.h>
+#include <inttypes.h>
 
 static struct mapping_t FolderHelp[] = {
   { N_("Exit"),  OP_EXIT },
@@ -265,8 +266,8 @@
     case 's':
       if (folder->ff->st != NULL)
       {
-       snprintf (tmp, sizeof (tmp), "%%%sld", fmt);
-       snprintf (dest, destlen, tmp, (long) folder->ff->st->st_size);
+       snprintf (tmp, sizeof (tmp), "%%%s" PRId64 , fmt);
+       snprintf (dest, destlen, tmp, folder->ff->st->st_size);
       }
       else
        mutt_format_s (dest, destlen, fmt, "");
Index: buffy.c
===================================================================
RCS file: /cvsroots/mutt/buffy.c,v
retrieving revision 3.17
diff -u -r3.17 buffy.c
--- buffy.c     13 Dec 2005 21:25:10 -0000      3.17
+++ buffy.c     21 Apr 2006 23:21:45 -0000
@@ -162,7 +162,7 @@
     return;
 
   if (stat (b->path, &sb) == 0)
-    b->size = (long) sb.st_size;
+    b->size = sb.st_size;
   else
     b->size = 0;
   return;
@@ -240,7 +240,7 @@
     if (stat ((*tmp)->path, &sb) == 0 && !test_new_folder ((*tmp)->path))
     {
       /* some systems out there don't have an off_t type */
-      (*tmp)->size = (long) sb.st_size;
+      (*tmp)->size = sb.st_size;
     }
     else
       (*tmp)->size = 0;
@@ -365,7 +365,7 @@
        else
        {
          /* some other program has deleted mail from the folder */
-         tmp->size = (long) sb.st_size;
+         tmp->size = sb.st_size;
        }
 #endif
        if (tmp->newly_created &&
@@ -405,7 +405,7 @@
     }
 #ifdef BUFFY_SIZE
     else if (Context && Context->path)
-      tmp->size = (long) sb.st_size;   /* update the size */
+      tmp->size = sb.st_size;  /* update the size */
 #endif
 
     if (!tmp->new)
Index: buffy.h
===================================================================
RCS file: /cvsroots/mutt/buffy.h,v
retrieving revision 3.4
diff -u -r3.4 buffy.h
--- buffy.h     17 Sep 2005 20:46:10 -0000      3.4
+++ buffy.h     21 Apr 2006 23:21:45 -0000
@@ -24,7 +24,7 @@
 {
   char *path;
 #ifdef BUFFY_SIZE
-  long size;
+  off_t size;
 #endif                         /* BUFFY_SIZE */
   struct buffy_t *next;
   short new;                   /* mailbox has new mail */
Index: compose.c
===================================================================
RCS file: /cvsroots/mutt/compose.c,v
retrieving revision 3.27
diff -u -r3.27 compose.c
--- compose.c   17 Sep 2005 20:46:10 -0000      3.27
+++ compose.c   21 Apr 2006 23:21:47 -0000
@@ -446,7 +446,7 @@
 
     case 'l': /* approx length of current message in bytes */
        snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
-       mutt_pretty_size (tmp, sizeof (tmp), menu ? cum_attachs_size(menu) : 0);
+       mutt_pretty_size (tmp, sizeof (tmp), menu ? 
(off_t)cum_attachs_size(menu) : (off_t)0);
        snprintf (buf, buflen, fmt, tmp);
       break;
 
Index: dotlock.c
===================================================================
RCS file: /cvsroots/mutt/dotlock.c,v
retrieving revision 3.4
diff -u -r3.4 dotlock.c
--- dotlock.c   17 Sep 2005 20:46:10 -0000      3.4
+++ dotlock.c   21 Apr 2006 23:21:47 -0000
@@ -589,7 +589,7 @@
 {
   char lockfile[_POSIX_PATH_MAX + LONG_STRING];
   char nfslockfile[_POSIX_PATH_MAX + LONG_STRING];
-  size_t prev_size = 0;
+  off_t prev_size = 0;
   int fd;
   int count = 0;
   int hard_count = 0;
Index: edit.c
===================================================================
RCS file: /cvsroots/mutt/edit.c,v
retrieving revision 3.9
diff -u -r3.9 edit.c
--- edit.c      21 Oct 2005 04:35:37 -0000      3.9
+++ edit.c      21 Apr 2006 23:21:48 -0000
@@ -33,6 +33,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <inttypes.h>
 
 /*
  * SLcurses_waddnstr() can't take a "const char *", so this is only
@@ -106,7 +107,7 @@
     buf = be_snarf_data (f, buf, max, len, 0, sb.st_size, 0);
     if (verbose)
     {
-      snprintf(tmp, sizeof(tmp), "\"%s\" %lu bytes\n", path, (unsigned long) 
sb.st_size);
+      snprintf(tmp, sizeof(tmp), "\"%s\" %" PRId64 " bytes\n", path, 
sb.st_size);
       addstr(tmp);
     }
     fclose (f);
Index: handler.c
===================================================================
RCS file: /cvsroots/mutt/handler.c,v
retrieving revision 3.26
diff -u -r3.26 handler.c
--- handler.c   16 Dec 2005 18:49:40 -0000      3.26
+++ handler.c   21 Apr 2006 23:21:49 -0000
@@ -1216,10 +1216,10 @@
     mustfree = 1;
     fstat (fileno (s->fpin), &st);
     b = mutt_new_body ();
-    b->length = (long) st.st_size;
+    b->length = st.st_size;
     b->parts = mutt_parse_multipart (s->fpin,
                  mutt_get_parameter ("boundary", a->parameter),
-                 (long) st.st_size, ascii_strcasecmp ("digest", a->subtype) == 
0);
+                 st.st_size, ascii_strcasecmp ("digest", a->subtype) == 0);
   }
   else
     b = a;
@@ -1373,7 +1373,7 @@
   {
     fstat (fileno (s->fpin), &st);
     b = mutt_new_body ();
-    b->length = (LOFF_T) st.st_size;
+    b->length = st.st_size;
     b->parts = mutt_parse_messageRFC822 (s->fpin, b);
   }
   else
@@ -1453,10 +1453,10 @@
   {
     fstat (fileno (s->fpin), &st);
     b = mutt_new_body ();
-    b->length = (long) st.st_size;
+    b->length = st.st_size;
     b->parts = mutt_parse_multipart (s->fpin,
                  mutt_get_parameter ("boundary", a->parameter),
-                 (long) st.st_size, ascii_strcasecmp ("digest", a->subtype) == 
0);
+                 st.st_size, ascii_strcasecmp ("digest", a->subtype) == 0);
   }
   else
     b = a;
@@ -1681,7 +1681,7 @@
       if (length)
       {
        mutt_pretty_size (pretty_size, sizeof (pretty_size),
-                         strtol (length, NULL, 10));
+                         (off_t) strtoll (length, NULL, 10));
        state_printf (s, _("(size %s bytes) "), pretty_size);
       }
       state_puts (_("has been deleted --]\n"), s);
Index: hdrline.c
===================================================================
RCS file: /cvsroots/mutt/hdrline.c,v
retrieving revision 3.18
diff -u -r3.18 hdrline.c
--- hdrline.c   10 Jan 2006 19:15:21 -0000      3.18
+++ hdrline.c   21 Apr 2006 23:21:50 -0000
@@ -302,7 +302,7 @@
       break;
     
     case 'c':
-      mutt_pretty_size (buf2, sizeof (buf2), (long) hdr->content->length);
+      mutt_pretty_size (buf2, sizeof (buf2), (off_t) hdr->content->length);
       mutt_format_s (dest, destlen, prefix, buf2);
       break;
 
Index: muttlib.c
===================================================================
RCS file: /cvsroots/mutt/muttlib.c,v
retrieving revision 3.41
diff -u -r3.41 muttlib.c
--- muttlib.c   21 Feb 2006 21:52:17 -0000      3.41
+++ muttlib.c   21 Apr 2006 23:21:52 -0000
@@ -47,6 +47,7 @@
 #include <time.h>
 #include <sys/types.h>
 #include <utime.h>
+#include <inttypes.h>
 
 BODY *mutt_new_body (void)
 {
@@ -811,23 +812,23 @@
   }
 }
 
-void mutt_pretty_size (char *s, size_t len, long n)
+void mutt_pretty_size (char *s, size_t len, off_t n)
 {
   if (n == 0)
     strfcpy (s, "0K", len);
   else if (n < 10189) /* 0.1K - 9.9K */
-    snprintf (s, len, "%3.1fK", (n < 103) ? 0.1 : n / 1024.0);
+    snprintf (s, len, "%3.1lfK", (n < 103) ? 0.1 : n / 1024.0);
   else if (n < 1023949) /* 10K - 999K */
   {
     /* 51 is magic which causes 10189/10240 to be rounded up to 10 */
-    snprintf (s, len, "%ldK", (n + 51) / 1024);
+    snprintf (s, len, "%" PRId64 "K", (n + 51) / 1024);
   }
   else if (n < 10433332) /* 1.0M - 9.9M */
-    snprintf (s, len, "%3.1fM", n / 1048576.0);
+    snprintf (s, len, "%3.1lfM", n / 1048576.0);
   else /* 10M+ */
   {
     /* (10433332 + 52428) / 1048576 = 10 */
-    snprintf (s, len, "%ldM", (n + 52428) / 1048576);
+    snprintf (s, len, "%" PRId64 "M", (n + 52428) / 1048576);
   }
 }
 
Index: pager.c
===================================================================
RCS file: /cvsroots/mutt/pager.c,v
retrieving revision 3.30
diff -u -r3.30 pager.c
--- pager.c     21 Oct 2005 04:35:37 -0000      3.30
+++ pager.c     21 Apr 2006 23:21:53 -0000
@@ -45,6 +45,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <inttypes.h>
 
 #define ISHEADER(x) ((x) == MT_COLOR_HEADER || (x) == MT_COLOR_HDEFAULT)
 
@@ -1764,7 +1765,7 @@
                    buffer : banner);
       addstr (" -- (");
       if (last_pos < sb.st_size - 1)
-       printw ("%d%%)", (int) (100 * last_offset / sb.st_size));
+       printw ("%" PRId64 "%%)", (off_t) (100 * last_offset / sb.st_size));
       else
        addstr (topline == 0 ? "all)" : "end)");
       BKGDSET (MT_COLOR_NORMAL);
Index: protos.h
===================================================================
RCS file: /cvsroots/mutt/protos.h,v
retrieving revision 3.43
diff -u -r3.43 protos.h
--- protos.h    9 Jan 2006 19:43:59 -0000       3.43
+++ protos.h    21 Apr 2006 23:21:54 -0000
@@ -223,7 +223,7 @@
 void mutt_prepare_envelope (ENVELOPE *, int);
 void mutt_unprepare_envelope (ENVELOPE *);
 void mutt_pretty_mailbox (char *);
-void mutt_pretty_size (char *, size_t, long);
+void mutt_pretty_size (char *, size_t, off_t);
 void mutt_pipe_message (HEADER *);
 void mutt_print_message (HEADER *);
 void mutt_print_patchlist (void);
Index: intl/loadmsgcat.c
===================================================================
RCS file: /cvsroots/mutt/intl/loadmsgcat.c,v
retrieving revision 3.3
diff -u -r3.3 loadmsgcat.c
--- intl/loadmsgcat.c   17 Sep 2005 20:46:11 -0000      3.3
+++ intl/loadmsgcat.c   21 Apr 2006 23:21:55 -0000
@@ -342,7 +342,7 @@
      struct binding *domainbinding;
 {
   int fd;
-  size_t size;
+  off_t size;
 #ifdef _LIBC
   struct stat64 st;
 #else
@@ -379,7 +379,7 @@
 #else
       __builtin_expect (fstat (fd, &st) != 0, 0)
 #endif
-      || __builtin_expect ((size = (size_t) st.st_size) != st.st_size, 0)
+      || __builtin_expect ((size = st.st_size) != st.st_size, 0)
       || __builtin_expect (size < sizeof (struct mo_file_header), 0))
     {
       /* Something went wrong.  */