From: uz Date: Thu, 3 Jun 2010 21:20:10 +0000 (+0000) Subject: Rewrote parts of the code for better error handling. fileno must set errno and X-Git-Tag: V2.13.3~734 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b97986b124e89de15ca591fffb86da92ef69466a;p=cc65 Rewrote parts of the code for better error handling. fileno must set errno and return -1 in case of an invalid argument, which it didn't until now. git-svn-id: svn://svn.cc65.org/cc65/trunk@4698 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/fmisc.s b/libsrc/common/fmisc.s index 98ad7214c..481be4176 100644 --- a/libsrc/common/fmisc.s +++ b/libsrc/common/fmisc.s @@ -9,70 +9,81 @@ .importzp ptr1 .include "_file.inc" + .include "errno.inc" ; -; Get the FILE* parameter, check if the file is open -; - -getf: sta ptr1 - stx ptr1+1 - ldy #_FILE::f_flags - lda (ptr1),y ; get f->f_flags - and #_FOPEN ; file open? - beq @L1 ; jump if no - clc ; ok - rts -@L1: sec +; Get the FILE* parameter, check if the file is open. Returns zero in A +; and zero flag set in case of an error. + +.proc getf + sta ptr1 + stx ptr1+1 + ldy #_FILE::f_flags + lda (ptr1),y ; get f->f_flags + and #_FOPEN ; file open? rts +.endproc ; ; void clearerr (FILE* f); ; -_clearerr: +.proc _clearerr jsr getf - bcs err + beq err lda (ptr1),y and #<~(_FEOF | _FERROR) sta (ptr1),y err: rts +.endproc ; ; int feof (FILE* f); ; -_feof: - jsr getf -; bcs err - lda (ptr1),y - and #_FEOF - ldx #0 +.proc _feof + jsr getf + beq @L1 ; Return 0 on error + lda (ptr1),y + and #_FEOF +@L1: ldx #0 rts +.endproc ; ; int ferror (FILE* f); ; -_ferror: - jsr getf -; bcs err +.proc _ferror + jsr getf + beq @L1 ; Return 0 on error lda (ptr1),y and #_FERROR - ldx #0 +@L1: ldx #0 rts +.endproc ; ; int fileno (FILE* f); ; -_fileno: - jsr getf -; bcs err +.proc _fileno + jsr getf + beq error ldy #_FILE::f_fd lda (ptr1),y ldx #0 rts +; If the file is not valid, fileno must set errno and return -1 + +error: lda #