diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-01-29 09:21:41 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-01-29 09:21:41 +0000 |
commit | 207b66ceeba9d6035037f120a03df437ce5ab3ea (patch) | |
tree | 8ed1f23b0d621e22b1f51629f0bef08be5b7c2fa /stdlib/tst-qsort.c | |
parent | afdef815547ff44caf8f65e7fd107ca482896284 (diff) | |
download | glibc-207b66ceeba9d6035037f120a03df437ce5ab3ea.tar.gz glibc-207b66ceeba9d6035037f120a03df437ce5ab3ea.tar.xz glibc-207b66ceeba9d6035037f120a03df437ce5ab3ea.zip |
Update.
* stdlib/Makefile (tests): Add tst-qsort. * stdlib/tst-qsort.c: New file. Written by Paul Eggert.
Diffstat (limited to 'stdlib/tst-qsort.c')
-rw-r--r-- | stdlib/tst-qsort.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/stdlib/tst-qsort.c b/stdlib/tst-qsort.c new file mode 100644 index 0000000000..f39667b17c --- /dev/null +++ b/stdlib/tst-qsort.c @@ -0,0 +1,42 @@ +/* Test case by Paul Eggert <eggert@twinsun.com> */ +#include <stdio.h> +#include <stdlib.h> + +struct big { char c[4 * 1024]; }; + +struct big *array; +struct big *array_end; + +int +compare (void const *a1, void const *b1) +{ + struct big const *a = a1; + struct big const *b = b1; + if (! (array <= a && a < array_end + && array <= b && b < array_end)) + { + exit (EXIT_FAILURE); + } + return b->c[0] - a->c[0]; +} + +int +main (int argc, char **argv) +{ + size_t i; + size_t array_members = argv[1] ? atoi (argv[1]) : 50; + array = (struct big *) malloc (array_members * sizeof *array); + if (array == NULL) + { + puts ("no memory"); + exit (EXIT_FAILURE); + } + + array_end = array + array_members; + for (i = 0; i < array_members; i++) + array[i].c[0] = i % 128; + + qsort (array, array_members, sizeof *array, compare); + + return 0; +} |