From: Greg King Date: Fri, 25 Sep 2015 18:06:58 +0000 (-0400) Subject: Moved two errno helper functions into separate files. X-Git-Tag: V2.16~226^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b82bb4f5ba31ea0b1954b36608eba32556c6645e;p=cc65 Moved two errno helper functions into separate files. Only the function that actually is needed will be linked. It is very useful for targets that do not have file-system I/O. --- diff --git a/libsrc/common/_directerrno.s b/libsrc/common/_directerrno.s new file mode 100644 index 000000000..794247148 --- /dev/null +++ b/libsrc/common/_directerrno.s @@ -0,0 +1,27 @@ +; +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King +; +; Helper function for several high-level file functions. +; + + .include "errno.inc" + + .macpack cpu + +; ---------------------------------------------------------------------------- +; int __fastcall__ _directerrno (unsigned char code); +; /* Set errno to a specific error code, clear _oserror, and return -1. Used +; ** by the library. +; */ + +__directerrno: + jsr __seterrno ; Set errno (returns with .A = 0) + sta __oserror ; Clear __oserror +.if (.cpu .bitand CPU_ISET_65SC02) + dec a +.else + lda #$FF ; Return -1 +.endif + tax + rts diff --git a/libsrc/common/_mappederrno.s b/libsrc/common/_mappederrno.s new file mode 100644 index 000000000..33f654c29 --- /dev/null +++ b/libsrc/common/_mappederrno.s @@ -0,0 +1,33 @@ +; +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King +; +; Helper function for several high-level file functions. +; + + .include "errno.inc" + + .macpack generic + .macpack cpu + +; ---------------------------------------------------------------------------- +; int __fastcall__ _mappederrno (unsigned char code); +; /* Set _oserror to the given platform-specific error code. If it is a real +; ** error code (not zero), set errno to the corresponding system error code, +; ** and return -1. Otherwise, return zero. +; ** Used by the library. +; */ + +__mappederrno: + sta __oserror ; Store the error code + tax ; Did we have an error? + bze ok ; Branch if no + jsr __osmaperrno ; Map OS error into errno code + jsr __seterrno ; Save in errno (returns with .A = 0) +.if (.cpu .bitand CPU_ISET_65SC02) + dec a +.else + lda #$FF ; Return -1 if error +.endif + tax +ok: rts diff --git a/libsrc/common/errno.s b/libsrc/common/errno.s index 3a1f1b6c8..f448c3c14 100644 --- a/libsrc/common/errno.s +++ b/libsrc/common/errno.s @@ -1,47 +1,14 @@ ; -; Ullrich von Bassewitz, 2003-08-12 +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King ; -; Helper functions for several high level file functions. +; extern int _errno; +; /* Library errors go here. */ ; - .include "errno.inc" -.code - -; ---------------------------------------------------------------------------- -; int __fastcall__ _directerrno (unsigned char code); -; /* Set errno to a specific error code, clear _oserror and return -1. Used -; ** by the library. -; */ - -__directerrno: - jsr __seterrno ; Set errno, returns with A = 0 - sta __oserror ; Clear __oserror - beq fail ; Branch always - -; ---------------------------------------------------------------------------- -; int __fastcall__ _mappederrno (unsigned char code); -; /* Set _oserror to the given platform specific error code. If it is a real -; ** error code (not zero) set errno to the corresponding system error code -; ** and return -1. Otherwise return zero. -; ** Used by the library. -; */ - -__mappederrno: - sta __oserror ; Store the error code - tax ; Did we have an error? - beq ok ; Branch if no - jsr __osmaperrno ; Map os error into errno code - jsr __seterrno ; Save in errno -fail: lda #$FF ; Return -1 - tax -ok: rts - - -; ---------------------------------------------------------------------------- .bss __errno: .word 0 - diff --git a/libsrc/sim6502/errno.s b/libsrc/sim6502/errno.s deleted file mode 100644 index d9f7e397e..000000000 --- a/libsrc/sim6502/errno.s +++ /dev/null @@ -1,30 +0,0 @@ -; -; 2013-05-16, Oliver Schmidt -; 2015-07-18, Greg King -; -; Helper functions for several high-level functions. -; - - .include "errno.inc" - -; ---------------------------------------------------------------------------- -; int __fastcall__ _directerrno (unsigned char code); -; /* Set errno to a specific error code; and, return -1. Used -; ** by the library. -; */ - -__directerrno: - jsr __seterrno ; Save in errno -fail: lda #$FF ; Return -1 - tax -ok: rts - - -; ---------------------------------------------------------------------------- -; -; extern int _errno; -; - .bss - -__errno: - .word 0