158f0484fSRodney W. Grimes.\" Copyright (c) 1990, 1991, 1993 258f0484fSRodney W. Grimes.\" The Regents of the University of California. All rights reserved. 358f0484fSRodney W. Grimes.\" 458f0484fSRodney W. Grimes.\" This code is derived from software contributed to Berkeley by 558f0484fSRodney W. Grimes.\" Chris Torek and the American National Standards Committee X3, 658f0484fSRodney W. Grimes.\" on Information Processing Systems. 758f0484fSRodney W. Grimes.\" 858f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without 958f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions 1058f0484fSRodney W. Grimes.\" are met: 1158f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright 1258f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer. 1358f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright 1458f0484fSRodney W. Grimes.\" notice, this list of conditions and the following disclaimer in the 1558f0484fSRodney W. Grimes.\" documentation and/or other materials provided with the distribution. 16fbbd9655SWarner Losh.\" 3. Neither the name of the University nor the names of its contributors 1758f0484fSRodney W. Grimes.\" may be used to endorse or promote products derived from this software 1858f0484fSRodney W. Grimes.\" without specific prior written permission. 1958f0484fSRodney W. Grimes.\" 2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3058f0484fSRodney W. Grimes.\" SUCH DAMAGE. 3158f0484fSRodney W. Grimes.\" 32*4b7f35dbSGordon Bergling.Dd April 2, 2022 3358f0484fSRodney W. Grimes.Dt FSEEK 3 3458f0484fSRodney W. Grimes.Os 3558f0484fSRodney W. Grimes.Sh NAME 3658f0484fSRodney W. Grimes.Nm fgetpos , 3758f0484fSRodney W. Grimes.Nm fseek , 387307d07dSDmitrij Tejblum.Nm fseeko , 3958f0484fSRodney W. Grimes.Nm fsetpos , 4058f0484fSRodney W. Grimes.Nm ftell , 417307d07dSDmitrij Tejblum.Nm ftello , 4258f0484fSRodney W. Grimes.Nm rewind 4358f0484fSRodney W. Grimes.Nd reposition a stream 4425bb73e0SAlexey Zelkin.Sh LIBRARY 4525bb73e0SAlexey Zelkin.Lb libc 4658f0484fSRodney W. Grimes.Sh SYNOPSIS 4732eef9aeSRuslan Ermilov.In stdio.h 4858f0484fSRodney W. Grimes.Ft int 4958f0484fSRodney W. Grimes.Fn fseek "FILE *stream" "long offset" "int whence" 5058f0484fSRodney W. Grimes.Ft long 5158f0484fSRodney W. Grimes.Fn ftell "FILE *stream" 5258f0484fSRodney W. Grimes.Ft void 5358f0484fSRodney W. Grimes.Fn rewind "FILE *stream" 5458f0484fSRodney W. Grimes.Ft int 5554e4e385SMike Barcroft.Fn fgetpos "FILE * restrict stream" "fpos_t * restrict pos" 5658f0484fSRodney W. Grimes.Ft int 5723f0c1fcSBruce Evans.Fn fsetpos "FILE *stream" "const fpos_t *pos" 5832eef9aeSRuslan Ermilov.In sys/types.h 597307d07dSDmitrij Tejblum.Ft int 607307d07dSDmitrij Tejblum.Fn fseeko "FILE *stream" "off_t offset" "int whence" 617307d07dSDmitrij Tejblum.Ft off_t 627307d07dSDmitrij Tejblum.Fn ftello "FILE *stream" 6358f0484fSRodney W. Grimes.Sh DESCRIPTION 6458f0484fSRodney W. GrimesThe 6558f0484fSRodney W. Grimes.Fn fseek 6658f0484fSRodney W. Grimesfunction sets the file position indicator for the stream pointed 6758f0484fSRodney W. Grimesto by 6858f0484fSRodney W. Grimes.Fa stream . 6958f0484fSRodney W. GrimesThe new position, measured in bytes, is obtained by adding 7058f0484fSRodney W. Grimes.Fa offset 7158f0484fSRodney W. Grimesbytes to the position specified by 7258f0484fSRodney W. Grimes.Fa whence . 7358f0484fSRodney W. GrimesIf 7458f0484fSRodney W. Grimes.Fa whence 7558f0484fSRodney W. Grimesis set to 7658f0484fSRodney W. Grimes.Dv SEEK_SET , 7758f0484fSRodney W. Grimes.Dv SEEK_CUR , 7858f0484fSRodney W. Grimesor 7958f0484fSRodney W. Grimes.Dv SEEK_END , 8058f0484fSRodney W. Grimesthe offset is relative to the 8158f0484fSRodney W. Grimesstart of the file, the current position indicator, or end-of-file, 8258f0484fSRodney W. Grimesrespectively. 8358f0484fSRodney W. GrimesA successful call to the 8458f0484fSRodney W. Grimes.Fn fseek 8558f0484fSRodney W. Grimesfunction clears the end-of-file indicator for the stream and undoes 8658f0484fSRodney W. Grimesany effects of the 8758f0484fSRodney W. Grimes.Xr ungetc 3 88419c4426STim J. Robbinsand 89419c4426STim J. Robbins.Xr ungetwc 3 90419c4426STim J. Robbinsfunctions on the same stream. 9158f0484fSRodney W. Grimes.Pp 9258f0484fSRodney W. GrimesThe 9358f0484fSRodney W. Grimes.Fn ftell 9458f0484fSRodney W. Grimesfunction 9558f0484fSRodney W. Grimesobtains the current value of the file position indicator for the 9658f0484fSRodney W. Grimesstream pointed to by 9758f0484fSRodney W. Grimes.Fa stream . 9858f0484fSRodney W. Grimes.Pp 9958f0484fSRodney W. GrimesThe 10058f0484fSRodney W. Grimes.Fn rewind 10158f0484fSRodney W. Grimesfunction sets the file position indicator for the stream pointed 10258f0484fSRodney W. Grimesto by 10358f0484fSRodney W. Grimes.Fa stream 10458f0484fSRodney W. Grimesto the beginning of the file. 10558f0484fSRodney W. GrimesIt is equivalent to: 10658f0484fSRodney W. Grimes.Pp 10758f0484fSRodney W. Grimes.Dl (void)fseek(stream, 0L, SEEK_SET) 10858f0484fSRodney W. Grimes.Pp 10958f0484fSRodney W. Grimesexcept that the error indicator for the stream is also cleared 11058f0484fSRodney W. Grimes(see 11158f0484fSRodney W. Grimes.Xr clearerr 3 ) . 11258f0484fSRodney W. Grimes.Pp 113c5981656SAndrey A. ChernovSince 114c5981656SAndrey A. Chernov.Fn rewind 115c5981656SAndrey A. Chernovdoes not return a value, 116c5981656SAndrey A. Chernovan application wishing to detect errors should clear 117c5981656SAndrey A. Chernov.Va errno , 118c5981656SAndrey A. Chernovthen call 119c5981656SAndrey A. Chernov.Fn rewind , 120c5981656SAndrey A. Chernovand if 121c5981656SAndrey A. Chernov.Va errno 122c5981656SAndrey A. Chernovis non-zero, assume an error has occurred. 123c5981656SAndrey A. Chernov.Pp 12458f0484fSRodney W. GrimesThe 1257307d07dSDmitrij Tejblum.Fn fseeko 1267307d07dSDmitrij Tejblumfunction is identical to 1277307d07dSDmitrij Tejblum.Fn fseek , 128b300c1d8SBruce Evansexcept it takes an 1297307d07dSDmitrij Tejblum.Fa off_t 1307307d07dSDmitrij Tejblumargument 1317307d07dSDmitrij Tejbluminstead of a 1327307d07dSDmitrij Tejblum.Fa long . 1337307d07dSDmitrij TejblumLikewise, the 1347307d07dSDmitrij Tejblum.Fn ftello 1357307d07dSDmitrij Tejblumfunction is identical to 1367307d07dSDmitrij Tejblum.Fn ftell , 137b300c1d8SBruce Evansexcept it returns an 1387307d07dSDmitrij Tejblum.Fa off_t . 1397307d07dSDmitrij Tejblum.Pp 1407307d07dSDmitrij TejblumThe 14158f0484fSRodney W. Grimes.Fn fgetpos 14258f0484fSRodney W. Grimesand 14358f0484fSRodney W. Grimes.Fn fsetpos 14458f0484fSRodney W. Grimesfunctions 1451e709c9cSTim J. Robbinsare alternate interfaces for retrieving and setting the current position in 1461e709c9cSTim J. Robbinsthe file, similar to 14758f0484fSRodney W. Grimes.Fn ftell 14858f0484fSRodney W. Grimesand 1491e709c9cSTim J. Robbins.Fn fseek , 1501e709c9cSTim J. Robbinsexcept that the current position is stored in an opaque object of 1511e709c9cSTim J. Robbinstype 1521e709c9cSTim J. Robbins.Vt fpos_t 1531e709c9cSTim J. Robbinspointed to by 15458f0484fSRodney W. Grimes.Fa pos . 1551e709c9cSTim J. RobbinsThese functions provide a portable way to seek to offsets larger than 1561e709c9cSTim J. Robbinsthose that can be represented by a 1571e709c9cSTim J. Robbins.Vt long int . 1581e709c9cSTim J. RobbinsThey may also store additional state information in the 1591e709c9cSTim J. Robbins.Vt fpos_t 1601e709c9cSTim J. Robbinsobject to facilitate seeking within files containing multibyte 1611e709c9cSTim J. Robbinscharacters with state-dependent encodings. 1621e709c9cSTim J. RobbinsAlthough 1631e709c9cSTim J. Robbins.Vt fpos_t 1641e709c9cSTim J. Robbinshas traditionally been an integral type, 1651e709c9cSTim J. Robbinsapplications cannot assume that it is; 1661e709c9cSTim J. Robbinsin particular, they must not perform arithmetic on objects 1671e709c9cSTim J. Robbinsof this type. 168419c4426STim J. Robbins.Pp 169419c4426STim J. RobbinsIf the stream is a wide character stream (see 1701798791dSRuslan Ermilov.Xr fwide 3 ) , 171419c4426STim J. Robbinsthe position specified by the combination of 172419c4426STim J. Robbins.Fa offset 173419c4426STim J. Robbinsand 174419c4426STim J. Robbins.Fa whence 175419c4426STim J. Robbinsmust contain the first byte of a multibyte sequence. 17658f0484fSRodney W. Grimes.Sh RETURN VALUES 17758f0484fSRodney W. GrimesThe 17858f0484fSRodney W. Grimes.Fn rewind 17958f0484fSRodney W. Grimesfunction 18058f0484fSRodney W. Grimesreturns no value. 181d6002fefSRuslan Ermilov.Pp 182d6002fefSRuslan Ermilov.Rv -std fgetpos fseek fseeko fsetpos 183d6002fefSRuslan Ermilov.Pp 18458f0484fSRodney W. GrimesUpon successful completion, 18558f0484fSRodney W. Grimes.Fn ftell 1867307d07dSDmitrij Tejblumand 1877307d07dSDmitrij Tejblum.Fn ftello 188b300c1d8SBruce Evansreturn the current offset. 189c5981656SAndrey A. ChernovOtherwise, \-1 is returned and the global variable 190c5981656SAndrey A. Chernov.Va errno 191c5981656SAndrey A. Chernovis set to indicate the error. 19258f0484fSRodney W. Grimes.Sh ERRORS 19303fc6303SAlexey Zelkin.Bl -tag -width Er 19458f0484fSRodney W. Grimes.It Bq Er EBADF 19558f0484fSRodney W. GrimesThe 19658f0484fSRodney W. Grimes.Fa stream 1972efeeba5SRuslan Ermilovargument 19858f0484fSRodney W. Grimesis not a seekable stream. 19958f0484fSRodney W. Grimes.It Bq Er EINVAL 20058f0484fSRodney W. GrimesThe 20158f0484fSRodney W. Grimes.Fa whence 202c5981656SAndrey A. Chernovargument is invalid or 203c5981656SAndrey A. Chernovthe resulting file-position 204d9e3eff3SAndrey A. Chernovindicator would be set to a negative value. 2057307d07dSDmitrij Tejblum.It Bq Er EOVERFLOW 206d9e3eff3SAndrey A. ChernovThe resulting file offset would be a value which 207c5981656SAndrey A. Chernovcannot be represented correctly in an object of type 208c5981656SAndrey A. Chernov.Fa off_t 20971b5a432SAndrey A. Chernovfor 21071b5a432SAndrey A. Chernov.Fn fseeko 2115fdaf178SAndrey A. Chernovand 2125fdaf178SAndrey A. Chernov.Fn ftello 213c5981656SAndrey A. Chernovor 214c5981656SAndrey A. Chernov.Fa long 215c5981656SAndrey A. Chernovfor 2165fdaf178SAndrey A. Chernov.Fn fseek 2175fdaf178SAndrey A. Chernovand 2185fdaf178SAndrey A. Chernov.Fn ftell . 219c5981656SAndrey A. Chernov.It Bq Er ESPIPE 22045892fd8SAndrey A. ChernovThe file descriptor underlying stream is associated with a pipe or FIFO 22145892fd8SAndrey A. Chernovor file-position indicator value is unspecified 2222f5eadffSAndrey A. Chernov(see 2232f5eadffSAndrey A. Chernov.Xr ungetc 3 ) . 22458f0484fSRodney W. Grimes.El 22558f0484fSRodney W. Grimes.Pp 2267307d07dSDmitrij TejblumThe functions 22758f0484fSRodney W. Grimes.Fn fgetpos , 22858f0484fSRodney W. Grimes.Fn fseek , 2297307d07dSDmitrij Tejblum.Fn fseeko , 23058f0484fSRodney W. Grimes.Fn fsetpos , 2317307d07dSDmitrij Tejblum.Fn ftell , 232b490b135SAndrey A. Chernov.Fn ftello , 23358f0484fSRodney W. Grimesand 234b490b135SAndrey A. Chernov.Fn rewind 23558f0484fSRodney W. Grimesmay also fail and set 23658f0484fSRodney W. Grimes.Va errno 23758f0484fSRodney W. Grimesfor any of the errors specified for the routines 23858f0484fSRodney W. Grimes.Xr fflush 3 , 23958f0484fSRodney W. Grimes.Xr fstat 2 , 24058f0484fSRodney W. Grimes.Xr lseek 2 , 24158f0484fSRodney W. Grimesand 24258f0484fSRodney W. Grimes.Xr malloc 3 . 24358f0484fSRodney W. Grimes.Sh SEE ALSO 2442f5eadffSAndrey A. Chernov.Xr lseek 2 , 2452f5eadffSAndrey A. Chernov.Xr clearerr 3 , 246419c4426STim J. Robbins.Xr fwide 3 , 247419c4426STim J. Robbins.Xr ungetc 3 , 248419c4426STim J. Robbins.Xr ungetwc 3 24958f0484fSRodney W. Grimes.Sh STANDARDS 25058f0484fSRodney W. GrimesThe 25158f0484fSRodney W. Grimes.Fn fgetpos , 25258f0484fSRodney W. Grimes.Fn fsetpos , 25358f0484fSRodney W. Grimes.Fn fseek , 25458f0484fSRodney W. Grimes.Fn ftell , 25558f0484fSRodney W. Grimesand 25658f0484fSRodney W. Grimes.Fn rewind 25758f0484fSRodney W. Grimesfunctions 25858f0484fSRodney W. Grimesconform to 259588a200cSRuslan Ermilov.St -isoC . 2607307d07dSDmitrij Tejblum.Pp 2617307d07dSDmitrij TejblumThe 2627307d07dSDmitrij Tejblum.Fn fseeko 2637307d07dSDmitrij Tejblumand 2647307d07dSDmitrij Tejblum.Fn ftello 2657307d07dSDmitrij Tejblumfunctions conform to 266647e4efdSGarrett Wollman.St -p1003.1-2001 . 267*4b7f35dbSGordon Bergling.Sh HISTORY 268*4b7f35dbSGordon BerglingThe functions 269*4b7f35dbSGordon Bergling.Fn fseek , 270*4b7f35dbSGordon Bergling.Fn ftell , 271*4b7f35dbSGordon Berglingand 272*4b7f35dbSGordon Bergling.Fn rewind 273*4b7f35dbSGordon Berglingfirst appeared in 274*4b7f35dbSGordon Bergling.At v7 . 275