lseek(2) lseek(2)
NAME
lseek - move read/write file pointer
SYNOPSIS
#include <sys/types.h>
#include <unistd.h>
off_t lseek(int fildes, off_t offset, int whence);
DESCRIPTION
lseek moves a read/write file pointer. fildes is a file
descriptor returned from a creat, open, dup, fcntl, pipe, or
ioctl system call. lseek sets the file pointer associated
with fildes as follows:
If whence is SEEK_SET, the pointer is set to offset
bytes.
If whence is SEEK_CUR, the pointer is set to its current
location plus offset.
If whence is SEEK_END, the pointer is set to the size of
the file plus offset.
On success, lseek returns the resulting pointer location, as
measured in bytes from the beginning of the file.
lseek allows the file pointer to be set beyond the existing
data in the file. If data is later written at this point,
subsequent reads in the gap between the previous end of data
and the newly written data return bytes of value 0 until data
is written into the gap.
Return Values
On success, lseek returns a non-negative integer indicating
the file pointer value. On failure, lseek returns -1, sets
errno to identify the error, and the file pointer remains
unchanged.
Some devices are incapable of seeking. The value of the file
pointer associated with such a device is undefined.
Errors
In the following conditions, lseek fails and sets errno to:
Copyright 1994 Novell, Inc. Page 1
lseek(2) lseek(2)
EBADF fildes is not an open file descriptor.
ESPIPE fildes is associated with a pipe or fifo.
EINVAL The resulting file pointer would be negative.
fildes is a remote file descriptor accessed
using NFS, the Network File System, and the
resulting file pointer would be negative.
ENOSYS The device for fstype does not support lseek.
REFERENCES
creat(2), dup(2), fcntl(2), open(2)
NOTICES
Considerations for Threads Programming
Open file descriptors are a process resource and available to
any sibling thread; if used concurrently, actions by one
thread can interfere with those of a sibling. For example,
the position of the file pointer is maintained per file
descriptor, not per thread.
The pread(2) and pwrite(2) system calls combine positioning
and I/O in a single operation.
Copyright 1994 Novell, Inc. Page 2