This source file includes following definitions.
- cmp
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 int
26 cmp (void const *va, void const *vb, void *varg)
27 {
28 char const *a = va;
29 char const *b = vb;
30 int *arg = varg;
31 return (*a < *b ? -1 : *a > *b) * *arg;
32 }
33
34 int
35 main (void)
36 {
37 char buf[] = "thequickbrownfoxjumpedoverthelazydogs";
38 int forward = 1;
39 int reverse = -1;
40 qsort_r (buf, sizeof buf - 1, 1, cmp, &forward);
41 if (strcmp (buf, "abcddeeeefghhijklmnoooopqrrsttuuvwxyz") != 0)
42 return 1;
43 qsort_r (buf, sizeof buf - 1, 1, cmp, &reverse);
44 if (strcmp (buf, "zyxwvuuttsrrqpoooonmlkjihhgfeeeeddcba") != 0)
45 return 1;
46 return 0;
47 }