832368cfba188a5fab95d879201e0e6ee582c007
[reactos.git] / reactos / lib / crtdll / stdio / putc.c
1 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2 #include <precomp.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 /*
13 * @implemented
14 */
15 int putc(int c, FILE* fp)
16 {
17 // valid stream macro should check that fp is dword aligned
18 if (!__validfp (fp)) {
19 __set_errno(EINVAL);
20 return -1;
21 }
22 // check for write access on fp
23
24 if ( !OPEN4WRITING(fp) ) {
25 __set_errno(EINVAL);
26 return -1;
27 }
28
29 fp->_flag |= _IODIRTY;
30 if (fp->_cnt > 0 ) {
31 fp->_cnt--;
32 *(fp)->_ptr++ = (unsigned char)c;
33 return (int)(unsigned char)c;
34 }
35 else {
36 return _flsbuf((unsigned char)c,fp);
37 }
38 return EOF;
39 }
40
41 //wint_t putwc(wint_t c, FILE* fp)
42 //int putwc(wchar_t c, FILE* fp)
43 int putwc(wint_t c, FILE* fp)
44 {
45 // might check on multi bytes if text mode
46
47 if (fp->_cnt > 0 ) {
48 fp->_cnt-= sizeof(wchar_t);
49 *((wchar_t *)(fp->_ptr)) = c;
50 fp->_ptr += sizeof(wchar_t);
51 return (wint_t)c;
52 }
53 else
54 return _flswbuf(c,fp);
55
56 return -1;
57
58
59 }