initial import
[ICEs.git] / 197191 / test.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <fcntl.h>
4 #include <unistd.h>
5 #include <stdlib.h>
6 #include <sys/mman.h>
7 #include <sys/stat.h>
8 #include <assert.h>
9
10 int main(int argc, char *argv[])
11 {
12 char *file;
13 struct stat buf;
14 int max, fd;
15
16 max = (argc < 2 ? sysconf(_SC_PAGE_SIZE) : atoi(argv[1]));
17 printf("size of file = %i\n", max);
18
19 fd = open("ppImage.config", O_WRONLY | O_TRUNC, 644);
20 assert(lseek(fd, max-1, SEEK_SET) != -1);
21 write(fd, argv[0], 1);
22 close(fd);
23
24 fd = open("ppImage.config", O_RDONLY);
25 assert(fstat(fd, &buf) == 0);
26 max = buf.st_size + 1;
27 file = mmap(0, max, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
28 printf("%i\n", file[0]);
29 printf("%i\n", file[max - 1]);
30 munmap(file, max);
31 close(fd);
32
33 return 0;
34 }