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       EINVAL The whence argument to fseek() was not  SEEK_SET,  SEEK_END,  or
58              SEEK_CUR.  Or: the resulting file offset would be negative.
59
60       ESPIPE The  file descriptor underlying stream is not seekable (e.g., it
61              refers to a pipe, FIFO, or socket).
62
63       The functions fgetpos(), fseek(), fsetpos(), and ftell() may also  fail
64       and  set  errno  for  any  of  the  errors  specified  for the routines
65       fflush(3), fstat(2), lseek(2), and malloc(3).
66

ATTRIBUTES

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

CONFORMING TO

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

SEE ALSO

82       lseek(2), fseeko(3)
83

COLOPHON

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