#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/mman.h>
#include <string.h>
int main()
{
int fd;
char *start;
char buf[100];
/*打开文件*/
fd = open("testfile",O_RDWR);
        
start=mmap(NULL,100,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
//这个函数就是把一纸文件内容,映射到内存特定未位置的函数,null 为随机分配内存位置,
        //100为分配内存的大小,PORT_READ此映射内容为可读,fd文件返回地址,0为offset 就是从文件内容第一个数读起。
/* 读出数据 */
strcpy(buf,start);
printf("buf = %s\n",buf);
/* 写入数据 */
strcpy(start,"Buf Is Not Null!");
munmap(start,100); /*解除映射*/
close(fd);  
return 0;
}