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. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 37.\" $FreeBSD: src/lib/libc/stdio/fseek.3,v 1.5.2.7 2001/12/14 18:33:57 ru Exp $ 38.\" $DragonFly: src/lib/libc/stdio/fseek.3,v 1.3 2007/07/30 22:11:33 swildner Exp $ 39.\" 40.Dd March 5, 1999 41.Dt FSEEK 3 42.Os 43.Sh NAME 44.Nm fgetpos , 45.Nm fseek , 46.Nm fseeko , 47.Nm fsetpos , 48.Nm ftell , 49.Nm ftello , 50.Nm rewind 51.Nd reposition a stream 52.Sh LIBRARY 53.Lb libc 54.Sh SYNOPSIS 55.In stdio.h 56.Ft int 57.Fn fseek "FILE *stream" "long offset" "int whence" 58.Ft long 59.Fn ftell "FILE *stream" 60.Ft void 61.Fn rewind "FILE *stream" 62.Ft int 63.Fn fgetpos "FILE *stream" "fpos_t *pos" 64.Ft int 65.Fn fsetpos "FILE *stream" "const fpos_t *pos" 66.In sys/types.h 67.Ft int 68.Fn fseeko "FILE *stream" "off_t offset" "int whence" 69.Ft off_t 70.Fn ftello "FILE *stream" 71.Sh DESCRIPTION 72The 73.Fn fseek 74function sets the file position indicator for the stream pointed 75to by 76.Fa stream . 77The new position, measured in bytes, is obtained by adding 78.Fa offset 79bytes to the position specified by 80.Fa whence . 81If 82.Fa whence 83is set to 84.Dv SEEK_SET , 85.Dv SEEK_CUR , 86or 87.Dv SEEK_END , 88the offset is relative to the 89start of the file, the current position indicator, or end-of-file, 90respectively. 91A successful call to the 92.Fn fseek 93function clears the end-of-file indicator for the stream and undoes 94any effects of the 95.Xr ungetc 3 96function on the same stream. 97.Pp 98The 99.Fn ftell 100function 101obtains the current value of the file position indicator for the 102stream pointed to by 103.Fa stream . 104.Pp 105The 106.Fn rewind 107function sets the file position indicator for the stream pointed 108to by 109.Fa stream 110to the beginning of the file. 111It is equivalent to: 112.Pp 113.Dl (void)fseek(stream, 0L, SEEK_SET) 114.Pp 115except that the error indicator for the stream is also cleared 116(see 117.Xr clearerr 3 ) . 118.Pp 119The 120.Fn fseeko 121function is identical to 122.Fn fseek , 123except it takes an 124.Fa off_t 125argument 126instead of a 127.Fa long . 128Likewise, the 129.Fn ftello 130function is identical to 131.Fn ftell , 132except it returns an 133.Fa off_t . 134.Pp 135The 136.Fn fgetpos 137and 138.Fn fsetpos 139functions 140are alternate interfaces equivalent to 141.Fn ftell 142and 143.Fn fseek 144(with whence set to 145.Dv SEEK_SET ) , 146setting and storing the current value of 147the file offset into or from the object referenced by 148.Fa pos . 149On some 150.Pq non- Ns Ux 151systems an 152.Dq Fa fpos_t 153object may be a complex object 154and these routines may be the only way to portably reposition a text stream. 155.Sh RETURN VALUES 156The 157.Fn rewind 158function 159returns no value. 160.Pp 161.Rv -std fgetpos fseek fseeko fsetpos 162.Pp 163Upon successful completion, 164.Fn ftell 165and 166.Fn ftello 167return the current offset. 168Otherwise, \-1 is returned and the global variable 169.Va errno 170is set to indicate the error. 171.Sh ERRORS 172.Bl -tag -width Er 173.It Bq Er EBADF 174The 175.Fa stream 176specified 177is not a seekable stream. 178.It Bq Er EINVAL 179The 180.Fa whence 181argument to 182.Fn fseek 183was not 184.Dv SEEK_SET , 185.Dv SEEK_END , 186or 187.Dv SEEK_CUR . 188.It Bq Er EOVERFLOW 189For 190.Fn ftell , 191the resulting file offset would be a value which 192cannot be represented correctly in an object of type long. 193.El 194.Pp 195The functions 196.Fn fgetpos , 197.Fn fseek , 198.Fn fseeko , 199.Fn fsetpos , 200.Fn ftell , 201and 202.Fn ftello 203may also fail and set 204.Va errno 205for any of the errors specified for the routines 206.Xr fflush 3 , 207.Xr fstat 2 , 208.Xr lseek 2 , 209and 210.Xr malloc 3 . 211.Sh SEE ALSO 212.Xr lseek 2 213.Sh STANDARDS 214The 215.Fn fgetpos , 216.Fn fsetpos , 217.Fn fseek , 218.Fn ftell , 219and 220.Fn rewind 221functions 222conform to 223.St -isoC . 224.Pp 225The 226.Fn fseeko 227and 228.Fn ftello 229functions conform to 230.St -susv2 . 231