c - 如何使用 lseek 检查文件中的当前偏移位置?

标签 c linux file file-io

我在 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/

相关文章:

c - 无法理解此函数 extern void _setvect1(int vector, _Interrupt1 void (*target)());

c - 将硬编码写入 RAM 的特定物理地址

linux - tar 排除特定路径上的错误输出

c - c 上的二进制文件

c - 从文件中读取选项

c - 试图将 stdin char[] 拆分为 ','

c++ - 常量变量在 header 中不起作用

linux - 从 OpenGL 2.1 更新到 OpenGL 3.2

Python Makefile 库

python - 在 Python 2 中搜索 FileNotFoundError 的等价物