135a9183fcc8f3d92cfca6f4128dbc4f8145b9df
[pintos-anon] / src / tests / filesys / extended / grow-sparse.c
1 /* Tests that seeking past the end of a file and writing will
2    properly zero out the region in between. */
3
4 #include <syscall.h>
5 #include "tests/lib.h"
6 #include "tests/main.h"
7
8 static char buf[76543];
9
10 void
11 test_main (void) 
12 {
13   const char *filename = "testfile";
14   char zero = 0;
15   int fd;
16   
17   CHECK (create (filename, 0), "create \"%s\"", filename);
18   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
19   msg ("seek \"%s\"", filename);
20   seek (fd, sizeof buf - 1);
21   CHECK (write (fd, &zero, 1) > 0, "write \"%s\"", filename);
22   msg ("close \"%s\"", filename);
23   close (fd);
24   check_file (filename, buf, sizeof buf);
25 }