From: cuz Date: Thu, 13 May 2004 21:09:08 +0000 (+0000) Subject: Use a subroutine to set errno to save some space. X-Git-Tag: V2.12.0~798 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8f7b91eea643dd6d0f1e280d976e4c7e04bad606;p=cc65 Use a subroutine to set errno to save some space. git-svn-id: svn://svn.cc65.org/cc65/trunk@3032 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index 21ed8aa29..6d4b5a06d 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -67,6 +67,7 @@ S_OBJS = _cwd.o \ _heapmemavail.o \ _oserror.o \ _printf.o \ + _seterrno.o \ _swap.o \ _sys.o \ abs.o \ diff --git a/libsrc/common/_fopen.s b/libsrc/common/_fopen.s index a7a9eb4b5..29f1c4cd9 100644 --- a/libsrc/common/_fopen.s +++ b/libsrc/common/_fopen.s @@ -69,10 +69,8 @@ invmode: lda #EINVAL - sta __errno - lda #0 - sta __errno+1 - tax + jsr __seterrno ; Set __errno, returns zero in A + tax ; a/x = 0 jmp incsp4 ; Mode string successfully parsed. Store the binary mode onto the stack in diff --git a/libsrc/common/_seterrno.s b/libsrc/common/_seterrno.s new file mode 100644 index 000000000..4321252be --- /dev/null +++ b/libsrc/common/_seterrno.s @@ -0,0 +1,22 @@ +; +; Ullrich von Bassewitz, 2004-05-13 +; +; __seterrno: Will set __errno to the value in A and return zero in A. Other +; registers aren't changed. The function is C callable, but +; currently only called from asm code. +; + + .include "errno.inc" + +.code + +.proc __seterrno + + sta __errno + lda #0 + sta __errno+1 + rts + +.endproc + + diff --git a/libsrc/common/atexit.s b/libsrc/common/atexit.s index 9827f7123..b66cce8e8 100644 --- a/libsrc/common/atexit.s +++ b/libsrc/common/atexit.s @@ -38,10 +38,8 @@ ; Error, no space left @Error: lda #ENOSPC ; No space left - sta __errno - ldx #$00 - stx __errno+1 - dex ; Make return value -1 + jsr __seterrno + ldx #$FF ; Return -1 txa rts diff --git a/libsrc/common/fclose.s b/libsrc/common/fclose.s index 0d43aa47e..5365d70da 100644 --- a/libsrc/common/fclose.s +++ b/libsrc/common/fclose.s @@ -31,11 +31,9 @@ ; File is not open lda #EINVAL - sta __errno - ldx #0 - stx __errno+1 - dex - txa + jsr __seterrno + lda #$FF ; Return -1 + tax rts ; File is open. Reset the flags and close the file. diff --git a/libsrc/common/fopen.s b/libsrc/common/fopen.s index 791dfcff5..d4d94acee 100644 --- a/libsrc/common/fopen.s +++ b/libsrc/common/fopen.s @@ -36,9 +36,7 @@ ; Failed to allocate a file stream lda #EMFILE - sta __errno - lda #0 - sta __errno+1 + jsr __seterrno ; Set __errno, will return 0 in A tax rts ; Return zero diff --git a/libsrc/common/fread.s b/libsrc/common/fread.s index c4941513d..e65f33bea 100644 --- a/libsrc/common/fread.s +++ b/libsrc/common/fread.s @@ -38,10 +38,8 @@ ; File not open - lda #EINVAL - sta __errno - lda #0 - sta __errno+1 + lda #EINVAL + jsr __seterrno @L1: jsr incsp6 jmp return0 diff --git a/libsrc/common/fwrite.s b/libsrc/common/fwrite.s index ef9c08d9e..586960d50 100644 --- a/libsrc/common/fwrite.s +++ b/libsrc/common/fwrite.s @@ -39,9 +39,7 @@ ; File not open lda #EINVAL - sta __errno - lda #0 - sta __errno+1 + jsr __seterrno @L1: jsr incsp6 jmp return0 diff --git a/libsrc/common/time.s b/libsrc/common/time.s index 9220b7f19..00171a82a 100644 --- a/libsrc/common/time.s +++ b/libsrc/common/time.s @@ -52,11 +52,9 @@ @L1: ldy sreg+1 bpl @L2 - - lda #$00 - sta __errno+1 + lda #ENOSYS ; Function not implemented - sta __errno + jsr __seterrno ; Set __errno ; Reload the low byte of the result and return