Index of Section 2 Manual Pages
| Interix / SUA | lseek.2 | Interix / SUA |
lseek(2) lseek(2)
lseek()
NAME
lseek() - reposition read/write file offset
SYNOPSIS
#include
off_t lseek (int fd, off_t offset, int whence)
DESCRIPTION
The lseek(2) function repositions the offset of the file descriptor fd to
the argument offset according to the directive whence. The argument fd
must be an open file descriptor. The lseek(2) function repositions the
file pointer fd as follows:
* If whence is SEEK_SET, the offset is set to offset bytes.
* If whence is SEEK_CUR, the offset is set to its current location
plus offset bytes.
* If whence is SEEK_END, the offset is set to the size of the file
plus offset bytes.
The lseek(2) function allows the file offset to be set beyond the end of
the existing end-of-file of the file. If data is later written at this
point, subsequent reads of the data in the gap return bytes of zeros
(until data is actually written into the gap).
Some devices are incapable of seeking. The value of the pointer associated
with such a device is undefined.
RETURN VALUES
Upon successful completion, lseek(2) returns the resulting offset location
as measured in bytes from the beginning of the file. Otherwise, a value of
-1 is returned and errno is set to indicate the error.
ERRORS
The lseek(2) call will fail and the file pointer will remain unchanged if:
[EBADF]
Fd is not an open file descriptor.
[ESPIPE]
Fd is associated with a pipe, socket, or FIFO.
[EINVAL]
Whence is not a proper value.
SEE ALSO
dup(2)
fseek(3)
open(2)
USAGE NOTES
The lseek function is thread safe.
The lseek function is async-signal safe.