Added functions fseeko() and ftello() (from susv2).

Fixed fgetpos() and fsetpos() for offsets > 2GB.

PR:		8637
Submitted by:	 Dan Nelson <dnelson@emsphone.com> (adjusted by me a little)
This commit is contained in:
dt 1999-02-08 21:32:38 +00:00
parent 00d9c6c1ed
commit 09f3411c47
7 changed files with 86 additions and 16 deletions

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)stdio.h 8.5 (Berkeley) 4/29/95
* $Id: stdio.h,v 1.20 1998/07/13 06:45:20 bde Exp $
* $Id: stdio.h,v 1.21 1998/12/14 19:23:16 dt Exp $
*/
#ifndef _STDIO_H_
@ -296,6 +296,8 @@ __BEGIN_DECLS
int asprintf __P((char **, const char *, ...)) __printflike(2, 3);
char *fgetln __P((FILE *, size_t *));
int fpurge __P((FILE *));
int fseeko __P((FILE *, _BSD_OFF_T_, int));
_BSD_OFF_T_ ftello __P((FILE *));
int getw __P((FILE *));
int pclose __P((FILE *));
FILE *popen __P((const char *, const char *));

View File

@ -1,5 +1,5 @@
# @(#)Makefile.inc 8.3 (Berkeley) 4/17/94
# $Id: Makefile.inc,v 1.14 1998/04/11 07:40:41 jb Exp $
# $Id: Makefile.inc,v 1.15 1998/05/08 05:17:11 jb Exp $
# stdio sources
.PATH: ${.CURDIR}/../libc/stdio
@ -28,6 +28,7 @@ MLINKS+=fopen.3 fdopen.3 fopen.3 freopen.3
MLINKS+=fputs.3 puts.3
MLINKS+=fread.3 fwrite.3
MLINKS+=fseek.3 fgetpos.3 fseek.3 fsetpos.3 fseek.3 ftell.3 fseek.3 rewind.3
MLINKS+=fseek.3 fseeko.3 fseek.3 ftello.3
MLINKS+=funopen.3 fropen.3 funopen.3 fwopen.3
MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3
MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3

View File

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$Id: fgetpos.c,v 1.5 1997/02/22 15:01:53 peter Exp $";
"$Id: fgetpos.c,v 1.6 1998/04/11 07:40:42 jb Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@ -52,7 +52,7 @@ fgetpos(fp, pos)
{
int retval;
FLOCKFILE(fp);
retval = (*pos = ftell(fp)) == (fpos_t)-1;
retval = (*pos = ftello(fp)) == (fpos_t)-1;
FUNLOCKFILE(fp);
return(retval);
}

View File

@ -41,8 +41,10 @@
.Sh NAME
.Nm fgetpos ,
.Nm fseek ,
.Nm fseeko ,
.Nm fsetpos ,
.Nm ftell ,
.Nm ftello ,
.Nm rewind
.Nd reposition a stream
.Sh SYNOPSIS
@ -57,6 +59,10 @@
.Fn fgetpos "FILE *stream" "fpos_t *pos"
.Ft int
.Fn fsetpos "FILE *stream" "const fpos_t *pos"
.Ft int
.Fn fseeko "FILE *stream" "off_t offset" "int whence"
.Ft off_t
.Fn ftello "FILE *stream"
.Sh DESCRIPTION
The
.Fn fseek
@ -106,6 +112,22 @@ except that the error indicator for the stream is also cleared
.Xr clearerr 3 ) .
.Pp
The
.Fn fseeko
function is identical to
.Fn fseek ,
but take an
.Fa off_t
argument
instead of a
.Fa long .
Likewise, the
.Fn ftello
function is identical to
.Fn ftell ,
but returns
.Fa off_t .
.Pp
The
.Fn fgetpos
and
.Fn fsetpos
@ -115,8 +137,8 @@ are alternate interfaces equivalent to
and
.Fn fseek
(with whence set to
.Dv SEEK_SET
), setting and storing the current value of
.Dv SEEK_SET ) ,
setting and storing the current value of
the file offset into or from the object referenced by
.Fa pos .
On some
@ -133,10 +155,14 @@ returns no value.
Upon successful completion,
.Fn fgetpos ,
.Fn fseek ,
.Fn fseeko ,
and
.Fn fsetpos
return 0,
and
.Fn ftell
and
.Fn ftello
returns the current offset.
Otherwise, \-1 is returned and the global variable errno is set to
indicate the error.
@ -157,14 +183,21 @@ was not
.Dv SEEK_END ,
or
.Dv SEEK_CUR .
.It Bq Er EOVERFLOW
For
.Fn ftell ,
the resulting file offset would be a value which
cannot be represented correctly in an object of type long.
.El
.Pp
The function
The functions
.Fn fgetpos ,
.Fn fseek ,
.Fn fseeko ,
.Fn fsetpos ,
and
.Fn ftell
.Fn ftell ,
and
.Fn ftello
may also fail and set
.Va errno
for any of the errors specified for the routines
@ -186,3 +219,10 @@ and
functions
conform to
.St -ansiC .
.Pp
The
.Fn fseeko
and
.Fn ftello
functions conform to
.St -susv2 .

View File

@ -39,7 +39,7 @@
static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94";
#endif
static const char rcsid[] =
"$Id: fseek.c,v 1.6 1997/02/22 15:02:05 peter Exp $";
"$Id: fseek.c,v 1.7 1998/04/11 07:40:44 jb Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -53,14 +53,23 @@ static const char rcsid[] =
#define POS_ERR (-(fpos_t)1)
int
fseek(fp, offset, whence)
register FILE *fp;
long offset;
int whence;
{
return (fseeko(fp, offset, whence));
}
/*
* Seek the given file to the given offset.
* `Whence' must be one of the three SEEK_* macros.
*/
int
fseek(fp, offset, whence)
fseeko(fp, offset, whence)
register FILE *fp;
long offset;
off_t offset;
int whence;
{
register fpos_t (*seekfn) __P((void *, fpos_t, int));

View File

@ -39,9 +39,10 @@
static char sccsid[] = "@(#)fsetpos.c 8.1 (Berkeley) 6/4/93";
#endif
static const char rcsid[] =
"$Id$";
"$Id: fsetpos.c,v 1.5 1997/02/22 15:02:06 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <stdio.h>
/*
@ -52,5 +53,5 @@ fsetpos(iop, pos)
FILE *iop;
const fpos_t *pos;
{
return (fseek(iop, (long)*pos, SEEK_SET));
return (fseeko(iop, (off_t)*pos, SEEK_SET));
}

View File

@ -39,20 +39,37 @@
static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
#endif
static const char rcsid[] =
"$Id: ftell.c,v 1.8 1997/03/11 11:40:40 peter Exp $";
"$Id: ftell.c,v 1.9 1998/04/11 07:40:44 jb Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include "local.h"
#include "libc_private.h"
/*
* ftell: return current offset.
* standard ftell function.
*/
long
ftell(fp)
register FILE *fp;
{
register off_t rv;
rv = ftello(fp);
if ((long)rv != rv) {
errno = EOVERFLOW;
return (-1);
}
return (rv);
}
/*
* ftello: return current offset.
*/
off_t
ftello(fp)
register FILE *fp;
{
register fpos_t pos;