diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-02-21 22:11:23 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-02-21 22:11:23 +0000 |
commit | c73a0ad4b650731afc9ff73ce3efa6a20bc12d0a (patch) | |
tree | cb01bc14f869b62fbde1335281f99360545f3170 /lib/libc/stdio | |
parent | c08bffdba7eb5dccf57b3c21bb64592637f27391 (diff) |
Add fseeko() and ftello() -- versions of fseek() and ftell() that use off_t.
Also make fsetpos() and fgetpos() use fseeko() and ftello() respectively
since fpos_t is actually a 64bit type.
Diffstat (limited to 'lib/libc/stdio')
-rw-r--r-- | lib/libc/stdio/fgetpos.c | 7 | ||||
-rw-r--r-- | lib/libc/stdio/fseek.3 | 54 | ||||
-rw-r--r-- | lib/libc/stdio/fseek.c | 26 | ||||
-rw-r--r-- | lib/libc/stdio/fsetpos.c | 6 | ||||
-rw-r--r-- | lib/libc/stdio/ftell.c | 27 |
5 files changed, 98 insertions, 22 deletions
diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c index 83edbcbcf1e..4ea497c7cf2 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -35,15 +35,18 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fgetpos.c,v 1.2 1996/08/19 08:32:30 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fgetpos.c,v 1.3 2000/02/21 22:11:21 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> +/* + * fgetpos: like ftello. + */ int fgetpos(fp, pos) FILE *fp; fpos_t *pos; { - return((*pos = ftell(fp)) == (fpos_t)-1); + return((*pos = ftello(fp)) == (fpos_t)-1); } diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3 index ec46cdbdbd2..a20f47d10c5 100644 --- a/lib/libc/stdio/fseek.3 +++ b/lib/libc/stdio/fseek.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fseek.3,v 1.4 1999/07/09 13:35:23 aaron Exp $ +.\" $OpenBSD: fseek.3,v 1.5 2000/02/21 22:11:22 millert Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -35,13 +35,15 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 4, 1993 +.Dd February 21, 2000 .Dt FSEEK 3 .Os .Sh NAME .Nm fgetpos , .Nm fseek , +.Nm fseeko , .Nm fsetpos , +.Nm ftello , .Nm ftell , .Nm rewind .Nd reposition a stream @@ -49,8 +51,12 @@ .Fd #include <stdio.h> .Ft int .Fn fseek "FILE *stream" "long offset" "int whence" +.Ft int +.Fn fseeko "FILE *stream" "off_t offset" "int whence" .Ft long .Fn ftell "FILE *stream" +.Ft off_t +.Fn ftello "FILE *stream" .Ft void .Fn rewind "FILE *stream" .Ft int @@ -85,6 +91,15 @@ any effects of the function on the same stream. .Pp The +.Fn fseeko +function is identical to +.Fn fseek +except that it takes an +.Dv off_t +as its +.Fa offset . +.Pp +The .Fn ftell function obtains the current value of the file position indicator for the @@ -92,6 +107,13 @@ stream pointed to by .Fa stream . .Pp The +.Fn ftello +function is identical to +.Fn ftell +except that its return value is of type +.Dv off_t . +.Pp +The .Fn rewind function sets the file position indicator for the stream pointed to by @@ -133,14 +155,18 @@ returns no value. Upon successful completion, .Fn fgetpos , .Fn fseek , +.Fn fseeko , .Fn fsetpos -return 0, -and +return 0 and .Fn ftell -returns the current offset. +and +.Fn ftello +return the current offset. Otherwise, .Fn fseek -returns \-1 and +and +.Fn fseeko +return \-1 and the others return a nonzero value and the global variable .Va errno @@ -167,9 +193,11 @@ or The function .Fn fgetpos , .Fn fseek , +.Fn fseeko , .Fn fsetpos , +.Fn ftell , and -.Fn ftell +.Fn ftello may also fail and set .Va errno for any of the errors specified for the routines @@ -190,4 +218,14 @@ and .Fn rewind functions conform to -.St -ansiC . +.St -ansiC +and +.St -xpg4 . +.Pp +The +.Fn fseeko +and +.Fn ftello +functions +conform to +.St -xpg4 . diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 035ac7918c3..8063c6a0d9b 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fseek.c,v 1.2 1996/08/19 08:32:46 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fseek.c,v 1.3 2000/02/21 22:11:22 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -53,9 +53,9 @@ static char rcsid[] = "$OpenBSD: fseek.c,v 1.2 1996/08/19 08:32:46 tholo Exp $"; * `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)); @@ -93,7 +93,7 @@ fseek(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1L) + if (curoff == (fpos_t)-1) return (EOF); } if (fp->_flags & __SRD) { @@ -245,3 +245,21 @@ dumb: fp->_flags &= ~__SEOF; return (0); } + +/* + * fseek()'s offset is a long and sizeof(off_t) != sizeof(long) on all arches + */ +#if defined(__alpha__) && defined(__indr_reference) +__indr_reference(fseeko, fseek); +#else +int +fseek(fp, offset, whence) + register FILE *fp; + long offset; + int whence; +{ + off_t off = offset; + + return(fseeko(fp, off, whence)); +} +#endif diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c index c6fae71d7b0..bc538ee4f7e 100644 --- a/lib/libc/stdio/fsetpos.c +++ b/lib/libc/stdio/fsetpos.c @@ -35,18 +35,18 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: fsetpos.c,v 1.2 1996/08/19 08:32:47 tholo Exp $"; +static char rcsid[] = "$OpenBSD: fsetpos.c,v 1.3 2000/02/21 22:11:22 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> /* - * fsetpos: like fseek. + * fsetpos: like fseeko. */ int fsetpos(iop, pos) FILE *iop; const fpos_t *pos; { - return (fseek(iop, (long)*pos, SEEK_SET)); + return (fseeko(iop, (off_t)*pos, SEEK_SET)); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 64d69266047..c4431fa527e 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: ftell.c,v 1.2 1996/08/19 08:32:47 tholo Exp $"; +static char rcsid[] = "$OpenBSD: ftell.c,v 1.3 2000/02/21 22:11:22 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> @@ -43,17 +43,17 @@ static char rcsid[] = "$OpenBSD: ftell.c,v 1.2 1996/08/19 08:32:47 tholo Exp $"; #include "local.h" /* - * ftell: return current offset. + * ftello: return current offset. */ -long -ftell(fp) +off_t +ftello(fp) register FILE *fp; { register fpos_t pos; if (fp->_seek == NULL) { errno = ESPIPE; /* historic practice */ - return (-1L); + return ((off_t)-1); } /* @@ -87,3 +87,20 @@ ftell(fp) } return (pos); } + +/* + * ftell() returns a long and sizeof(off_t) != sizeof(long) on all arches + */ +#if defined(__alpha__) && defined(__indr_reference) +__indr_reference(ftello, ftell); +#else +long +ftell(fp) + register FILE *fp; +{ + long pos; + + pos = (long)ftello(fp); + return(pos); +} +#endif |