Reverted latest changes.
[reactos.git] / reactos / lib / msvcrt / 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
11 int putc(int c, FILE *fp)
12 {
13
14 // valid stream macro should check that fp
15 // is dword aligned
16 if (!__validfp (fp)) {
17 __set_errno(EINVAL);
18 return -1;
19 }
20 // check for write access on fp
21
22 if ( !OPEN4WRITING(fp) ) {
23 __set_errno(EINVAL);
24 return -1;
25 }
26
27 fp->_flag |= _IODIRTY;
28 if (fp->_cnt > 0 ) {
29 fp->_cnt--;
30 *(fp)->_ptr++ = (unsigned char)c;
31 return (int)(unsigned char)c;
32 }
33 else {
34 return _flsbuf((unsigned char)c,fp);
35 }
36 return EOF;
37 }
38
39 wint_t putwc(wint_t c, FILE *fp)
40 {
41 // valid stream macro should check that fp
42 // is dword aligned
43 if (!__validfp (fp)) {
44 __set_errno(EINVAL);
45 return -1;
46 }
47 // check for write access on fp
48
49 if ( !OPEN4WRITING(fp) ) {
50 __set_errno(EINVAL);
51 return -1;
52 }
53 // might check on multi bytes if text mode
54
55 fp->_flag |= _IODIRTY;
56
57 if (fp->_cnt > 0 ) {
58 fp->_cnt-= sizeof(wchar_t);
59 *((wchar_t *)(fp->_ptr))++ = c;
60 return (wint_t)c;
61 }
62 else
63 return _flswbuf(c,fp);
64
65 return -1;
66
67
68 }