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)
65 int putwc(wint_t c, FILE* fp)
67 // valid stream macro should check that fp is dword aligned
72 // check for write access on fp
73 if (!OPEN4WRITING(fp)) {
77 // might check on multi bytes if text mode
78 if (fp->_flag & _IOBINARY) {
81 fp->_flag |= _IODIRTY;
83 fp->_cnt -= sizeof(wchar_t);
84 //*((wchar_t*)(fp->_ptr))++ = c;
85 *((wchar_t*)(fp->_ptr)) = c;
86 ++((wchar_t*)(fp->_ptr));
91 result = _flsbuf(c, fp);
94 result = _flsbuf((int)(c >> 8), fp);
99 return _flswbuf(c, fp);
107 char mbchar[MB_CUR_MAX_CONST];
109 // Convert wide character to the corresponding multibyte character.
110 mb_cnt = wctomb(mbchar, (wchar_t)c);
115 if (mb_cnt > MB_CUR_MAX_CONST) {
118 for (i = 0; i < mb_cnt; i++) {
119 fp->_flag |= _IODIRTY;
122 *(fp)->_ptr++ = (unsigned char)mbchar[i];
124 if (_flsbuf((unsigned char)mbchar[i], fp) == EOF) {
130 fp->_flag |= _IODIRTY;
133 *(fp)->_ptr++ = (unsigned char)c;
135 if (_flsbuf(c, fp) == EOF) {