flag fields are u_int's
[unix-history] / usr / src / lib / libc / sys / lseek.2
CommitLineData
931b8415
CL
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
ec7838a8 3.\"
931b8415 4.\" %sccs.include.redist.man%
ec7838a8 5.\"
931b8415
CL
6.\" @(#)lseek.2 6.5 (Berkeley) %G%
7.\"
8.Dd
9.Dt LSEEK 2
10.Os BSD 4
11.Sh NAME
12.Nm lseek
13.Nd reposition read/write file offset
14.Sh SYNOPSIS
15.Fd #include <unistd.h>
16.Ft off_t
17.Fn lseek "int fildes" "off_t offset" "int whence"
18.Sh DESCRIPTION
19The
20.Fn lseek
21function repositions the offset of the file descriptor
22.Fa fildes
23to the
24argument
25.Fa offset
26according to the directive
27.Fa whence.
28The argument
29.Fa fildes
30must be an open
31file descriptor.
32.Fn Lseek
33repositions the file pointer
34.Fa fildes
84648ee2 35as follows:
931b8415
CL
36.Bl -item -offset indent
37.It
ec7838a8 38If
931b8415
CL
39.Fa whence
40is
41.Dv SEEK_SET ,
42the offset is set to
43.Fa offset
ec7838a8 44bytes.
931b8415 45.It
ec7838a8 46If
931b8415
CL
47.Fa whence
48is
49.Dv SEEK_CUR ,
50the offset is set to its current location plus
51.Fa offset
52bytes.
53.It
ec7838a8 54If
931b8415
CL
55.Fa whence
56is
57.Dv SEEK_END ,
58the offset is set to the size of the
ec7838a8 59file plus
931b8415
CL
60.Fa offset
61bytes.
62.El
63.Pp
64The
65.Fn lseek
66function allows the file offset to be set beyond the end
67of the existing end-of-file of the file. If data is later written
68at this point, subsequent reads of the data in the gap return
69bytes of zeros (until data is actualy written into the gap).
70.Pp
84648ee2
KM
71Some devices are incapable of seeking. The value of the pointer
72associated with such a device is undefined.
931b8415 73.Sh RETURN VALUES
594f4c31 74Upon successful completion,
931b8415
CL
75.Fn lseek
76returns the resulting offset location as measured in bytes from the
77begining of the file.
594f4c31 78Otherwise,
931b8415
CL
79a value of -1 is returned and
80.Va errno
81is set to indicate
84648ee2 82the error.
931b8415
CL
83.Sh ERRORS
84.Fn Lseek
84648ee2 85will fail and the file pointer will remain unchanged if:
931b8415
CL
86.Bl -tag -width [EINVAL]
87.It Bq Er EBADF
88.Em Fildes
84648ee2 89is not an open file descriptor.
931b8415
CL
90.It Bq Er ESPIPE
91.Em Fildes
92is associated with a pipe, socket, or FIFO.
93.It Bq Er EINVAL
94.Fa Whence
84648ee2 95is not a proper value.
931b8415
CL
96.El
97.Sh SEE ALSO
98.Xr dup 2 ,
99.Xr open 2
100.Sh BUGS
84648ee2 101This document's use of
931b8415 102.Fa whence
84648ee2 103is incorrect English, but maintained for historical reasons.
931b8415
CL
104.Sh STANDARDS
105The
106.Fn lseek
107function
108conforms to IEEE Std 1003.1-1988
109.Pq Dq Tn POSIX .