LSEEK(2) INTERACTIVE UNIX System LSEEK(2)
NAME
lseek - move read/write file pointer
SYNOPSIS
#include <unistd.h>
long lseek (fildes, offset, whence)
int fildes;
long offset;
int whence;
DESCRIPTION
The fildes argument is a file descriptor returned from a
creat, open, dup, or fcntl system call. The lseek system
call sets the file pointer associated with fildes as fol-
lows:
If whence is 0, the pointer is set to offset bytes.
If whence is 1, the pointer is set to its current loca-
tion plus offset.
If whence is 2, the pointer is set to the size of the
file plus offset.
Symbolic constants for whence are defined in the <unistd.h>
header file:
Name Description
SEEK_SET Set file-pointer equal to offset bytes.
SEEK_CUR Set file-pointer to current location plus
offset.
SEEK_END Set file-pointer to EOF plus offset.
Upon successful completion, the resulting pointer location,
as measured in bytes from the beginning of the file, is
returned. Note that if fildes is a remote file descriptor
and offset is negative, lseek will return the file pointer
even if it is negative.
lseek will fail and the file pointer will remain unchanged
if one or more of the following is true:
[EBADF] Fildes is not an open file descriptor.
[ESPIPE] Fildes is associated with a pipe or fifo.
[EINVAL and SIGSYS signal]
Whence is not 0, 1, or 2.
[EINVAL] Fildes is not a remote file descriptor, and
the resulting file pointer would be negative.
Rev. C Software Development Set Page 1
LSEEK(2) INTERACTIVE UNIX System LSEEK(2)
Some devices are incapable of seeking. The value of the
file pointer associated with such a device is undefined.
SEE ALSO
creat(2), dup(2), fcntl(2), open(2).
DIAGNOSTICS
Upon successful completion, a non-negative integer indicat-
ing the file pointer value is returned. Otherwise, a value
of -1 is returned, and errno is set to indicate the error.
Rev. C Software Development Set Page 2