1
0
mirror of https://github.com/cc65/cc65.git synced 2025-04-08 19:38:55 +00:00

Merge pull request #2565 from sidneycadot/fix-fgets

Temporary fix for fgets() not using target-specific newline.
This commit is contained in:
Sidney Cadot 2024-12-22 17:59:35 +01:00 committed by GitHub
commit 4802b5b27b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,6 +8,8 @@
.import _fgetc, popptr1, pushptr1, popax, pushax, return0, ___errno
.importzp ptr1, ptr4
.feature string_escapes
.include "errno.inc"
.include "stdio.inc"
.include "_file.inc"
@ -88,7 +90,22 @@ read_loop:
bne :+
inc ptr4+1
: cmp #$0A ; Stop at \n
; The next code line:
;
; .byte $c9, "\n"
;
; corresponds to a CMP #imm with the target-specific newline value as its operand.
; This works because (with the 'string_escapes' feature enabled), the "\n" string
; assembles to the target-specific value for the newline character.
;
; It would be better if we could just write:
;
; cmp #'\n'
;
; Unfortunately, ca65 doesn't currently handle escape characters in character
; constants. In the longer term, fixing that would be the preferred solution.
: .byte $c9, "\n" ; cmp #'\n'
beq done
bne read_loop