1 .\" Copyright (c) 1980, 1991, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
13 .\" may be used to endorse or promote products derived from this software
14 .\" without specific prior written permission.
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .\" @(#)lseek.2 8.3 (Berkeley) 4/19/94
36 .Nd reposition read/write file offset
42 .Fn lseek "int fildes" "off_t offset" "int whence"
46 system call repositions the offset of the file descriptor
51 according to the directive
60 repositions the file position pointer associated with the file
64 .Bl -item -offset indent
78 the offset is set to its current location plus
86 the offset is set to the size of the
95 the offset is set to the start of the next hole greater than or equal
98 The definition of a hole is provided below.
104 the offset is set to the start of the next non-hole file region greater
105 than or equal to the supplied
111 system call allows the file offset to be set beyond the end
112 of the existing end-of-file of the file.
113 If data is later written
114 at this point, subsequent reads of the data in the gap return
115 bytes of zeros (until data is actually written into the gap).
118 system call does not, by itself, extend the size of a file.
122 is defined as a contiguous range of bytes in a file, all having the value of
123 zero, but not all zeros in a file are guaranteed to be represented as holes
126 File systems are allowed to expose ranges of zeros with
131 to optimise their behavior for ranges of zeros, but must not depend on it to
132 find all such ranges in a file.
133 Each file is presented as having a zero-size virtual hole at the very
135 The existence of a hole at the end of every data region allows for easy
136 programming and also provides compatibility to the original implementation
138 It also causes the current file size (i.e., end-of-file offset) to be returned
139 to indicate that there are no more holes past the supplied
141 Applications should use
142 .Fn fpathconf _PC_MIN_HOLE_SIZE
144 .Fn pathconf _PC_MIN_HOLE_SIZE
145 to determine if a file system supports
150 For file systems that do not supply information about holes, the file will be
151 represented as one entire data region.
153 Upon successful completion,
155 returns the resulting offset location as measured in bytes from the
156 beginning of the file.
158 a value of -1 is returned and
166 will fail and the file position pointer will remain unchanged if:
172 is not an open file descriptor.
177 is not a proper value
178 or the resulting file offset would
179 be negative for a non-character special file.
183 there are no more data regions past the supplied offset.
184 Due to existence of the hole at the end of the file, for
186 this error is only returned when the
188 already points to the end-of-file position.
190 The resulting file offset would be a value which cannot be represented
191 correctly in an object of type
197 is associated with a pipe, socket, or FIFO.
206 system call is expected to conform to
213 directives, along with the
215 error, are extensions to that specification.
224 system call is operating on a device which is incapable of seeking,
225 it will request the seek operation and return successfully,
226 even though no seek was performed.
229 argument will be stored unconditionally in the file descriptor of that device,
230 there is no way to confirm if the seek operation succeeded or not
234 Device types which are known to be incapable of seeking include
239 system call will not detect whether media are present in changeable
240 media devices such as DVD or Blu-ray devices.
241 A requested seek operation will therefore return sucessfully when no
244 This document's use of
246 is incorrect English, but is maintained for historical reasons.