Skip to content

Commit a3e4dca

Browse files
author
Erik van der Kouwe
committed
Add fseeko function
1 parent 66b8f17 commit a3e4dca

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎include/stdio.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ _PROTOTYPE( size_t fwrite,
117117
(const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream) );
118118
_PROTOTYPE( int fgetpos, (FILE *_stream, fpos_t *_pos) );
119119
_PROTOTYPE( int fseek, (FILE *_stream, long _offset, int _whence) );
120+
_PROTOTYPE( int fseeko, (FILE *_stream, off_t _offset, int _whence) );
120121
_PROTOTYPE( int fsetpos, (FILE *_stream, fpos_t *_pos) );
121122
_PROTOTYPE( long ftell, (FILE *_stream) );
122123
_PROTOTYPE( void rewind, (FILE *_stream) );

‎lib/libc/stdio/fseek.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
/* $Header$ */
55

6+
#include <assert.h>
67
#include <stdio.h>
78

89
#if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)
@@ -17,6 +18,13 @@ off_t _lseek(int fildes, off_t offset, int whence);
1718

1819
int
1920
fseek(FILE *stream, long int offset, int whence)
21+
{
22+
assert(sizeof(offset) == sizeof(off_t));
23+
return fseeko(stream, (off_t) offset, whence);
24+
}
25+
26+
int
27+
fseeko(FILE *stream, off_t offset, int whence)
2028
{
2129
int adjust = 0;
2230
long pos;

‎man/man3/fseek.3‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
.TH FSEEK 3 "February 24, 1986"
44
.AT 3
55
.SH NAME
6-
fseek, ftell, rewind \- reposition a stream
6+
fseek, fseeko, ftell, rewind \- reposition a stream
77
.SH SYNOPSIS
88
.nf
99
.ft B
1010
#include <stdio.h>
1111

1212
int fseek(FILE *\fIstream\fP, long \fIoffset\fP, int \fIptrname\fP)
13+
int fseeko(FILE *\fIstream\fP, off_t \fIoffset\fP, int \fIptrname\fP)
1314
long ftell(FILE *\fIstream\fP)
1415
void rewind(FILE *\fIstream\fP)
1516
.ft R
1617
.fi
1718
.SH DESCRIPTION
1819
.B Fseek
19-
sets the position of the next input or output
20+
and
21+
.B fseeko
22+
set the position of the next input or output
2023
operation on the
2124
.IR stream .
2225
The new position is at the signed distance
@@ -28,7 +31,9 @@ according as
2831
has the value 0, 1, or 2.
2932
.PP
3033
.B Fseek
31-
undoes any effects of
34+
and
35+
.B fseeko
36+
undo any effects of
3237
.BR ungetc (3).
3338
.PP
3439
.B Ftell
@@ -40,7 +45,9 @@ on some other systems it is a magic cookie,
4045
and the only foolproof way to obtain an
4146
.I offset
4247
for
43-
.BR fseek .
48+
.BR fseek
49+
and
50+
.BR fseeko .
4451
.PP
4552
.BR Rewind "(\fIstream\fR)"
4653
is equivalent to
@@ -50,4 +57,6 @@ is equivalent to
5057
.BR fopen (3).
5158
.SH DIAGNOSTICS
5259
.B Fseek
53-
returns \-1 for improper seeks, otherwise zero.
60+
and
61+
.B fseeko
62+
return \-1 for improper seeks, otherwise zero.

0 commit comments

Comments
 (0)