diff options
| author | Andrey A. Chernov <ache@FreeBSD.org> | 2001-08-30 20:49:47 +0000 |
|---|---|---|
| committer | Andrey A. Chernov <ache@FreeBSD.org> | 2001-08-30 20:49:47 +0000 |
| commit | 57935eeb3db88d457a4cf191698c1eda65f1bc2e (patch) | |
| tree | b5233f91f9af0f77f51575cc524e26be94066702 /lib/libc | |
| parent | 77f71bc5aca018193a57bbb8d9fbcc53eb30ada1 (diff) | |
Notes
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/stdio/fseek.c | 20 | ||||
| -rw-r--r-- | lib/libc/stdio/ftell.c | 12 |
2 files changed, 25 insertions, 7 deletions
diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index aa886d2d28ab..8af60ba2a761 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -151,8 +151,14 @@ _fseeko(fp, offset, whence, ltest) if (HASUB(fp)) { curoff -= fp->_ur; if (curoff < 0) { - errno = EBADF; - return (-1); + if (-curoff <= fp->_r) { + fp->_p -= curoff; + fp->_r += curoff; + curoff = 0; + } else { + errno = EBADF; + return (-1); + } } } } else if ((fp->_flags & __SWR) && fp->_p != NULL) { @@ -261,8 +267,14 @@ _fseeko(fp, offset, whence, ltest) } if (HASUB(fp)) { curoff -= fp->_ur; - if (curoff < 0) - goto dumb; + if (curoff < 0) { + if (-curoff <= fp->_r) { + fp->_p -= curoff; + fp->_r += curoff; + curoff = 0; + } else + goto dumb; + } } } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 38a164e6b609..46a309cea692 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -118,9 +118,15 @@ ftello(fp) if (HASUB(fp)) { pos -= fp->_ur; if (pos < 0) { - errno = EBADF; - FUNLOCKFILE(fp); - return (-1); + if (-pos <= fp->_r) { + fp->_p -= pos; + fp->_r += pos; + pos = 0; + } else { + errno = EBADF; + FUNLOCKFILE(fp); + return (-1); + } } } } else if ((fp->_flags & __SWR) && fp->_p != NULL) { |
