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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

69       The fseek()  and fseeko()  functions shall return 0 if they succeed.
70
71       Otherwise, they shall return -1 and set errno to indicate the error.
72

ERRORS

74       The fseek()  and fseeko()  functions shall fail if,  either the  stream
75       is unbuffered or the stream's buffer needed to be flushed, and the call
76       to fseek() or fseeko() causes an underlying lseek() or  write()  to  be
77       invoked, and:
78
79       EAGAIN The  O_NONBLOCK  flag  is  set  for  the file descriptor and the
80              process would be delayed in the write operation.
81
82       EBADF  The file descriptor underlying the stream file is not  open  for
83              writing or the stream's buffer needed to be flushed and the file
84              is not open.
85
86       EFBIG  An attempt was made to write a file  that  exceeds  the  maximum
87              file size.
88
89       EFBIG  An  attempt  was  made to write a file that exceeds the process'
90              file size limit.
91
92       EFBIG  The file is a regular file and an attempt was made to  write  at
93              or  beyond  the offset maximum associated with the corresponding
94              stream.
95
96       EINTR  The write operation was terminated due to the receipt of a  sig‐
97              nal, and no data was transferred.
98
99       EINVAL The  whence  argument  is  invalid.  The resulting file-position
100              indicator would be set to a negative value.
101
102       EIO    A physical I/O error has occurred, or the process is a member of
103              a  background  process  group attempting to perform a write() to
104              its controlling terminal, TOSTOP is set, the process is  neither
105              ignoring  nor  blocking  SIGTTOU,  and  the process group of the
106              process is orphaned.  This error  may  also  be  returned  under
107              implementation-defined conditions.
108
109       ENOSPC There  was  no free space remaining on the device containing the
110              file.
111
112       ENXIO  A request was made of a nonexistent device, or the  request  was
113              outside the capabilities of the device.
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              or FIFO.
129
130
131       The following sections are informative.
132

EXAMPLES

134       None.
135

APPLICATION USAGE

137       None.
138

RATIONALE

140       None.
141

FUTURE DIRECTIONS

143       None.
144

SEE ALSO

146       fopen(), fsetpos(), ftell(), getrlimit(), lseek(), rewind(),  ulimit(),
147       ungetc(), write(), the Base Definitions volume of IEEE Std 1003.1-2001,
148       <stdio.h>
149
151       Portions of this text are reprinted and reproduced in  electronic  form
152       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
153       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
154       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
155       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
156       event of any discrepancy between this version and the original IEEE and
157       The Open Group Standard, the original IEEE and The Open Group  Standard
158       is  the  referee document. The original Standard can be obtained online
159       at http://www.opengroup.org/unix/online.html .
160
161
162
163IEEE/The Open Group                  2003                            FSEEK(3P)
Impressum