'\" te .\" Copyright 1989, AT&.T. Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved. .\" 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. .\" 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. .\" 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] .TH lseek 2 "4 May 2005" "SunOS 5.11" "System Calls" .SH NAME lseek \- move read/write file pointer .SH SYNOPSIS .LP .nf #include #include \fBoff_t\fR \fBlseek\fR(\fBint\fR \fIfildes\fR, \fBoff_t\fR \fIoffset\fR, \fBint\fR \fIwhence\fR); .fi .SH DESCRIPTION .sp .LP The \fBlseek()\fR function sets the file pointer associated with the open file descriptor specified by \fIfildes\fR as follows: .RS +4 .TP .ie t \(bu .el o If \fIwhence\fR is \fBSEEK_SET\fR, the pointer is set to \fIoffset\fR bytes. .RE .RS +4 .TP .ie t \(bu .el o If \fIwhence\fR is \fBSEEK_CUR\fR, the pointer is set to its current location plus \fIoffset\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fIwhence\fR is \fBSEEK_END\fR, the pointer is set to the size of the file plus \fIoffset\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fIwhence\fR is \fBSEEK_HOLE\fR, the offset of the start of the next hole greater than or equal to the supplied offset is returned. The definition of a hole is provided near the end of the DESCRIPTION. .RE .RS +4 .TP .ie t \(bu .el o If \fIwhence\fR is \fBSEEK_DATA\fR, the file pointer is set to the start of the next non-hole file region greater than or equal to the supplied offset. .RE .sp .LP The symbolic constants \fBSEEK_SET\fR, \fBSEEK_CUR\fR, \fBSEEK_END\fR, \fBSEEK_HOLE\fR, and \fBSEEK_DATA\fR are defined in the header <\fBunistd.h\fR>. .sp .LP Some devices are incapable of seeking. The value of the file pointer associated with such a device is undefined. .sp .LP The \fBlseek()\fR function allows the file pointer to be set beyond the existing data in the file. If data are later written at this point, subsequent reads in the gap between the previous end of data and the newly written data will return bytes of value 0 until data are written into the gap. .sp .LP If \fIfildes\fR is a remote file descriptor and \fIoffset\fR is negative, \fBlseek()\fR returns the file pointer even if it is negative. The \fBlseek()\fR function will not, by itself, extend the size of a file. .sp .LP If \fIfildes\fR refers to a shared memory object, \fBlseek()\fR behaves as if \fIfildes\fR referred to a regular file. .sp .LP A "hole" is defined as a contiguous range of bytes in a file, all having the value of zero, but not all zeros in a file are guaranteed to be represented as holes returned with \fBSEEK_HOLE\fR. Filesystems are allowed to expose ranges of zeros with \fBSEEK_HOLE\fR, but not required to. Applications can use \fBSEEK_HOLE\fR to optimise their behavior for ranges of zeros, but must not depend on it to find all such ranges in a file. The existence of a hole at the end of every data region allows for easy programming and implies that a virtual hole exists at the end of the file. Applications should use \fBfpathconf\fR(\fB_PC_MIN_HOLE_SIZE\fR) or \fBpathconf\fR(\fB_PC_MIN_HOLE_SIZE\fR) to determine if a filesystem supports \fBSEEK_HOLE\fR. See \fBfpathconf\fR(2). .sp .LP For filesystems that do not supply information about holes, the file will be represented as one entire data region. .SH RETURN VALUES .sp .LP Upon successful completion, the resulting offset, as measured in bytes from the beginning of the file, is returned. Otherwise, \fB(off_t)\(mi1\fR is returned, the file offset remains unchanged, and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBlseek()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBEBADF\fR\fR .ad .RS 13n .rt The \fIfildes\fR argument is not an open file descriptor. .RE .sp .ne 2 .mk .na \fB\fBEINVAL\fR\fR .ad .RS 13n .rt The \fIwhence\fR argument is not \fBSEEK_SET\fR, \fBSEEK_CUR\fR, or \fBSEEK_END\fR; or the \fIfildes\fR argument is not a remote file descriptor and the resulting file pointer would be negative. .RE .sp .ne 2 .mk .na \fB\fBENXIO\fR\fR .ad .RS 13n .rt For \fBSEEK_DATA\fR, there are no more data regions past the supplied offset. For \fBSEEK_HOLE\fR, there are no more holes past the supplied offset. .RE .sp .ne 2 .mk .na \fB\fBEOVERFLOW\fR\fR .ad .RS 13n .rt The resulting file offset would be a value which cannot be represented correctly in an object of type \fBoff_t\fR for regular files. .RE .sp .ne 2 .mk .na \fB\fBESPIPE\fR\fR .ad .RS 13n .rt The \fIfildes\fR argument is associated with a pipe, a FIFO, or a socket. .RE .SH USAGE .sp .LP The \fBlseek()\fR function has a transitional interface for 64-bit file offsets. See \fBlf64\fR(5). .sp .LP In multithreaded applications, using \fBlseek()\fR in conjunction with a \fBread\fR(2) or \fBwrite\fR(2) call on a file descriptor shared by more than one thread is not an atomic operation. To ensure atomicity, use \fBpread()\fR or \fBpwrite()\fR. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityStandard _ MT-LevelAsync-Signal-Safe .TE .SH SEE ALSO .sp .LP \fBcreat\fR(2), \fBdup\fR(2), \fBfcntl\fR(2), \fBfpathconf\fR(2), \fBopen\fR(2), \fBread\fR(2), \fBwrite\fR(2), \fBattributes\fR(5), \fBlf64\fR(5), \fBstandards\fR(5)