Fix link errors with GCC 10 and binutils 2.34 on Fedora
[pintos-anon] / src / tests / vm / child-sort.c
1 /* Reads a 128 kB file into static data and "sorts" the bytes in
2    it, using counting sort, a single-pass algorithm.  The sorted
3    data is written back to the same file in-place. */
4
5 #include <debug.h>
6 #include <syscall.h>
7 #include "tests/lib.h"
8 #include "tests/main.h"
9
10 unsigned char buf[128 * 1024];
11 size_t histogram[256];
12
13 int
14 main (int argc UNUSED, char *argv[]) 
15 {
16   int handle;
17   unsigned char *p;
18   size_t size;
19   size_t i;
20
21   test_name = "child-sort";
22   quiet = true;
23
24   CHECK ((handle = open (argv[1])) > 1, "open \"%s\"", argv[1]);
25
26   size = read (handle, buf, sizeof buf);
27   for (i = 0; i < size; i++)
28     histogram[buf[i]]++;
29   p = buf;
30   for (i = 0; i < sizeof histogram / sizeof *histogram; i++) 
31     {
32       size_t j = histogram[i];
33       while (j-- > 0)
34         *p++ = i;
35     }
36   seek (handle, 0);
37   write (handle, buf, size);
38   close (handle);
39   
40   return 123;
41 }