xref: /csrg-svn/lib/libc/stdio/fseek.3 (revision 61180)
1*61180Sbostic.\" Copyright (c) 1990, 1991, 1993
2*61180Sbostic.\"	The Regents of the University of California.  All rights reserved.
320319Smckusick.\"
446086Sbostic.\" This code is derived from software contributed to Berkeley by
550293Sbostic.\" Chris Torek and the American National Standards Committee X3,
650293Sbostic.\" on Information Processing Systems.
750293Sbostic.\"
846086Sbostic.\" %sccs.include.redist.man%
946086Sbostic.\"
10*61180Sbostic.\"     @(#)fseek.3	8.1 (Berkeley) 06/04/93
1146086Sbostic.\"
1248351Scael.Dd
1348351Scael.Dt FSEEK 3
1448351Scael.Os
1548351Scael.Sh NAME
1648351Scael.Nm fgetpos ,
1748351Scael.Nm fseek ,
1848351Scael.Nm fsetpos ,
1948351Scael.Nm ftell ,
2048351Scael.Nm rewind
2148351Scael.Nd reposition a stream
2248351Scael.Sh SYNOPSIS
2348351Scael.Fd #include <stdio.h>
2448351Scael.Ft int
2548351Scael.Fn fseek "FILE *stream" "long offset" "int whence"
2648351Scael.Ft long
2748351Scael.Fn ftell "FILE *stream"
2848351Scael.Ft void
2948351Scael.Fn rewind "FILE *stream"
3048351Scael.Ft int
3148351Scael.Fn fgetpos "FILE *stream" "fpos_t *pos"
3248351Scael.Ft int
3348351Scael.Fn fsetpos "FILE *stream" "fpos_t *pos"
3448351Scael.Sh DESCRIPTION
3548351ScaelThe
3648351Scael.Fn fseek
3748351Scaelfunction sets the file position indicator for the stream pointed
3848351Scaelto by
3948351Scael.Fa stream .
4048351ScaelThe new position, measured in bytes, is obtained by adding
4148351Scael.Fa offset
4248351Scaelbytes to the position specified by
4348351Scael.Fa whence .
4446086SbosticIf
4548351Scael.Fa whence
4648351Scaelis set to
4748351Scael.Dv SEEK_SET ,
4848351Scael.Dv SEEK_CUR ,
4948351Scaelor
5048351Scael.Dv SEEK_END ,
5148351Scaelthe offset is relative to the
5248351Scaelstart of the file, the current position indicator, or end-of-file,
5348351Scaelrespectively.
5448351ScaelA successful call to the
5548351Scael.Fn fseek
5648351Scaelfunction clears the end-of-file indicator for the stream and undoes
5748351Scaelany effects of the
5848351Scael.Xr ungetc 3
5948351Scaelfunction on the same stream.
6048351Scael.Pp
6148351ScaelThe
6248351Scael.Fn ftell
6348351Scaelfunction
6448351Scaelobtains the current value of the file position indicator for the
6548351Scaelstream pointed to by
6648351Scael.Fa stream .
6748351Scael.Pp
6848351ScaelThe
6948351Scael.Fn rewind
7048351Scaelfunction sets the file position indicator for the stream pointed
7148351Scaelto by
7248351Scael.Fa stream
7348351Scaelto the beginning of the file.
7448351ScaelIt is equivalent to:
7548351Scael.Pp
7648351Scael.Dl (void)fseek(stream, 0L, SEEK_SET)
7748351Scael.Pp
7848351Scaelexcept that the error indicator for the stream is also cleared
7948351Scael(see
8048351Scael.Xr clearerr 3 ) .
8148351Scael.Pp
8248351ScaelThe
8348351Scael.Fn fgetpos
8446086Sbosticand
8548351Scael.Fn fsetpos
8648351Scaelfunctions
8746086Sbosticare alternate interfaces equivalent to
8848351Scael.Fn ftell
8946086Sbosticand
9048351Scael.Fn fseek
9148351Scael(with whence set to
9248351Scael.Dv SEEK_SET
9348351Scael), setting and storing the current value of
9446086Sbosticthe file offset into or from the object referenced by
9548351Scael.Fa pos .
9648351ScaelOn some
9748376Scael.Pq non- Ns Tn UNIX
9848351Scaelsystems an
9948351Scael.Dq Fa fpos_t
10048351Scaelobject may be a complex object
10146086Sbosticand these routines may be the only way to portably reposition a text stream.
10248351Scael.Sh RETURN VALUES
10348351ScaelThe
10448351Scael.Fn rewind
10548351Scaelfunction
10646086Sbosticreturns no value.
10746086SbosticUpon successful completion,
10848351Scael.Fn fgetpos ,
10948351Scael.Fn fseek ,
11048376Scael.Fn fsetpos
11148376Scaelreturn 0,
11246086Sbosticand
11348351Scael.Fn ftell
11448376Scaelreturns the current offset.
11546086SbosticOtherwise, \-1 is returned and the global variable errno is set to
11646086Sbosticindicate the error.
11748351Scael.Sh ERRORS
11848351Scael.Bl -tag -width [EINVAL]
11948351Scael.It Bq Er EBADF
12048351ScaelThe
12148351Scael.Fa stream
12248351Scaelspecified
12346086Sbosticis not a seekable stream.
12448351Scael.It Bq Er EINVAL
12546086SbosticThe
12648351Scael.Fa whence
12746086Sbosticargument to
12848351Scael.Fn fseek
12948351Scaelwas not
13048351Scael.Dv SEEK_SET ,
13148351Scael.Dv SEEK_END ,
13248351Scaelor
13348351Scael.Dv SEEK_CUR .
13448351Scael.El
13548351Scael.Pp
13648351ScaelThe function
13748351Scael.Fn fgetpos ,
13848351Scael.Fn fseek ,
13948351Scael.Fn fsetpos ,
14046086Sbosticand
14148351Scael.Fn ftell
14246086Sbosticmay also fail and set
14348351Scael.Va errno
14446086Sbosticfor any of the errors specified for the routines
14548351Scael.Xr fflush 3 ,
14648351Scael.Xr fstat 2 ,
14748351Scael.Xr lseek 2 ,
14846086Sbosticand
14948351Scael.Xr malloc 3 .
15048351Scael.Sh SEE ALSO
15148351Scael.Xr lseek 2
15248351Scael.Sh STANDARDS
15348351ScaelThe
15448351Scael.Fn fgetpos ,
15548351Scael.Fn fsetpos ,
15648351Scael.Fn fseek ,
15748351Scael.Fn ftell ,
15846086Sbosticand
15948351Scael.Fn rewind
16048351Scaelfunctions
16148351Scaelconform to
16248351Scael.St -ansiC .
163