2 ; Christian Groessler, May-2002
4 ; int open(const char *name,int flags,...);
12 .import fddecusage,newfd
14 .import __do_oserror,__seterrno,incsp4
15 .import ldaxysp,addysp
25 cpy #4 ; correct # of arguments (bytes)?
26 beq parmok ; parameter count ok
27 tya ; parm count < 4 shouldn't be needed to be checked
28 sec ; (it generates a c compiler warning)
31 jsr addysp ; fix stack, throw away unused parameters
33 parmok: jsr findfreeiocb
34 beq iocbok ; we found one
36 lda #<EMFILE ; "too many open files"
38 seterr: jsr __seterrno
39 jsr incsp4 ; clean up stack
44 ; process the mode argument
47 jsr clriocb ; init with zero
49 jsr ldaxysp ; get mode
57 cmp #O_RDONLY ; DOS supports append with write-only only
64 .ifndef UCASE_FILENAME
65 invret: lda #<EINVAL ; file name is too long
87 ; process the filename argument
96 invret: lda #<EINVAL ; file name is too long
101 .endif ; defined UCASE_FILENAME
105 ;AX - points to filename
106 ;Y - iocb to use, if open needed
107 jsr newfd ; maybe we don't need to open and can reuse an iocb
108 ; returns fd num to use in tmp2, all regs unchanged
109 bcs doopen ; C set: open needed
110 lda #0 ; clears N flag
129 .ifdef UCASE_FILENAME
131 jsr addysp ; free used space on the stack
132 .endif ; defined UCASE_FILENAME
134 jsr incsp4 ; clean up stack
143 jsr fddecusage ; decrement usage counter of fd as open failed
146 ok: lda tmp2 ; get fd