Add fseeko function

This commit is contained in:
Erik van der Kouwe 2010-08-16 17:06:08 +00:00
parent 66b8f17a29
commit a3e4dcafe0
3 changed files with 23 additions and 5 deletions

View File

@ -117,6 +117,7 @@ _PROTOTYPE( size_t fwrite,
(const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream) ); (const void *_ptr, size_t _size, size_t _nmemb, FILE *_stream) );
_PROTOTYPE( int fgetpos, (FILE *_stream, fpos_t *_pos) ); _PROTOTYPE( int fgetpos, (FILE *_stream, fpos_t *_pos) );
_PROTOTYPE( int fseek, (FILE *_stream, long _offset, int _whence) ); _PROTOTYPE( int fseek, (FILE *_stream, long _offset, int _whence) );
_PROTOTYPE( int fseeko, (FILE *_stream, off_t _offset, int _whence) );
_PROTOTYPE( int fsetpos, (FILE *_stream, fpos_t *_pos) ); _PROTOTYPE( int fsetpos, (FILE *_stream, fpos_t *_pos) );
_PROTOTYPE( long ftell, (FILE *_stream) ); _PROTOTYPE( long ftell, (FILE *_stream) );
_PROTOTYPE( void rewind, (FILE *_stream) ); _PROTOTYPE( void rewind, (FILE *_stream) );

View File

@ -3,6 +3,7 @@
*/ */
/* $Header$ */ /* $Header$ */
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0) #if (SEEK_CUR != 1) || (SEEK_END != 2) || (SEEK_SET != 0)
@ -17,6 +18,13 @@ off_t _lseek(int fildes, off_t offset, int whence);
int int
fseek(FILE *stream, long int offset, int whence) fseek(FILE *stream, long int offset, int whence)
{
assert(sizeof(offset) == sizeof(off_t));
return fseeko(stream, (off_t) offset, whence);
}
int
fseeko(FILE *stream, off_t offset, int whence)
{ {
int adjust = 0; int adjust = 0;
long pos; long pos;

View File

@ -3,20 +3,23 @@
.TH FSEEK 3 "February 24, 1986" .TH FSEEK 3 "February 24, 1986"
.AT 3 .AT 3
.SH NAME .SH NAME
fseek, ftell, rewind \- reposition a stream fseek, fseeko, ftell, rewind \- reposition a stream
.SH SYNOPSIS .SH SYNOPSIS
.nf .nf
.ft B .ft B
#include <stdio.h> #include <stdio.h>
int fseek(FILE *\fIstream\fP, long \fIoffset\fP, int \fIptrname\fP) int fseek(FILE *\fIstream\fP, long \fIoffset\fP, int \fIptrname\fP)
int fseeko(FILE *\fIstream\fP, off_t \fIoffset\fP, int \fIptrname\fP)
long ftell(FILE *\fIstream\fP) long ftell(FILE *\fIstream\fP)
void rewind(FILE *\fIstream\fP) void rewind(FILE *\fIstream\fP)
.ft R .ft R
.fi .fi
.SH DESCRIPTION .SH DESCRIPTION
.B Fseek .B Fseek
sets the position of the next input or output and
.B fseeko
set the position of the next input or output
operation on the operation on the
.IR stream . .IR stream .
The new position is at the signed distance The new position is at the signed distance
@ -28,7 +31,9 @@ according as
has the value 0, 1, or 2. has the value 0, 1, or 2.
.PP .PP
.B Fseek .B Fseek
undoes any effects of and
.B fseeko
undo any effects of
.BR ungetc (3). .BR ungetc (3).
.PP .PP
.B Ftell .B Ftell
@ -40,7 +45,9 @@ on some other systems it is a magic cookie,
and the only foolproof way to obtain an and the only foolproof way to obtain an
.I offset .I offset
for for
.BR fseek . .BR fseek
and
.BR fseeko .
.PP .PP
.BR Rewind "(\fIstream\fR)" .BR Rewind "(\fIstream\fR)"
is equivalent to is equivalent to
@ -50,4 +57,6 @@ is equivalent to
.BR fopen (3). .BR fopen (3).
.SH DIAGNOSTICS .SH DIAGNOSTICS
.B Fseek .B Fseek
returns \-1 for improper seeks, otherwise zero. and
.B fseeko
return \-1 for improper seeks, otherwise zero.