关于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 anderrno
is set to indicate the error.
有mentions off_t
必须是有符号类型,因此检查结果是负数还是非负数似乎是安全的。
关于c - C语言中lseek系统调用成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43664725/