]> granicus.if.org Git - mutt/commitdiff
Use fseeko/ftello when available while opening mbox/mmdf. Closes: #2084.
authorBrendan Cully <brendan@kublai.com>
Sat, 24 Sep 2005 19:45:22 +0000 (19:45 +0000)
committerBrendan Cully <brendan@kublai.com>
Sat, 24 Sep 2005 19:45:22 +0000 (19:45 +0000)
configure.in
mbox.c
mutt.h

index 5d9c57c09cdd788d995bc9f97a221dd9ed0d848c..bd516358bdee9a195d14666d4e143ab3261d6a1e 100644 (file)
@@ -41,6 +41,7 @@ AC_C_INLINE
 AC_C_CONST
 
 AC_SYS_LARGEFILE
+AC_FUNC_FSEEKO
 
 AC_PATH_PROG(DBX, dbx, no)
 AC_PATH_PROG(GDB, gdb, no)
@@ -82,6 +83,15 @@ AH_TEMPLATE([ICONV_NONTRANS],
             [Define as 1 if iconv() only converts exactly and we should treat
              all return values other than (size_t)(-1) as equivalent.])
 
+AH_BOTTOM([/* fseeko portability defines */
+#ifdef HAVE_FSEEKO
+# define LOFF_T off_t
+#else
+# define LOFF_T long
+# define fseeko fseek
+# define ftello ftell
+#endif
+])
 MUTT_C99_INTTYPES
 
 ac_aux_path_sendmail=/usr/sbin:/usr/lib
diff --git a/mbox.c b/mbox.c
index 131b867e6c5b3986d95ed5c3bb9aacc0133a8cfd..cd8a20545d93bef365eeb23bad3d8e860efc0eee 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -85,7 +85,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
   int count = 0, oldmsgcount = ctx->msgcount;
   int lines;
   time_t t, tz;
-  long loc, tmploc;
+  LOFF_T loc, tmploc;
   HEADER *hdr;
   struct stat sb;
 #ifdef NFS_ATTRIBUTE_HACK
@@ -122,7 +122,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
 
     if (mutt_strcmp (buf, MMDF_SEP) == 0)
     {
-      loc = ftell (ctx->fp);
+      loc = ftello (ctx->fp);
       
       count++;
       if (!ctx->quiet && ReadInc && ((count % ReadInc == 0) || count == 1))
@@ -159,7 +159,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
 
       hdr->env = mutt_read_rfc822_header (ctx->fp, hdr, 0, 0);
 
-      loc = ftell (ctx->fp);
+      loc = ftello (ctx->fp);
 
       if (hdr->content->length > 0 && hdr->lines > 0)
       {
@@ -186,7 +186,7 @@ int mmdf_parse_mailbox (CONTEXT *ctx)
       {
        lines = -1;
        do {
-         loc = ftell (ctx->fp);
+         loc = ftello (ctx->fp);
          if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
            break;
          lines++;
@@ -231,7 +231,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
   HEADER *curhdr;
   time_t t, tz;
   int count = 0, lines = 0;
-  long loc;
+  LOFF_T loc;
 #ifdef NFS_ATTRIBUTE_HACK
   struct utimbuf newtime;
 #endif
@@ -262,7 +262,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
      date received */
   tz = mutt_local_tz (0);
 
-  loc = ftell (ctx->fp);
+  loc = ftello (ctx->fp);
   while (fgets (buf, sizeof (buf), ctx->fp) != NULL)
   {
     if (is_from (buf, return_path, sizeof (return_path), &t))
@@ -304,9 +304,9 @@ int mbox_parse_mailbox (CONTEXT *ctx)
        */
       if (curhdr->content->length > 0)
       {
-       long tmploc;
+       LOFF_T tmploc;
 
-       loc = ftell (ctx->fp);
+       loc = ftello (ctx->fp);
        tmploc = loc + curhdr->content->length + 1;
 
        if (0 < tmploc && tmploc < ctx->size)
@@ -315,13 +315,13 @@ int mbox_parse_mailbox (CONTEXT *ctx)
           * check to see if the content-length looks valid.  we expect to
           * to see a valid message separator at this point in the stream
           */
-         if (fseek (ctx->fp, tmploc, SEEK_SET) != 0 ||
+         if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0 ||
              fgets (buf, sizeof (buf), ctx->fp) == NULL ||
              mutt_strncmp ("From ", buf, 5) != 0)
          {
            dprint (1, (debugfile, "mbox_parse_mailbox: bad content-length in message %d (cl=%ld)\n", curhdr->index, curhdr->content->length));
            dprint (1, (debugfile, "\tLINE: %s", buf));
-           if (fseek (ctx->fp, loc, SEEK_SET) != 0) /* nope, return the previous position */
+           if (fseeko (ctx->fp, loc, SEEK_SET) != 0) /* nope, return the previous position */
            {
              dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n"));
            }
@@ -346,7 +346,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
            int cl = curhdr->content->length;
 
            /* count the number of lines in this message */
-           if (fseek (ctx->fp, loc, SEEK_SET) != 0)
+           if (fseeko (ctx->fp, loc, SEEK_SET) != 0)
              dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n"));
            while (cl-- > 0)
            {
@@ -356,7 +356,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
          }
 
          /* return to the offset of the next message separator */
-         if (fseek (ctx->fp, tmploc, SEEK_SET) != 0)
+         if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0)
            dprint (1, (debugfile, "mbox_parse_mailbox: fseek() failed\n"));
        }
       }
@@ -374,7 +374,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
     else
       lines++;
     
-    loc = ftell (ctx->fp);
+    loc = ftello (ctx->fp);
   }
   
   /*
@@ -387,7 +387,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
   {
     if (PREV->content->length < 0)
     {
-      PREV->content->length = ftell (ctx->fp) - PREV->content->offset - 1;
+      PREV->content->length = ftello (ctx->fp) - PREV->content->offset - 1;
       if (PREV->content->length < 0)
        PREV->content->length = 0;
     }
diff --git a/mutt.h b/mutt.h
index 533619780443548ac0a25a5756088d92fdfed326..164e5edfd39bf6c3a49329631727f46d7e6bc9bc 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -627,7 +627,7 @@ typedef struct body
                                 * attachment
                                 */
   long offset;                  /* offset where the actual data begins */
-  long length;                  /* length (in bytes) of attachment */
+  LOFF_T length;                  /* length (in bytes) of attachment */
   char *filename;               /* when sending a message, this is the file
                                 * to which this structure refers
                                 */