lseek()

NAME

lseek() - reposition read/write file offset

SYNOPSIS

#include <unistd.h>

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:

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)