📄 lseek.2
字号:
.\" Copyright (c) 1980, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" @(#)lseek.2 8.3 (Berkeley) 4/19/94.\".Dd April 19, 1994.Dt LSEEK 2.Os BSD 4.Sh NAME.Nm lseek.Nd reposition read/write file offset.Sh SYNOPSIS.Fd #include <unistd.h>.Ft off_t.Fn lseek "int fildes" "off_t offset" "int whence".Sh DESCRIPTIONThe.Fn lseekfunction repositions the offset of the file descriptor.Fa fildesto theargument.Fa offsetaccording to the directive.Fa whence.The argument.Fa fildesmust be an openfile descriptor..Fn Lseekrepositions the file pointer.Fa fildesas follows:.Bl -item -offset indent.ItIf.Fa whenceis.Dv SEEK_SET ,the offset is set to.Fa offsetbytes..ItIf.Fa whenceis.Dv SEEK_CUR ,the offset is set to its current location plus.Fa offsetbytes..ItIf.Fa whenceis.Dv SEEK_END ,the offset is set to the size of thefile plus.Fa offsetbytes..El.PpThe.Fn lseekfunction allows the file offset to be set beyond the endof the existing end-of-file of the file. If data is later writtenat this point, subsequent reads of the data in the gap returnbytes of zeros (until data is actually written into the gap)..PpSome devices are incapable of seeking. The value of the pointerassociated with such a device is undefined..Sh RETURN VALUESUpon successful completion,.Fn lseekreturns the resulting offset location as measured in bytes from thebeginning of the file.Otherwise,a value of -1 is returned and.Va errnois set to indicatethe error..Sh ERRORS.Fn Lseekwill fail and the file pointer will remain unchanged if:.Bl -tag -width [EINVAL].It Bq Er EBADF.Em Fildesis not an open file descriptor..It Bq Er ESPIPE.Em Fildesis associated with a pipe, socket, or FIFO..It Bq Er EINVAL.Fa Whenceis not a proper value..El.Sh SEE ALSO.Xr dup 2 ,.Xr open 2.Sh BUGSThis document's use of.Fa whenceis incorrect English, but is maintained for historical reasons..Sh STANDARDSThe.Fn lseekfunctionconforms to IEEE Std 1003.1-1988.Pq Dq Tn POSIX .
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -