通过man 2 lseek可以查看linux中的系统函数lseek函数的帮助文档,为了更好的学习,我把这些重要内容翻译过来
1 NAME 2 lseek - reposition read/write file offset//重置读或写文件的偏移量 3 4 SYNOPSIS//摘要 5 #include <sys/types.h>//如果要使用lseek函数,需要包含这两个头文件 6 #include <unistd.h> 7 8 off_t lseek(int fd, off_t offset, int whence);//lseek的声明格式 9 10 DESCRIPTION//描述 11 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: 13 //lseek()函数的作用是,重置和文件描述符fd关联的打开的文件的偏移量,把这个偏移量重置为参数offset,在重置时要根据指令whence来做。whence的可包含的指令如下: 14 SEEK_SET 15 The offset is set to offset bytes.//如果whence的指令是SEEK_SET,则文件偏移量设定为参数offset大小的字节 16 17 SEEK_CUR 18 The offset is set to its current location plus offset bytes.//如果whence的指令是SEEK_CUR,则文件偏移量设定为当前位置加上offset大小的字节 19 20 SEEK_END 21 The offset is set to the size of the file plus offset bytes.//如果whence的指令是SEEK_END,则文件偏移量设定为文件大小再加上offset大小的字节 22 23 The lseek() function allows the file offset to be set beyond the end of the file (but this does not change the 24 size of the file). If data is later written at this point, subsequent reads of the data in the gap (a "hole") 25 return null bytes ('