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