内容简介
#include <sys/types.h>%uA0#include <unistd.h>
off_t lseek(int%uA0fildes, off_t%uA0offset, int%uA0whence)
描述
The%uA0lseek() function repositions the offset of the open file associated with the file descriptor%uA0fildes%uA0to the argument%uA0offsetꂬcording to the directive%uA0whence%uA0as follows:标签 | 描述 |
---|---|
SEEK_SET | |
%uA0 | The offset is set to%uA0offset%uA0bytes. |
SEEK_CUR | |
%uA0 | The offset is set to its current location plus%uA0offset%uA0bytes. |
SEEK_END | |
%uA0 | The offset is set to the size of the file plus%uA0offset%uA0bytes. |
返回值
Upon successful completion,%uA0lseek() returns the resulting offset location as measured in bytes from the beginning of the file. Otherwise, a value of%uA0(off_t)-1%uA0is returned and%uA0errnois set to indicate the error.错误
标签 | 描述 |
---|---|
EBADF | fildes%uA0is not an open file descriptor. |
EINVAL | whence%uA0is not one of SEEK_SET, SEEK_CUR, SEEK_END or the resulting file offset would be negative, or beyond the end of a seekable device. |
EOVERFLOW | |
%uA0 | The resulting file offset cannot be represented in an%uA0off_t. |
ESPIPE | fildes%uA0is associated with a pipe, socket, or FIFO. |
遵循于
SVr4, 4.3BSD, POSIX.1-2001.RESTRICTIONS
Some devices are incapable of seeking and POSIX does not specify which devices must support%uA0lseek().Linux specific restrictions: using%uA0lseek() on a tty device returns%uA0ESPIPE.
注意
本文档的使用那里的是英文不正确,但维持历史原因。当与下面的宏转换旧的代码,用于何处替换值:
old | new |
0 | SEEK_SET |
1 | SEEK_CUR |
2 | SEEK_END |
L_SET | SEEK_SET |
L_INCR | SEEK_CUR |
L_XTND | SEEK_END |
SVr1-3 returns%uA0long%uA0instead of%uA0off_t, BSD returns%uA0int.
Note that file descriptors created by%uA0dup(2) or%uA0fork(2) share the current file position yiibaier, so seeking on such files may be subject to race conditions.