1FSEEK(3P)                  POSIX Programmer's Manual                 FSEEK(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fseek, fseeko — reposition a file-position indicator in a stream
14

SYNOPSIS

16       #include <stdio.h>
17
18       int fseek(FILE *stream, long offset, int whence);
19       int fseeko(FILE *stream, off_t offset, int whence);
20

DESCRIPTION

22       The functionality described on this reference page is aligned with  the
23       ISO C  standard.  Any  conflict between the requirements described here
24       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
25       defers to the ISO C standard.
26
27       The  fseek()  function  shall  set  the file-position indicator for the
28       stream pointed to by stream.  If a read  or  write  error  occurs,  the
29       error indicator for the stream shall be set and fseek() fails.
30
31       The  new  position,  measured  in bytes from the beginning of the file,
32       shall be obtained by adding offset to the position specified by whence.
33       The specified point is the beginning of the file for SEEK_SET, the cur‐
34       rent value of the file-position indicator for SEEK_CUR, or  end-of-file
35       for SEEK_END.
36
37       If the stream is to be used with wide-character input/output functions,
38       the application shall ensure  that  offset  is  either  0  or  a  value
39       returned by an earlier call to ftell() on the same stream and whence is
40       SEEK_SET.
41
42       A successful call to fseek() shall clear the end-of-file indicator  for
43       the  stream  and undo any effects of ungetc() and ungetwc() on the same
44       stream. After an fseek() call, the next operation on an  update  stream
45       may be either input or output.
46
47       If  the most recent operation, other than ftell(), on a given stream is
48       fflush(), the file offset in the underlying open file description shall
49       be adjusted to reflect the location specified by fseek().
50
51       The  fseek() function shall allow the file-position indicator to be set
52       beyond the end of existing data in the file. If data is  later  written
53       at  this  point, subsequent reads of data in the gap shall return bytes
54       with the value 0 until data is actually written into the gap.
55
56       The behavior of fseek() on devices which are incapable  of  seeking  is
57       implementation-defined.   The  value of the file offset associated with
58       such a device is undefined.
59
60       If the stream is writable and buffered data had not been written to the
61       underlying  file,  fseek() shall cause the unwritten data to be written
62       to the file and shall mark the last data  modification  and  last  file
63       status change timestamps of the file for update.
64
65       In a locale with state-dependent encoding, whether fseek() restores the
66       stream's shift state is implementation-defined.
67
68       The fseeko() function shall  be  equivalent  to  the  fseek()  function
69       except that the offset argument is of type off_t.
70

RETURN VALUE

72       The fseek() and fseeko() functions shall return 0 if they succeed.
73
74       Otherwise, they shall return −1 and set errno to indicate the error.
75

ERRORS

77       The  fseek() and fseeko() functions shall fail if, either the stream is
78       unbuffered or the stream's buffer needed to be flushed, and the call to
79       fseek()  or  fseeko()  causes  an  underlying  lseek() or write() to be
80       invoked, and:
81
82       EAGAIN The O_NONBLOCK flag is set  for  the  file  descriptor  and  the
83              thread would be delayed in the write operation.
84
85       EBADF  The  file  descriptor underlying the stream file is not open for
86              writing or the stream's buffer needed to be flushed and the file
87              is not open.
88
89       EFBIG  An  attempt  was  made  to write a file that exceeds the maximum
90              file size.
91
92       EFBIG  An attempt was made to write a file that exceeds the  file  size
93              limit of the process.
94
95       EFBIG  The  file  is a regular file and an attempt was made to write at
96              or beyond the offset maximum associated with  the  corresponding
97              stream.
98
99       EINTR  The  write operation was terminated due to the receipt of a sig‐
100              nal, and no data was transferred.
101
102       EINVAL The whence argument  is  invalid.  The  resulting  file-position
103              indicator would be set to a negative value.
104
105       EIO    A physical I/O error has occurred, or the process is a member of
106              a background process group attempting to perform  a  write()  to
107              its  controlling  terminal, TOSTOP is set, the calling thread is
108              not blocking SIGTTOU, the process is not ignoring  SIGTTOU,  and
109              the  process  group  of the process is orphaned.  This error may
110              also be returned under implementation-defined conditions.
111
112       ENOSPC There was no free space remaining on the device  containing  the
113              file.
114
115       EOVERFLOW
116              For  fseek(),  the  resulting file offset would be a value which
117              cannot be represented correctly in an object of type long.
118
119       EOVERFLOW
120              For fseeko(), the resulting file offset would be a  value  which
121              cannot be represented correctly in an object of type off_t.
122
123       EPIPE  An  attempt was made to write to a pipe or FIFO that is not open
124              for reading by any process; a SIGPIPE signal shall also be  sent
125              to the thread.
126
127       ESPIPE The file descriptor underlying stream is associated with a pipe,
128              FIFO, or socket.
129
130       The fseek() and fseeko() functions may fail if:
131
132       ENXIO  A request was made of a nonexistent device, or the  request  was
133              outside the capabilities of the device.
134
135       The following sections are informative.
136

EXAMPLES

138       None.
139

APPLICATION USAGE

141       None.
142

RATIONALE

144       None.
145

FUTURE DIRECTIONS

147       None.
148

SEE ALSO

150       Section  2.5,  Standard I/O Streams, fopen(), fsetpos(), ftell(), getr‐
151       limit(), lseek(), rewind(), ulimit(), ungetc(), write()
152
153       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
154
156       Portions of this text are reprinted and reproduced in  electronic  form
157       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
158       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
159       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
160       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
161       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
162       event of any discrepancy between this version and the original IEEE and
163       The  Open Group Standard, the original IEEE and The Open Group Standard
164       is the referee document. The original Standard can be  obtained  online
165       at http://www.unix.org/online.html .
166
167       Any  typographical  or  formatting  errors that appear in this page are
168       most likely to have been introduced during the conversion of the source
169       files  to  man page format. To report such errors, see https://www.ker
170       nel.org/doc/man-pages/reporting_bugs.html .
171
172
173
174IEEE/The Open Group                  2013                            FSEEK(3P)
Impressum