]>
Commit | Line | Data |
---|---|---|
5b2abdfb A |
1 | .\" Copyright (c) 1990, 1991, 1993 |
2 | .\" The Regents of the University of California. 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 | .\" | |
8 | .\" Redistribution and use in source and binary forms, with or without | |
9 | .\" modification, are permitted provided that the following conditions | |
10 | .\" are met: | |
11 | .\" 1. Redistributions of source code must retain the above copyright | |
12 | .\" notice, this list of conditions and the following disclaimer. | |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
14 | .\" notice, this list of conditions and the following disclaimer in the | |
15 | .\" documentation and/or other materials provided with the distribution. | |
5b2abdfb A |
16 | .\" 4. Neither the name of the University nor the names of its contributors |
17 | .\" may be used to endorse or promote products derived from this software | |
18 | .\" without specific prior written permission. | |
19 | .\" | |
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
30 | .\" SUCH DAMAGE. | |
31 | .\" | |
32 | .\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 | |
1f2f436a | 33 | .\" $FreeBSD: src/lib/libc/stdio/fseek.3,v 1.27 2007/06/18 02:13:04 ache Exp $ |
5b2abdfb | 34 | .\" |
3d9156a7 | 35 | .Dd March 19, 2004 |
5b2abdfb A |
36 | .Dt FSEEK 3 |
37 | .Os | |
38 | .Sh NAME | |
39 | .Nm fgetpos , | |
40 | .Nm fseek , | |
41 | .Nm fseeko , | |
42 | .Nm fsetpos , | |
43 | .Nm ftell , | |
44 | .Nm ftello , | |
45 | .Nm rewind | |
46 | .Nd reposition a stream | |
47 | .Sh LIBRARY | |
48 | .Lb libc | |
49 | .Sh SYNOPSIS | |
50 | .In stdio.h | |
51 | .Ft int | |
52 | .Fn fseek "FILE *stream" "long offset" "int whence" | |
53 | .Ft long | |
54 | .Fn ftell "FILE *stream" | |
55 | .Ft void | |
56 | .Fn rewind "FILE *stream" | |
57 | .Ft int | |
9385eb3d | 58 | .Fn fgetpos "FILE * restrict stream" "fpos_t * restrict pos" |
5b2abdfb A |
59 | .Ft int |
60 | .Fn fsetpos "FILE *stream" "const fpos_t *pos" | |
61 | .In sys/types.h | |
62 | .Ft int | |
63 | .Fn fseeko "FILE *stream" "off_t offset" "int whence" | |
64 | .Ft off_t | |
65 | .Fn ftello "FILE *stream" | |
66 | .Sh DESCRIPTION | |
67 | The | |
68 | .Fn fseek | |
69 | function sets the file position indicator for the stream pointed | |
70 | to by | |
71 | .Fa stream . | |
72 | The new position, measured in bytes, is obtained by adding | |
73 | .Fa offset | |
74 | bytes to the position specified by | |
75 | .Fa whence . | |
76 | If | |
77 | .Fa whence | |
78 | is set to | |
79 | .Dv SEEK_SET , | |
80 | .Dv SEEK_CUR , | |
81 | or | |
82 | .Dv SEEK_END , | |
83 | the offset is relative to the | |
84 | start of the file, the current position indicator, or end-of-file, | |
85 | respectively. | |
86 | A successful call to the | |
87 | .Fn fseek | |
88 | function clears the end-of-file indicator for the stream and undoes | |
89 | any effects of the | |
90 | .Xr ungetc 3 | |
9385eb3d A |
91 | and |
92 | .Xr ungetwc 3 | |
93 | functions on the same stream. | |
5b2abdfb A |
94 | .Pp |
95 | The | |
96 | .Fn ftell | |
97 | function | |
98 | obtains the current value of the file position indicator for the | |
99 | stream pointed to by | |
100 | .Fa stream . | |
101 | .Pp | |
102 | The | |
103 | .Fn rewind | |
104 | function sets the file position indicator for the stream pointed | |
105 | to by | |
106 | .Fa stream | |
107 | to the beginning of the file. | |
108 | It is equivalent to: | |
109 | .Pp | |
110 | .Dl (void)fseek(stream, 0L, SEEK_SET) | |
111 | .Pp | |
112 | except that the error indicator for the stream is also cleared | |
113 | (see | |
114 | .Xr clearerr 3 ) . | |
115 | .Pp | |
116 | Since | |
117 | .Fn rewind | |
118 | does not return a value, | |
119 | an application wishing to detect errors should clear | |
120 | .Va errno , | |
121 | then call | |
122 | .Fn rewind , | |
123 | and if | |
124 | .Va errno | |
125 | is non-zero, assume an error has occurred. | |
126 | .Pp | |
127 | The | |
128 | .Fn fseeko | |
129 | function is identical to | |
130 | .Fn fseek , | |
131 | except it takes an | |
132 | .Fa off_t | |
133 | argument | |
134 | instead of a | |
135 | .Fa long . | |
136 | Likewise, the | |
137 | .Fn ftello | |
138 | function is identical to | |
139 | .Fn ftell , | |
140 | except it returns an | |
141 | .Fa off_t . | |
142 | .Pp | |
143 | The | |
144 | .Fn fgetpos | |
145 | and | |
146 | .Fn fsetpos | |
147 | functions | |
3d9156a7 A |
148 | are alternate interfaces for retrieving and setting the current position in |
149 | the file, similar to | |
5b2abdfb A |
150 | .Fn ftell |
151 | and | |
3d9156a7 A |
152 | .Fn fseek , |
153 | except that the current position is stored in an opaque object of | |
154 | type | |
155 | .Vt fpos_t | |
156 | pointed to by | |
5b2abdfb | 157 | .Fa pos . |
3d9156a7 A |
158 | These functions provide a portable way to seek to offsets larger than |
159 | those that can be represented by a | |
160 | .Vt long int . | |
161 | They may also store additional state information in the | |
162 | .Vt fpos_t | |
163 | object to facilitate seeking within files containing multibyte | |
164 | characters with state-dependent encodings. | |
165 | Although | |
166 | .Vt fpos_t | |
167 | has traditionally been an integral type, | |
168 | applications cannot assume that it is; | |
169 | in particular, they must not perform arithmetic on objects | |
170 | of this type. | |
9385eb3d A |
171 | .Pp |
172 | If the stream is a wide character stream (see | |
173 | .Xr fwide 3 ) , | |
174 | the position specified by the combination of | |
175 | .Fa offset | |
176 | and | |
177 | .Fa whence | |
178 | must contain the first byte of a multibyte sequence. | |
5b2abdfb A |
179 | .Sh RETURN VALUES |
180 | The | |
181 | .Fn rewind | |
182 | function | |
183 | returns no value. | |
184 | .Pp | |
185 | .Rv -std fgetpos fseek fseeko fsetpos | |
186 | .Pp | |
187 | Upon successful completion, | |
188 | .Fn ftell | |
189 | and | |
190 | .Fn ftello | |
191 | return the current offset. | |
192 | Otherwise, \-1 is returned and the global variable | |
193 | .Va errno | |
194 | is set to indicate the error. | |
195 | .Sh ERRORS | |
196 | .Bl -tag -width Er | |
197 | .It Bq Er EBADF | |
198 | The | |
199 | .Fa stream | |
9385eb3d | 200 | argument |
5b2abdfb A |
201 | is not a seekable stream. |
202 | .It Bq Er EINVAL | |
203 | The | |
204 | .Fa whence | |
205 | argument is invalid or | |
206 | the resulting file-position | |
207 | indicator would be set to a negative value. | |
208 | .It Bq Er EOVERFLOW | |
209 | The resulting file offset would be a value which | |
210 | cannot be represented correctly in an object of type | |
211 | .Fa off_t | |
212 | for | |
213 | .Fn fseeko | |
214 | and | |
215 | .Fn ftello | |
216 | or | |
217 | .Fa long | |
218 | for | |
219 | .Fn fseek | |
220 | and | |
221 | .Fn ftell . | |
222 | .It Bq Er ESPIPE | |
223 | The file descriptor underlying stream is associated with a pipe or FIFO | |
224 | or file-position indicator value is unspecified | |
225 | (see | |
226 | .Xr ungetc 3 ) . | |
227 | .El | |
228 | .Pp | |
229 | The functions | |
230 | .Fn fgetpos , | |
231 | .Fn fseek , | |
232 | .Fn fseeko , | |
233 | .Fn fsetpos , | |
234 | .Fn ftell , | |
1f2f436a | 235 | .Fn ftello , |
5b2abdfb | 236 | and |
1f2f436a | 237 | .Fn rewind |
5b2abdfb A |
238 | may also fail and set |
239 | .Va errno | |
240 | for any of the errors specified for the routines | |
241 | .Xr fflush 3 , | |
242 | .Xr fstat 2 , | |
243 | .Xr lseek 2 , | |
244 | and | |
245 | .Xr malloc 3 . | |
246 | .Sh SEE ALSO | |
247 | .Xr lseek 2 , | |
248 | .Xr clearerr 3 , | |
9385eb3d A |
249 | .Xr fwide 3 , |
250 | .Xr ungetc 3 , | |
251 | .Xr ungetwc 3 | |
5b2abdfb A |
252 | .Sh STANDARDS |
253 | The | |
254 | .Fn fgetpos , | |
255 | .Fn fsetpos , | |
256 | .Fn fseek , | |
257 | .Fn ftell , | |
258 | and | |
259 | .Fn rewind | |
260 | functions | |
261 | conform to | |
262 | .St -isoC . | |
263 | .Pp | |
264 | The | |
265 | .Fn fseeko | |
266 | and | |
267 | .Fn ftello | |
268 | functions conform to | |
9385eb3d | 269 | .St -p1003.1-2001 . |