scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 25f8a36bd65b91a403016fabc7d3e8fc15575c3b
parent 7110c21ad718ac19314d54b996a29ce1ad9c1016
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  5 Oct 2021 07:47:46 +0200

libc: Don't set ferror if _lseek fails

The C99 standard says literally:

	If a read or write error occurs, the error indicator
	for the stream is set and fseek fails.

and our fseek implementation was setting the error indicator
when the call to _lseek() was failling. _lseek() is not a
a read or write function, so a fail in _lseek() should not
set the error indicator.

Diffstat:
Msrc/libc/stdio/fseek.c | 4+---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/libc/stdio/fseek.c b/src/libc/stdio/fseek.c @@ -16,10 +16,8 @@ fseek(FILE *fp, long off, int whence) else if (whence == SEEK_CUR && (fp->flags & _IOREAD)) off -= fp->wp - fp->rp; - if (_lseek(fp->fd, off, whence) < 0) { - fp->flags |= _IOERR; + if (_lseek(fp->fd, off, whence) < 0) return EOF; - } if (fp->flags & _IORW) fp->flags &= ~(_IOREAD | _IOWRITE);