分页: 1 / 1

lseek()返回值可能是负数的情况?

发表于 : 2010-01-15 8:45
小锐同学
《Unix环境高级编程》上说:

代码: 全选

通常,文件的当前偏移量是一个非负整数,但是,某些设备也可能允许负的偏移量。但对于普通文件,则其偏移量必须是非负值。因为偏移量可能是负值,所以在比较lseek的返回值时应当谨慎,不要测试它是否小于0,而要测试它是否等于-1.
这个不明白,参考资料上都没说lseek能返回除了-1之外的其他负值。

Re: lseek()返回值可能是负数的情况?

发表于 : 2010-01-15 13:54
BigSnake.NET

代码: 全选

RETURN VALUE
       Upon successful completion, lseek() returns the resulting offset location as measured
       in bytes from the beginning of  the  file.   Otherwise,  a  value  of  (off_t) -1  is
       returned and errno is set to indicate the error.
错误返回 -1 并设置 errno, 否则就不是错误