我在 Linux 中使用 lseek() 从头到尾遍历一个文本文件。 如何检查偏移位置是否已到达文件的开头。
PS 我不是在寻找使用文件大小来手动跟踪偏移量的解决方案。
最佳答案
我猜您正在使用带有负偏移量
的SEEK_CUR
。如果你想知道它返回后你在哪里,直接使用lseek()
的返回值。
来自 man lseek
:
Upon successful completion, lseek() returns the resulting offset location as measured in bytes from the beginning of the file.
关于c - 如何使用 lseek 检查文件中的当前偏移位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18067438/