SCCS id got lost along the way
[unix-history] / usr / src / lib / libc / stdio / fseek.3
CommitLineData
411867e7
KB
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
4f278f49 3.\"
411867e7
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\"
7.\" %sccs.include.redist.man%
8.\"
36e9970b 9.\" @(#)fseek.3 6.8 (Berkeley) %G%
411867e7
KB
10.\"
11.TH FSEEK 3 ""
12.UC 7
4f278f49 13.SH NAME
411867e7 14fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
4f278f49 15.SH SYNOPSIS
411867e7
KB
16.nf
17.ft B
18#include <stdio.h>
19
20int
21fseek(FILE *stream, long offset, int whence);
22
23long
24ftell(FILE *stream);
25
26void
27rewind(FILE *stream);
28
29int
30fgetpos(FILE *stream, fpos_t *pos);
31
32int
33fsetpos(FILE *stream, fpos_t *pos);
34.ft R
35.fi
4f278f49
KM
36.SH DESCRIPTION
37.I Fseek
38sets the position of the next input or output
411867e7 39operation on the given
4f278f49
KM
40.IR stream .
41The new position is at the signed distance
42.I offset
411867e7
KB
43bytes from a specified point in the file depending on the
44value of
45.IR whence .
46If
47.I whence
1382c0b2
KB
48is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is from the
49beginning, the current position, or the end of the file, respectively.
4f278f49
KM
50.I Fseek
51undoes any effects of
411867e7 52.IR ungetc .
4f278f49
KM
53.PP
54.I Ftell
55returns the current value of the offset relative to the beginning
56of the file associated with the named
57.IR stream .
4f278f49 58.PP
411867e7
KB
59.IR Rewind
60is equivalent to ``fseek(stream, 0L, SEEK_SET)'', except the error
61indicator for the stream is cleared as well (see
62.IR clearerr (3)).
63.PP
64.I Fgetpos
65and
66.I fsetpos
67are alternate interfaces equivalent to
68.I ftell
69and
70.I fseek
71(with whence set to SEEK_SET), setting and storing the current value of
72the file offset into or from the object referenced by
73.IR pos .
74On some (non-UNIX) systems an ``fpos_t'' object may be a complex object
75and these routines may be the only way to portably reposition a text stream.
4f278f49 76.SH "SEE ALSO"
411867e7
KB
77lseek(2)
78.SH "RETURN VALUE"
79.I Rewind
80returns no value.
81Upon successful completion,
82.IR fgetpos ,
83.IR fseek ,
411867e7 84and
36e9970b
KB
85.I fsetpos
86return 0,
87and
88.I ftell
89returns the current offset.
411867e7
KB
90Otherwise, \-1 is returned and the global variable errno is set to
91indicate the error.
92.SH ERRORS
93.TP 15
94[EBADF]
95.I Stream
96is not a seekable stream.
97.TP
98[EINVAL]
99The
100.I whence
101argument to
102.I fseek
103was not SEEK_SET, SEEK_END, or SEEK_CUR.
104.PP
105.IR Fgetpos ,
106.IR fseek ,
107.IR fsetpos ,
108and
109.I ftell
110may also fail and set
111.I errno
112for any of the errors specified for the routines
113.IR fflush (3),
114.IR fstat (2),
115.IR lseek (2),
116and
117.IR malloc (3).
118.SH STANDARDS
119.IR Fgetpos ,
120.IR fsetpos ,
121.IR fseek ,
122.IR ftell ,
123and
124.IR rewind
125conform to ANSI X3.159-1989 (``ANSI C'').