>From: <wollman@uvm-gen.emba.uvm.edu>
[unix-history] / lib / libc / sys / lseek.2
CommitLineData
15637ed4
RG
1.\" Copyright (c) 1980, 1991 Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)lseek.2 6.5 (Berkeley) 3/10/91
33.\"
34.Dd March 10, 1991
35.Dt LSEEK 2
36.Os BSD 4
37.Sh NAME
38.Nm lseek
39.Nd reposition read/write file offset
40.Sh SYNOPSIS
41.Fd #include <unistd.h>
42.Ft off_t
43.Fn lseek "int fildes" "off_t offset" "int whence"
44.Sh DESCRIPTION
45The
46.Fn lseek
47function repositions the offset of the file descriptor
48.Fa fildes
49to the
50argument
51.Fa offset
52according to the directive
53.Fa whence.
54The argument
55.Fa fildes
56must be an open
57file descriptor.
58.Fn Lseek
59repositions the file pointer
60.Fa fildes
61as follows:
62.Bl -item -offset indent
63.It
64If
65.Fa whence
66is
67.Dv SEEK_SET ,
68the offset is set to
69.Fa offset
70bytes.
71.It
72If
73.Fa whence
74is
75.Dv SEEK_CUR ,
76the offset is set to its current location plus
77.Fa offset
78bytes.
79.It
80If
81.Fa whence
82is
83.Dv SEEK_END ,
84the offset is set to the size of the
85file plus
86.Fa offset
87bytes.
88.El
89.Pp
90The
91.Fn lseek
92function allows the file offset to be set beyond the end
93of the existing end-of-file of the file. If data is later written
94at this point, subsequent reads of the data in the gap return
95bytes of zeros (until data is actualy written into the gap).
96.Pp
97Some devices are incapable of seeking. The value of the pointer
98associated with such a device is undefined.
99.Sh RETURN VALUES
100Upon successful completion,
101.Fn lseek
102returns the resulting offset location as measured in bytes from the
103begining of the file.
104Otherwise,
105a value of -1 is returned and
106.Va errno
107is set to indicate
108the error.
109.Sh ERRORS
110.Fn Lseek
111will fail and the file pointer will remain unchanged if:
112.Bl -tag -width [EINVAL]
113.It Bq Er EBADF
114.Em Fildes
115is not an open file descriptor.
116.It Bq Er ESPIPE
117.Em Fildes
118is associated with a pipe, socket, or FIFO.
119.It Bq Er EINVAL
120.Fa Whence
121is not a proper value.
122.El
123.Sh SEE ALSO
124.Xr dup 2 ,
125.Xr open 2
126.Sh BUGS
127This document's use of
128.Fa whence
129is incorrect English, but maintained for historical reasons.
130.Sh STANDARDS
131The
132.Fn lseek
133function
134conforms to IEEE Std 1003.1-1988
135.Pq Dq Tn POSIX .