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 <stdio.h>
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);
}
This commit is contained in:
Stephen Heumann 2022-06-24 18:31:50 -05:00
parent 997e430562
commit ab2f17c249
1 changed files with 12 additions and 9 deletions

View File

@ -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
****************************************************************