From 6e1794a9c95a6dca79a3464fc33311638b6a0b2b Mon Sep 17 00:00:00 2001 From: Lorenz Schori Date: Tue, 8 Sep 2009 10:40:47 +0200 Subject: [PATCH] check endianness at runtime in md5.c Signed-off-by: Eric Bollengier --- bacula/src/lib/md5.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/bacula/src/lib/md5.c b/bacula/src/lib/md5.c index 26532fbf0f..05f49acb9b 100644 --- a/bacula/src/lib/md5.c +++ b/bacula/src/lib/md5.c @@ -52,23 +52,22 @@ #include "bacula.h" -#ifndef HAVE_BIGENDIAN -#define byteReverse(buf, len) /* Nothing */ -#else /* - * Note: this code is harmless on little-endian machines. + * Note: this code is harmless on little-endian machines. We'll swap the bytes + * on big-endian machines. */ void byteReverse(unsigned char *buf, unsigned longs) { uint32_t t; - do { - t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32_t *) buf = t; - buf += 4; - } while (--longs); + if (htonl(1) == 1L) { + do { + t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | + ((unsigned) buf[1] << 8 | buf[0]); + *(uint32_t *) buf = t; + buf += 4; + } while (--longs); + } } -#endif /* * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious -- 2.39.5