Fix errno/oserror handling.
git-svn-id: svn://svn.cc65.org/cc65/trunk@4711 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
.import CLOSE
|
.import CLOSE
|
||||||
.import readdiskerror, closecmdchannel
|
.import readdiskerror, closecmdchannel
|
||||||
.import __oserror
|
|
||||||
.importzp tmp2
|
.importzp tmp2
|
||||||
|
|
||||||
.include "errno.inc"
|
.include "errno.inc"
|
||||||
@@ -34,7 +33,7 @@
|
|||||||
tax
|
tax
|
||||||
lda fdtab,x ; Get flags for this handle
|
lda fdtab,x ; Get flags for this handle
|
||||||
and #LFN_OPEN
|
and #LFN_OPEN
|
||||||
beq notopen
|
beq invalidfd
|
||||||
|
|
||||||
; Valid lfn, close it. The close call is always error free, at least as far
|
; Valid lfn, close it. The close call is always error free, at least as far
|
||||||
; as the kernal is involved
|
; as the kernal is involved
|
||||||
@@ -49,39 +48,25 @@
|
|||||||
; Read the drive error channel, then close it
|
; Read the drive error channel, then close it
|
||||||
|
|
||||||
ldy tmp2 ; Get the handle
|
ldy tmp2 ; Get the handle
|
||||||
ldx unittab,y ; Get teh disk for this handle
|
ldx unittab,y ; Get the disk for this handle
|
||||||
jsr readdiskerror ; Read the disk error code
|
jsr readdiskerror ; Read the disk error code
|
||||||
pha ; Save it on stack
|
pha ; Save it on stack
|
||||||
ldy tmp2
|
ldy tmp2
|
||||||
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
|
||||||
bne error ; Jump if error
|
jmp oserrcheck ; Set _oserror and _errno, returns 0/-1
|
||||||
|
|
||||||
; Successful
|
; Error entry: The given file descriptor is not valid or not open
|
||||||
|
|
||||||
tax ; Return zero in a/x
|
|
||||||
rts
|
|
||||||
|
|
||||||
; Error entry, file descriptor is invalid
|
|
||||||
|
|
||||||
invalidfd:
|
invalidfd:
|
||||||
lda #EINVAL
|
lda #EBADF
|
||||||
sta __errno
|
|
||||||
lda #0
|
|
||||||
sta __errno+1
|
|
||||||
beq errout
|
|
||||||
|
|
||||||
; Error entry, file is not open
|
; Error entry. Sets _errno, clears _oserror, returns -1
|
||||||
|
|
||||||
notopen:
|
error: jsr __seterrno ; Returns 0 in A
|
||||||
lda #3 ; File not open
|
sta __oserror
|
||||||
bne error
|
lda #$FF
|
||||||
|
|
||||||
; Error entry, status not ok
|
|
||||||
|
|
||||||
error: sta __oserror
|
|
||||||
errout: lda #$FF
|
|
||||||
tax ; Return -1
|
tax ; Return -1
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user