summary refs log tree commit diff
path: root/stdlib/testsort.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
committerRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
commit28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch)
tree15f07c4c43d635959c6afee96bde71fb1b3614ee /stdlib/testsort.c
downloadglibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.gz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.xz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.zip
initial import
Diffstat (limited to 'stdlib/testsort.c')
-rw-r--r--stdlib/testsort.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/stdlib/testsort.c b/stdlib/testsort.c
new file mode 100644
index 0000000000..a171a62130
--- /dev/null
+++ b/stdlib/testsort.c
@@ -0,0 +1,38 @@
+#include <ansidecl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+int
+DEFUN(compare, (a, b), CONST PTR a AND CONST PTR b)
+{
+  return strcmp (*(char **) a, *(char **) b);
+}
+
+
+int
+DEFUN_VOID(main)
+{
+  char bufs[500][20];
+  char *lines[500];
+  size_t lens[500];
+  size_t i, j;
+
+  srandom (1);
+
+  for (i = 0; i < 500; ++i)
+    {
+      lens[i] = random() % 19;
+      lines[i] = bufs[i];
+      for (j = 0; j < lens[i]; ++j)
+	lines[i][j] = random() % 26 + 'a';
+      lines[i][j] = '\0';
+    }
+
+  qsort (lines, 500, sizeof (char *), compare);
+
+  for (i = 0; i < 500 && lines[i] != NULL; ++i)
+    puts (lines[i]);
+
+  return 0;
+}