taskrambler  0.1.9
Web server and task management solution.
mmapfiletest.c File Reference
#include <sys/mman.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <time.h>
+ Include dependency graph for mmapfiletest.c:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 19 of file mmapfiletest.c.

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 }