]> git.sur5r.net Git - cc65/blob - libsrc/common/fmisc.s
Updated to use cbm_kernal.inc. Whitespace cleanups
[cc65] / libsrc / common / fmisc.s
1 ;
2 ; Ullrich von Bassewitz, 31.05.1998
3 ;
4 ; Several small file stream functions
5 ;
6
7         .export         _clearerr, _feof, _ferror, _fileno, _fflush
8         .import         return0
9         .importzp       ptr1
10
11         .include        "_file.inc"
12         .include        "errno.inc"
13
14 ;
15 ; Get the FILE* parameter, check if the file is open. Returns zero in A
16 ; and zero flag set in case of an error.
17
18 .proc   getf
19         sta     ptr1
20         stx     ptr1+1
21         ldy     #_FILE::f_flags
22         lda     (ptr1),y        ; get f->f_flags
23         and     #_FOPEN         ; file open?
24         rts
25 .endproc
26
27 ;
28 ; void clearerr (FILE* f);
29 ;
30
31 .proc   _clearerr
32         jsr     getf
33         beq     err
34         lda     (ptr1),y
35         and     #<~(_FEOF | _FERROR)
36         sta     (ptr1),y
37 err:    rts
38 .endproc
39
40 ;
41 ; int feof (FILE* f);
42 ;
43
44 .proc   _feof
45         jsr     getf
46         beq     @L1             ; Return 0 on error
47         lda     (ptr1),y
48         and     #_FEOF
49 @L1:    ldx     #0
50         rts
51 .endproc
52
53 ;
54 ; int ferror (FILE* f);
55 ;
56
57 .proc   _ferror
58         jsr     getf
59         beq     @L1             ; Return 0 on error
60         lda     (ptr1),y
61         and     #_FERROR
62 @L1:    ldx     #0
63         rts
64 .endproc
65
66 ;
67 ; int fileno (FILE* f);
68 ;
69
70 .proc   _fileno
71         jsr     getf
72         beq     error
73         ldy     #_FILE::f_fd
74         lda     (ptr1),y
75         ldx     #0
76         rts
77
78 ; If the file is not valid, fileno must set errno and return -1
79
80 error:  lda     #<EBADF
81         jsr     __seterrno
82         lda     #$FF
83         tax
84         rts
85 .endproc
86
87 ;
88 ; int __fastcall__ fflush (FILE* f);
89 ;
90
91 _fflush = return0
92
93