]> git.sur5r.net Git - cc65/blob - libsrc/common/_mappederrno.s
Merge pull request #389 from IrgendwerA8/stringimprovements
[cc65] / libsrc / common / _mappederrno.s
1 ;
2 ; 2003-08-12, Ullrich von Bassewitz
3 ; 2015-09-24, Greg King
4 ;
5 ; Helper function for several high-level file functions.
6 ;
7
8         .include        "errno.inc"
9
10         .macpack        generic
11         .macpack        cpu
12
13 ; ----------------------------------------------------------------------------
14 ; int __fastcall__ _mappederrno (unsigned char code);
15 ; /* Set _oserror to the given platform-specific error code. If it is a real
16 ; ** error code (not zero), set errno to the corresponding system error code,
17 ; ** and return -1. Otherwise, return zero.
18 ; ** Used by the library.
19 ; */
20
21 __mappederrno:
22         sta     __oserror               ; Store the error code
23         tax                             ; Did we have an error?
24         bze     ok                      ; Branch if no
25         jsr     __osmaperrno            ; Map OS error into errno code
26         jsr     __seterrno              ; Save in errno (returns with .A = 0)
27 .if (.cpu .bitand CPU_ISET_65SC02)
28         dec     a
29 .else
30         lda     #$FF                    ; Return -1 if error
31 .endif
32         tax
33 ok:     rts