From b81b4e1109782405d8e23f13666e819d94be70a6 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 15 Oct 2022 19:01:16 -0500 Subject: [PATCH] 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). --- stdio.asm | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/stdio.asm b/stdio.asm index 7ae9d4b..8befdf1 100644 --- a/stdio.asm +++ b/stdio.asm @@ -688,24 +688,26 @@ disp equ 1 disp in s ph4 stdin if error encountered, return NULL + jsl ferror + tax + beq rts else return s +err stz s stz s+2 bra rts lb2 cmp #LF quit if it was a \n