Blame man3/fseek.3

Packit 7cfc04
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
Packit 7cfc04
.\" All rights reserved.
Packit 7cfc04
.\"
Packit 7cfc04
.\" This code is derived from software contributed to Berkeley by
Packit 7cfc04
.\" Chris Torek and the American National Standards Committee X3,
Packit 7cfc04
.\" on Information Processing Systems.
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
Packit 7cfc04
.\" Redistribution and use in source and binary forms, with or without
Packit 7cfc04
.\" modification, are permitted provided that the following conditions
Packit 7cfc04
.\" are met:
Packit 7cfc04
.\" 1. Redistributions of source code must retain the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer.
Packit 7cfc04
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit 7cfc04
.\"    notice, this list of conditions and the following disclaimer in the
Packit 7cfc04
.\"    documentation and/or other materials provided with the distribution.
Packit 7cfc04
.\" 3. All advertising materials mentioning features or use of this software
Packit 7cfc04
.\"    must display the following acknowledgement:
Packit 7cfc04
.\"	This product includes software developed by the University of
Packit 7cfc04
.\"	California, Berkeley and its contributors.
Packit 7cfc04
.\" 4. Neither the name of the University nor the names of its contributors
Packit 7cfc04
.\"    may be used to endorse or promote products derived from this software
Packit 7cfc04
.\"    without specific prior written permission.
Packit 7cfc04
.\"
Packit 7cfc04
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
Packit 7cfc04
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 7cfc04
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit 7cfc04
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
Packit 7cfc04
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 7cfc04
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit 7cfc04
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit 7cfc04
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit 7cfc04
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit 7cfc04
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit 7cfc04
.\" SUCH DAMAGE.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\"     @(#)fseek.3	6.11 (Berkeley) 6/29/91
Packit 7cfc04
.\"
Packit 7cfc04
.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
Packit 7cfc04
.\"
Packit 7cfc04
.TH FSEEK 3  2017-09-15 "GNU" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.B #include <stdio.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int fseek(FILE *" stream ", long " offset ", int " whence );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "long ftell(FILE *" stream );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "void rewind(FILE *" stream );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int fgetpos(FILE *" stream ", fpos_t *" pos );
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int fsetpos(FILE *" stream ", const fpos_t *" pos );
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
The
Packit 7cfc04
.BR fseek ()
Packit 7cfc04
function sets the file position indicator for the stream pointed to by
Packit 7cfc04
.IR stream .
Packit 7cfc04
The new position, measured in bytes, is obtained by adding
Packit 7cfc04
.I offset
Packit 7cfc04
bytes to the position specified by
Packit 7cfc04
.IR whence .
Packit 7cfc04
If
Packit 7cfc04
.I whence
Packit 7cfc04
is set to
Packit 7cfc04
.BR SEEK_SET ,
Packit 7cfc04
.BR SEEK_CUR ,
Packit 7cfc04
or
Packit 7cfc04
.BR SEEK_END ,
Packit 7cfc04
the offset is relative to the start of the file, the current position
Packit 7cfc04
indicator, or end-of-file, respectively.
Packit 7cfc04
A successful call to the
Packit 7cfc04
.BR fseek ()
Packit 7cfc04
function clears the end-of-file indicator for the stream and undoes
Packit 7cfc04
any effects of the
Packit 7cfc04
.BR ungetc (3)
Packit 7cfc04
function on the same stream.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR ftell ()
Packit 7cfc04
function obtains the current value of the file position indicator for the
Packit 7cfc04
stream pointed to by
Packit 7cfc04
.IR stream .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR rewind ()
Packit 7cfc04
function sets the file position indicator for the stream pointed to by
Packit 7cfc04
.I stream
Packit 7cfc04
to the beginning of the file.
Packit 7cfc04
It is equivalent to:
Packit 7cfc04
.PP
Packit 7cfc04
.RS
Packit 7cfc04
(void) fseek(stream, 0L, SEEK_SET)
Packit 7cfc04
.RE
Packit 7cfc04
.PP
Packit 7cfc04
except that the error indicator for the stream is also cleared (see
Packit 7cfc04
.BR clearerr (3)).
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR fgetpos ()
Packit 7cfc04
and
Packit 7cfc04
.BR fsetpos ()
Packit 7cfc04
functions are alternate interfaces equivalent to
Packit 7cfc04
.BR ftell ()
Packit 7cfc04
and
Packit 7cfc04
.BR fseek ()
Packit 7cfc04
(with
Packit 7cfc04
.I whence
Packit 7cfc04
set to
Packit 7cfc04
.BR SEEK_SET ),
Packit 7cfc04
setting and storing the current value of the file offset into or from the
Packit 7cfc04
object referenced by
Packit 7cfc04
.IR pos .
Packit 7cfc04
On some non-UNIX systems, an
Packit 7cfc04
.I fpos_t
Packit 7cfc04
object may be a complex object and these routines may be the only way to
Packit 7cfc04
portably reposition a text stream.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
The
Packit 7cfc04
.BR rewind ()
Packit 7cfc04
function returns no value.
Packit 7cfc04
Upon successful completion,
Packit 7cfc04
.BR fgetpos (),
Packit 7cfc04
.BR fseek (),
Packit 7cfc04
.BR fsetpos ()
Packit 7cfc04
return 0,
Packit 7cfc04
and
Packit 7cfc04
.BR ftell ()
Packit 7cfc04
returns the current offset.
Packit 7cfc04
Otherwise, \-1 is returned and
Packit 7cfc04
.I errno
Packit 7cfc04
is set to indicate the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
.TP
Packit 7cfc04
.B EBADF
Packit 7cfc04
The
Packit 7cfc04
.I stream
Packit 7cfc04
specified is not a seekable stream.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
The
Packit 7cfc04
.I whence
Packit 7cfc04
argument to
Packit 7cfc04
.BR fseek ()
Packit 7cfc04
was not
Packit 7cfc04
.BR SEEK_SET ,
Packit 7cfc04
.BR SEEK_END ,
Packit 7cfc04
or
Packit 7cfc04
.BR SEEK_CUR .
Packit 7cfc04
Or: the resulting file offset would be negative.
Packit 7cfc04
.PP
Packit 7cfc04
The functions
Packit 7cfc04
.BR fgetpos (),
Packit 7cfc04
.BR fseek (),
Packit 7cfc04
.BR fsetpos (),
Packit 7cfc04
and
Packit 7cfc04
.BR ftell ()
Packit 7cfc04
may also fail and set
Packit 7cfc04
.I errno
Packit 7cfc04
for any of the errors specified for the routines
Packit 7cfc04
.BR fflush (3),
Packit 7cfc04
.BR fstat (2),
Packit 7cfc04
.BR lseek (2),
Packit 7cfc04
and
Packit 7cfc04
.BR malloc (3).
Packit 7cfc04
.SH ATTRIBUTES
Packit 7cfc04
For an explanation of the terms used in this section, see
Packit 7cfc04
.BR attributes (7).
Packit 7cfc04
.TS
Packit 7cfc04
allbox;
Packit 7cfc04
lbw27 lb lb
Packit 7cfc04
l l l.
Packit 7cfc04
Interface	Attribute	Value
Packit 7cfc04
T{
Packit 7cfc04
.BR fseek (),
Packit 7cfc04
.BR ftell (),
Packit 7cfc04
.BR rewind (),
Packit 7cfc04
.br
Packit 7cfc04
.BR fgetpos (),
Packit 7cfc04
.BR fsetpos ()
Packit 7cfc04
T}	Thread safety	MT-Safe
Packit 7cfc04
.TE
Packit 7cfc04
.sp 1
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, C89, C99.
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR lseek (2),
Packit 7cfc04
.BR fseeko (3)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.