名字
Name : lseek - reposition read/write file offset
lseek函数的作用是用来重新定位文件读写的位移。
头文件以及函数声明
#include <sys/types.h> #include <unistd.h> off_t lseek(int fd, off_t offset, int whence);
offset为正则向文件末尾移动(向前移),为负数则向文件头部(向后移)。
描述
lseek() repositions the file offset of the open file description associated with the file descriptor fd to the argument offset according to the directive whence as follows:
SEEK_SET The file offset is set to offset bytes.
SEEK_CUR The file offset is set to its current location plus offset bytes.
SEEK_END The file offset is set to the size of the file plus offset bytes.
lseek() allows the file offset to be set beyond the end of the file (but this does not change the size of the file). If data is later written at this point, subsequent reads of the data in the gap (a “hole”) return null bytes (‘