The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

lseek - move the read/write file offset

 SYNOPSIS



#include <sys/types.h>
#include <unistd.h>

off_t lseek(int fildes, off_t offset, int whence);

 DESCRIPTION

The lseek() function will set the file offset for the open file description associated with the file descriptor fildes, as follows:

The symbolic constants SEEK_SET, SEEK_CUR and SEEK_END are defined in the header <unistd.h>.

The behaviour of lseek() on devices which are incapable of seeking is implementation-dependent. The value of the file offset associated with such a device is undefined.

The lseek() function will allow the file offset to be set beyond the end of the existing data in the file. If data is later written at this point, subsequent reads of data in the gap will return bytes with the value 0 until data is actually written into the gap.

The lseek() function will not, by itself, extend the size of a file.

If fildes refers to a shared memory object, the result of the lseek() function is unspecified.

 RETURN VALUE

Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, is returned. Otherwise, (off_t)-1 is returned, errno is set to indicate the error and the file offset will remain unchanged.

 ERRORS

The lseek() function will fail if:
[EBADF]
The fildes argument is not an open file descriptor.
[EINVAL]
The whence argument is not a proper value, or the resulting file offset would be invalid.
[EOVERFLOW]
The resulting file offset would be a value which cannot be represented correctly in an object of type off_t.
[ESPIPE]
The fildes argument is associated with a pipe or FIFO.

 EXAMPLES

None.

 APPLICATION USAGE

None.

 FUTURE DIRECTIONS

None.

 SEE ALSO

open(), <sys/types.h>, <unistd.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]