Commit | Line | Data |
---|---|---|
21c4e167 H |
1 | #include <stdio.h> |
2 | #include <fcntl.h> | |
3 | #include <sys/mman.h> | |
4 | #include <sys/stat.h> | |
5 | #include <sys/types.h> | |
6 | ||
7 | unsigned char *fmmap(FILE *fd) { | |
8 | struct stat sb; | |
9 | ||
10 | if(!fd) perror(""); | |
11 | fd = fileno(fd); | |
12 | fstat((int)fd, &sb); | |
13 | return mmap(0, sb.st_size, PROT_READ, MAP_PRIVATE, (int)fd, 0); | |
14 | } | |
15 | ||
16 | int main() { | |
17 | FILE *fd; | |
18 | unsigned char *mm; | |
19 | ||
20 | fd = fopen("mmap.c", "r"); | |
21 | mm = fmmap(fd); | |
22 | ||
23 | perror("Status"); | |
24 | puts(mm); | |
25 | ||
26 | //munmap(mm, 10); | |
27 | fclose(fd); | |
28 | } |