diff options
author | ache <ache@FreeBSD.org> | 2001-09-02 19:10:10 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2001-09-02 19:10:10 +0000 |
commit | 245c459c3f4dcbc6da4c66aebc8879251e9af682 (patch) | |
tree | be15c0be354e09f766522b411a1ad2af5d566a99 /lib/libc/stdio/stdio.c | |
parent | b3ac07522908287b53a4f7e77f2e5205c4f72fb7 (diff) | |
download | FreeBSD-src-245c459c3f4dcbc6da4c66aebc8879251e9af682.zip FreeBSD-src-245c459c3f4dcbc6da4c66aebc8879251e9af682.tar.gz |
Move all stdio internal flags processing and setting out of __sread(),
__swrite() and __sseek() to higher level. According to funopen(3) they all
are just wrappers to something like standard read(2), write(2) and
lseek(2), i.e. must not touch stdio internals because they are replaceable
with any other functions knows nothing about stdio internals. See example
of funopen(3) usage in sendmail sources f.e.
NOTE: this is original stdio bug, not result of my range checkin added.
Diffstat (limited to 'lib/libc/stdio/stdio.c')
-rw-r--r-- | lib/libc/stdio/stdio.c | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c index ea8a4c1..b4bf299 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -45,7 +45,6 @@ static const char rcsid[] = #include "namespace.h" #include <errno.h> #include <fcntl.h> -#include <limits.h> #include <stdio.h> #include <unistd.h> #include "un-namespace.h" @@ -53,7 +52,6 @@ static const char rcsid[] = /* * Small standard I/O/seek/close functions. - * These maintain the `known seek offset' for seek optimisation. */ int __sread(cookie, buf, n) @@ -62,24 +60,8 @@ __sread(cookie, buf, n) int n; { register FILE *fp = cookie; - register int ret; - ret = _read(fp->_file, buf, (size_t)n); - /* if the read succeeded, update the current offset */ - if (ret >= 0) { - if (fp->_flags & __SOFF) { - if (fp->_offset > OFF_MAX - ret) { - errno = EOVERFLOW; - ret = -1; - } else { - fp->_offset += ret; - return (ret); - } - } else - return (ret); - } - fp->_flags &= ~__SOFF; - return (ret); + return(_read(fp->_file, buf, (size_t)n)); } int @@ -90,9 +72,6 @@ __swrite(cookie, buf, n) { register FILE *fp = cookie; - if (fp->_flags & __SAPP) - (void) lseek(fp->_file, (off_t)0, SEEK_END); - fp->_flags &= ~__SOFF; /* in case FAPPEND mode is set */ return (_write(fp->_file, buf, (size_t)n)); } @@ -103,32 +82,8 @@ __sseek(cookie, offset, whence) int whence; { register FILE *fp = cookie; - register off_t ret; - int serrno, errret; - serrno = errno; - errno = 0; - ret = lseek(fp->_file, (off_t)offset, whence); - errret = errno; - if (errno == 0) - errno = serrno; - /* - * Disallow negative seeks per POSIX. - * It is needed here to help upper level caller - * (fseek) in the cases it can't detect. - */ - if (ret < 0) { - if (errret == 0) { - fp->_flags |= __SERR; - errno = EINVAL; - } - fp->_flags &= ~__SOFF; - ret = -1; - } else { - fp->_flags |= __SOFF; - fp->_offset = ret; - } - return (ret); + return (lseek(fp->_file, (off_t)offset, whence)); } int |