]>
Commit | Line | Data |
---|---|---|
1f205a47 UD |
1 | /* Test for strverscmp() */ |
2 | ||
3 | #include <stdlib.h> | |
4 | #include <stdio.h> | |
5 | #include <string.h> | |
6 | ||
7 | #define MAX_STRINGS 256 | |
8 | #define MAX_LINE_SIZE 32 | |
9 | ||
de149cdb | 10 | static int |
1f205a47 UD |
11 | compare (const void *p1, const void *p2) |
12 | { | |
13 | return strverscmp (*((char **) p1), *((char **) p2)); | |
14 | } | |
15 | ||
fb82116f | 16 | int |
c1f41083 | 17 | do_test (void) |
1f205a47 UD |
18 | { |
19 | char line[MAX_LINE_SIZE + 1]; | |
20 | char *str[MAX_STRINGS]; | |
21 | int count = 0; | |
22 | int i, n; | |
23 | ||
24 | while (count < MAX_STRINGS && fgets (line, MAX_LINE_SIZE, stdin) != NULL) | |
25 | { | |
26 | n = strlen (line) - 1; | |
27 | ||
28 | if (line[n] == '\n') | |
29 | line[n] = '\0'; | |
30 | ||
31 | str[count] = strdup (line); | |
32 | ||
33 | if (str[count] == NULL) | |
34 | exit (EXIT_FAILURE); | |
35 | ||
36 | ++count; | |
37 | } | |
38 | ||
39 | qsort (str, count, sizeof (char *), compare); | |
40 | ||
41 | for (i = 0; i < count; ++i) | |
42 | puts (str[i]); | |
43 | ||
bf4de8f3 | 44 | return EXIT_SUCCESS; |
1f205a47 | 45 | } |
c1f41083 | 46 | |
fb82116f | 47 | #include <support/test-driver.c> |