summaryrefslogtreecommitdiff
path: root/test/stdlib/qsort.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-08 18:04:43 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-08 18:04:43 +0000
commitf8a65069905b067fda10667f4275c9f3ead64eed (patch)
tree7ff621f926961047f3a4a5e27525d5634f071132 /test/stdlib/qsort.c
parentd25de224769281dc702430752fc4c64e8a317a9b (diff)
Add in a qsort, alphasort, scandir test from Jon Nelson, jnelson@securepipe.com
Diffstat (limited to 'test/stdlib/qsort.c')
-rw-r--r--test/stdlib/qsort.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/stdlib/qsort.c b/test/stdlib/qsort.c
new file mode 100644
index 000000000..50464979e
--- /dev/null
+++ b/test/stdlib/qsort.c
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <dirent.h>
+#include <stdlib.h>
+
+int select_files(const struct dirent *dirbuf)
+{
+ if (dirbuf->d_name[0] == '.')
+ return 0;
+ else
+ return 1;
+}
+
+
+int main(void)
+{
+ struct dirent **array;
+ struct dirent *dirbuf;
+
+ int i, numdir;
+
+ chdir("/");
+ numdir = scandir(".", &array, select_files, NULL);
+ printf("\nGot %d entries from scandir().\n", numdir);
+ for (i = 0; i < numdir; ++i) {
+ dirbuf = array[i];
+ printf("[%d] %s\n", i, dirbuf->d_name);
+ free(array[i]);
+ }
+ free(array);
+ numdir = scandir(".", &array, select_files, alphasort);
+ printf("\nGot %d entries from scandir() using alphasort().\n", numdir);
+ for (i = 0; i < numdir; ++i) {
+ dirbuf = array[i];
+ printf("[%d] %s\n", i, dirbuf->d_name);
+ }
+ printf("\nCalling qsort()\n", numdir);
+ qsort(array, numdir, sizeof(struct dirent *), alphasort);
+ for (i = 0; i < numdir; ++i) {
+ dirbuf = array[i];
+ printf("[%d] %s\n", i, dirbuf->d_name);
+ free(array[i]);
+ }
+ free(array);
+ return(0);
+}
+