From c6d085e3ae73a758f762b64405521fec792d331e Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Thu, 17 Jul 2008 13:52:02 +0000 Subject: [PATCH] backport fix from trunk git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/branches/stable@26792 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/Additions/GSCategories.m | 34 ++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30bab081b..c2b9b843a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-07-17 Richard Frith-Macdonald + + * Source/Additions/GSCategories.m: littleEndian() fix to work on + systems with other word sizes. + 2008-07-05 Richard Frith-Macdonald * Version 1.16.3 diff --git a/Source/Additions/GSCategories.m b/Source/Additions/GSCategories.m index c7099e98e..01320dec3 100644 --- a/Source/Additions/GSCategories.m +++ b/Source/Additions/GSCategories.m @@ -392,23 +392,27 @@ static void MD5Transform (uint32_t buf[4], uint32_t const in[16]); */ static void littleEndian (void *buf, unsigned words) { - uint32_t *ptr = (uint32_t*)buf; + if (NSHostByteOrder() == NS_BigEndian) + { + while (words-- > 0) + { + union swap { + uint32_t num; + uint8_t byt[4]; + } tmp; + uint8_t b0; + uint8_t b1; -#if (INT_MAX == 2147483647) - do - { - *ptr = NSSwapHostIntToLittle(*ptr); - ptr++; + tmp.num = ((uint32_t*)buf)[words]; + b0 = tmp.byt[0]; + b1 = tmp.byt[1]; + tmp.byt[0] = tmp.byt[3]; + tmp.byt[1] = tmp.byt[2]; + tmp.byt[2] = b1; + tmp.byt[3] = b0; + ((uint32_t*)buf)[words] = tmp.num; + } } - while (--words); -#else - do - { - *ptr = NSSwapHostLongToLittle(*ptr); - ptr++; - } - while (--words); -#endif } /*