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.\" from: @(#)lseek.2 6.5 (Berkeley) 3/10/91 33.\" $Id: lseek.2,v 1.5 1994/01/10 23:54:23 jtc Exp $ 34.\" 35.Dd March 10, 1991 36.Dt LSEEK 2 37.Os BSD 4 38.Sh NAME 39.Nm lseek 40.Nd reposition read/write file offset 41.Sh SYNOPSIS 42.Fd #include <unistd.h> 43.Ft off_t 44.Fn lseek "int fildes" "off_t offset" "int whence" 45.Sh DESCRIPTION 46The 47.Fn lseek 48function repositions the offset of the file descriptor 49.Fa fildes 50to the 51argument 52.Fa offset 53according to the directive 54.Fa whence. 55The argument 56.Fa fildes 57must be an open 58file descriptor. 59.Fn Lseek 60repositions the file pointer 61.Fa fildes 62as follows: 63.Bl -item -offset indent 64.It 65If 66.Fa whence 67is 68.Dv SEEK_SET , 69the offset is set to 70.Fa offset 71bytes. 72.It 73If 74.Fa whence 75is 76.Dv SEEK_CUR , 77the offset is set to its current location plus 78.Fa offset 79bytes. 80.It 81If 82.Fa whence 83is 84.Dv SEEK_END , 85the offset is set to the size of the 86file plus 87.Fa offset 88bytes. 89.El 90.Pp 91The 92.Fn lseek 93function allows the file offset to be set beyond the end 94of the existing end-of-file of the file. If data is later written 95at this point, subsequent reads of the data in the gap return 96bytes of zeros (until data is actually written into the gap). 97.Pp 98Some devices are incapable of seeking. The value of the pointer 99associated with such a device is undefined. 100.Sh RETURN VALUES 101Upon successful completion, 102.Fn lseek 103returns the resulting offset location as measured in bytes from the 104beginning of the file. 105Otherwise, 106a value of -1 is returned and 107.Va errno 108is set to indicate 109the error. 110.Sh ERRORS 111.Fn Lseek 112will fail and the file pointer will remain unchanged if: 113.Bl -tag -width Er 114.It Bq Er EBADF 115.Em Fildes 116is not an open file descriptor. 117.It Bq Er ESPIPE 118.Em Fildes 119is associated with a pipe, socket, or FIFO. 120.It Bq Er EINVAL 121.Fa Whence 122is not a proper value. 123.El 124.Sh SEE ALSO 125.Xr dup 2 , 126.Xr open 2 127.Sh BUGS 128This document's use of 129.Fa whence 130is incorrect English, but maintained for historical reasons. 131.Sh STANDARDS 132The 133.Fn lseek 134function conforms to 135.St -p1003.1-88 . 136