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