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.\" 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.\" from: @(#)fseek.3 6.11 (Berkeley) 6/29/91 37.\" $Id: fseek.3,v 1.4 1993/11/29 22:06:53 jtc Exp $ 38.\" 39.Dd June 29, 1991 40.Dt FSEEK 3 41.Os 42.Sh NAME 43.Nm fgetpos , 44.Nm fseek , 45.Nm fsetpos , 46.Nm ftell , 47.Nm rewind 48.Nd reposition a stream 49.Sh SYNOPSIS 50.Fd #include <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 58.Fn fgetpos "FILE *stream" "fpos_t *pos" 59.Ft int 60.Fn fsetpos "FILE *stream" "fpos_t *pos" 61.Sh DESCRIPTION 62The 63.Fn fseek 64function sets the file position indicator for the stream pointed 65to by 66.Fa stream . 67The new position, measured in bytes, is obtained by adding 68.Fa offset 69bytes to the position specified by 70.Fa whence . 71If 72.Fa whence 73is set to 74.Dv SEEK_SET , 75.Dv SEEK_CUR , 76or 77.Dv SEEK_END , 78the offset is relative to the 79start of the file, the current position indicator, or end-of-file, 80respectively. 81A successful call to the 82.Fn fseek 83function clears the end-of-file indicator for the stream and undoes 84any effects of the 85.Xr ungetc 3 86function on the same stream. 87.Pp 88The 89.Fn ftell 90function 91obtains the current value of the file position indicator for the 92stream pointed to by 93.Fa stream . 94.Pp 95The 96.Fn rewind 97function sets the file position indicator for the stream pointed 98to by 99.Fa stream 100to the beginning of the file. 101It is equivalent to: 102.Pp 103.Dl (void)fseek(stream, 0L, SEEK_SET) 104.Pp 105except that the error indicator for the stream is also cleared 106(see 107.Xr clearerr 3 ) . 108.Pp 109The 110.Fn fgetpos 111and 112.Fn fsetpos 113functions 114are alternate interfaces equivalent to 115.Fn ftell 116and 117.Fn fseek 118(with whence set to 119.Dv SEEK_SET 120), setting and storing the current value of 121the file offset into or from the object referenced by 122.Fa pos . 123On some 124.Pq non- Ns Tn UNIX 125systems an 126.Dq Fa fpos_t 127object may be a complex object 128and these routines may be the only way to portably reposition a text stream. 129.Sh RETURN VALUES 130The 131.Fn rewind 132function 133returns no value. 134Upon successful completion, 135.Fn fgetpos , 136.Fn fseek , 137.Fn fsetpos 138return 0, 139and 140.Fn ftell 141returns the current offset. 142Otherwise, 143.Fn fseek 144returns \-1 and 145the others 146return a nonzero value and the global variable errno is 147set to indicate the error. 148.Sh ERRORS 149.Bl -tag -width Er 150.It Bq Er EBADF 151The 152.Fa stream 153specified 154is not a seekable stream. 155.It Bq Er EINVAL 156The 157.Fa whence 158argument to 159.Fn fseek 160was not 161.Dv SEEK_SET , 162.Dv SEEK_END , 163or 164.Dv SEEK_CUR . 165.El 166.Pp 167The function 168.Fn fgetpos , 169.Fn fseek , 170.Fn fsetpos , 171and 172.Fn ftell 173may also fail and set 174.Va errno 175for any of the errors specified for the routines 176.Xr fflush 3 , 177.Xr fstat 2 , 178.Xr lseek 2 , 179and 180.Xr malloc 3 . 181.Sh SEE ALSO 182.Xr lseek 2 183.Sh STANDARDS 184The 185.Fn fgetpos , 186.Fn fsetpos , 187.Fn fseek , 188.Fn ftell , 189and 190.Fn rewind 191functions 192conform to 193.St -ansiC . 194