Fix link errors with GCC 10 and binutils 2.34 on Fedora
[pintos-anon] / src / tests / filesys / extended / child-syn-rw.c
1 /* Child process for syn-rw.
2    Reads from a file created by our parent process, which is
3    growing it.  We loop until we've read the whole file
4    successfully.  Many iterations through the loop will return 0
5    bytes, because the file has not grown in the meantime.  That
6    is, we are "busy waiting" for the file to grow.
7    (This test could be improved by adding a "yield" system call
8    and calling yield whenever we receive a 0-byte read.) */
9
10 #include <random.h>
11 #include <stdlib.h>
12 #include <syscall.h>
13 #include "tests/filesys/extended/syn-rw.h"
14 #include "tests/lib.h"
15
16 static char buf1[BUF_SIZE];
17 static char buf2[BUF_SIZE];
18
19 int
20 main (int argc, const char *argv[]) 
21 {
22   int child_idx;
23   int fd;
24   size_t ofs;
25
26   test_name = "child-syn-rw";
27   quiet = true;
28   
29   CHECK (argc == 2, "argc must be 2, actually %d", argc);
30   child_idx = atoi (argv[1]);
31
32   random_init (0);
33   random_bytes (buf1, sizeof buf1);
34
35   CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
36   ofs = 0;
37   while (ofs < sizeof buf2)
38     {
39       int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
40       CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
41              "%zu-byte read on \"%s\" returned invalid value of %d",
42              sizeof buf2 - ofs, file_name, bytes_read);
43       if (bytes_read > 0) 
44         {
45           compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name);
46           ofs += bytes_read;
47         }
48     }
49   close (fd);
50
51   return child_idx;
52 }