1*f14fb602SLionel Sambuc.\" $NetBSD: fseek.3,v 1.27 2012/01/22 19:13:42 wiz Exp $ 22fe8fb19SBen Gras.\" 32fe8fb19SBen Gras.\" Copyright (c) 1990, 1991, 1993 42fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 52fe8fb19SBen Gras.\" 62fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by 72fe8fb19SBen Gras.\" Chris Torek and the American National Standards Committee X3, 82fe8fb19SBen Gras.\" on Information Processing Systems. 92fe8fb19SBen Gras.\" 102fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 112fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 122fe8fb19SBen Gras.\" are met: 132fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 142fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 152fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 162fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 172fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 182fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 192fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 202fe8fb19SBen Gras.\" without specific prior written permission. 212fe8fb19SBen Gras.\" 222fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 232fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 242fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 252fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 262fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 272fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 282fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 292fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 302fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 312fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 322fe8fb19SBen Gras.\" SUCH DAMAGE. 332fe8fb19SBen Gras.\" 342fe8fb19SBen Gras.\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 352fe8fb19SBen Gras.\" 36*f14fb602SLionel Sambuc.Dd January 21, 2012 372fe8fb19SBen Gras.Dt FSEEK 3 382fe8fb19SBen Gras.Os 392fe8fb19SBen Gras.Sh NAME 402fe8fb19SBen Gras.Nm fgetpos , 412fe8fb19SBen Gras.Nm fseek , 422fe8fb19SBen Gras.Nm fseeko , 432fe8fb19SBen Gras.Nm fsetpos , 442fe8fb19SBen Gras.Nm ftell , 452fe8fb19SBen Gras.Nm ftello , 462fe8fb19SBen Gras.Nm rewind 472fe8fb19SBen Gras.Nd reposition a stream 482fe8fb19SBen Gras.Sh LIBRARY 492fe8fb19SBen Gras.Lb libc 502fe8fb19SBen Gras.Sh SYNOPSIS 512fe8fb19SBen Gras.In stdio.h 522fe8fb19SBen Gras.Ft int 532fe8fb19SBen Gras.Fn fseek "FILE *stream" "long int offset" "int whence" 542fe8fb19SBen Gras.Ft int 552fe8fb19SBen Gras.Fn fseeko "FILE *stream" "off_t offset" "int whence" 562fe8fb19SBen Gras.Ft long int 572fe8fb19SBen Gras.Fn ftell "FILE *stream" 582fe8fb19SBen Gras.Ft off_t 592fe8fb19SBen Gras.Fn ftello "FILE *stream" 602fe8fb19SBen Gras.Ft void 612fe8fb19SBen Gras.Fn rewind "FILE *stream" 622fe8fb19SBen Gras.Ft int 632fe8fb19SBen Gras.Fn fgetpos "FILE * restrict stream" "fpos_t * restrict pos" 642fe8fb19SBen Gras.Ft int 652fe8fb19SBen Gras.Fn fsetpos "FILE * restrict stream" "const fpos_t * restrict pos" 662fe8fb19SBen Gras.Sh DESCRIPTION 672fe8fb19SBen GrasThe 682fe8fb19SBen Gras.Fn fseek 692fe8fb19SBen Grasfunction sets the file position indicator for the stream pointed 702fe8fb19SBen Grasto by 712fe8fb19SBen Gras.Fa stream . 722fe8fb19SBen GrasThe new position, measured in bytes, is obtained by adding 732fe8fb19SBen Gras.Fa offset 742fe8fb19SBen Grasbytes to the position specified by 752fe8fb19SBen Gras.Fa whence . 762fe8fb19SBen GrasIf 772fe8fb19SBen Gras.Fa whence 782fe8fb19SBen Grasis set to 792fe8fb19SBen Gras.Dv SEEK_SET , 802fe8fb19SBen Gras.Dv SEEK_CUR , 812fe8fb19SBen Grasor 822fe8fb19SBen Gras.Dv SEEK_END , 832fe8fb19SBen Grasthe offset is relative to the 842fe8fb19SBen Grasstart of the file, the current position indicator, or end-of-file, 852fe8fb19SBen Grasrespectively. 862fe8fb19SBen GrasA successful call to the 872fe8fb19SBen Gras.Fn fseek 882fe8fb19SBen Grasfunction clears the end-of-file indicator for the stream and undoes 892fe8fb19SBen Grasany effects of the 902fe8fb19SBen Gras.Xr ungetc 3 912fe8fb19SBen Grasfunction on the same stream. 922fe8fb19SBen Gras.Pp 932fe8fb19SBen GrasThe 942fe8fb19SBen Gras.Fn fseeko 952fe8fb19SBen Grasfunction is identical to the 962fe8fb19SBen Gras.Fn fseek 972fe8fb19SBen Grasfunction except that the 982fe8fb19SBen Gras.Fa offset 992fe8fb19SBen Grasargument is of type 1002fe8fb19SBen Gras.Fa off_t . 1012fe8fb19SBen Gras.Pp 1022fe8fb19SBen GrasThe 1032fe8fb19SBen Gras.Fn ftell 1042fe8fb19SBen Grasfunction 1052fe8fb19SBen Grasobtains the current value of the file position indicator for the 1062fe8fb19SBen Grasstream pointed to by 1072fe8fb19SBen Gras.Fa stream . 1082fe8fb19SBen Gras.Pp 1092fe8fb19SBen GrasThe 1102fe8fb19SBen Gras.Fn ftello 1112fe8fb19SBen Grasfunction is identical to the 1122fe8fb19SBen Gras.Fn ftell 1132fe8fb19SBen Grasfunction except that the return value is of type 1142fe8fb19SBen Gras.Fa off_t . 1152fe8fb19SBen Gras.Pp 1162fe8fb19SBen GrasThe 1172fe8fb19SBen Gras.Fn rewind 1182fe8fb19SBen Grasfunction sets the file position indicator for the stream pointed 1192fe8fb19SBen Grasto by 1202fe8fb19SBen Gras.Fa stream 1212fe8fb19SBen Grasto the beginning of the file. 1222fe8fb19SBen GrasIt is equivalent to: 1232fe8fb19SBen Gras.Pp 1242fe8fb19SBen Gras.Dl (void)fseek(stream, 0L, SEEK_SET) 1252fe8fb19SBen Gras.Pp 1262fe8fb19SBen Grasexcept that the error indicator for the stream is also cleared 1272fe8fb19SBen Gras(see 1282fe8fb19SBen Gras.Xr clearerr 3 ) . 1292fe8fb19SBen Gras.Pp 130*f14fb602SLionel SambucIn this implementations, an 1312fe8fb19SBen Gras.Dq Fa fpos_t 132*f14fb602SLionel Sambucobject is a complex object that represents both the position and the parse 133*f14fb602SLionel Sambucstate of the stream making these routines are the only way to portably 134*f14fb602SLionel Sambucreposition a text stream. 135*f14fb602SLionel SambucThe 136*f14fb602SLionel Sambuc.Ar pos 137*f14fb602SLionel Sambucargument of 138*f14fb602SLionel Sambuc.Fn fsetpos 139*f14fb602SLionel Sambucmust always be initialized by 140*f14fb602SLionel Sambuca call to 141*f14fb602SLionel Sambuc.Fn fgetpos . 1422fe8fb19SBen Gras.Sh RETURN VALUES 1432fe8fb19SBen GrasThe 1442fe8fb19SBen Gras.Fn rewind 1452fe8fb19SBen Grasfunction 1462fe8fb19SBen Grasreturns no value. 1472fe8fb19SBen GrasUpon successful completion, 1482fe8fb19SBen Gras.Fn fgetpos , 1492fe8fb19SBen Gras.Fn fseek , 1502fe8fb19SBen Gras.Fn fseeko , 1512fe8fb19SBen Grasand 1522fe8fb19SBen Gras.Fn fsetpos 1532fe8fb19SBen Grasreturn 0. 1542fe8fb19SBen GrasThe functions 1552fe8fb19SBen Gras.Fn ftell 1562fe8fb19SBen Grasand 1572fe8fb19SBen Gras.Fn ftello 1582fe8fb19SBen Grasreturn the current offset. 1592fe8fb19SBen GrasOtherwise, 1602fe8fb19SBen Gras.Fn fseek , 1612fe8fb19SBen Gras.Fn fseeko , 1622fe8fb19SBen Gras.Fn ftell , 1632fe8fb19SBen Grasand 1642fe8fb19SBen Gras.Fn ftello 1652fe8fb19SBen Grasreturn \-1 while 1662fe8fb19SBen Gras.Fn fgetpos 1672fe8fb19SBen Grasand 1682fe8fb19SBen Gras.Fn fsetpos 1692fe8fb19SBen Grasreturn a nonzero value. 1702fe8fb19SBen GrasOn error all functions the global variable 1712fe8fb19SBen Gras.Va errno 1722fe8fb19SBen Grasis set to indicate the error. 1732fe8fb19SBen GrasSince the 1742fe8fb19SBen Gras.Fn rewind 1752fe8fb19SBen Grasfunction does not return an error code, applications need to clear 1762fe8fb19SBen Gras.Va errno 1772fe8fb19SBen Grasbefore calling it in order to detect errors. 1782fe8fb19SBen Gras.Sh ERRORS 1792fe8fb19SBen Gras.Bl -tag -width Er 1802fe8fb19SBen Gras.It Bq Er EBADF 1812fe8fb19SBen GrasThe 1822fe8fb19SBen Gras.Fa stream 1832fe8fb19SBen Grasspecified 1842fe8fb19SBen Grasis not a seekable stream. 1852fe8fb19SBen Gras.It Bq Er EINVAL 1862fe8fb19SBen GrasThe 1872fe8fb19SBen Gras.Fa whence 1882fe8fb19SBen Grasargument to 1892fe8fb19SBen Gras.Fn fseek 1902fe8fb19SBen Graswas not 1912fe8fb19SBen Gras.Dv SEEK_SET , 1922fe8fb19SBen Gras.Dv SEEK_END , 1932fe8fb19SBen Grasor 1942fe8fb19SBen Gras.Dv SEEK_CUR . 1952fe8fb19SBen Gras.It Bq Er EOVERFLOW 1962fe8fb19SBen GrasFor 1972fe8fb19SBen Gras.Fn ftell , 1982fe8fb19SBen Grasthe current file offset cannot be represented correctly in an object of type 1992fe8fb19SBen Gras.Fa long . 2002fe8fb19SBen Gras.El 2012fe8fb19SBen Gras.Pp 2022fe8fb19SBen GrasThe function 2032fe8fb19SBen Gras.Fn fgetpos , 2042fe8fb19SBen Gras.Fn fseek , 2052fe8fb19SBen Gras.Fn fseeko , 2062fe8fb19SBen Gras.Fn fsetpos , 2072fe8fb19SBen Gras.Fn ftell , 2082fe8fb19SBen Gras.Fn ftello , 2092fe8fb19SBen Grasand 2102fe8fb19SBen Gras.Fn rewind 2112fe8fb19SBen Grasmay also fail and set 2122fe8fb19SBen Gras.Va errno 2132fe8fb19SBen Grasfor any of the errors specified for the routines 2142fe8fb19SBen Gras.Xr fflush 3 , 2152fe8fb19SBen Gras.Xr fstat 2 , 2162fe8fb19SBen Gras.Xr lseek 2 , 2172fe8fb19SBen Grasand 2182fe8fb19SBen Gras.Xr malloc 3 . 2192fe8fb19SBen Gras.Sh SEE ALSO 2202fe8fb19SBen Gras.Xr lseek 2 2212fe8fb19SBen Gras.Sh STANDARDS 2222fe8fb19SBen GrasThe 2232fe8fb19SBen Gras.Fn fgetpos , 2242fe8fb19SBen Gras.Fn fsetpos , 2252fe8fb19SBen Gras.Fn fseek , 2262fe8fb19SBen Gras.Fn ftell , 2272fe8fb19SBen Grasand 2282fe8fb19SBen Gras.Fn rewind 2292fe8fb19SBen Grasfunctions 2302fe8fb19SBen Grasconform to 2312fe8fb19SBen Gras.St -ansiC . 2322fe8fb19SBen GrasThe 2332fe8fb19SBen Gras.Fn fseeko 2342fe8fb19SBen Grasand 2352fe8fb19SBen Gras.Fn ftello 2362fe8fb19SBen Grasfunctions conform to 2372fe8fb19SBen Gras.St -xsh5 . 2382fe8fb19SBen Gras.Sh BUGS 2392fe8fb19SBen GrasThe 2402fe8fb19SBen Gras.Fn fgetpos 2412fe8fb19SBen Grasand 2422fe8fb19SBen Gras.Fn fsetpos 2432fe8fb19SBen Grasfunctions don't store/set shift states of the stream in this implementation. 244