Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ lseek(2) — OPENSTEP 4.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

creat(2)

dup(2)

fcntl(2)

open(2)

read(2)

sigaction(2P)

write(2)

LSEEK(2)  —  UNIX Programmer’s Manual

NAME

lseek − move read/write pointer

BSD SYNOPSIS

#include <sys/file.h>

#define L_SET0/∗ set the seek pointer ∗/
#define L_INCR1/∗ increment the seek pointer ∗/
#define L_XTND2/∗ extend the file size ∗/

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

POSIX SYNOPSIS

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

#define SEEK_SET0/∗ set the seek pointer ∗/
#define SEEK_CUR1 /∗ increment the seek pointer ∗/
#define SEEK_END2 /∗ extend the file size ∗/

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

DESCRIPTION

The descriptor fd refers to a file or device open for reading and/or writing.  The lseek function sets the file pointer of fd as follows:

(1) If whence is L_SET (SEEK_SET for POSIX applications), the offset is set to offset bytes. 

(2) If whence is L_INCR (SEEK_CUR for POSIX applications), the offset is set to its current value plus offset bytes. 

(3) If whence is L_XTND (SEEK_END for POSIX applications), the offset is set to the size of the file plus offset bytes. 

Upon successful completion, the resulting pointer location as measured in bytes from beginning of the file is returned.  Some devices are incapable of seeking.  The value of the pointer associated with such a device is undefined. 

Seeking far beyond the end of a file, then writing, creates a gap or “hole”, which occupies no physical space and reads as zeros.  The lseek function does not, by itself, extend the size of the file. 

RETURN VALUE

Upon successful completion, the current file pointer value is returned.  Otherwise, a value of −1 is returned and errno is set to indicate the error. 

ERRORS

The lseek function will fail and the file pointer will remain unchanged if:

[EBADF] fd is not an open file descriptor. 

[ESPIPE] fd is associated with a pipe or a socket. 

[EINVAL] whence is not a proper value, or the resulting file offset is less than 0. 

SEE ALSO

creat(2), dup(2), fcntl(2), open(2), read(2), sigaction(2P), write(2)

POSIX 1003.1  —  August 1, 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026