[uClibc]fseek(3) idempotency

Matt Kraai kraai at alumni.carnegiemellon.edu
Tue Sep 25 19:24:21 UTC 2001


On Tue, Sep 25, 2001 at 12:48:14PM -0600, Manuel Novoa III wrote:
> Yes.  After rereading the standards, I agree that the stream error flag
> shouldn't be set just because lseek fails.  Note though that the error
> flag can be set indirectly by an fseek() call if it needs to flush any
> buffered writes and the write call fails.  That is allowed by ANSI/ISO,
> even if it isn't mentioned by SUSv2.

Hmm, I don't have write access to uClibc, so could someone please
commit the following patch?

Matt

--- libc/stdio/stdio.c	Tue Sep 25 13:20:33 2001
+++ libc/stdio/stdio.c.bak	Tue Sep 25 09:21:18 2001
@@ -588,15 +588,14 @@
 				--offset;			/* adjust offset (clear flag below). */
 			}
 		}
-		fp->bufpos = fp->bufread = fp->bufstart;
 	}
 
 	if ((fp->mode & __MODE_ERR) || 
 		(((ref != SEEK_CUR) || offset) && (lseek(fp->fd, offset, ref) < 0))) {
-		fp->mode |= __MODE_ERR;	/* Possibly redundant, but doesn't hurt. */
 		return -1;
 	}
 
+	fp->bufpos = fp->bufread = fp->bufstart;
 	fp->mode &=	~(__MODE_EOF | __MODE_UNGOT);
 
 	return 0;





More information about the uClibc mailing list