1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
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.
8 .\" SPDX-License-Identifier: BSD-4-Clause-UC
10 .\" @(#)fseek.3 6.11 (Berkeley) 6/29/91
12 .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
14 .TH FSEEK 3 2021-03-22 "Linux man-pages (unreleased)"
16 fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
19 .RI ( libc ", " \-lc )
24 .BI "int fseek(FILE *" stream ", long " offset ", int " whence );
25 .BI "long ftell(FILE *" stream );
27 .BI "void rewind(FILE *" stream );
29 .BI "int fgetpos(FILE *restrict " stream ", fpos_t *restrict " pos );
30 .BI "int fsetpos(FILE *" stream ", const fpos_t *" pos );
35 function sets the file position indicator for the stream pointed to by
37 The new position, measured in bytes, is obtained by adding
39 bytes to the position specified by
48 the offset is relative to the start of the file, the current position
49 indicator, or end-of-file, respectively.
50 A successful call to the
52 function clears the end-of-file indicator for the stream and undoes
55 function on the same stream.
59 function obtains the current value of the file position indicator for the
65 function sets the file position indicator for the stream pointed to by
67 to the beginning of the file.
71 (void) fseek(stream, 0L, SEEK_SET)
74 except that the error indicator for the stream is also cleared (see
81 functions are alternate interfaces equivalent to
89 setting and storing the current value of the file offset into or from the
92 On some non-UNIX systems, an
94 object may be a complex object and these routines may be the only way to
95 portably reposition a text stream.
97 If the stream refers to a regular file
98 and the resulting stream offset is beyond the size of the file,
99 subsequent writes will extend the file with a hole, up to the offset,
100 before committing any data.
103 for details on file seeking semantics.
107 function returns no value.
108 Upon successful completion,
115 returns the current offset.
116 Otherwise, \-1 is returned and
118 is set to indicate the error.
131 Or: the resulting file offset would be negative.
134 The file descriptor underlying
136 is not seekable (e.g., it refers to a pipe, FIFO, or socket).
144 may also fail and set
146 for any of the errors specified for the routines
153 For an explanation of the terms used in this section, see
161 Interface Attribute Value
168 T} Thread safety MT-Safe
174 POSIX.1-2001, POSIX.1-2008, C89, C99.