Fix for md5 digest generation on some big endian 64bit machines.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26791 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-07-17 13:49:59 +00:00
parent 0b3f1e08b2
commit 2de7a94930
2 changed files with 24 additions and 15 deletions

View file

@ -1,3 +1,8 @@
2008-07-17 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSCategories.m: littleEndian() fix to work on
systems with other word sizes.
2008-07-15 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSPrivate.h: New private function to get range of string func.

View file

@ -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
}
/*