]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fseek.3
_exit.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres...
[thirdparty/man-pages.git] / man3 / fseek.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 1990, 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek and the American National Standards Committee X3,
6.\" on Information Processing Systems.
7.\"
a9cd9cb7 8.\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
fea681da
MK
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in the
16.\" documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\" must display the following acknowledgement:
19.\" This product includes software developed by the University of
20.\" California, Berkeley and its contributors.
21.\" 4. Neither the name of the University nor the names of its contributors
22.\" may be used to endorse or promote products derived from this software
23.\" without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35.\" SUCH DAMAGE.
8c9302dc 36.\" %%%LICENSE_END
fea681da
MK
37.\"
38.\" @(#)fseek.3 6.11 (Berkeley) 6/29/91
39.\"
40.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
41.\"
460495ca 42.TH FSEEK 3 2015-08-08 "GNU" "Linux Programmer's Manual"
fea681da
MK
43.SH NAME
44fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
45.SH SYNOPSIS
46.B #include <stdio.h>
68e4db0a 47.PP
fea681da 48.BI "int fseek(FILE *" stream ", long " offset ", int " whence );
5895e7eb 49
fea681da 50.BI "long ftell(FILE *" stream );
5895e7eb 51
fea681da 52.BI "void rewind(FILE *" stream );
5895e7eb 53
fea681da
MK
54.BI "int fgetpos(FILE *" stream ", fpos_t *" pos );
55.br
d19a532b 56.BI "int fsetpos(FILE *" stream ", const fpos_t *" pos );
fea681da
MK
57.SH DESCRIPTION
58The
e511ffb6 59.BR fseek ()
fea681da
MK
60function sets the file position indicator for the stream pointed to by
61.IR stream .
62The new position, measured in bytes, is obtained by adding
63.I offset
64bytes to the position specified by
65.IR whence .
66If
67.I whence
68is set to
69.BR SEEK_SET ,
70.BR SEEK_CUR ,
71or
72.BR SEEK_END ,
73the offset is relative to the start of the file, the current position
c13182ef
MK
74indicator, or end-of-file, respectively.
75A successful call to the
e511ffb6 76.BR fseek ()
fea681da
MK
77function clears the end-of-file indicator for the stream and undoes
78any effects of the
79.BR ungetc (3)
80function on the same stream.
81.PP
82The
e511ffb6 83.BR ftell ()
fea681da
MK
84function obtains the current value of the file position indicator for the
85stream pointed to by
86.IR stream .
87.PP
88The
e511ffb6 89.BR rewind ()
fea681da
MK
90function sets the file position indicator for the stream pointed to by
91.I stream
c13182ef
MK
92to the beginning of the file.
93It is equivalent to:
fea681da
MK
94.PP
95.RS
0c535394 96(void) fseek(stream, 0L, SEEK_SET)
fea681da
MK
97.RE
98.PP
99except that the error indicator for the stream is also cleared (see
100.BR clearerr (3)).
101.PP
102The
e511ffb6 103.BR fgetpos ()
fea681da 104and
e511ffb6 105.BR fsetpos ()
fea681da 106functions are alternate interfaces equivalent to
e511ffb6 107.BR ftell ()
fea681da 108and
e511ffb6 109.BR fseek ()
949aff4c
MK
110(with
111.I whence
112set to
fea681da
MK
113.BR SEEK_SET ),
114setting and storing the current value of the file offset into or from the
115object referenced by
116.IR pos .
824464a9 117On some non-UNIX systems, an
f19a0f03 118.I fpos_t
fea681da
MK
119object may be a complex object and these routines may be the only way to
120portably reposition a text stream.
47297adb 121.SH RETURN VALUE
fea681da 122The
e511ffb6 123.BR rewind ()
c13182ef
MK
124function returns no value.
125Upon successful completion,
e511ffb6
MK
126.BR fgetpos (),
127.BR fseek (),
128.BR fsetpos ()
fea681da
MK
129return 0,
130and
e511ffb6 131.BR ftell ()
c13182ef
MK
132returns the current offset.
133Otherwise, \-1 is returned and
134.I errno
845f2c47 135is set to indicate the error.
fea681da
MK
136.SH ERRORS
137.TP
138.B EBADF
139The
140.I stream
141specified is not a seekable stream.
142.TP
143.B EINVAL
144The
145.I whence
c13182ef 146argument to
e511ffb6 147.BR fseek ()
fea681da
MK
148was not
149.BR SEEK_SET ,
150.BR SEEK_END ,
151or
152.BR SEEK_CUR .
f3ef4558 153Or: the resulting file offset would be negative.
fea681da 154.PP
845f2c47 155The functions
e511ffb6
MK
156.BR fgetpos (),
157.BR fseek (),
158.BR fsetpos (),
c13182ef 159and
e511ffb6 160.BR ftell ()
fea681da
MK
161may also fail and set
162.I errno
163for any of the errors specified for the routines
164.BR fflush (3),
165.BR fstat (2),
166.BR lseek (2),
c13182ef 167and
fea681da 168.BR malloc (3).
011bc011
MS
169.SH ATTRIBUTES
170For an explanation of the terms used in this section, see
171.BR attributes (7).
172.TS
173allbox;
174lbw27 lb lb
175l l l.
176Interface Attribute Value
177T{
178.BR fseek (),
179.BR ftell (),
180.BR rewind (),
181.br
182.BR fgetpos (),
183.BR fsetpos ()
184T} Thread safety MT-Safe
185.TE
186
47297adb 187.SH CONFORMING TO
e2e7a617 188POSIX.1-2001, POSIX.1-2008, C89, C99.
47297adb 189.SH SEE ALSO
fea681da
MK
190.BR lseek (2),
191.BR fseeko (3)