lseek

OS/161 Reference Manual

Name

lseek - change current position in file

Library

Standard C Library (libc, -lc)

Synopsis

#include <unistd.h>

off_t
lseek(int fd, off_t pos, int whence);

Description

lseek alters the current seek position of the file handle filehandle, seeking to a new position based on pos and whence.

If whence is

Note that pos is a signed quantity.

It is not meaningful to seek on certain objects (such as the console device). All seeks on these objects fail.

Seek positions less than zero are invalid. Seek positions beyond EOF are legal.

Note that each distinct open of a file should have an independent seek pointer.

Return Values

On success, lseek returns the new position. On error, -1 is returned, and errno is set according to the error encountered.

Errors

The following error codes should be returned under the conditions given. Other error codes may be returned for other errors not mentioned here.
  
EBADF fd is not a valid file handle.
ESPIPE fd refers to an object which does not support seeking.
EINVAL whence is invalid.
EINVAL The resulting seek position would be negative.