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
13 long ftell(FILE *stream);
14
15 void rewind(FILE *stream);
16
17 int fgetpos(FILE *stream, fpos_t *pos);
18 int fsetpos(FILE *stream, fpos_t *pos);
19
21 The fseek() function sets the file position indicator for the stream
22 pointed to by stream. The new position, measured in bytes, is obtained
23 by adding offset bytes to the position specified by whence. If whence
24 is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to
25 the start of the file, the current position indicator, or end-of-file,
26 respectively. A successful call to the fseek() function clears the
27 end-of-file indicator for the stream and undoes any effects of the
28 ungetc(3) function on the same stream.
29
30 The ftell() function obtains the current value of the file position
31 indicator for the stream pointed to by stream.
32
33 The rewind() function sets the file position indicator for the stream
34 pointed to by stream to the beginning of the file. It is equivalent
35 to:
36
37 (void) fseek(stream, 0L, SEEK_SET)
38
39 except that the error indicator for the stream is also cleared (see
40 clearerr(3)).
41
42 The fgetpos() and fsetpos() functions are alternate interfaces equiva‐
43 lent to ftell() and fseek() (with whence set to SEEK_SET), setting and
44 storing the current value of the file offset into or from the object
45 referenced by pos. On some non-Unix systems an fpos_t object may be a
46 complex object and these routines may be the only way to portably repo‐
47 sition a text stream.
48
50 The rewind() function returns no value. Upon successful completion,
51 fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current
52 offset. Otherwise, -1 is returned and errno is set to indicate the
53 error.
54
56 EBADF The stream specified is not a seekable stream.
57
58 EINVAL The whence argument to fseek() was not SEEK_SET, SEEK_END, or
59 SEEK_CUR.
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 C89, C99.
67
69 lseek(2), fseeko(3)
70
72 This page is part of release 3.22 of the Linux man-pages project. A
73 description of the project, and information about reporting bugs, can
74 be found at http://www.kernel.org/doc/man-pages/.
75
76
77
78GNU 1993-11-29 FSEEK(3)