shithub: scc

Download patch

ref: 26ec24167f2d789373c64a0b3440628f0337cdc3
parent: cb1b6c86fe82527f4c3c5f8f11ea4f5e4ae6a350
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Oct 5 03:47:46 EDT 2021

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.

--- a/src/libc/stdio/fseek.c
+++ b/src/libc/stdio/fseek.c
@@ -16,10 +16,8 @@
 	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);