1FSEEK(3)                   Linux Programmer's Manual                  FSEEK(3)
2
3
4

NAME

6       fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
7

SYNOPSIS

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
19       int fsetpos(FILE *stream, const fpos_t *pos);
20

DESCRIPTION

22       The  fseek()  function  sets the file position indicator for the stream
23       pointed to by stream.  The new position, measured in bytes, is obtained
24       by  adding offset bytes to the position specified by whence.  If whence
25       is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset  is  relative  to
26       the  start of the file, the current position indicator, or end-of-file,
27       respectively.  A successful call to the  fseek()  function  clears  the
28       end-of-file  indicator  for  the  stream  and undoes any effects of the
29       ungetc(3) function on the same stream.
30
31       The ftell() function obtains the current value  of  the  file  position
32       indicator for the stream pointed to by stream.
33
34       The  rewind()  function sets the file position indicator for the stream
35       pointed to by stream to the beginning of the file.   It  is  equivalent
36       to:
37
38              (void) fseek(stream, 0L, SEEK_SET)
39
40       except  that  the  error  indicator for the stream is also cleared (see
41       clearerr(3)).
42
43       The fgetpos() and fsetpos() functions are alternate interfaces  equiva‐
44       lent  to ftell() and fseek() (with whence set to SEEK_SET), setting and
45       storing the current value of the file offset into or  from  the  object
46       referenced by pos.  On some non-UNIX systems, an fpos_t object may be a
47       complex object and these routines may be the only way to portably repo‐
48       sition a text stream.
49

RETURN VALUE

51       The  rewind()  function  returns no value.  Upon successful completion,
52       fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current
53       offset.   Otherwise,  -1  is  returned and errno is set to indicate the
54       error.
55

ERRORS

57       EBADF  The stream specified is not a seekable stream.
58
59       EINVAL The whence argument to fseek() was not  SEEK_SET,  SEEK_END,  or
60              SEEK_CUR.  Or: the resulting file offset would be negative.
61
62       The  functions fgetpos(), fseek(), fsetpos(), and ftell() may also fail
63       and set errno  for  any  of  the  errors  specified  for  the  routines
64       fflush(3), fstat(2), lseek(2), and malloc(3).
65

ATTRIBUTES

67       For   an   explanation   of   the  terms  used  in  this  section,  see
68       attributes(7).
69
70       ┌────────────────────────────┬───────────────┬─────────┐
71Interface                   Attribute     Value   
72       ├────────────────────────────┼───────────────┼─────────┤
73fseek(), ftell(), rewind(), │ Thread safety │ MT-Safe │
74fgetpos(), fsetpos()        │               │         │
75       └────────────────────────────┴───────────────┴─────────┘
76

CONFORMING TO

78       POSIX.1-2001, POSIX.1-2008, C89, C99.
79

SEE ALSO

81       lseek(2), fseeko(3)
82

COLOPHON

84       This page is part of release 4.15 of the Linux  man-pages  project.   A
85       description  of  the project, information about reporting bugs, and the
86       latest    version    of    this    page,    can     be     found     at
87       https://www.kernel.org/doc/man-pages/.
88
89
90
91GNU                               2017-09-15                          FSEEK(3)
Impressum