X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=libiberty%2Fsort.c;h=90c97e04e07f2525cbd8370c49e2ede049d83f5b;hb=e2f15cdff31f90c14c3c18915942c3c853d260b8;hp=6dca09a9242e923dca8bd116b6ab6c0fceb76044;hpb=85993fc6735aeb2c9ff912bb80506a3c0384108e;p=pf3gnuchains%2Fgcc-fork.git diff --git a/libiberty/sort.c b/libiberty/sort.c index 6dca09a9242..90c97e04e07 100644 --- a/libiberty/sort.c +++ b/libiberty/sort.c @@ -24,14 +24,25 @@ Boston, MA 02111-1307, USA. */ #endif #include "libiberty.h" #include "sort.h" +#ifdef HAVE_LIMITS_H #include +#endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif #ifdef HAVE_STDLIB_H #include #endif +#ifdef HAVE_STRING_H +#include +#endif -/* POINTERSP and WORKP both point to arrays of N pointers. When - this function returns POINTERSP will point to a sorted version of - the original array pointed to by POINTERSP. */ +#ifndef UCHAR_MAX +#define UCHAR_MAX ((unsigned char)(-1)) +#endif + +/* POINTERS and WORK are both arrays of N pointers. When this + function returns POINTERS will be sorted in ascending order. */ void sort_pointers (n, pointers, work) size_t n; @@ -63,8 +74,11 @@ void sort_pointers (n, pointers, work) abort (); /* Figure out the endianness of the machine. */ - for (i = 0; i < sizeof (size_t); ++i) - ((char *)&j)[i] = i; + for (i = 0, j = 0; i < sizeof (size_t); ++i) + { + j *= (UCHAR_MAX + 1); + j += i; + } big_endian_p = (((char *)&j)[0] == 0); /* Move through the pointer values from least significant to most @@ -91,8 +105,8 @@ void sort_pointers (n, pointers, work) /* Compute the address of the appropriate digit in the first and one-past-the-end elements of the array. On a little-endian machine, the least-significant digit is closest to the front. */ - bias = ((digit_t *) pointers) + i; - top = ((digit_t *) (pointers + n)) + i; + bias = ((digit_t *) pointers) + j; + top = ((digit_t *) (pointers + n)) + j; /* Count how many there are of each value. At the end of this loop, COUNT[K] will contain the number of pointers whose Ith @@ -109,7 +123,7 @@ void sort_pointers (n, pointers, work) /* Now, drop the pointers into their correct locations. */ for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp) - work[--count[((digit_t *) pointerp)[i]]] = *pointerp; + work[--count[((digit_t *) pointerp)[j]]] = *pointerp; /* Swap WORK and POINTERS so that POINTERS contains the sorted array. */