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