APUE 函数详解系列(一) lseek/stat/poll
来源:互联网 发布:java jasperreports 编辑:程序博客网 时间:2024/06/05 14:58
1. lseek - reposition read/write file offset
SYSNOPSIS
#include<sys/types.h> and <unistd.h>
off_t lseek(int fd, off_t offset,int whence);
DESCRIPTION
The lseek() function repositions the offset of the open file associated descriptor fd to the argument offset according to the directive whence as follows:
SEEK_SET:The offset is set to offset bytes.
SEEK_CUR:The offset is set to its current location plus offset bytes.
SEEK_END:The offset is set to the size of file plus offset bytes.RETURE VALUE
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the begining of the file. On error, the value (off_t) -1 is returned and errno is set to indicate the error.特别使用方式:
1) 将读写位置移到文件开头:lseek(int fd, 0, SEEK_SET);
2) 将读写位置一道文件末尾:lseek(int fd, 0, SEEK_END);
3) 取得目前文件位置:lseek(int fd, 0 , SEEK_CUR);
2. stat - display file or file system status
- SYSNOPSIS
#include<sys/stat.h> . <unistd.h> . <sys/types.h>int stat(const char *path, struct stat *buf)
- DESCRIPTION
This function return information about a file.
struct stat{ dev_t st_dev; ino_t st_ino; mode_t st_mode; //文件类型和许可权限 nlink_t st_nlink; //文件连接数 uid_t st_uid; //用户所有者ID gid_t st_gid; //所属组ID time_t st_mtime; //文件最后修改时间 time_t st_atime; //文件最后访问时间 time_t st_ctime; //文件属性最后修改时间}
3.Poll
类似select,接口不同
#include<poll.h>int poll(struct pollfd fdarray[], nfds_t nfds, int timeout);struct pollfd{ int fd; short events; //events of interest on fd 请求事件 short revents; //events that occurred on fd 返回事件}
nfds指定fdarray数组中元素,events告诉内核我们关心的是每个描述符哪些事件,返回时,revents成员由内核设置,用于说明每个描述符发生了哪些事件。 poll中events和revents标志
- APUE 函数详解系列(一) lseek/stat/poll
- poll()函数详解
- poll()函数详解
- poll()函数详解
- lseek函数详解
- 【必看】Linux开发入门实战笔记系列(一):lseek 函数用法
- linux stat函数详解
- linux stat函数详解
- Linux stat函数详解
- stat 函数详解
- 文件操作中的lseek函数详解
- lseek()详解
- lseek详解
- lseek函数
- lseek函数
- lseek函数
- lseek函数
- lseek()函数
- js实现-新闻间歇性向上无缝滚动
- Eclipse导入项目常见问题----服务器版本问题02
- 深入理解JavaScript系列(25):设计模式之单例模式
- python bottle 简介
- Zookeeper系列(二十九)Zookeeper场景应用之分布式锁实现
- APUE 函数详解系列(一) lseek/stat/poll
- 我与python约个会:01概述
- Android打印机--TSC 标签打印
- ActivityLifecycleCallbacks 代替BaseActivity (扩展Activity的最好方法)
- 发布系统报错,SpringObjectFactory.java:220:-1,解决方法
- 深入理解JavaScript系列(26):设计模式之构造函数模式
- 对于JAVA中访问权限修饰符的理解
- 一种在windows平台下实现自动操作应用的方法,附带源码地址及使用方法
- Tomcat配置文件修改无效自动恢复还原的解决办法总结