正在加载图片...
文件映射举例 #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> c -a program that uses mmap to copy itself to stdout * int maino( s七 uct stat sta七 int主,fd,size; char *bufp; /* open the file get its size*/ fd= open("/mmap. c",O RDONLY); fstat(fd, &stat) size=s七at.s七size; /* map the file to a new VM area * bufp mmap(o, size, PROT READ, MAP PRIVATE, fd,0)i /* write the vm area to stdout write(l, bufp, size)i文件映射举例 #include <unistd.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> /* mmap.c - a program that uses mmap to copy itself to stdout */ int main() { struct stat stat; int i, fd, size; char *bufp; /* open the file & get its size*/ fd = open("./mmap.c", O_RDONLY); fstat(fd, &stat); size = stat.st_size; /* map the file to a new VM area */ bufp = mmap(0, size, PROT_READ, MAP_PRIVATE, fd, 0); /* write the VM area to stdout */ write(1, bufp, size); }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有