Get rid of unnecessary barrier. Improve comment.
[pintos-anon] / grading / userprog / write-boundary.c
1 #include <inttypes.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <syscall.h>
5 #include "sample.inc"
6
7 static char *
8 mk_boundary_string (const char *src) 
9 {
10   static char dst[8192];
11   char *p = dst + (4096 - (uintptr_t) dst % 4096 - strlen (src) / 2);
12   strlcpy (p, src, 4096);
13   return p;
14 }
15
16 int
17 main (void) 
18 {
19   int handle;
20   int byte_cnt;
21   char *sample_p;
22
23   sample_p = mk_boundary_string (sample);
24
25   printf ("(write-boundary) begin\n");
26
27   handle = open ("sample.txt");
28   if (handle < 2)
29     printf ("(write-boundary) fail: open() returned %d\n", handle);
30
31   byte_cnt = write (handle, sample_p, sizeof sample - 1);
32   if (byte_cnt != sizeof sample - 1)
33     printf ("(write-boundary) fail: write() returned %d instead of %zu\n",
34             byte_cnt, sizeof sample - 1);
35   
36   printf ("(write-boundary) end\n");
37   return 0;
38 }