A demo usging mmap() to read a file
来源:互联网 发布:域名升级访问中 编辑:程序博客网 时间:2024/06/07 04:00
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> int main (int argc, char *argv[]) { struct stat sb; off_t len; char *p; int fd; if (argc < 2) { fprintf (stderr, "usage: %s <file>\n", argv[0]); return 1; } fd = open (argv[1], O_RDONLY); if (fd == -1) { perror ("open"); return 1; } if (fstat (fd, &sb) == -1) { perror ("fstat"); return 1; } if (!S_ISREG (sb.st_mode)) { fprintf (stderr, "%s is not a file\n", argv[1]); return 1; } p = mmap (0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { perror ("mmap"); return 1; } if (close (fd) == -1) { perror ("close"); return 1; } for (len = 0; len < sb.st_size; len++) putchar (p[len]); if (munmap (p, sb.st_size) == -1) { perror ("munmap"); return 1; } return 0; }
- A demo usging mmap() to read a file
- A demo usging mmap() to read a file
- Windows Batch File: How to read a file
- How To Read a File From Your Application Bundle
- Shell Script Utility To Read a File Line By Line
- A simple way to read an XML file in Java
- Use eof() to read and display a text file.
- Use eof() to read and display a text file.
- C++ - Read / Write std::map to a file
- Tcl/TK -- How to read a ini file
- How to read data from a file in reverse order?
- How to read a PCap file from Wireshark with C++
- How to read a file line by line?
- a network error occurred while attempting to read the file..
- Shell: How to read lines in a file.
- How to read a frame from YUV file in OpenCV?
- Xcode localization failed to read a strings file问题原因
- Cannot create a symlink to ...... Read only file system
- launcher widget 添加过程分析
- GNU make 中文手册
- freemarker 标签使用
- 2011-9-8复习mysql
- 静态测试 --需求测试的核心
- A demo usging mmap() to read a file
- launcher widget 添加过程分析2
- xml和widget
- Ant(another net tool)--1
- 20个开源项目托管站点推荐
- 回圈 (loop)--for...do...done (固定回圈)
- 辗转相除法求最大公约数(最小公倍数)
- 【转】myEclipse 中文 乱码 .
- ado异常代码含义对照表及SQL Access,oracle 数据类型对照表