mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2025-08-07 12:25:11 +00:00
Fix bug with fseek(..., SEEK_CUR) on read-only streams.
This would seek to the wrong location, and in some cases try to seek before the beginning of the file, leading to an error condition. The problem stemmed from fseek calling fflush, which sets up the stream's buffer state in a way appropriate for writing but not for reading. It then calls ftell, which (for a read-only stream) would misinterpret this state and miscalculate the current position. The fix is to make fflush work correctly on a read-only stream, setting up the state for reading. (User code calling fflush on a read-only stream would be undefined behavior, but since fseek does it we need to make it work.) This fixes #6.
This commit is contained in:
11
stdio.asm
11
stdio.asm
@@ -4500,13 +4500,20 @@ orVal ds 2 for setting the case of characters
|
||||
dey
|
||||
dey
|
||||
sta [stream],Y
|
||||
ldy #FILE_size set the number of chars the buffer
|
||||
ldy #FILE_flag if read stream
|
||||
lda [stream],Y
|
||||
bit _IOREAD
|
||||
beq ib1
|
||||
lda #0 set count of chars in buffer to 0
|
||||
tax
|
||||
bra ib2 else
|
||||
ib1 ldy #FILE_size set the number of chars the buffer
|
||||
lda [stream],Y can hold
|
||||
tax
|
||||
iny
|
||||
iny
|
||||
lda [stream],Y
|
||||
ldy #FILE_cnt+2
|
||||
ib2 ldy #FILE_cnt+2
|
||||
sta [stream],Y
|
||||
dey
|
||||
dey
|
||||
|
Reference in New Issue
Block a user