diff options
| author | Dmitrij Tejblum <dt@FreeBSD.org> | 1999-05-05 22:18:12 +0000 |
|---|---|---|
| committer | Dmitrij Tejblum <dt@FreeBSD.org> | 1999-05-05 22:18:12 +0000 |
| commit | c0d0cd800b91e3c706c1218001a59dd187a41f4b (patch) | |
| tree | 10ff5588eb741a24d89158610d7a39ddc89590cc /lib/libc/stdio | |
| parent | f9b77ed91ea12fbae83af78b6b5ceafe81e13857 (diff) | |
Notes
Diffstat (limited to 'lib/libc/stdio')
| -rw-r--r-- | lib/libc/stdio/Makefile.inc | 5 | ||||
| -rw-r--r-- | lib/libc/stdio/fgetpos.c | 4 | ||||
| -rw-r--r-- | lib/libc/stdio/fseek.3 | 56 | ||||
| -rw-r--r-- | lib/libc/stdio/fseek.c | 15 | ||||
| -rw-r--r-- | lib/libc/stdio/fsetpos.c | 5 | ||||
| -rw-r--r-- | lib/libc/stdio/ftell.c | 21 |
6 files changed, 88 insertions, 18 deletions
diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index fc9b8034ce04..699374930d4d 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.17 1999/03/05 13:01:22 bde Exp $ # stdio sources .PATH: ${.CURDIR}/../libc/stdio @@ -27,7 +27,8 @@ MLINKS+=fgets.3 gets.3 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 fgetpos.3 fseek.3 fseeko.3 fseek.3 fsetpos.3 fseek.3 ftell.3 \ + fseek.3 ftello.3 fseek.3 rewind.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 7cac82eeab6b..bbb5cca7d2a7 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.7 1999/02/08 21:32:38 dt 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 5dd79e91aa50..37afb0eb7a3c 100644 --- a/lib/libc/stdio/fseek.3 +++ b/lib/libc/stdio/fseek.3 @@ -34,15 +34,18 @@ .\" SUCH DAMAGE. .\" .\" @(#)fseek.3 8.1 (Berkeley) 6/4/93 +.\" $Id: fseek.3,v 1.4 1999/03/05 12:56:37 bde Exp $ .\" -.Dd June 4, 1993 +.Dd Mar 5, 1999 .Dt FSEEK 3 .Os .Sh NAME .Nm fgetpos , .Nm fseek , +.Nm fseeko , .Nm fsetpos , .Nm ftell , +.Nm ftello , .Nm rewind .Nd reposition a stream .Sh SYNOPSIS @@ -57,6 +60,11 @@ .Fn fgetpos "FILE *stream" "fpos_t *pos" .Ft int .Fn fsetpos "FILE *stream" "const fpos_t *pos" +.Fd #include <sys/types.h> +.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 +114,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 , +except it takes an +.Fa off_t +argument +instead of a +.Fa long . +Likewise, the +.Fn ftello +function is identical to +.Fn ftell , +except it returns an +.Fa off_t . +.Pp +The .Fn fgetpos and .Fn fsetpos @@ -115,8 +139,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,11 +157,15 @@ returns no value. Upon successful completion, .Fn fgetpos , .Fn fseek , +.Fn fseeko , +and .Fn fsetpos return 0, and .Fn ftell -returns the current offset. +and +.Fn ftello +return the current offset. Otherwise, \-1 is returned and the global variable errno is set to indicate the error. .Sh ERRORS @@ -157,14 +185,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 +221,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 808d3ae3a153..e6d3915351e1 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.8 1999/02/08 21:32:38 dt 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 d521a2054871..ec7bab6aa585 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.6 1999/02/08 21:32:38 dt 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 34da2713321b..ca739c80285f 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.10 1999/02/08 21:32:38 dt 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) { |
