2 ; Ullrich von Bassewitz, 16.11.2002
4 ; int __fastcall__ close (int fd);
9 .import readdiskerror, closecmdchannel
14 .include "filedes.inc"
17 ;--------------------------------------------------------------------------
22 ; Check if we have a valid handle
26 cmp #MAX_FDS ; Is it valid?
27 bcs invalidfd ; Jump if no
28 sta tmp2 ; Save the handle
30 ; Check if the file is actually open
33 lda fdtab,x ; Get flags for this handle
37 ; Valid lfn, close it. The close call is always error free, at least as far
38 ; as the kernal is involved
44 adc #LFN_OFFS ; Make LFN from handle
47 ; Read the drive error channel, then close it
49 ldy tmp2 ; Get the handle
50 ldx unittab,y ; Get the disk for this handle
51 jsr readdiskerror ; Read the disk error code
52 pha ; Save it on stack
55 jsr closecmdchannel ; Close the disk command channel
56 pla ; Get the error code from the disk
57 jmp __mappederrno ; Set _oserror and _errno, return 0/-1
59 ; Error entry: The given file descriptor is not valid or not open
63 jmp __directerrno ; Set _errno, clear _oserror, return -1