]> git.sur5r.net Git - cc65/blob - libsrc/common/fopen.s
Merge remote-tracking branch 'irgendwer/AtariOS_Structure' into master
[cc65] / libsrc / common / fopen.s
1 ;
2 ; Ullrich von Bassewitz, 22.11.2002
3 ;
4 ; FILE* __fastcall__ fopen (const char* name, const char* mode)
5 ; /* Open a file */
6 ;
7
8         .export         _fopen
9
10         .import         __fopen, __fdesc
11         .import         pushax, return0
12
13         .include        "errno.inc"
14
15
16 ; ------------------------------------------------------------------------
17 ; Code
18
19 .proc   _fopen
20
21 ; Bring the mode parameter on the stack
22
23         jsr     pushax
24
25 ; Allocate a new file stream
26
27         jsr     __fdesc
28
29 ; Check if we have a stream
30
31         cmp     #$00
32         bne     @L1
33         cpx     #$00
34         bne     @L1
35
36 ; Failed to allocate a file stream
37
38         lda     #EMFILE
39         jsr     __seterrno      ; Set __errno, will return 0 in A
40         tax
41         rts                     ; Return zero
42
43 ; Open the file and return the file descriptor. All arguments are already
44 ; in place: name and mode on the stack, and f in a/x
45
46 @L1:    jmp     __fopen
47
48 .endproc
49