mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2024-06-17 23:29:30 +00:00
Fix several bugs in fgets() and gets().
Bugs fixes: *fgets() would write 2 bytes in the buffer if called with n=1 (should be 1). *fgets() would write 2 bytes in the buffer if it encountered EOF before reading any characters, but the EOF flag had not previously been set. (It should not modify the buffer in this case.) *fgets() and gets() would return NULL if EOF was encountered after reading one or more characters. (They should return the buffer pointer).
This commit is contained in:
parent
505f1c2804
commit
b81b4e1109
38
stdio.asm
38
stdio.asm
|
@ -688,24 +688,26 @@ disp equ 1 disp in s
|
||||||
|
|
||||||
ph4 <stream verify that stream exists
|
ph4 <stream verify that stream exists
|
||||||
jsl ~VerifyStream
|
jsl ~VerifyStream
|
||||||
bcs err1
|
bcs err
|
||||||
ph4 <stream quit with NULL if at EOF
|
stz disp no characters processed so far
|
||||||
jsl feof
|
|
||||||
tax
|
|
||||||
beq lb0
|
|
||||||
err1 stz s
|
|
||||||
stz s+2
|
|
||||||
bra rts
|
|
||||||
lb0 stz disp no characters processed so far
|
|
||||||
lda #0
|
|
||||||
sta [s]
|
|
||||||
dec n leave room for the null terminator
|
dec n leave room for the null terminator
|
||||||
bmi err
|
bmi err
|
||||||
beq err
|
bne lb1
|
||||||
|
short M n = 1: store null terminator only
|
||||||
|
lda #0
|
||||||
|
sta [s]
|
||||||
|
long M
|
||||||
|
bra rts
|
||||||
lb1 ph4 <stream get a character
|
lb1 ph4 <stream get a character
|
||||||
jsl fgetc
|
jsl fgetc
|
||||||
tax quit with error if it is an EOF
|
tax if error or EOF encountered
|
||||||
bpl lb2
|
bpl lb2
|
||||||
|
lda disp if no characters read, return NULL
|
||||||
|
beq err
|
||||||
|
ldy #FILE_flag if error encountered, return NULL
|
||||||
|
lda [stream],Y
|
||||||
|
and #_IOERR
|
||||||
|
beq rts else return s
|
||||||
err stz s
|
err stz s
|
||||||
stz s+2
|
stz s+2
|
||||||
bra rts
|
bra rts
|
||||||
|
@ -2249,9 +2251,15 @@ disp equ 1 disp in s
|
||||||
|
|
||||||
stz disp no characters processed so far
|
stz disp no characters processed so far
|
||||||
lb1 jsl getchar get a character
|
lb1 jsl getchar get a character
|
||||||
tax quit with error if it is an EOF
|
tax if error or EOF encountered
|
||||||
bpl lb2
|
bpl lb2
|
||||||
stz s
|
lda disp if no characters read, return NULL
|
||||||
|
beq err
|
||||||
|
ph4 >stdin if error encountered, return NULL
|
||||||
|
jsl ferror
|
||||||
|
tax
|
||||||
|
beq rts else return s
|
||||||
|
err stz s
|
||||||
stz s+2
|
stz s+2
|
||||||
bra rts
|
bra rts
|
||||||
lb2 cmp #LF quit if it was a \n
|
lb2 cmp #LF quit if it was a \n
|
||||||
|
|
Loading…
Reference in New Issue
Block a user