dovecot-1.2: Try to use (Apple) gcc's __BIG_ENDIAN__ and __LITTL...

dovecot at dovecot.org dovecot at dovecot.org
Fri Dec 19 08:50:19 EET 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/9ec2882243a6
changeset: 8572:9ec2882243a6
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 19 08:50:14 2008 +0200
description:
Try to use (Apple) gcc's __BIG_ENDIAN__ and __LITTLE_ENDIAN__ macros if possible.
Based on a patch by Apple.

diffstat:

4 files changed, 22 insertions(+), 18 deletions(-)
configure.in                   |   28 ++++++++++++++++------------
src/lib-index/mail-index-map.c |    4 ++--
src/lib-index/mail-index.c     |    2 +-
src/lib/sha1.c                 |    6 +++---

diffs (103 lines):

diff -r 563e61fa7726 -r 9ec2882243a6 configure.in
--- a/configure.in	Fri Dec 19 07:49:08 2008 +0200
+++ b/configure.in	Fri Dec 19 08:50:14 2008 +0200
@@ -2124,20 +2124,24 @@ AC_SUBST(dict_drivers)
 AC_SUBST(dict_drivers)
 
 dnl **
-dnl ** Index file compatibility flags
+dnl ** Endianess
 dnl **
 
-dnl * currently just checking for endianess
-
-AC_C_BIGENDIAN
-
-if test $ac_cv_c_bigendian = yes; then
-	flags=0
-else
-	flags=1
-fi
-
-AC_DEFINE_UNQUOTED(MAIL_INDEX_COMPAT_FLAGS, $flags, Index file compatibility flags)
+dnl At least Apple's gcc supports __BIG_ENDIAN__ and __LITTLE_ENDIAN__
+dnl defines. Use them if possible to allow cross-compiling.
+AC_MSG_CHECKING([if __BIG_ENDIAN__ or __LITTLE_ENDIAN__ is defined])
+AC_TRY_COMPILE([
+  #if !(__BIG_ENDIAN__ || __LITTLE_ENDIAN__)
+  #error nope
+  #endif
+], [
+], [
+  AC_DEFINE(WORDS_BIGENDIAN, __BIG_ENDIAN__, Define if your CPU is big endian)
+  AC_MSG_RESULT(yes)
+], [
+  AC_MSG_RESULT(no)
+  AC_C_BIGENDIAN
+])
 
 dnl **
 dnl ** IPv6 support
diff -r 563e61fa7726 -r 9ec2882243a6 src/lib-index/mail-index-map.c
--- a/src/lib-index/mail-index-map.c	Fri Dec 19 07:49:08 2008 +0200
+++ b/src/lib-index/mail-index-map.c	Fri Dec 19 08:50:14 2008 +0200
@@ -368,7 +368,7 @@ static bool mail_index_check_header_comp
 {
         enum mail_index_header_compat_flags compat_flags = 0;
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
 	compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
 
@@ -785,7 +785,7 @@ static void mail_index_header_init(struc
 	hdr->header_size = sizeof(*hdr);
 	hdr->record_size = sizeof(struct mail_index_record);
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
 	hdr->compat_flags |= MAIL_INDEX_COMPAT_LITTLE_ENDIAN;
 #endif
 
diff -r 563e61fa7726 -r 9ec2882243a6 src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c	Fri Dec 19 07:49:08 2008 +0200
+++ b/src/lib-index/mail-index.c	Fri Dec 19 08:50:14 2008 +0200
@@ -641,7 +641,7 @@ void mail_index_reset_error(struct mail_
         index->index_lock_timeout = FALSE;
 }
 
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
 /* FIXME: Unfortunately these functions were originally written to use
    endian-specific code and we can't avoid that without breaking backwards
    compatibility. When we do break it, just select one of these. */
diff -r 563e61fa7726 -r 9ec2882243a6 src/lib/sha1.c
--- a/src/lib/sha1.c	Fri Dec 19 07:49:08 2008 +0200
+++ b/src/lib/sha1.c	Fri Dec 19 08:50:14 2008 +0200
@@ -80,7 +80,7 @@ sha1_step(struct sha1_ctxt *ctxt)
 	size_t t, s;
 	uint32_t	tmp;
 
-#ifndef WORDS_BIGENDIAN
+#if !WORDS_BIGENDIAN
 	struct sha1_ctxt tctxt;
 	memmove(&tctxt.m.b8[0], &ctxt->m.b8[0], 64);
 	ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
@@ -189,7 +189,7 @@ sha1_pad(struct sha1_ctxt *ctxt)
 	memset(&ctxt->m.b8[padstart], 0, padlen - 8);
 	COUNT += (padlen - 8);
 	COUNT %= 64;
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
 	PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
 	PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
 	PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
@@ -235,7 +235,7 @@ sha1_result(struct sha1_ctxt *ctxt, void
 
 	digest = (uint8_t *)digest0;
 	sha1_pad(ctxt);
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
 	memmove(digest, &ctxt->h.b8[0], 20);
 #else
 	digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];


More information about the dovecot-cvs mailing list