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