dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / share / man / man2 / lseek.2
blob69b3b65abbeb0cae36dc43110edba148060cd544
1 '\" te
2 .\" Copyright 1989, AT&.T. Copyright (c) 2005, Sun Microsystems, Inc.  All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH LSEEK 2 "May 4, 2005"
7 .SH NAME
8 lseek \- move read/write file pointer
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <sys/types.h>
13 #include <unistd.h>
15 \fBoff_t\fR \fBlseek\fR(\fBint\fR \fIfildes\fR, \fBoff_t\fR \fIoffset\fR, \fBint\fR \fIwhence\fR);
16 .fi
18 .SH DESCRIPTION
19 .sp
20 .LP
21 The \fBlseek()\fR function sets the file pointer associated with the open file
22 descriptor specified by \fIfildes\fR as follows:
23 .RS +4
24 .TP
25 .ie t \(bu
26 .el o
27 If \fIwhence\fR is \fBSEEK_SET\fR, the pointer is set to \fIoffset\fR bytes.
28 .RE
29 .RS +4
30 .TP
31 .ie t \(bu
32 .el o
33 If \fIwhence\fR is \fBSEEK_CUR\fR, the pointer is set to its current location
34 plus \fIoffset\fR.
35 .RE
36 .RS +4
37 .TP
38 .ie t \(bu
39 .el o
40 If \fIwhence\fR is \fBSEEK_END\fR, the pointer is set to the size of the file
41 plus \fIoffset\fR.
42 .RE
43 .RS +4
44 .TP
45 .ie t \(bu
46 .el o
47 If \fIwhence\fR is \fBSEEK_HOLE\fR, the offset of the start of the next hole
48 greater than or equal to the supplied offset is returned. The definition of a
49 hole is provided near the end of the DESCRIPTION.
50 .RE
51 .RS +4
52 .TP
53 .ie t \(bu
54 .el o
55 If \fIwhence\fR is \fBSEEK_DATA\fR, the file pointer is set to the start of the
56 next non-hole file region greater than or equal to the supplied offset.
57 .RE
58 .sp
59 .LP
60 The symbolic constants \fBSEEK_SET\fR, \fBSEEK_CUR\fR, \fBSEEK_END\fR,
61 \fBSEEK_HOLE\fR, and \fBSEEK_DATA\fR are defined in the header
62 <\fBunistd.h\fR>.
63 .sp
64 .LP
65 Some devices are incapable of seeking. The value of the file pointer associated
66 with such a device is undefined.
67 .sp
68 .LP
69 The \fBlseek()\fR function allows the file pointer to be set beyond the
70 existing data in the file. If data are later written at this point, subsequent
71 reads in the gap between the previous end of data and the newly written data
72 will return bytes of value 0 until data are written into the gap.
73 .sp
74 .LP
75 If \fIfildes\fR is a remote file descriptor and \fIoffset\fR is negative,
76 \fBlseek()\fR returns the file pointer  even if it is negative. The
77 \fBlseek()\fR function will not, by itself, extend the size of a file.
78 .sp
79 .LP
80 If \fIfildes\fR refers to a shared memory object, \fBlseek()\fR behaves as if
81 \fIfildes\fR referred to a regular file.
82 .sp
83 .LP
84 A "hole" is defined as a contiguous range of bytes in a file, all having the
85 value of zero, but not all zeros in a file are guaranteed to be represented as
86 holes returned with \fBSEEK_HOLE\fR. Filesystems are allowed to expose ranges
87 of zeros with \fBSEEK_HOLE\fR, but not required to. Applications can use
88 \fBSEEK_HOLE\fR to optimise their behavior for ranges of zeros, but must not
89 depend on it to find all such ranges in a file. The existence of a hole at the
90 end of every data region allows for easy programming and implies that a virtual
91 hole exists at the end of the file. Applications should use
92 \fBfpathconf\fR(\fB_PC_MIN_HOLE_SIZE\fR) or
93 \fBpathconf\fR(\fB_PC_MIN_HOLE_SIZE\fR) to determine if a filesystem supports
94 \fBSEEK_HOLE\fR. See \fBfpathconf\fR(2).
95 .sp
96 .LP
97 For filesystems that do not supply information about holes, the file will be
98 represented as one entire data region.
99 .SH RETURN VALUES
102 Upon successful completion, the resulting offset, as measured in bytes from the
103 beginning of the file, is returned. Otherwise, \fB(off_t)\(mi1\fR is returned,
104 the file offset remains unchanged, and \fBerrno\fR is set to indicate the
105 error.
106 .SH ERRORS
109 The \fBlseek()\fR function will fail if:
111 .ne 2
113 \fB\fBEBADF\fR\fR
115 .RS 13n
116 The \fIfildes\fR argument is not an open file descriptor.
120 .ne 2
122 \fB\fBEINVAL\fR\fR
124 .RS 13n
125 The \fIwhence\fR argument is not \fBSEEK_SET\fR, \fBSEEK_CUR\fR, or
126 \fBSEEK_END\fR; or the \fIfildes\fR argument is not a remote file descriptor
127 and the resulting file pointer would be negative.
131 .ne 2
133 \fB\fBENXIO\fR\fR
135 .RS 13n
136 For \fBSEEK_DATA\fR, there are no more data regions past the supplied offset.
137 For \fBSEEK_HOLE\fR, there are no more holes past the supplied offset.
141 .ne 2
143 \fB\fBEOVERFLOW\fR\fR
145 .RS 13n
146 The resulting file offset would be a value which cannot be represented
147 correctly in an object of type \fBoff_t\fR for regular files.
151 .ne 2
153 \fB\fBESPIPE\fR\fR
155 .RS 13n
156 The \fIfildes\fR argument is associated with a pipe, a FIFO, or a socket.
159 .SH USAGE
162 The \fBlseek()\fR function has a transitional interface for 64-bit file
163 offsets.  See \fBlf64\fR(5).
166 In multithreaded applications, using \fBlseek()\fR in conjunction with a
167 \fBread\fR(2) or \fBwrite\fR(2) call on a file descriptor shared by more than
168 one thread is not an atomic operation.  To ensure atomicity, use \fBpread()\fR
169 or \fBpwrite()\fR.
170 .SH ATTRIBUTES
173 See \fBattributes\fR(5) for descriptions of the following attributes:
178 box;
179 c | c
180 l | l .
181 ATTRIBUTE TYPE  ATTRIBUTE VALUE
183 Interface Stability     Standard
185 MT-Level        Async-Signal-Safe
188 .SH SEE ALSO
191 \fBcreat\fR(2), \fBdup\fR(2), \fBfcntl\fR(2), \fBfpathconf\fR(2),
192 \fBopen\fR(2), \fBread\fR(2), \fBwrite\fR(2), \fBattributes\fR(5),
193 \fBlf64\fR(5), \fBstandards\fR(5)