]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" Chris Torek and the American National Standards Committee X3, | |
6 | .\" on Information Processing Systems. | |
7 | .\" | |
a9cd9cb7 | 8 | .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) |
fea681da MK |
9 | .\" Redistribution and use in source and binary forms, with or without |
10 | .\" modification, are permitted provided that the following conditions | |
11 | .\" are met: | |
12 | .\" 1. Redistributions of source code must retain the above copyright | |
13 | .\" notice, this list of conditions and the following disclaimer. | |
14 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
15 | .\" notice, this list of conditions and the following disclaimer in the | |
16 | .\" documentation and/or other materials provided with the distribution. | |
17 | .\" 3. All advertising materials mentioning features or use of this software | |
18 | .\" must display the following acknowledgement: | |
19 | .\" This product includes software developed by the University of | |
20 | .\" California, Berkeley and its contributors. | |
21 | .\" 4. Neither the name of the University nor the names of its contributors | |
22 | .\" may be used to endorse or promote products derived from this software | |
23 | .\" without specific prior written permission. | |
24 | .\" | |
25 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
26 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
27 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
28 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
29 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
30 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
31 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
32 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
33 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
35 | .\" SUCH DAMAGE. | |
8c9302dc | 36 | .\" %%%LICENSE_END |
fea681da MK |
37 | .\" |
38 | .\" @(#)fseek.3 6.11 (Berkeley) 6/29/91 | |
39 | .\" | |
40 | .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu | |
41 | .\" | |
09b8afdc | 42 | .TH FSEEK 3 2018-04-30 "GNU" "Linux Programmer's Manual" |
fea681da MK |
43 | .SH NAME |
44 | fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream | |
45 | .SH SYNOPSIS | |
46 | .B #include <stdio.h> | |
68e4db0a | 47 | .PP |
fea681da | 48 | .BI "int fseek(FILE *" stream ", long " offset ", int " whence ); |
dbfe9c70 | 49 | .PP |
fea681da | 50 | .BI "long ftell(FILE *" stream ); |
dbfe9c70 | 51 | .PP |
fea681da | 52 | .BI "void rewind(FILE *" stream ); |
dbfe9c70 | 53 | .PP |
fea681da | 54 | .BI "int fgetpos(FILE *" stream ", fpos_t *" pos ); |
dbfe9c70 | 55 | .PP |
d19a532b | 56 | .BI "int fsetpos(FILE *" stream ", const fpos_t *" pos ); |
fea681da MK |
57 | .SH DESCRIPTION |
58 | The | |
e511ffb6 | 59 | .BR fseek () |
fea681da MK |
60 | function sets the file position indicator for the stream pointed to by |
61 | .IR stream . | |
62 | The new position, measured in bytes, is obtained by adding | |
63 | .I offset | |
64 | bytes to the position specified by | |
65 | .IR whence . | |
66 | If | |
67 | .I whence | |
68 | is set to | |
69 | .BR SEEK_SET , | |
70 | .BR SEEK_CUR , | |
71 | or | |
72 | .BR SEEK_END , | |
73 | the offset is relative to the start of the file, the current position | |
c13182ef MK |
74 | indicator, or end-of-file, respectively. |
75 | A successful call to the | |
e511ffb6 | 76 | .BR fseek () |
fea681da MK |
77 | function clears the end-of-file indicator for the stream and undoes |
78 | any effects of the | |
79 | .BR ungetc (3) | |
80 | function on the same stream. | |
81 | .PP | |
82 | The | |
e511ffb6 | 83 | .BR ftell () |
fea681da MK |
84 | function obtains the current value of the file position indicator for the |
85 | stream pointed to by | |
86 | .IR stream . | |
87 | .PP | |
88 | The | |
e511ffb6 | 89 | .BR rewind () |
fea681da MK |
90 | function sets the file position indicator for the stream pointed to by |
91 | .I stream | |
c13182ef MK |
92 | to the beginning of the file. |
93 | It is equivalent to: | |
fea681da MK |
94 | .PP |
95 | .RS | |
0c535394 | 96 | (void) fseek(stream, 0L, SEEK_SET) |
fea681da MK |
97 | .RE |
98 | .PP | |
99 | except that the error indicator for the stream is also cleared (see | |
100 | .BR clearerr (3)). | |
101 | .PP | |
102 | The | |
e511ffb6 | 103 | .BR fgetpos () |
fea681da | 104 | and |
e511ffb6 | 105 | .BR fsetpos () |
fea681da | 106 | functions are alternate interfaces equivalent to |
e511ffb6 | 107 | .BR ftell () |
fea681da | 108 | and |
e511ffb6 | 109 | .BR fseek () |
949aff4c MK |
110 | (with |
111 | .I whence | |
112 | set to | |
fea681da MK |
113 | .BR SEEK_SET ), |
114 | setting and storing the current value of the file offset into or from the | |
115 | object referenced by | |
116 | .IR pos . | |
824464a9 | 117 | On some non-UNIX systems, an |
f19a0f03 | 118 | .I fpos_t |
fea681da MK |
119 | object may be a complex object and these routines may be the only way to |
120 | portably reposition a text stream. | |
47297adb | 121 | .SH RETURN VALUE |
fea681da | 122 | The |
e511ffb6 | 123 | .BR rewind () |
c13182ef MK |
124 | function returns no value. |
125 | Upon successful completion, | |
e511ffb6 MK |
126 | .BR fgetpos (), |
127 | .BR fseek (), | |
128 | .BR fsetpos () | |
fea681da MK |
129 | return 0, |
130 | and | |
e511ffb6 | 131 | .BR ftell () |
c13182ef MK |
132 | returns the current offset. |
133 | Otherwise, \-1 is returned and | |
134 | .I errno | |
845f2c47 | 135 | is set to indicate the error. |
fea681da MK |
136 | .SH ERRORS |
137 | .TP | |
fea681da MK |
138 | .B EINVAL |
139 | The | |
140 | .I whence | |
c13182ef | 141 | argument to |
e511ffb6 | 142 | .BR fseek () |
fea681da MK |
143 | was not |
144 | .BR SEEK_SET , | |
145 | .BR SEEK_END , | |
146 | or | |
147 | .BR SEEK_CUR . | |
f3ef4558 | 148 | Or: the resulting file offset would be negative. |
f2e2bdc0 MK |
149 | .TP |
150 | .B ESPIPE | |
f019faae | 151 | The file descriptor underlying |
f2e2bdc0 | 152 | .I stream |
f019faae | 153 | is not seekable (e.g., it refers to a pipe, FIFO, or socket). |
fea681da | 154 | .PP |
845f2c47 | 155 | The functions |
e511ffb6 MK |
156 | .BR fgetpos (), |
157 | .BR fseek (), | |
158 | .BR fsetpos (), | |
c13182ef | 159 | and |
e511ffb6 | 160 | .BR ftell () |
fea681da MK |
161 | may also fail and set |
162 | .I errno | |
163 | for any of the errors specified for the routines | |
164 | .BR fflush (3), | |
165 | .BR fstat (2), | |
166 | .BR lseek (2), | |
c13182ef | 167 | and |
fea681da | 168 | .BR malloc (3). |
011bc011 MS |
169 | .SH ATTRIBUTES |
170 | For an explanation of the terms used in this section, see | |
171 | .BR attributes (7). | |
172 | .TS | |
173 | allbox; | |
174 | lbw27 lb lb | |
175 | l l l. | |
176 | Interface Attribute Value | |
177 | T{ | |
178 | .BR fseek (), | |
179 | .BR ftell (), | |
180 | .BR rewind (), | |
181 | .br | |
182 | .BR fgetpos (), | |
183 | .BR fsetpos () | |
184 | T} Thread safety MT-Safe | |
185 | .TE | |
847e0d88 | 186 | .sp 1 |
47297adb | 187 | .SH CONFORMING TO |
e2e7a617 | 188 | POSIX.1-2001, POSIX.1-2008, C89, C99. |
47297adb | 189 | .SH SEE ALSO |
fea681da MK |
190 | .BR lseek (2), |
191 | .BR fseeko (3) |