📄 fseeko.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>fseek</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_005_284"> </a>NAME</h4><blockquote>fseek, fseeko - reposition a file-position indicator in a stream</blockquote><h4><a name = "tag_000_005_285"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="stdio.h.html">stdio.h</a>>int fseek(FILE *<i>stream</i>, long int <i>offset</i>, int <i>whence</i>);int fseeko(FILE *<i>stream</i>, off_t <i>offset</i>, int <i>whence</i>);</code></pre></blockquote><h4><a name = "tag_000_005_286"> </a>DESCRIPTION</h4><blockquote>The<i>fseek()</i>function sets the file-position indicator for the stream pointed to by<i>stream</i>.<p>The new position, measured in bytes from the beginning of the file, isobtained by adding<i>offset</i>to the position specified by<i>whence</i>.The specified point is the beginning of the file for SEEK_SET, thecurrent value of the file-position indicator for SEEK_CUR, orend-of-file for SEEK_END.<p>If the stream is to be used with wide-character input/output functions,<i>offset</i> must either be 0 or a value returned by an earlier call to<i><a href="ftell.html">ftell()</a></i>on the same stream and <i>whence</i> must be SEEK_SET.<p>A successful call to<i>fseek()</i>clears the end-of-file indicator for the stream and undoes any effects of<i><a href="ungetc.html">ungetc()</a></i>and<i><a href="ungetwc.html">ungetwc()</a></i>on the same stream. After an<i>fseek()</i>call, the next operation on an update stream may be either input or output.<p>If the most recent operation, other than<i><a href="ftell.html">ftell()</a></i>,on a given stream is<i><a href="fflush.html">fflush()</a></i>,the file offset in the underlying open file description willbe adjusted to reflect the location specified by<i>fseek()</i>.<p>The<i>fseek()</i>function allows the file-position indicator to be setbeyond the end of existing data in the file.If data is later writtenat this point, subsequent reads of data in the gap will return byteswith the value 0 until data is actually written into the gap.<p>The behaviour of<i>fseek()</i>on devices which are incapable of seeking is implementation-dependent.The value of the file offset associated with such a device is undefined.<p>If the stream is writable and buffered data had not been written to theunderlying file,<i>fseek()</i>will cause the unwritten data to be written tothe file and mark the<i>st_ctime</i>and<i>st_mtime</i>fields of the file for update.<p>In a locale with state-dependent encoding, whether<i>fseek()</i>restores the stream's shift state is implementation-dependent.<p>The <i>fseeko()</i>function is identical to the <i>fseek()</i>function except that the <i>offset</i>argument is of type <b>off_t</b>.</blockquote><h4><a name = "tag_000_005_287"> </a>RETURN VALUE</h4><blockquote>The<i>fseek()</i>and<i>fseeko()</i>functions return 0 if they succeed; otherwise they return-1and set<i>errno</i>to indicate the error.</blockquote><h4><a name = "tag_000_005_288"> </a>ERRORS</h4><blockquote>The<i>fseek()</i>and<i>fseeko()</i>functions will fail if, either the<i>stream</i>is unbuffered or the<i>stream</i>sbuffer needed to be flushed, and the call to<i>fseek()</i>or<i>fseeko()</i>causes an underlying<i><a href="lseek.html">lseek()</a></i>or<i><a href="write.html">write()</a></i>to be invoked:<dl compact><dt>[EAGAIN]<dd>The O_NONBLOCK flag is set for the file descriptor and the processwould be delayed in the write operation.<dt>[EBADF]<dd>The file descriptor underlying the stream file is not open for writing orthe stream's buffer needed to be flushed and the file is not open.<dt>[EFBIG]<dd>An attempt was made to write a file that exceedsthe maximum file size or the process' file size limit.<dt>[EFBIG]<dd>The file is a regular file and an attempt was made to write at or beyondthe offset maximum associated with the corresponding stream.<dt>[EINTR]<dd>The write operation was terminated due to the receipt of a signal,and no data was transferred.<dt>[EINVAL]<dd>The<i>whence</i>argument is invalid.The resulting file-position indicator would be set to a negative value.<dt>[EIO]<dd>A physical I/O error has occurred, or the process is a memberof a background process group attempting to perform a<i><a href="write.html">write()</a></i>to itscontrolling terminal, TOSTOP is set, the process is neither ignoring norblocking SIGTTOU and the process group of the process isorphaned.This error may also be returned under implementation-dependent conditions.<dt>[ENOSPC]<dd>There was no free space remaining on the device containing the file.<dt>[EOVERFLOW]<dd>For<i>fseek()</i>,the resulting file offset would be a value which cannot be representedcorrectly in an object of type <b>long</b>.<dt>[EOVERFLOW]<dd>For<i>fseeko()</i>,the resulting file offset would be a value which cannot be representedcorrectly in an object of type <b>off_t</b>.<dt>[EPIPE]<dd>The file descriptor underlying<i>stream</i>is associated with a pipe or FIFO.<dt>[EPIPE]<dd>An attempt was made to write to a pipe or FIFO thatis not open for reading by any process; a SIGPIPEsignal will also be sent to the thread.<dt>[ENXIO]<dd>A request was made of a non-existent device, or the request wasoutside the capabilities of the device.</dl></blockquote><h4><a name = "tag_000_005_289"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_290"> </a>APPLICATION USAGE</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_291"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_292"> </a>SEE ALSO</h4><blockquote><i><a href="fopen.html">fopen()</a></i>,<i><a href="fsetpos.html">fsetpos()</a></i>,<i><a href="ftell.html">ftell()</a></i>,<i><a href="getrlimit.html">getrlimit()</a></i>,<i><a href="rewind.html">rewind()</a></i>,<i><a href="ulimit.html">ulimit()</a></i>,<i><a href="ungetc.html">ungetc()</a></i>,<i><a href="stdio.h.html"><stdio.h></a></i>.</blockquote><h4>DERIVATION</h4><blockquote>Derived from Issue 1 of the SVID.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -