man-pages/man3/fseek.3.html
2021-03-31 01:06:50 +01:00

281 lines
5.2 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of FSEEK</TITLE>
</HEAD><BODY>
<H1>FSEEK</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2018-04-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<B>#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;</B>
<P>
<B>int fseek(FILE *</B><I>stream</I><B>, long </B><I>offset</I><B>, int </B><I>whence</I><B>);</B>
<P>
<B>long ftell(FILE *</B><I>stream</I><B>);</B>
<P>
<B>void rewind(FILE *</B><I>stream</I><B>);</B>
<P>
<B>int fgetpos(FILE *</B><I>stream</I><B>, fpos_t *</B><I>pos</I><B>);</B>
<P>
<B>int fsetpos(FILE *</B><I>stream</I><B>, const fpos_t *</B><I>pos</I><B>);</B>
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
The
<B>fseek</B>()
function sets the file position indicator for the stream pointed to by
<I>stream</I>.
The new position, measured in bytes, is obtained by adding
<I>offset</I>
bytes to the position specified by
<I>whence</I>.
If
<I>whence</I>
is set to
<B>SEEK_SET</B>,
<B>SEEK_CUR</B>,
or
<B>SEEK_END</B>,
the offset is relative to the start of the file, the current position
indicator, or end-of-file, respectively.
A successful call to the
<B>fseek</B>()
function clears the end-of-file indicator for the stream and undoes
any effects of the
<B><A HREF="/cgi-bin/man/man2html?3+ungetc">ungetc</A></B>(3)
function on the same stream.
<P>
The
<B>ftell</B>()
function obtains the current value of the file position indicator for the
stream pointed to by
<I>stream</I>.
<P>
The
<B>rewind</B>()
function sets the file position indicator for the stream pointed to by
<I>stream</I>
to the beginning of the file.
It is equivalent to:
<P>
<DL COMPACT><DT id="1"><DD>
(void) fseek(stream, 0L, SEEK_SET)
</DL>
<P>
except that the error indicator for the stream is also cleared (see
<B><A HREF="/cgi-bin/man/man2html?3+clearerr">clearerr</A></B>(3)).
<P>
The
<B>fgetpos</B>()
and
<B>fsetpos</B>()
functions are alternate interfaces equivalent to
<B>ftell</B>()
and
<B>fseek</B>()
(with
<I>whence</I>
set to
<B>SEEK_SET</B>),
setting and storing the current value of the file offset into or from the
object referenced by
<I>pos</I>.
On some non-UNIX systems, an
<I>fpos_t</I>
object may be a complex object and these routines may be the only way to
portably reposition a text stream.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>rewind</B>()
function returns no value.
Upon successful completion,
<B>fgetpos</B>(),
<B>fseek</B>(),
<B>fsetpos</B>()
return 0,
and
<B>ftell</B>()
returns the current offset.
Otherwise, -1 is returned and
<I>errno</I>
is set to indicate the error.
<A NAME="lbAF">&nbsp;</A>
<H2>ERRORS</H2>
<DL COMPACT>
<DT id="2"><B>EINVAL</B>
<DD>
The
<I>whence</I>
argument to
<B>fseek</B>()
was not
<B>SEEK_SET</B>,
<B>SEEK_END</B>,
or
<B>SEEK_CUR</B>.
Or: the resulting file offset would be negative.
<DT id="3"><B>ESPIPE</B>
<DD>
The file descriptor underlying
<I>stream</I>
is not seekable (e.g., it refers to a pipe, FIFO, or socket).
</DL>
<P>
The functions
<B>fgetpos</B>(),
<B>fseek</B>(),
<B>fsetpos</B>(),
and
<B>ftell</B>()
may also fail and set
<I>errno</I>
for any of the errors specified for the routines
<B><A HREF="/cgi-bin/man/man2html?3+fflush">fflush</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?2+fstat">fstat</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2),
and
<B><A HREF="/cgi-bin/man/man2html?3+malloc">malloc</A></B>(3).
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>fseek</B>(),
<B>ftell</B>(),
<B>rewind</B>(),
<BR>
<B>fgetpos</B>(),
<B>fsetpos</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
</TABLE>
<P>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
POSIX.1-2001, POSIX.1-2008, C89, C99.
<A NAME="lbAI">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?2+lseek">lseek</A></B>(2),
<B><A HREF="/cgi-bin/man/man2html?3+fseeko">fseeko</A></B>(3)
<A NAME="lbAJ">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="8"><A HREF="#lbAF">ERRORS</A><DD>
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="11"><A HREF="#lbAI">SEE ALSO</A><DD>
<DT id="12"><A HREF="#lbAJ">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:43 GMT, March 31, 2021
</BODY>
</HTML>