1. Andrew Schein
  2. usort

Commits

Alex Reynolds  committed 27aa7df

Submitted changes to code which fix testbench and enable compilation with Clang/LLVM compilers in Mac OS X

  • Participants
  • Parent commits 474cc2a
  • Branches default

Comments (0)

Files changed (27)

File Makefile

View file
  • Ignore whitespace
-.PHONY : timing-binaries clean
+.PHONY: timing-binaries clean
 
-timing-binaries :
-	cd ./usort ; make 
-	cd csort ; make 
-	cd hsort ; make 
+timing-binaries:
+	cd usort; make 
+	cd csort; make 
+	cd hsort; make 
 
-clean :
-	cd ./usort ; make clean
-	cd csort ; make clean
-	cd hsort ; make clean
-	cd isort ; make clean
+clean:
+	cd usort; make clean
+	cd csort; make clean
+	cd hsort; make clean
+	cd isort; make clean

File csort/Makefile

View file
  • Ignore whitespace
 	cd t/ ; make clean
 	rm -f code_sample.tar
 	rm -f code_sample.tar.gz
+	rm -f *~
 
 cmp   : all
 	cd t ; ./cmp-all.sh

File csort/csort.c

View file
  • Ignore whitespace
 /* c 2008 Andrew I. Schein.  All rights reserved.
    
-   A fast general-purpose sorting smplemention based on Bentley and McIlroy, 1993's discussion
+   A fast general-purpose sorting implemention based on Bentley and McIlroy, 1993's discussion
    of quicksort... altered into an introsort.
    
    Caller defines a few macros:

File csort/defs.mk

View file
  • Ignore whitespace
-I=-L/usr/lib/gcc/i486-linux-gnu/4.2/ -I../  -I/usr/include  -I../../ -I../../../
+I=-I/usr/include -I../ -I../../ -I../../../
 W=-Wall
-#O=-fmudflap -lmudflap
 LIB=-lm
-O=-O9 -g
-CC=gcc#/usr/bin/colorgcc
+O=-O3 -g
 OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
 
 %.o : %.c

File csort/t/Makefile

View file
  • Ignore whitespace
 all : $(APPS)
 
 u1  : csort-cmp.c ../swap.c ../csort.c $(SRC)  
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o u1 u1.c 
+	${CC} $(G) $(W) $(I) $(O) -o u1 u1.c ${LIB}
 
 s1  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o s1 s1.c 
+	${CC} $(G) $(W) $(I) $(O) -o s1 s1.c ${LIB} 
 
 u2  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o u2 u2.c 
+	${CC} $(G) $(W) $(I) $(O) -o u2 u2.c ${LIB}
 
 s2  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o s2 s2.c 
+	${CC} $(G) $(W) $(I) $(O) -o s2 s2.c ${LIB}
 
 f4  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o f4 f4.c 
+	${CC} $(G) $(W) $(I) $(O) -o f4 f4.c ${LIB}
 
 s4  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o s4 s4.c 
+	${CC} $(G) $(W) $(I) $(O) -o s4 s4.c ${LIB}
 
 u4  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o u4 u4.c 
+	${CC} $(G) $(W) $(I) $(O) -o u4 u4.c ${LIB}
 
 f8  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o f8 f8.c 
+	${CC} $(G) $(W) $(I) $(O) -o f8 f8.c ${LIB}
 
 u8  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o u8 u8.c 
+	${CC} $(G) $(W) $(I) $(O) -o u8 u8.c ${LIB}
 
 s8  : csort-cmp.c ../swap.c ../csort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(LIB) $(O) -o s8 s8.c 
+	${CC} $(G) $(W) $(I) $(O) -o s8 s8.c ${LIB}
 
 
 clean :
-	rm -f $(APPS) csort-cmp 
+	rm -Rf $(APPS) csort-cmp *~ *.dSYM

File csort/t/csort-cmp.c

View file
  • Ignore whitespace
 
 long long k,j;
 const char* usage="csort-cmp dist N trials\n"
-"dist is one of: RAND, BOUNDED , SORTED, REVSORTED, IDENT\n"
+"dist is one of: RAND, BOUNDED, SORTED, REVERSE, IDENT\n"
 "N:              size of the array.\n"
 "trials:         how many trials to do.  Necessary for small N.\n";
 
 int compare(const void *a, const void *b) {
     TY A = *(const TY *)a, B = *(const TY *)b;
     if (A > B) return 1;
-    if (B < A) return -1;
+    if (A < B) return -1;
     return 0;
 }
 
-void fill(char* dist, TY* array1,long n) {
+void fill(char* dist, TY* array1, long n) {
     switch (parseDist(dist)) {
     case RAND : 
         randomized(array1,n) ; break;
     if (getenv("SEED")) srand(time(NULL)); /* default is debugging mode. */
     for (i = 0; i < num_trials; i++) {
         fill(argv[2],array1,n);
+
         start = TIME();
-        qsort (array1,n,sizeof(TY),&compare);
+        qsort (array1, n, sizeof(TY), &compare);
         end   = TIME();
+
         if (i) {
             g_tot += end-start;
         }  

File hsort/Makefile

View file
  • Ignore whitespace
 include defs.mk
 
-.PHONY : clean all cmp sample 
+.PHONY: clean all cmp sample 
 
-all :
-	cd t/ ; make all
+all:
+	cd t/; make all
 
-clean : 
-	cd t/ ; make clean
+clean: 
+	cd t/; make clean
+	rm -f *~
 
-cmp   : all
-	cd t ; ./cmp-all.sh
+cmp: all
+	cd t; ./cmp-all.sh
 

File hsort/defs.mk

View file
  • Ignore whitespace
-I=-L/usr/lib/gcc/i486-linux-gnu/4.2/ -I../  -I/usr/include -I../../ -I../../../
+I=-I/usr/include -I../ -I../../ -I../../../
 W=-Wall
-#O=-fmudflap -lmudflap
-O=-O9 -g
-CC=gcc#/usr/bin/colorgcc
+O=-O3 -g
 OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
 
 %.o : %.c

File hsort/t/Makefile

View file
  • Ignore whitespace
 	echo $(SRC)
 
 u1  : hsort-cmp.c  ../hsort.c $(SRC)  
-	gcc $(G) $(W) $(I) $(O) -o u1 u1.c 
+	${CC} $(G) $(W) $(I) $(O) -o u1 u1.c 
 
 s1  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s1 s1.c 
+	${CC} $(G) $(W) $(I) $(O) -o s1 s1.c 
 
 u2  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o u2 u2.c 
+	${CC} $(G) $(W) $(I) $(O) -o u2 u2.c 
 
 s2  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s2 s2.c 
+	${CC} $(G) $(W) $(I) $(O) -o s2 s2.c 
 
 f4  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o f4 f4.c 
+	${CC} $(G) $(W) $(I) $(O) -o f4 f4.c 
 
 s4  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s4 s4.c 
+	${CC} $(G) $(W) $(I) $(O) -o s4 s4.c 
 
 u4  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o u4 u4.c 
+	${CC} $(G) $(W) $(I) $(O) -o u4 u4.c 
 
 f8  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o f8 f8.c 
+	${CC} $(G) $(W) $(I) $(O) -o f8 f8.c 
 
 u8  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o u8 u8.c 
+	${CC} $(G) $(W) $(I) $(O) -o u8 u8.c 
 
 s8  : hsort-cmp.c  ../hsort.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s8 s8.c 
+	${CC} $(G) $(W) $(I) $(O) -o s8 s8.c 
 
 clean :
-	rm -f $(APPS) 
+	rm -Rf $(APPS) *~ *.dSYM

File hsort/t/hsort-cmp.c

View file
  • Ignore whitespace
 
 long long k,j;
 const char* usage="hsort-cmp dist N trials\n"
-"dist is one of: RAND, BOUNDED , SORTED, REVSORTED, IDENT\n"
+"dist is one of: RAND, BOUNDED, SORTED, REVERSE, IDENT\n"
 "N:              size of the array.\n"
 "trials:         how many trials to do.  Necessary for small N.\n";
 
 int compare(const void *a, const void *b) {
     TY A = *(const TY *)a, B = *(const TY *)b;
     if (A > B) return 1;
-    if (B < A) return -1;
+    if (A < B) return -1;
     return 0;
 }
 

File isort/Makefile

View file
  • Ignore whitespace
-.PHONY : timing-binaries clean
+.PHONY: timing-binaries clean
 
-timing-binaries : 
-	cd t ; make
+timing-binaries: 
+	cd t; make
 
-clean :
-	cd t ; make clean
+clean:
+	cd t; make clean
+	rm -f *~

File isort/defs.mk

View file
  • Ignore whitespace
-I=-L/usr/lib/gcc/i486-linux-gnu/4.2/ -I../  -I/usr/include -I../../ 
+I=-I/usr/include -I../ -I../../ 
 W=-Wall
-#O=-fmudflap -lmudflap
-O=-O9 -g
-CC=/usr/bin/colorgcc
+O=-O3 -g
 OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
 
 %.o : %.c

File isort/t/Makefile

View file
  • Ignore whitespace
 all : $(APPS)
 
 s2  : isort-cmp.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s2 s2.c 
+	${CC} $(G) $(W) $(I) $(O) -o s2 s2.c 
 s8  : isort-cmp.c  $(SRC)
-	gcc $(G) $(W) $(I) $(O) -o s8 s8.c 
+	${CC} $(G) $(W) $(I) $(O) -o s8 s8.c 
 
 clean :
-	rm -f $(APPS) csort-cmp 
+	rm -Rf $(APPS) csort-cmp *~ *.dSYM

File isort/t/isort-cmp.c

View file
  • Ignore whitespace
 #define CHECKNAN(x) (ISNAN((x)) ? 0 : (x)) 
 #endif
 
-enum generator {RAND,BOUNDED,SORTED, REVERSE ,IDENT} ;
+enum generator { RAND, BOUNDED, SORTED, REVERSE, IDENT } ;
 
 long long k,j;
 const char* usage="csort-cmp dist N trials\n"
-"dist is one of: RAND, BOUNDED , SORTED, REVSORTED, IDENT\n"
+"dist is one of: RAND, BOUNDED, SORTED, REVERSE, IDENT\n"
 "N:              size of the array.\n"
 "trials:         how many trials to do.  Necessary for small N.\n";
 

File usort/Makefile

View file
  • Ignore whitespace
-all : 
-	cd t ; make all
-clean :
-	rm -f test
-	cd t ; make clean
+include defs.mk
+
+all: 
+	cd t; make all
+
+clean:
+	rm -f test *~ *.o *.a
+	cd t; make clean

File usort/defs.mk

View file
  • Ignore whitespace
-I= -I/usr/include -I./ -I../ -I../../ -I../../../ -I../../../../   
+I=-I/usr/include -I./ -I../ -I../../ -I../../../ -I../../../../
+F=-std=c99 -fgnu89-inline
 W=-Wall
-#O=-fmudflap -lmudflap
-O=-O5
+O=-O3
 G=-g
 L=-lm
 LD_LIBRARY_PATH=/usr/lib:/lib:
-CC=/usr/bin/colorgcc -std=c99 -fgnu89-inline
 OBJS=$(patsubst %.c,%.o,$(wildcard *.c))
 
 %.o : %.cc
-	$(CC) $(I) $(W) $(O) -o $@ -c $<
+	$(CC) ${F} $(I) $(W) $(O) -o $@ -c $<
 
 
-#notes: c89 has no isfinite.  c99 inline is not supported.
+#notes: c89 has no isfinite.  c99 inline is not supported.

File usort/f4_sort.c

View file
  • Ignore whitespace
 
 #include "f4_sort.h"
 #include <string.h> /* endian */
-#ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+
+#ifndef __BYTE_ORDER 
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
 #  include <stdlib.h>
 #  define CSORT_TY float
 #  define CS_(name) f4_c##name

File usort/f8_sort.c

View file
  • Ignore whitespace
 
 #include "f8_sort.h"
 #include <string.h>
-#ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+
+#ifndef __BYTE_ORDER 
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
+#if __BYTE_ORDER == __LITTLE_ENDIAN
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
 #  include <stdlib.h>
 #  define CSORT_TY double
 #  define CS_(name) f8_c##name

File usort/s2_sort.c

View file
  • Ignore whitespace
 #include "s2_sort.h"
 #include <string.h> /* __BYTE_ORDER */
 
-#ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+#ifndef __BYTE_ORDER 
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
-#if __BYTE_ORDER == __BIG_ENDIAN
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
 #include <stdlib.h>
 
 #define CSORT_TY short

File usort/s4_sort.c

View file
  • Ignore whitespace
 #include "s4_sort.h"
 #include <string.h> /* __BYTE_ORDER */
 
-#ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+#ifndef __BYTE_ORDER 
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 

File usort/s8_sort.c

View file
  • Ignore whitespace
 #include <string.h>
 
 #ifndef __BYTE_ORDER 
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
 #if __BYTE_ORDER == __LITTLE_ENDIAN
+
 #include <stdlib.h>
 
 #define CS_(name) s8_c##name

File usort/t/Makefile

View file
  • Ignore whitespace
 	echo $(SRC)
 
 u1  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L)  -o u1 u1.c 
+	$(CC) -o u1 u1.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 s1  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L)  -o s1 s1.c 
+	$(CC) -o s1 s1.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 s2  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L)  -o s2 s2.c 
+	$(CC) -o s2 s2.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 u4  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o u4 u4.c 
+	$(CC) -o u4 u4.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 s4  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L)  -o s4 s4.c 
+	$(CC) -o s4 s4.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 u2  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o u2 u2.c 
+	$(CC) -o u2 u2.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 u8  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o u8 u8.c 
+	$(CC) -o u8 u8.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 s8  : ctype-cmp.c  $(SRC)  
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o s8 s8.c 
+	$(CC) -o s8 s8.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 f4  : ctype-cmp.c $(SRC)
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o f4  f4.c
+	$(CC) -o f4 f4.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 f8  : ctype-cmp.c $(SRC)
-	$(CC) $(G) $(W) $(I) $(O) $(L) -o f8  f8.c
+	$(CC) -o f8 f8.c ${F} $(G) $(W) $(I) $(O) $(L)
 
 
 clean :
-	rm -f $(APPS)
+	rm -Rf $(APPS) *.dSYM *~

File usort/t/ctype-cmp.c

View file
  • Ignore whitespace
 #define ISFINITE(x) 1
 #endif
 
-enum generator {RAND,BOUNDED,SORTED, REVERSE ,IDENT} ;
+enum generator {RAND, BOUNDED, SORTED, REVERSE ,IDENT} ;
 union { char l[8]; TY t; double d; unsigned long long llu; } u, u1, u2;
     
 
 long long k,j;
 const char* usage="csort-cmp N dist trials\n"
-"dist is one of: RAND, BOUNDED , SORTED, REVSORTED, IDENT\n"
+"dist is one of: RAND, BOUNDED, SORTED, REVERSE, IDENT\n"
 "N:              size of the array.\n"
 "trials:         how many trials to do.  Necessary for small N.\n";
 
 
 int compare(const void *a, const void *b) {
     TY A = *(const TY *)a, B = *(const TY *)b;
-    if (A > B) return 1;
-    if (B < A) return -1;
+    /* fprintf(stderr, "compare(a, b): [  %d  -vs-  %d  ]\n", *(TY *) a, *(TY *) b); */
+    if (A > B) { return 1; }
+    if (B > A) { return -1; }
     return 0;
 }
 
         }
     if (getenv("SEED")) srand(time(NULL)); /* default is debugging mode. */
     for (i = 0; i < num_trials; i++) {
-        /* fprintf(stderr,"trial: %lld\n",i); */
-        fill(argv[2],array_orig,n);
-        memcpy(array_g,array_orig,n*sizeof(TY));
-        memcpy(array_m,array_orig,n*sizeof(TY));
+        fill(argv[2], array_orig, n);
+        memcpy(array_g, array_orig, n*sizeof(TY));
+        memcpy(array_m, array_orig, n*sizeof(TY));
         
         start = TIME();
-        qsort (array_g,n,sizeof(TY),&compare);
-        end   = TIME();
+        qsort(array_g, n, sizeof(TY), &compare);
+        end = TIME();
+
         if (i) {
-            g_tot += end-start;
+            g_tot += end - start;
         }  
-        checkWork("GNU",array_g,n);
+        checkWork("GNU", array_g, n);
         u1.d = array_g[0] ; u2.d = array_g[1];
         //fprintf(stderr,"GNU: %llx %llx\n",u1.ull,u2.ull);
         

File usort/u1_sort.c

View file
  • Ignore whitespace
 #define CS_(name) u1_##name
 #include "../common/defs.c"
 
-
-
 /* implements in place u1 bucket sort. */
 
 U1_SORT_LKG void u1_sort(unsigned char *a, const long sz) {

File usort/u2_sort.c

View file
  • Ignore whitespace
 #include <string.h>  /* __BYTE_ORDER */
 
 #ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
 #if __BYTE_ORDER == __BIG_ENDIAN
 #include <stdlib.h> /* malloc among others */
 #define CSORT_TY unsigned short
 #define CS_(name) u2_##name
 #include "../common/defs.c"
+#include "../isort/ufunc/u2_isort.c"
 
 #define _0(v) ((v)         & 0xFF)
 #define _1(v) (((v) >> 8)  & 0xFF)
     long n, sum0=0 , sum1=0 , tsum=0;
     unsigned short *reader, *writer, *buf;
     long *b0, *b1;
-    if (sz < 32) { return u2_isort(a,sz);}
+    if (sz < 32) { return u2_isort(a,sz); }
     buf = (unsigned short*) malloc(sz * sizeof(unsigned short));
     b0   = calloc(HIST_SIZE * 2, sizeof(long));
     b1   = b0 + HIST_SIZE;

File usort/u4_sort.c

View file
  • Ignore whitespace
 #include "u4_sort.h"
 #include <string.h> /* __BYTE_ORDER */
 
-#ifndef __BYTE_ORDER
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+#ifndef __BYTE_ORDER 
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 

File usort/u8_sort.c

View file
  • Ignore whitespace
 #include <string.h>
 
 #ifndef __BYTE_ORDER 
-#error __FILE__ ": __BYTE_ORDER is not defined!"
+# ifdef __APPLE__
+#  define __BYTE_ORDER __DARWIN_BYTE_ORDER
+#  define __LITTLE_ENDIAN __DARWIN_LITTLE_ENDIAN
+#  define __BIG_ENDIAN __DARWIN_BIG_ENDIAN
+# else
+#  error __FILE__ ": __BYTE_ORDER is not defined!"
+# endif
 #endif
 #if __BYTE_ORDER == __LITTLE_ENDIAN