9 compare (const void *a1
, const void *b1
)
14 if (! (array
<= a
&& a
< array_end
15 && array
<= b
&& b
< array_end
))
17 puts ("compare arguments not inside of the array");
20 int ret
= b
[0] - a
[0];
29 test (size_t nmemb
, size_t size
)
31 array
= malloc (nmemb
* size
);
34 printf ("%zd x %zd: no memory", nmemb
, size
);
38 array_end
= array
+ nmemb
* size
;
43 size_t bias
= random ();
44 for (i
= 0, p
= array
; i
< nmemb
; i
++, p
+= size
)
46 p
[0] = (char) (i
+ bias
);
48 p
[1] = (char) ((i
+ bias
) >> 8);
51 qsort (array
, nmemb
, size
, compare
);
53 for (i
= 0, p
= array
; i
< nmemb
- 1; i
++, p
+= size
)
56 || (size
> 1 && p
[0] == p
[size
] && p
[1] < p
[size
+ 1]))
58 printf ("%zd x %zd: failure at offset %zd\n", nmemb
,
70 main (int argc
, char **argv
)
74 ret
|= test (atoi (argv
[1]), atoi (argv
[2]));
77 ret
|= test (10000, 1);
78 ret
|= test (200000, 2);
79 ret
|= test (2000000, 3);
80 ret
|= test (2132310, 4);
81 ret
|= test (1202730, 7);
82 ret
|= test (1184710, 8);
83 ret
|= test (272710, 12);
84 ret
|= test (14170, 32);
85 ret
|= test (4170, 320);