]> git.sur5r.net Git - cc65/blob - libsrc/common/oserrcheck.s
Moved reusable parts of remove into oserrcheck.
[cc65] / libsrc / common / oserrcheck.s
1 ;
2 ; Ullrich von Bassewitz, 2003-08-12
3 ;
4 ; Helper function for several high level file functions.
5 ;
6 ; The function will store the value in A into _oserror. If the value is not
7 ; zero, it is translated into a standard error number which is then stored
8 ; into errno, and -1 is returned in a/x. If the value in A was zero, errno
9 ; is not changed, and zero is returned in a/x.
10 ;
11
12         .export         oserrcheck
13         .import         __oserror
14         .import         __osmaperrno
15         .import         __errno
16
17 .proc   oserrcheck
18
19         sta     __oserror               ; Store the error code
20         tay                             ; Did we have an error?
21         beq     ok                      ; Branch if no
22         jsr     __osmaperrno            ; Map os error into errno code
23         sta     __errno
24         stx     __errno+1               ; Save in errno
25         lda     #$FF                    ; Return -1
26
27 ; Error free, A contains zero
28
29 ok:     tax                             ; Make high byte also zero
30         rts
31
32 .endproc
33
34
35