Author: akhaldi
Date: Tue May 13 13:11:22 2014
New Revision: 63273
URL:
http://svn.reactos.org/svn/reactos?rev=63273&view=rev
Log:
[CRT]
* Update fgetwc().
* Fixes some msvcrt tests.
CORE-8080
Modified:
trunk/reactos/lib/sdk/crt/stdio/file.c
Modified: trunk/reactos/lib/sdk/crt/stdio/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdio/file.c?r…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/stdio/file.c [iso-8859-1] Tue May 13 13:11:22 2014
@@ -2634,60 +2634,50 @@
/*********************************************************************
* fgetwc (MSVCRT.@)
- *
- * In _O_TEXT mode, multibyte characters are read from the file, dropping
- * the CR from CR/LF combinations
*/
wint_t CDECL fgetwc(FILE* file)
{
- int c;
+ wint_t ret;
+ int ch;
_lock_file(file);
- if (!(get_ioinfo(file->_file)->wxflag & WX_TEXT))
- {
- wchar_t wc;
- unsigned int i;
- int j;
- char *chp, *wcp;
- wcp = (char *)&wc;
- for(i=0; i<sizeof(wc); i++)
- {
- if (file->_cnt>0)
- {
- file->_cnt--;
- chp = file->_ptr++;
- wcp[i] = *chp;
+
+ if((get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16))
+ || !(get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
+ char *p;
+
+ for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) {
+ ch = fgetc(file);
+ if(ch == EOF) {
+ ret = WEOF;
+ break;
+ }
+ *p = (char)ch;
}
- else
- {
- j = _filbuf(file);
- if(file->_cnt<=0)
- {
- file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR;
- file->_cnt = 0;
-
- _unlock_file(file);
- return WEOF;
- }
- wcp[i] = j;
+ }else {
+ char mbs[MB_LEN_MAX];
+ int len = 0;
+
+ ch = fgetc(file);
+ if(ch != EOF) {
+ mbs[0] = (char)ch;
+ if(isleadbyte((unsigned char)mbs[0])) {
+ ch = fgetc(file);
+ if(ch != EOF) {
+ mbs[1] = (char)ch;
+ len = 2;
+ }
+ }else {
+ len = 1;
+ }
}
- }
-
- _unlock_file(file);
- return wc;
- }
-
- c = fgetc(file);
- if ((__mb_cur_max > 1) && isleadbyte(c))
- {
- FIXME("Treat Multibyte characters\n");
- }
-
- _unlock_file(file);
- if (c == EOF)
- return WEOF;
- else
- return (wint_t)c;
+
+ if(!len || mbtowc(&ret, mbs, len)==-1)
+ ret = WEOF;
+ }
+
+ _unlock_file(file);
+ return ret;
}
/*********************************************************************