1FSEEK(3) Linux Programmer's Manual FSEEK(3)
2
3
4
6 fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
7
9 #include <stdio.h>
10
11 int fseek(FILE *stream, long offset, int whence);
12 long ftell(FILE *stream);
13
14 void rewind(FILE *stream);
15
16 int fgetpos(FILE *restrict stream, fpos_t *restrict pos);
17 int fsetpos(FILE *stream, const fpos_t *pos);
18
20 The fseek() function sets the file position indicator for the stream
21 pointed to by stream. The new position, measured in bytes, is obtained
22 by adding offset bytes to the position specified by whence. If whence
23 is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to
24 the start of the file, the current position indicator, or end-of-file,
25 respectively. A successful call to the fseek() function clears the
26 end-of-file indicator for the stream and undoes any effects of the
27 ungetc(3) function on the same stream.
28
29 The ftell() function obtains the current value of the file position in‐
30 dicator for the stream pointed to by stream.
31
32 The rewind() function sets the file position indicator for the stream
33 pointed to by stream to the beginning of the file. It is equivalent
34 to:
35
36 (void) fseek(stream, 0L, SEEK_SET)
37
38 except that the error indicator for the stream is also cleared (see
39 clearerr(3)).
40
41 The fgetpos() and fsetpos() functions are alternate interfaces equiva‐
42 lent to ftell() and fseek() (with whence set to SEEK_SET), setting and
43 storing the current value of the file offset into or from the object
44 referenced by pos. On some non-UNIX systems, an fpos_t object may be a
45 complex object and these routines may be the only way to portably repo‐
46 sition a text stream.
47
49 The rewind() function returns no value. Upon successful completion,
50 fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current
51 offset. Otherwise, -1 is returned and errno is set to indicate the er‐
52 ror.
53
55 EINVAL The whence argument to fseek() was not SEEK_SET, SEEK_END, or
56 SEEK_CUR. Or: the resulting file offset would be negative.
57
58 ESPIPE The file descriptor underlying stream is not seekable (e.g., it
59 refers to a pipe, FIFO, or socket).
60
61 The functions fgetpos(), fseek(), fsetpos(), and ftell() may also fail
62 and set errno for any of the errors specified for the routines
63 fflush(3), fstat(2), lseek(2), and malloc(3).
64
66 For an explanation of the terms used in this section, see at‐
67 tributes(7).
68
69 ┌────────────────────────────────────────────┬───────────────┬─────────┐
70 │Interface │ Attribute │ Value │
71 ├────────────────────────────────────────────┼───────────────┼─────────┤
72 │fseek(), ftell(), rewind(), fgetpos(), │ Thread safety │ MT-Safe │
73 │fsetpos() │ │ │
74 └────────────────────────────────────────────┴───────────────┴─────────┘
75
77 POSIX.1-2001, POSIX.1-2008, C89, C99.
78
80 lseek(2), fseeko(3)
81
83 This page is part of release 5.12 of the Linux man-pages project. A
84 description of the project, information about reporting bugs, and the
85 latest version of this page, can be found at
86 https://www.kernel.org/doc/man-pages/.
87
88
89
90GNU 2021-03-22 FSEEK(3)