From ab2f17c24915d95367eebd15f8ff876903430da1 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 24 Jun 2022 18:31:50 -0500 Subject: [PATCH] Clear the IO error indicator as part of rewind(). The C standards require it to do this, in addition to calling fseek. Here is a test that can show the issue (in a realistic program, the indicator would be set due to an actual IO error, but for testing purposes this just sets it explicitly): #include int main(void) { FILE *f = tmpfile(); if (!f) return 0; f->_flag |= _IOERR; if (!ferror(f)) puts("bad ferror"); rewind(f); if (ferror(f)) puts("rewind does not reset ferror"); fclose(f); } --- stdio.asm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/stdio.asm b/stdio.asm index af88cd5..4baac3c 100644 --- a/stdio.asm +++ b/stdio.asm @@ -2473,31 +2473,34 @@ cpNewPathName ds 4 **************************************************************** * -* int rewind(stream) +* void rewind(stream) * FILE *stream; * -* Change the read/write location for the stream. +* Rewind the read/write location for the stream. * * Inputs: * stream - file to change * -* Outputs: -* Returns non-zero for error -* **************************************************************** * rewind start -err equ 1 return code + csubroutine (4:stream),0 - csubroutine (4:stream),2 + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs ret ph2 #SEEK_SET ph4 #0 ph4 stream jsl __fseek - sta err + + ldy #FILE_flag clear the error flag + lda [stream],Y + and #$FFFF-_IOERR + sta [stream],Y - creturn 2:err +ret creturn end ****************************************************************