Added binary and unicode file i/o support to msvcrt.
[reactos.git] / reactos / lib / crtdll / stdio / putc.c
1 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2 #include <windows.h>
3 #include <msvcrt/stdio.h>
4 #include <msvcrt/wchar.h>
5 #include <msvcrt/errno.h>
6 #include <msvcrt/internal/file.h>
7
8 // putc can be a macro
9 #undef putc
10 #undef putwc
11
12 int putc(int c, FILE* fp)
13 {
14 // valid stream macro should check that fp is dword aligned
15 if (!__validfp (fp)) {
16 __set_errno(EINVAL);
17 return -1;
18 }
19 // check for write access on fp
20
21 if ( !OPEN4WRITING(fp) ) {
22 __set_errno(EINVAL);
23 return -1;
24 }
25
26 fp->_flag |= _IODIRTY;
27 if (fp->_cnt > 0 ) {
28 fp->_cnt--;
29 *(fp)->_ptr++ = (unsigned char)c;
30 return (int)(unsigned char)c;
31 }
32 else {
33 return _flsbuf((unsigned char)c,fp);
34 }
35 return EOF;
36 }
37
38 //wint_t putwc(wint_t c, FILE* fp)
39 //int putwc(wchar_t c, FILE* fp)
40 int putwc(wint_t c, FILE* fp)
41 {
42 // might check on multi bytes if text mode
43
44 if (fp->_cnt > 0 ) {
45 fp->_cnt-= sizeof(wchar_t);
46 *((wchar_t *)(fp->_ptr))++ = c;
47 return (wint_t)c;
48 }
49 else
50 return _flswbuf(c,fp);
51
52 return -1;
53
54
55 }