lseek.2

来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 2 代码 · 共 106 行

2
106
字号
.\" SCCSID: @(#)lseek.2	2.1	3/10/87.TH lseek 2.SH Namelseek, tell \- move read or write pointer.SH Syntax.nf#include <sys/types.h>#include <unistd.h>.PPpos = lseek(\fId, offset, whence\fP).broff_t pos;.brint \fId, whence\fP;.broff_t \fIoffset\fP;.PPpos = tell(\fId\fP).broff_t pos;.brint \fId\fP;.fi.SH Description.NXR "lseek system call".NXR "tell system call".NXR "file pointer" "moving"The system call.PN lseekmoves the file pointer associated with afile or device open for reading or writing.  .PPThe descriptor .I drefers to a file or device open for reading or writing.The.PN lseeksystem call sets the file pointer of.I das follows:.IP \(bu 5If.I whenceis SEEK_SET, the pointer is set to.I offsetbytes..IP \(bu 5If.I whenceis SEEK_CUR the pointer is set to its current location plus.IR offset ..IP \(bu 5If.I whenceis SEEK_END, the pointer is set to the size of thefile plus.IR offset ..PPSeeking beyond the end of a file and then writing to the file creates a gap or hole that does not occupy physical spaceand reads as zeros..PPThe .PN tellsystem call returns the offset of the current byte relative to thebeginning of the file associated with the file descriptor..SH Environment.SS System FiveIf you compile a program in the System Five environment,an invalid .I whence argument causes SIGSYS to be sent.  This complies withthe behavior described in the System V Interface Definition (SVID), Issue 1..SH Return ValuesUpon successful completion, a long integer(the current file pointer value) is returned.  This pointeris measured in bytes from the beginning of the file, wherethe first byte is byte 0.  (Note that some devices are incapableof seeking.  The value of the pointer associated with sucha device is undefined.)If a value of \-1 is returned, \fIerrno\fP is set to indicatethe error..SH DiagnosticsThe.PN lseeksystem call fails and the file pointer remains unchanged under thefollowing conditions:.TP 15[EBADF] The.I fildes is not an open file descriptor.  .TP 15[EINVAL]The.I whenceis not a proper value..TP 15[ESPIPE]The.I fildesis associated with a pipe or a socket..SH See Alsodup(2), open(2)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?