通过man 2 lseek可以查看linux中的系统函数lseek函数的帮助文档,为了更好的学习,我把这些重要内容翻译过来

 NAME
lseek - reposition read/write file offset//重置读或写文件的偏移量 SYNOPSIS//摘要
#include <sys/types.h>//如果要使用lseek函数,需要包含这两个头文件
#include <unistd.h> off_t lseek(int fd, off_t offset, int whence);//lseek的声明格式 DESCRIPTION//描述
The lseek() function repositions the offset of the open file associated with the file descriptor fd to the argument offset according to the directive whence as follows:
//lseek()函数的作用是,重置和文件描述符fd关联的打开的文件的偏移量,把这个偏移量重置为参数offset,在重置时要根据指令whence来做。whence的可包含的指令如下:
SEEK_SET
The offset is set to offset bytes.//如果whence的指令是SEEK_SET,则文件偏移量设定为参数offset大小的字节 SEEK_CUR
The offset is set to its current location plus offset bytes.//如果whence的指令是SEEK_CUR,则文件偏移量设定为当前位置加上offset大小的字节 SEEK_END
The offset is set to the size of the file plus offset bytes.//如果whence的指令是SEEK_END,则文件偏移量设定为文件大小再加上offset大小的字节 The lseek() function 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 ('\0') until data is actually written into the gap.//lseek()函数允许把文件的偏移量设置的值超过文件的结束(虽然把偏移量设定的值超过了文件的结尾,但是并不会改变文件大小)。如果数据后来被写入到这个偏移量位置,在把数据真正写入这个从文件末尾到偏移量之间的空间,那么随后在读取从文件末尾到设置的偏移量的位置,返回的都是‘\0’,
RETURN VALUE
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the begin‐
ning of the file. On error, the value (off_t) - is returned and errno is set to indicate the error.//当lseek成功完成,lseek()返回的偏移量是距离文件开头的偏移量,大小以自己为单位衡量。如果错误,返回值为-1,并设置errno的值
05-11 15:51