1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Fixed sources to use the new __mappederrno and __directerrno functions, and

made handling of _oserror and errno consistent.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4731 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-06-26 11:28:44 +00:00
parent 672cffa1d2
commit ae98a6db40
4 changed files with 44 additions and 55 deletions

View File

@ -55,13 +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 __mappederrno ; Set _oserror and _errno, returns 0/-1 jmp __mappederrno ; Set _oserror and _errno, return 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 jmp __directerrno ; Set _errno, clear _oserror, return -1
.endproc .endproc

View File

@ -10,11 +10,11 @@
.import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST .import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST
.import rwcommon .import rwcommon
.import popax .import popax
.import __oserror
.importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3 .importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3
.include "fcntl.inc"
.include "cbm.inc" .include "cbm.inc"
.include "errno.inc"
.include "fcntl.inc"
.include "filedes.inc" .include "filedes.inc"
@ -44,7 +44,7 @@
.proc _read .proc _read
jsr rwcommon ; Pop params, check handle jsr rwcommon ; Pop params, check handle
bcs errout ; Invalid handle, errno already set bcs invalidfd ; Invalid handle
; Check if the LFN is valid and the file is open for writing ; Check if the LFN is valid and the file is open for writing
@ -52,7 +52,7 @@
tax tax
lda fdtab-LFN_OFFS,x; Get flags for this handle lda fdtab-LFN_OFFS,x; Get flags for this handle
and #LFN_READ ; File open for writing? and #LFN_READ ; File open for writing?
beq notopen beq invalidfd
; Check the EOF flag. If it is set, don't read anything ; Check the EOF flag. If it is set, don't read anything
@ -62,11 +62,8 @@
; Valid lfn. Make it the input file ; Valid lfn. Make it the input file
jsr CHKIN jsr CHKIN
bcs error bcc @L3 ; Branch if ok
jmp __mappederrno ; Store into __oserror, map to errno, return -1
; Go looping...
bcc @L3 ; Branch always
; Read the next byte ; Read the next byte
@ -76,7 +73,7 @@
jsr READST ; Read the IEEE status jsr READST ; Read the IEEE status
sta tmp3 ; Save it sta tmp3 ; Save it
and #%10111111 ; Check anything but the EOI bit and #%10111111 ; Check anything but the EOI bit
bne error5 ; Assume device not present bne devnotpresent ; Assume device not present
; Store the byte just read ; Store the byte just read
@ -118,25 +115,25 @@
done: jsr CLRCH done: jsr CLRCH
; Return the number of chars read ; Clear _oserror and return the number of chars read
eof: lda ptr3 eof: lda #0
sta __oserror
lda ptr3
ldx ptr3+1 ldx ptr3+1
rts rts
; Error entry, file is not open ; Error entry: Device not present
notopen: devnotpresent:
lda #3 ; File not open lda #ENODEV
bne error jmp __directerrno ; Sets _errno, clears _oserror, returns -1
; Error entry, status not ok ; Error entry: The given file descriptor is not valid or not open
error5: lda #5 ; Device not present invalidfd:
error: sta __oserror lda #EBADF
errout: lda #$FF jmp __directerrno ; Sets _errno, clears _oserror, returns -1
tax ; Return -1
rts
.endproc .endproc

View File

@ -37,18 +37,10 @@
jsr popax ; Get the handle jsr popax ; Get the handle
cpx #$01 cpx #$01
bcs invhandle bcs @L9
cmp #MAX_FDS cmp #MAX_FDS ; Set carry if fd too large
bcs invhandle
sta tmp2 sta tmp2
rts ; Return with carry clear @L9: rts ; Return with result in carry
invhandle:
lda #EINVAL
sta __errno
lda #0
sta __errno+1
rts ; Return with carry set
.endproc .endproc

View File

@ -9,11 +9,11 @@
.import SETLFS, OPEN, CKOUT, BSOUT, CLRCH .import SETLFS, OPEN, CKOUT, BSOUT, CLRCH
.import rwcommon .import rwcommon
.import __oserror
.importzp sp, ptr1, ptr2, ptr3 .importzp sp, ptr1, ptr2, ptr3
.include "fcntl.inc"
.include "cbm.inc" .include "cbm.inc"
.include "errno.inc"
.include "fcntl.inc"
.include "filedes.inc" .include "filedes.inc"
@ -48,7 +48,7 @@
.proc _write .proc _write
jsr rwcommon ; Pop params, check handle jsr rwcommon ; Pop params, check handle
bcs errout ; Invalid handle, errno already set bcs invalidfd ; Invalid handle
; Check if the LFN is valid and the file is open for writing ; Check if the LFN is valid and the file is open for writing
@ -56,13 +56,13 @@
tax tax
lda fdtab-LFN_OFFS,x; Get flags for this handle lda fdtab-LFN_OFFS,x; Get flags for this handle
and #LFN_WRITE ; File open for writing? and #LFN_WRITE ; File open for writing?
beq notopen beq invalidfd
; Valid lfn. Make it the output file ; Valid lfn. Make it the output file
jsr CKOUT jsr CKOUT
bcs error
bcc @L2 bcc @L2
@error: jmp __mappederrno ; Store into __oserror, map to errno, return -1
; Output the next character from the buffer ; Output the next character from the buffer
@ -72,7 +72,7 @@
bne @L1 bne @L1
inc ptr2+1 ; A = *buf++; inc ptr2+1 ; A = *buf++;
@L1: jsr BSOUT @L1: jsr BSOUT
bcs error ; Bail out on errors bcs @error ; Bail out on errors
; Count characters written ; Count characters written
@ -91,25 +91,25 @@
jsr CLRCH jsr CLRCH
; Return the number of chars written ; Clear _oserror and return the number of chars written
lda #0
sta __oserror
lda ptr3 lda ptr3
ldx ptr3+1 ldx ptr3+1
rts rts
; Error entry, file is not open ; Error entry: Device not present
notopen: devnotpresent:
lda #3 ; File not open lda #ENODEV
bne error jmp __directerrno ; Sets _errno, clears _oserror, returns -1
; Error entry, status not ok ; Error entry: The given file descriptor is not valid or not open
error5: lda #5 ; Device not present invalidfd:
error: sta __oserror lda #EBADF
errout: lda #$FF jmp __directerrno ; Sets _errno, clears _oserror, returns -1
tax ; Return -1
rts
.endproc .endproc