summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordt <dt@FreeBSD.org>1999-02-08 21:32:38 +0000
committerdt <dt@FreeBSD.org>1999-02-08 21:32:38 +0000
commitdd5f24e20cdd683adbb5885bb01814ac81fbc90b (patch)
tree2f7f0b89a7c12e8dce152773c267d5fe10f78eb6 /lib
parentaf242fbed135e989cc0ff0985a4ebdad783ef2eb (diff)
downloadFreeBSD-src-dd5f24e20cdd683adbb5885bb01814ac81fbc90b.zip
FreeBSD-src-dd5f24e20cdd683adbb5885bb01814ac81fbc90b.tar.gz
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)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/Makefile.inc3
-rw-r--r--lib/libc/stdio/fgetpos.c4
-rw-r--r--lib/libc/stdio/fseek.350
-rw-r--r--lib/libc/stdio/fseek.c15
-rw-r--r--lib/libc/stdio/fsetpos.c5
-rw-r--r--lib/libc/stdio/ftell.c21
6 files changed, 83 insertions, 15 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc
index fc9b803..09a6030 100644
--- a/lib/libc/stdio/Makefile.inc
+++ b/lib/libc/stdio/Makefile.inc
@@ -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
diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c
index 7cac82e..eed7b13 100644
--- a/lib/libc/stdio/fgetpos.c
+++ b/lib/libc/stdio/fgetpos.c
@@ -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);
}
diff --git a/lib/libc/stdio/fseek.3 b/lib/libc/stdio/fseek.3
index 5dd79e9..064130a 100644
--- a/lib/libc/stdio/fseek.3
+++ b/lib/libc/stdio/fseek.3
@@ -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 .
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c
index 808d3ae..7d7254a 100644
--- a/lib/libc/stdio/fseek.c
+++ b/lib/libc/stdio/fseek.c
@@ -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));
diff --git a/lib/libc/stdio/fsetpos.c b/lib/libc/stdio/fsetpos.c
index d521a20..72a4bf2 100644
--- a/lib/libc/stdio/fsetpos.c
+++ b/lib/libc/stdio/fsetpos.c
@@ -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));
}
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 34da271..552ed21 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -39,21 +39,38 @@
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;
if (fp->_seek == NULL) {
OpenPOWER on IntegriCloud