]> git.sur5r.net Git - cc65/blob - libsrc/common/fgetc.c
New loadable mouse drivers
[cc65] / libsrc / common / fgetc.c
1 /*
2  * fgetc.c
3  *
4  * (C) Copyright 1998, 2002 Ullrich von Bassewitz (uz@cc65.org)
5  *
6  */
7
8
9
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <errno.h>
13 #include "_file.h"
14
15
16
17 /*****************************************************************************/
18 /*                                   Code                                    */
19 /*****************************************************************************/
20
21
22
23 int __fastcall__ fgetc (FILE* f)
24 {
25     unsigned char c;
26
27     /* Check if the file is open or if there is an error condition */
28     if ((f->f_flags & _FOPEN) == 0 || (f->f_flags & (_FERROR | _FEOF)) != 0) {
29         return EOF;
30     }
31
32     /* Read the byte */
33     switch (read (f->f_fd, &c, 1)) {
34
35         case -1:
36             /* Error */
37             f->f_flags |= _FERROR;
38             return EOF;
39
40         case 0:
41             /* EOF */
42             f->f_flags |= _FEOF;
43             return EOF;
44
45         default:
46             /* Char read */
47             return c;
48
49     }
50 }
51
52
53