[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / runtime / io / fileGetc.lc
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1994
3 %
4 \subsection[fileGetc.lc]{hGetChar Runtime Support}
5
6 \begin{code}
7
8 #include "rtsdefs.h"
9 #include "stgio.h"
10 #include "error.h"
11
12 StgInt
13 fileGetc(fp)
14 StgAddr fp;
15 {
16     int c;
17
18     if (feof((FILE *) fp)) {
19         ghc_errtype = ERR_EOF;
20         ghc_errstr = "";
21         return EOF;
22     }
23
24     /* Try to read a character */
25     while ((c = getc((FILE *) fp)) == EOF && errno == EINTR)
26         clearerr((FILE *) fp);
27
28     if (feof((FILE *) fp)) {
29         ghc_errtype = ERR_EOF;
30         ghc_errstr = "";
31     } else if (c == EOF) {
32         cvtErrno();
33         stdErrno();
34     }
35     return c;
36 }
37
38 \end{code}