:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / stdio / getc.c
1 #include <windows.h>
2 #include <crtdll/stdio.h>
3 #include <crtdll/wchar.h>
4 #include <crtdll/errno.h>
5 #include <crtdll/internal/file.h>
6
7 //getc can be a macro
8 #undef getc
9
10 int getc(FILE *fp)
11 {
12         int c = -1;
13 // check for invalid stream
14
15         if ( !__validfp (fp) ) {
16                 __set_errno(EINVAL);
17                 return EOF;
18         }
19 // check for read access on stream
20
21         if ( !OPEN4READING(fp) ) {
22                 __set_errno(EINVAL);
23                 return -1;
24         }
25
26         if(fp->_cnt > 0) {
27                 fp->_cnt--;
28                 c =  (int)*fp->_ptr++;
29         } 
30         else {
31                 c =  _filbuf(fp);
32         }
33         return c;
34 }
35
36 // not exported
37
38 wint_t  getwc(FILE *fp)
39 {
40         
41  // might check on multi bytes if text mode
42  
43   if(fp->_cnt > 0) {
44         fp->_cnt -= sizeof(wchar_t);
45         return (wint_t )*((wchar_t *)(fp->_ptr))++;
46   } 
47   else {
48         return _filwbuf(fp);
49   }
50   
51   // never reached
52   return -1;
53 }
54
55
56
57