off_tlseek(int fd, off_t offset, int whence);
// 功能:移动文件指针。若执行成功,则返回新的当前文件偏移量
描述: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:
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 the file plus offset bytes.
// 把文件指针位置设置为:whence+offset// SEEK_SET:当前文件指针在:offset处// SEEK_CUR:当前文件指针在:cfo+offset处// 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',
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the
file. On error, the value(off_t) -1 is returned and errno is set to indicate the error.
// 成功,则返回文件当前指针距离文件开头的偏移量,失败则返回-1并设置errno
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理