taskrambler  v0.1.8
Web server and task management solution.
mmapfiletest.c
Go to the documentation of this file.
1 // for mmap
2 #include <sys/mman.h>
3 
4 // for random
5 #include <stdlib.h>
6 
7 // for open and fstat
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 
12 // for puts
13 #include <stdio.h>
14 
15 // for time
16 #include <time.h>
17 
18 int
19 main(int argc, char * argv[])
20 {
21  struct stat st;
22  char * map;
23  size_t position;
24  char print_buf[101];
25  int i;
26 
27  print_buf[100] = '\0';
28 
29  int fd = open("./mmapfiletest.c", O_RDONLY);
30 
31  fstat(fd, &st);
32  map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
33 
34  srandom(time(NULL));
35  position = random() % (st.st_size - 100);
36 
37  for (i=0; i<100; i+=10) {
38  print_buf[i+0] = map[position + i + 0];
39  print_buf[i+1] = map[position + i + 1];
40  print_buf[i+2] = map[position + i + 2];
41  print_buf[i+3] = map[position + i + 3];
42  print_buf[i+4] = map[position + i + 4];
43  print_buf[i+5] = map[position + i + 5];
44  print_buf[i+6] = map[position + i + 6];
45  print_buf[i+7] = map[position + i + 7];
46  print_buf[i+8] = map[position + i + 8];
47  print_buf[i+9] = map[position + i + 9];
48  }
49 
50  puts(print_buf);
51 
52  return 0;
53 }
54 
55 // vim: set et ts=4 sw=4:
int main(int argc, char *argv[])
Definition: mmapfiletest.c:19