DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

lseek(S-osr5)


lseek -- move read/write file pointer

Syntax

cc . . . -lc

#include  <unistd.h>

off_t lseek(int fildes, off_t 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 follows:

Symbolic constants for whence are defined in the <unistd.h> header file:

Name Description
SEEK_CUR Set file-pointer to current location plus offset.
SEEK_END Set file-pointer to EOF plus offset.
SEEK_SET Set file-pointer equal to offset bytes.

 +---------+---------------------------------------------------+
 |Name     | Description                                       |
 +---------+---------------------------------------------------+
 |SEEK_CUR | Set file-pointer to current location plus offset. |
 +---------+---------------------------------------------------+
 |SEEK_END | Set file-pointer to EOF plus offset.              |
 +---------+---------------------------------------------------+
 |SEEK_SET | Set file-pointer equal to offset bytes.           |
 +---------+---------------------------------------------------+

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 returns the file pointer even if it is negative.

lseek fails and the file pointer remains unchanged if one or more of the following is true:


[EBADF]
fildes is not an open file descriptor.

[EINVAL]

  1. (with SIGSYS signal is present): The whence argument is not 0, 1, or 2.

  2. fildes is not a remote file descriptor, and the resulting file pointer would be negative.

    Some devices are incapable of seeking. The value of the file pointer associated with such a device is undefined.


[ESPIPE]
fildes is associated with a pipe or fifo.

Diagnostics

Upon successful completion, a non-negative integer indicating the file pointer value is returned. Otherwise, a value of -1 is returned, and errno is set to indicate the error.

See also

creat(S-osr5), dup(S-osr5), fcntl(S-osr5), open(S-osr5)

Standards conformance

lseek is conformant with:

X/Open Portability Guide, Issue 3, 1989 ;
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2) ;
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005