1 /* Copyright (c) 2014 Yaakov Selkowitz <yselkowi@redhat.com> */
2 /*
3 FUNCTION
4 <<qsort_r>>---sort an array
5 
6 INDEX
7 	qsort_r
8 
9 SYNOPSIS
10 	#define _BSD_SOURCE
11 	#include <stdlib.h>
12 	void qsort_r(void *<[base]>, size_t <[nmemb]>, size_t <[size]>,
13 		     void *<[thunk]>,
14 		     int (*<[compar]>)(void*, const void *, const void *));
15 
16 	#define _GNU_SOURCE
17 	#include <stdlib.h>
18 	void qsort_r(void *<[base]>, size_t <[nmemb]>, size_t <[size]>,
19 		     int (*<[compar]>)(const void *, const void *, void *),
20 		     void *<[thunk]>);
21 
22 DESCRIPTION
23 <<qsort_r>> sorts an array (beginning at <[base]>) of <[nmemb]> objects.
24 <[size]> describes the size of each element of the array.
25 
26 You must supply a pointer to a comparison function, using the argument
27 shown as <[compar]>.  (This permits sorting objects of unknown
28 properties.)  There are two forms of this function, in each the
29 comparison function is defined to accept three arguments, but in a
30 different order.  Two are pointers to an element of the array starting at
31 <[base]>, and another being an arbitrary pointer <[thunk]>.  The
32 result of <<(*<[compar]>)>> must be negative if the first argument is
33 less than the second, zero if the two arguments match, and positive if
34 the first argument is greater than the second (where ``less than'' and
35 ``greater than'' refer to whatever arbitrary ordering is appropriate).
36 
37 The array is sorted in place; that is, when <<qsort_r>> returns, the
38 array elements beginning at <[base]> have been reordered.
39 
40 RETURNS
41 <<qsort_r>> does not return a result.
42 
43 PORTABILITY
44 <<qsort_r>>, in various forms, appears in both BSD and glibc.
45 */
46 
47 #define _GNU_SOURCE
48 #define I_AM_GNU_QSORT_R
49 #include "qsort.c"
50