2 ; Christian Groessler, Jan-2003
4 ; int open(const char *name,int flags,...);
13 .destructor closeallfiles, 17
17 .import fddecusage,newfd
19 .import __do_oserror,__seterrno,incsp4
20 .import ldaxysp,addysp
30 cpy #4 ; correct # of arguments (bytes)?
31 beq parmok ; parameter count ok
32 tya ; parm count < 4 shouldn't be needed to be checked
33 sec ; (it generates a c compiler warning)
36 jsr addysp ; fix stack, throw away unused parameters
38 parmok: jsr findfreeiocb
39 beq iocbok ; we found one
41 lda #<EMFILE ; "too many open files"
43 seterr: jsr __seterrno
44 jsr incsp4 ; clean up stack
49 ; process the mode argument
52 jsr clriocb ; init with zero
54 jsr ldaxysp ; get mode
61 cmp #O_RDONLY ; DOS supports append with write-only only
68 .ifndef UCASE_FILENAME
69 invret: lda #<EINVAL ; file name is too long
91 ; process the filename argument
100 invret: lda #<EINVAL ; file name is too long
105 .endif ; defined UCASE_FILENAME
109 ;AX - points to filename
110 ;Y - iocb to use, if open needed
111 jsr newfd ; maybe we don't need to open and can reuse an iocb
112 ; returns fd num to use in tmp2, all regs unchanged
113 bcs doopen ; C set: open needed
114 lda #0 ; clears N flag
133 .ifdef UCASE_FILENAME
135 jsr addysp ; free used space on the stack
136 .endif ; defined UCASE_FILENAME
138 jsr incsp4 ; clean up stack
147 jsr fddecusage ; decrement usage counter of fd as open failed
150 ok: lda tmp2 ; get fd
158 ; closeallfiles: Close all files opened by the program.