LSEEK
Section: System Calls (2)
Updated: August 1, 1992
Index
Return to Main Contents
NAME
lseek - move read/write pointer
BSD SYNOPSIS
#include <sys/file.h>
#define L_SET 0 /* set the seek pointer */
#define L_INCR 1 /* increment the seek pointer */
#define L_XTND 2 /* 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_SET 0 /* set the seek pointer */
#define SEEK_CUR 1 /* increment the seek pointer */
#define SEEK_END 2 /* 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)
Index
- NAME
-
- BSD SYNOPSIS
-
- POSIX SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUE
-
- ERRORS
-
- SEE ALSO
-
This document was created by
man2html,
using the manual pages.
Time: 13:52:40 GMT, September 25, 2024