]> git.sur5r.net Git - cc65/blob - libsrc/common/fclose.s
removed some duplicated GEOS conio stuff
[cc65] / libsrc / common / fclose.s
1 ;
2 ; Ullrich von Bassewitz, 22.11.2002
3 ;
4 ; int __fastcall__ fclose (FILE* f);
5 ; /* Close a file */
6 ;
7
8         .export         _fclose
9
10         .import         _close
11         .importzp       ptr1                                   
12
13         .include        "errno.inc"
14         .include        "_file.inc"
15
16 ; ------------------------------------------------------------------------
17 ; Code
18
19 .proc   _fclose
20
21         sta     ptr1
22         stx     ptr1+1          ; Store f
23
24 ; Check if the file is really open
25
26         ldy     #_FILE_f_flags
27         lda     (ptr1),y
28         and     #_FOPEN
29         bne     @L1
30
31 ; File is not open
32
33         lda     #EINVAL
34         sta     __errno
35         ldx     #0
36         stx     __errno+1
37         dex
38         txa
39         rts
40
41 ; File is open. Reset the flags and close the file.
42
43 @L1:    lda     #_FCLOSED
44         sta     (ptr1),y
45
46         ldy     #_FILE_f_fd
47         lda     (ptr1),y
48         ldx     #0
49         jmp     _close          ; Will set errno and return an error flag
50
51 .endproc
52