Re: [PATCH] init warning
Hi,
* Paul Walker wrote:
Right. On AMD-64 (and probably the other x86-64 architectures too), off_t is
8 bytes, and so is "long int". So we don't need to use "%lld", just "%ld".
Yes, I agree. However, the only 64bit machine I have is IA64 running
32bit OS X. If I compile mutt in 64bit mode I still get the 'off_t' vs.
'long int' warning. So I defined the proper long int names and cast all
values accordingly. Note that I can't link the 64bit mutt binary (since
the libs are 32bit and I'm too lazy to compile 64bit libs), just compile
the object files. Using the attached patch I also get no warnings, but
I'm not sure the approach using casts is really right...
Rocco
diff --git a/configure.ac b/configure.ac
--- a/configure.ac
+++ b/configure.ac
@@ -88,16 +88,19 @@ AH_BOTTOM([/* fseeko portability defines
AH_BOTTOM([/* fseeko portability defines */
#ifdef HAVE_FSEEKO
# define LOFF_T off_t
-# if SIZEOF_OFF_T == 8
+# if (SIZEOF_OFF_T == 8) && (SIZEOF_LONG == 4)
# define OFF_T_FMT "%lld"
+# define OFF_T_CAST LOFF_T
# else
# define OFF_T_FMT "%ld"
+# define OFF_T_CAST long
# endif
#else
# define LOFF_T long
# define fseeko fseek
# define ftello ftell
# define OFF_T_FMT "%ld"
+# define OFF_T_CAST long
#endif
])
MUTT_C99_INTTYPES
diff --git a/copy.c b/copy.c
--- a/copy.c
+++ b/copy.c
@@ -459,7 +459,7 @@ mutt_copy_header (FILE *in, HEADER *h, F
if (flags & CH_UPDATE_LEN &&
(flags & CH_NOLEN) == 0)
{
- fprintf (out, "Content-Length: " OFF_T_FMT "\n", h->content->length);
+ fprintf (out, "Content-Length: " OFF_T_FMT "\n", (OFF_T_CAST)
h->content->length);
if (h->lines != 0 || h->content->length == 0)
fprintf (out, "Lines: %d\n", h->lines);
}
@@ -568,7 +568,7 @@ _mutt_copy_message (FILE *fpout, FILE *f
if (mutt_copy_header (fpin, hdr, fpout,
chflags | CH_NOLEN | CH_NONEWLINE, NULL))
return -1;
- fprintf (fpout, "Content-Length: " OFF_T_FMT "\n", new_length);
+ fprintf (fpout, "Content-Length: " OFF_T_FMT "\n", (OFF_T_CAST)
new_length);
if (new_lines <= 0)
new_lines = 0;
else
@@ -811,7 +811,7 @@ static int copy_delete_attach (BODY *b,
fprintf (fpout,
"Content-Type: message/external-body;
access-type=x-mutt-deleted;\n"
"\texpiration=%s; length=" OFF_T_FMT "\n"
- "\n", date + 5, part->length);
+ "\n", date + 5, (OFF_T_CAST) part->length);
if (ferror (fpout))
return -1;
diff --git a/m4/types.m4 b/m4/types.m4
--- a/m4/types.m4
+++ b/m4/types.m4
@@ -10,11 +10,11 @@ AC_DEFUN([MUTT_C99_INTTYPES],
[dnl
AC_CHECK_HEADERS([inttypes.h])
AC_CHECK_TYPE([uint32_t],
- [AC_DEFINE(HAVE_C99_INTTYPES, 1, [Define if you have the C99 integer
types])],
- [AC_CHECK_SIZEOF(short)
- AC_CHECK_SIZEOF(int)
- AC_CHECK_SIZEOF(long)
- AC_CHECK_SIZEOF(long long)])
+ [AC_DEFINE(HAVE_C99_INTTYPES, 1, [Define if you have the C99 integer
types])])
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(long long)])
AH_VERBATIM([X_HAVE_C99_INTTYPES],
[#ifndef HAVE_C99_INTTYPES
# if SIZEOF_SHORT == 4
@@ -32,5 +32,4 @@ typedef unsigned long long uint64_t;
typedef unsigned long long uint64_t;
# endif
#endif
- ])
])
diff --git a/mbox.c b/mbox.c
--- a/mbox.c
+++ b/mbox.c
@@ -335,7 +335,7 @@ int mbox_parse_mailbox (CONTEXT *ctx)
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=" OFF_T_FMT ")\n", curhdr->index, curhdr->content->length));
+ dprint (1, (debugfile, "mbox_parse_mailbox: bad content-length in
message %d (cl=" OFF_T_FMT ")\n", curhdr->index, (OFF_T_CAST)
curhdr->content->length));
dprint (1, (debugfile, "\tLINE: %s", buf));
if (fseeko (ctx->fp, loc, SEEK_SET) != 0) /* nope, return the
previous position */
{
diff --git a/muttlib.c b/muttlib.c
--- a/muttlib.c
+++ b/muttlib.c
@@ -821,14 +821,14 @@ void mutt_pretty_size (char *s, size_t l
else if (n < 1023949) /* 10K - 999K */
{
/* 51 is magic which causes 10189/10240 to be rounded up to 10 */
- snprintf (s, len, OFF_T_FMT "K", (n + 51) / 1024);
+ snprintf (s, len, OFF_T_FMT "K", (OFF_T_CAST) (n + 51) / 1024);
}
else if (n < 10433332) /* 1.0M - 9.9M */
snprintf (s, len, "%3.1fM", n / 1048576.0);
else /* 10M+ */
{
/* (10433332 + 52428) / 1048576 = 10 */
- snprintf (s, len, OFF_T_FMT "M", (n + 52428) / 1048576);
+ snprintf (s, len, OFF_T_FMT "M", (OFF_T_CAST) (n + 52428) / 1048576);
}
}
diff --git a/pager.c b/pager.c
--- a/pager.c
+++ b/pager.c
@@ -1742,7 +1742,7 @@ mutt_pager (const char *banner, const ch
hfi.pager_progress = pager_progress_str;
if (last_pos < sb.st_size - 1)
- snprintf(pager_progress_str, sizeof(pager_progress_str), OFF_T_FMT
"%%", (100 * last_offset / sb.st_size));
+ snprintf(pager_progress_str, sizeof(pager_progress_str), OFF_T_FMT
"%%", (OFF_T_CAST) (100 * last_offset / sb.st_size));
else
strfcpy(pager_progress_str, (topline == 0) ? "all" : "end",
sizeof(pager_progress_str));
diff --git a/sendlib.c b/sendlib.c
--- a/sendlib.c
+++ b/sendlib.c
@@ -2668,7 +2668,7 @@ int mutt_write_fcc (const char *path, HE
rewind (tempfp);
while (fgets (sasha, sizeof (sasha), tempfp) != NULL)
lines++;
- fprintf (msg->fp, "Content-Length: " OFF_T_FMT "\n", (LOFF_T) ftell
(tempfp));
+ fprintf (msg->fp, "Content-Length: " OFF_T_FMT "\n", (OFF_T_CAST) ftell
(tempfp));
fprintf (msg->fp, "Lines: %d\n\n", lines);
/* copy the body and clean up */