00001
00002
00003
00004
00005 #include <debug.h>
00006 #include <syscall.h>
00007 #include "tests/lib.h"
00008 #include "tests/main.h"
00009
00010 const char *test_name = "child-sort";
00011
00012 unsigned char buf[128 * 1024];
00013 size_t histogram[256];
00014
00015 int
00016 main (int argc UNUSED, char *argv[])
00017 {
00018 int handle;
00019 unsigned char *p;
00020 size_t size;
00021 size_t i;
00022
00023 quiet = true;
00024
00025 CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
00026
00027 size = read (handle, buf, sizeof buf);
00028 for (i = 0; i < size; i++)
00029 histogram[buf[i]]++;
00030 p = buf;
00031 for (i = 0; i < sizeof histogram / sizeof *histogram; i++)
00032 {
00033 size_t j = histogram[i];
00034 while (j-- > 0)
00035 *p++ = i;
00036 }
00037 seek (handle, 0);
00038 write (handle, buf, size);
00039 close (handle);
00040
00041 return 123;
00042 }