1LSEEK(2)                   Linux Programmer's Manual                  LSEEK(2)
2
3
4

NAME

6       lseek - reposition read/write file offset
7

SYNOPSIS

9       #include <sys/types.h>
10       #include <unistd.h>
11
12       off_t lseek(int fildes, off_t offset, int whence);
13

DESCRIPTION

15       The lseek() function repositions the offset of the open file associated
16       with the file descriptor fildes to the argument offset according to the
17       directive whence as follows:
18
19       SEEK_SET
20              The offset is set to offset bytes.
21
22       SEEK_CUR
23              The offset is set to its current location plus offset bytes.
24
25       SEEK_END
26              The offset is set to the size of the file plus offset bytes.
27
28       The lseek() function allows the file offset to be set beyond the end of
29       the file (but this does not change the size of the file).  If  data  is
30       later written at this point, subsequent reads of the data in the gap (a
31       "hole") return null bytes ('\0') until data is  actually  written  into
32       the gap.
33

RETURN VALUE

35       Upon  successful completion, lseek() returns the resulting offset loca‐
36       tion as measured in bytes from the beginning of the file.  Otherwise, a
37       value of (off_t)-1 is returned and errno is set to indicate the error.
38

ERRORS

40       EBADF  fildes is not an open file descriptor.
41
42       EINVAL whence  is  not  one  of  SEEK_SET,  SEEK_CUR,  SEEK_END; or the
43              resulting file offset would be negative, or beyond the end of  a
44              seekable device.
45
46       EOVERFLOW
47              The resulting file offset cannot be represented in an off_t.
48
49       ESPIPE fildes is associated with a pipe, socket, or FIFO.
50

CONFORMING TO

52       SVr4, 4.3BSD, POSIX.1-2001.
53

RESTRICTIONS

55       Some  devices are incapable of seeking and POSIX does not specify which
56       devices must support lseek().
57
58       Linux specific restrictions: using lseek()  on  a  tty  device  returns
59       ESPIPE.
60

NOTES

62       This  document's use of whence is incorrect English, but maintained for
63       historical reasons.
64
65       When converting old code, substitute values for whence with the follow‐
66       ing macros:
67
68        old       new
69       0        SEEK_SET
70       1        SEEK_CUR
71       2        SEEK_END
72       L_SET    SEEK_SET
73       L_INCR   SEEK_CUR
74       L_XTND   SEEK_END
75
76       SVr1-3 returns long instead of off_t, BSD returns int.
77
78       Note  that file descriptors created by dup(2) or fork(2) share the cur‐
79       rent file position pointer, so seeking on such files may be subject  to
80       race conditions.
81

SEE ALSO

83       dup(2), fork(2), open(2), fseek(3), lseek64(3), posix_fallocate(3)
84
85
86
87Linux                             2001-09-24                          LSEEK(2)
Impressum