diff options
Diffstat (limited to 'lib/libc/stdio/ftell.c')
| -rw-r--r-- | lib/libc/stdio/ftell.c | 12 |
1 files changed, 9 insertions, 3 deletions
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) { |
