c - C语言中lseek系统调用成功

标签 c system-calls

关于lseek(C 系统调用)的一个小问题。我知道失败时函数的返回值将为负数。我们能否确定,如果返回值不为负,函数实际上已移动到所需的位置?

最佳答案

如果值为 (off_t)-1,则出现错误。

如果该值不是(off_t)-1,则调用成功。

从我的系统的手册页,

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.

mentions off_t 必须是有符号类型,因此检查结果是负数还是非负数似乎是安全的。

关于c - C语言中lseek系统调用成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43664725/

相关文章:

c - 使用 xcode 学习 C(通过 K&R)

C ascii 字符表

multithreading - 从不同的 goroutines 进行昂贵的系统调用是否有意义?

从 Go 调用 setns 为 mnt 命名空间返回 EINVAL

c - Linux 和 Windows 上的 malloc_size 替代方案

c - 这个用 C 编写的程序没有给出正确的输出

c - C 中带有 typedef 结构的未知类型名称

c - Linux Kernel 4.2.x:为什么选中时预期的系统调用地址与实际地址不匹配?

c - int 80 不出现在汇编代码中

python - 防止Python脚本中的写入中断