3 * ReactOS msvcrt library
7 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
9 * Based on original work Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
28 #include <msvcrt/stdio.h>
29 #include <msvcrt/wchar.h>
30 #include <msvcrt/errno.h>
31 #include <msvcrt/internal/file.h>
33 // putc can be a macro
37 #ifndef MB_CUR_MAX_CONST
38 #define MB_CUR_MAX_CONST 10
41 int putc(int c, FILE* fp)
43 // valid stream macro should check that fp is dword aligned
48 // check for write access on fp
49 if (!OPEN4WRITING(fp)) {
53 fp->_flag |= _IODIRTY;
56 *(fp)->_ptr++ = (unsigned char)c;
57 return (int)(unsigned char)c;
59 return _flsbuf((unsigned char)c, fp);
64 //wint_t putwc(wint_t c, FILE* fp)
68 int putwc(wint_t c, FILE* fp)
70 // valid stream macro should check that fp is dword aligned
75 // check for write access on fp
76 if (!OPEN4WRITING(fp)) {
80 // might check on multi bytes if text mode
81 if (fp->_flag & _IOBINARY) {
84 fp->_flag |= _IODIRTY;
86 fp->_cnt -= sizeof(wchar_t);
87 //*((wchar_t*)(fp->_ptr))++ = c;
88 *((wchar_t*)(fp->_ptr)) = c;
89 ++((wchar_t*)(fp->_ptr));
94 result = _flsbuf(c, fp);
95 if (result == (wint_t)EOF)
97 result = _flsbuf((int)(c >> 8), fp);
98 if (result == (wint_t)EOF)
102 return _flswbuf(c, fp);
110 char mbchar[MB_CUR_MAX_CONST];
112 // Convert wide character to the corresponding multibyte character.
113 mb_cnt = wctomb(mbchar, (wchar_t)c);
118 if (mb_cnt > MB_CUR_MAX_CONST) {
121 for (i = 0; i < mb_cnt; i++) {
122 fp->_flag |= _IODIRTY;
125 *(fp)->_ptr++ = (unsigned char)mbchar[i];
127 if (_flsbuf((unsigned char)mbchar[i], fp) == EOF) {
133 fp->_flag |= _IODIRTY;
136 *(fp)->_ptr++ = (unsigned char)c;
138 if (_flsbuf(c, fp) == EOF) {