Created
May 1, 2015 22:10
-
-
Save benaryorg/7882b3941f4740c42b29 to your computer and use it in GitHub Desktop.
mmap cat implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <assert.h> | |
#include <fcntl.h> | |
#include <sys/mman.h> | |
int main(int argc,char **argv) | |
{ | |
assert(argc==2); | |
int file=open(argv[1],O_RDONLY); | |
assert(file>0); | |
struct stat st; | |
fstat(file,&st); | |
void *addr=mmap((void *)0xffffffff00000000,st.st_size,PROT_READ,MAP_PRIVATE,file,0); | |
assert(addr); | |
fwrite(addr,st.st_size,1,stdout); | |
munmap(addr,st.st_size); | |
close(file); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment