Renamed oserrcheck to __mappederrno. Added an additional function named
__directerrno and moved both to errno.s. Changed several sources to use these
functions. Needs testing.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4718 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
;
|
;
|
||||||
; Ullrich von Bassewitz, 16.05.2000
|
; Ullrich von Bassewitz, 16.05.2000
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
.global __errno, __oserror
|
.global __errno, __oserror
|
||||||
.global __osmaperrno
|
.global __osmaperrno
|
||||||
.global __seterrno
|
.global __seterrno
|
||||||
.global oserrcheck
|
.global __directerrno, __mappederrno
|
||||||
|
|
||||||
; Error codes, must match the values in the C headers
|
; Error codes, must match the values in the C headers
|
||||||
.enum
|
.enum
|
||||||
|
|||||||
@@ -38,23 +38,20 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Operating system specific error codes */
|
/*****************************************************************************/
|
||||||
|
/* Data */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Operating system specific error code */
|
||||||
extern unsigned char _oserror;
|
extern unsigned char _oserror;
|
||||||
|
|
||||||
/* The following functions maps an operating system specific error code (for
|
|
||||||
* example from _oserror) into one of the E... codes below. It is user
|
|
||||||
* callable.
|
|
||||||
*/
|
|
||||||
int __fastcall__ _osmaperrno (unsigned char oserror);
|
|
||||||
|
|
||||||
/* Set errno to a specific error code and return zero. Used by the library */
|
|
||||||
unsigned char __fastcall__ _seterrno (unsigned char code);
|
|
||||||
|
|
||||||
/* System error codes go here */
|
|
||||||
extern int _errno;
|
extern int _errno;
|
||||||
|
/* System errors go here */
|
||||||
|
|
||||||
/* errno must be a macro */
|
|
||||||
#define errno _errno
|
#define errno _errno
|
||||||
|
/* errno must be a macro */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -79,6 +76,35 @@ extern int _errno;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int __fastcall__ _osmaperrno (unsigned char oserror);
|
||||||
|
/* Map an operating system specific error code (for example from _oserror)
|
||||||
|
* into one of the E... codes above. It is user callable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
unsigned char __fastcall__ _seterrno (unsigned char code);
|
||||||
|
/* Set errno to a specific error code and return zero. Used by the library */
|
||||||
|
|
||||||
|
int __fastcall__ _directerrno (unsigned char code);
|
||||||
|
/* Set errno to a specific error code, clear _oserror and return -1. Used
|
||||||
|
* by the library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of errno.h */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
; _close
|
; _close
|
||||||
|
|
||||||
.proc _close
|
.proc _close
|
||||||
|
|
||||||
; Check if we have a valid handle
|
; Check if we have a valid handle
|
||||||
@@ -55,20 +55,13 @@
|
|||||||
ldx unittab,y
|
ldx unittab,y
|
||||||
jsr closecmdchannel ; Close the disk command channel
|
jsr closecmdchannel ; Close the disk command channel
|
||||||
pla ; Get the error code from the disk
|
pla ; Get the error code from the disk
|
||||||
jmp oserrcheck ; Set _oserror and _errno, returns 0/-1
|
jmp __mappederrno ; Set _oserror and _errno, returns 0/-1
|
||||||
|
|
||||||
; Error entry: The given file descriptor is not valid or not open
|
; Error entry: The given file descriptor is not valid or not open
|
||||||
|
|
||||||
invalidfd:
|
invalidfd:
|
||||||
lda #EBADF
|
lda #EBADF
|
||||||
|
jmp __directerrno ; Sets _errno, clears _oserror, returns -1
|
||||||
; Error entry. Sets _errno, clears _oserror, returns -1
|
|
||||||
|
|
||||||
error: jsr __seterrno ; Returns 0 in A
|
|
||||||
sta __oserror
|
|
||||||
lda #$FF
|
|
||||||
tax ; Return -1
|
|
||||||
rts
|
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
.import addysp, popax
|
.import addysp, popax
|
||||||
.import scratch, fnparse, fnaddmode, fncomplete, fnset
|
.import scratch, fnparse, fnaddmode, fncomplete, fnset
|
||||||
.import opencmdchannel, closecmdchannel, readdiskerror
|
.import opencmdchannel, closecmdchannel, readdiskerror
|
||||||
.import __oserror
|
|
||||||
.import fnunit
|
.import fnunit
|
||||||
.import _close
|
.import _close
|
||||||
.importzp sp, tmp2, tmp3
|
.importzp sp, tmp2, tmp3
|
||||||
@@ -76,12 +75,13 @@ parmok: jsr popax ; Get flags
|
|||||||
jsr popax ; Get name
|
jsr popax ; Get name
|
||||||
jsr fnparse ; Parse it
|
jsr fnparse ; Parse it
|
||||||
cmp #0
|
cmp #0
|
||||||
bne error ; Bail out if problem with name
|
bne oserror ; Bail out if problem with name
|
||||||
|
|
||||||
; Get a free file handle and remember it in tmp2
|
; Get a free file handle and remember it in tmp2
|
||||||
|
|
||||||
jsr freefd
|
jsr freefd
|
||||||
bcs nofile
|
lda #EMFILE ; Load error code
|
||||||
|
bcs seterrno ; Jump in case of errors
|
||||||
stx tmp2
|
stx tmp2
|
||||||
|
|
||||||
; Check the flags. We cannot have both, read and write flags set, and we cannot
|
; Check the flags. We cannot have both, read and write flags set, and we cannot
|
||||||
@@ -92,10 +92,36 @@ parmok: jsr popax ; Get flags
|
|||||||
cmp #O_RDONLY ; Open for reading?
|
cmp #O_RDONLY ; Open for reading?
|
||||||
beq doread ; Yes: Branch
|
beq doread ; Yes: Branch
|
||||||
cmp #(O_WRONLY | O_CREAT) ; Open for writing?
|
cmp #(O_WRONLY | O_CREAT) ; Open for writing?
|
||||||
bne invflags ; No: Invalid open mode
|
beq flagsok
|
||||||
|
|
||||||
|
; Invalid open mode
|
||||||
|
|
||||||
|
lda #EINVAL
|
||||||
|
|
||||||
|
; Error entry. Sets _errno, clears _oserror, returns -1
|
||||||
|
|
||||||
|
seterrno:
|
||||||
|
jmp __directerrno
|
||||||
|
|
||||||
|
; Error entry: Close the file and exit. OS error code is in A on entry
|
||||||
|
|
||||||
|
closeandexit:
|
||||||
|
pha
|
||||||
|
lda tmp2
|
||||||
|
clc
|
||||||
|
adc #LFN_OFFS
|
||||||
|
jsr CLOSE
|
||||||
|
ldx fnunit
|
||||||
|
jsr closecmdchannel
|
||||||
|
pla
|
||||||
|
|
||||||
|
; Error entry: Set oserror and errno using error code in A and return -1
|
||||||
|
|
||||||
|
oserror:jmp __mappederrno
|
||||||
|
|
||||||
; If O_TRUNC is set, scratch the file, but ignore any errors
|
; If O_TRUNC is set, scratch the file, but ignore any errors
|
||||||
|
|
||||||
|
flagsok:
|
||||||
lda tmp3
|
lda tmp3
|
||||||
and #O_TRUNC
|
and #O_TRUNC
|
||||||
beq notrunc
|
beq notrunc
|
||||||
@@ -136,7 +162,7 @@ common: sta tmp3
|
|||||||
jsr SETLFS ; Set the file params
|
jsr SETLFS ; Set the file params
|
||||||
|
|
||||||
jsr OPEN
|
jsr OPEN
|
||||||
bcs error
|
bcs oserror
|
||||||
|
|
||||||
; Open the the drive command channel and read it
|
; Open the the drive command channel and read it
|
||||||
|
|
||||||
@@ -159,41 +185,9 @@ common: sta tmp3
|
|||||||
|
|
||||||
txa ; Handle
|
txa ; Handle
|
||||||
ldx #0
|
ldx #0
|
||||||
|
stx __oserror ; Clear _oserror
|
||||||
rts
|
rts
|
||||||
|
|
||||||
; Error entry: No more file handles
|
|
||||||
|
|
||||||
nofile: lda #1 ; Too many open files
|
|
||||||
|
|
||||||
; Error entry. Error code is in A.
|
|
||||||
|
|
||||||
error: sta __oserror
|
|
||||||
errout: lda #$FF
|
|
||||||
tax ; Return -1
|
|
||||||
rts
|
|
||||||
|
|
||||||
; Error entry: Invalid flag parameter
|
|
||||||
|
|
||||||
invflags:
|
|
||||||
lda #EINVAL
|
|
||||||
sta __errno
|
|
||||||
lda #0
|
|
||||||
sta __errno+1
|
|
||||||
beq errout
|
|
||||||
|
|
||||||
; Error entry: Close the file and exit
|
|
||||||
|
|
||||||
closeandexit:
|
|
||||||
pha
|
|
||||||
lda tmp2
|
|
||||||
clc
|
|
||||||
adc #LFN_OFFS
|
|
||||||
jsr CLOSE
|
|
||||||
ldx fnunit
|
|
||||||
jsr closecmdchannel
|
|
||||||
pla
|
|
||||||
bne error ; Branch always
|
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ S_OBJS = _cwd.o \
|
|||||||
mkdir.o \
|
mkdir.o \
|
||||||
modfree.o \
|
modfree.o \
|
||||||
modload.o \
|
modload.o \
|
||||||
oserrcheck.o \
|
|
||||||
printf.o \
|
printf.o \
|
||||||
putchar.o \
|
putchar.o \
|
||||||
putenv.o \
|
putenv.o \
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _chdir
|
.export _chdir
|
||||||
|
|
||||||
.import __syschdir
|
.import __syschdir
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
.proc _chdir
|
.proc _chdir
|
||||||
|
|
||||||
jsr __syschdir ; Call the machine specific function
|
jsr __syschdir ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,45 @@
|
|||||||
;
|
;
|
||||||
; Ullrich von Bassewitz, 06.06.1998
|
; Ullrich von Bassewitz, 2003-08-12
|
||||||
;
|
;
|
||||||
; int _errno;
|
; Helper functions for several high level file functions.
|
||||||
;
|
;
|
||||||
|
|
||||||
.export __errno
|
|
||||||
|
|
||||||
|
.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
|
.bss
|
||||||
|
|
||||||
__errno:
|
__errno:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _mkdir
|
.export _mkdir
|
||||||
|
|
||||||
.import __sysmkdir
|
.import __sysmkdir
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -15,6 +15,6 @@
|
|||||||
.proc _mkdir
|
.proc _mkdir
|
||||||
|
|
||||||
jsr __sysmkdir ; Call the machine specific function
|
jsr __sysmkdir ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
;
|
|
||||||
; Ullrich von Bassewitz, 2003-08-12
|
|
||||||
;
|
|
||||||
; Helper function for several high level file functions.
|
|
||||||
;
|
|
||||||
; The function will store the value in A into _oserror. If the value is not
|
|
||||||
; zero, it is translated into a standard error number which is then stored
|
|
||||||
; into errno, and -1 is returned in a/x. If the value in A was zero, errno
|
|
||||||
; is not changed, and zero is returned in a/x.
|
|
||||||
;
|
|
||||||
|
|
||||||
.export oserrcheck
|
|
||||||
|
|
||||||
.include "errno.inc"
|
|
||||||
|
|
||||||
.proc oserrcheck
|
|
||||||
|
|
||||||
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
|
|
||||||
lda #$FF ; Return -1
|
|
||||||
tax
|
|
||||||
ok: rts
|
|
||||||
|
|
||||||
.endproc
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _remove
|
.export _remove
|
||||||
|
|
||||||
.import __sysremove
|
.import __sysremove
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
.proc _remove
|
.proc _remove
|
||||||
|
|
||||||
jsr __sysremove ; Call the machine specific function
|
jsr __sysremove ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _rename
|
.export _rename
|
||||||
|
|
||||||
.import __sysrename
|
.import __sysrename
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
.proc _rename
|
.proc _rename
|
||||||
|
|
||||||
jsr __sysrename ; Call the machine specific function
|
jsr __sysrename ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _rmdir
|
.export _rmdir
|
||||||
|
|
||||||
.import __sysrmdir
|
.import __sysrmdir
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -15,6 +15,6 @@
|
|||||||
.proc _rmdir
|
.proc _rmdir
|
||||||
|
|
||||||
jsr __sysrmdir ; Call the machine specific function
|
jsr __sysrmdir ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
.export _uname
|
.export _uname
|
||||||
|
|
||||||
.import __sysuname
|
.import __sysuname
|
||||||
.import oserrcheck
|
.import __mappederrno
|
||||||
|
|
||||||
|
|
||||||
;--------------------------------------------------------------------------
|
;--------------------------------------------------------------------------
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
.proc _uname
|
.proc _uname
|
||||||
|
|
||||||
jsr __sysuname ; Call the machine specific function
|
jsr __sysuname ; Call the machine specific function
|
||||||
jmp oserrcheck ; Store into _oserror, set errno, return 0/-1
|
jmp __mappederrno ; Store into _oserror, set errno, return 0/-1
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user