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.9 (Berkeley) 04/19/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 , 109and 110.Fn ftell 111return 0. 112Otherwise, \-1 is returned and the global variable errno is set to 113indicate the error. 114.Sh ERRORS 115.Bl -tag -width [EINVAL] 116.It Bq Er EBADF 117The 118.Fa stream 119specified 120is not a seekable stream. 121.It Bq Er EINVAL 122The 123.Fa whence 124argument to 125.Fn fseek 126was not 127.Dv SEEK_SET , 128.Dv SEEK_END , 129or 130.Dv SEEK_CUR . 131.El 132.Pp 133The function 134.Fn fgetpos , 135.Fn fseek , 136.Fn fsetpos , 137and 138.Fn ftell 139may also fail and set 140.Va errno 141for any of the errors specified for the routines 142.Xr fflush 3 , 143.Xr fstat 2 , 144.Xr lseek 2 , 145and 146.Xr malloc 3 . 147.Sh SEE ALSO 148.Xr lseek 2 149.Sh STANDARDS 150The 151.Fn fgetpos , 152.Fn fsetpos , 153.Fn fseek , 154.Fn ftell , 155and 156.Fn rewind 157functions 158conform to 159.St -ansiC . 160