]> git.sur5r.net Git - cc65/blob - libsrc/common/fgetc.c
Avoid unintended file "shadowing".
[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 "_file.h"
13
14
15
16 /*****************************************************************************/
17 /*                                   Code                                    */
18 /*****************************************************************************/
19
20
21
22 int __fastcall__ fgetc (register FILE* f)
23 {
24     unsigned char c;
25
26     /* Check if the file is open or if there is an error condition */
27     if ((f->f_flags & _FOPEN) == 0 || (f->f_flags & (_FERROR | _FEOF)) != 0) {
28         return EOF;
29     }
30
31     /* If we have a pushed back character, return it */
32     if (f->f_flags & _FPUSHBACK) {
33         f->f_flags &= ~_FPUSHBACK;
34         return f->f_pushback;
35     }
36
37     /* Read one byte */
38     switch (read (f->f_fd, &c, 1)) {
39
40         case -1:
41             /* Error */
42             f->f_flags |= _FERROR;
43             return EOF;
44
45         case 0:
46             /* EOF */
47             f->f_flags |= _FEOF;
48             return EOF;
49
50         default:
51             /* Char read */
52             return c;
53
54     }
55 }
56
57
58