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       long ftell(FILE *stream);
13       void rewind(FILE *stream);
14       int fgetpos(FILE *stream, fpos_t *pos);
15       int fsetpos(FILE *stream, fpos_t *pos);
16

DESCRIPTION

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

RETURN VALUE

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

ERRORS

53       EBADF  The stream specified is not a seekable stream.
54
55       EINVAL The whence argument to fseek() was not  SEEK_SET,  SEEK_END,  or
56              SEEK_CUR.
57
58       The  functions fgetpos(), fseek(), fsetpos(), and ftell() may also fail
59       and set errno  for  any  of  the  errors  specified  for  the  routines
60       fflush(3), fstat(2), lseek(2), and malloc(3).
61

CONFORMING TO

63       C89, C99.
64

SEE ALSO

66       lseek(2), fseeko(3)
67
68
69
70BSD MANPAGE                       1993-11-29                          FSEEK(3)
Impressum