mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
[CRT]
* Update fgetwc(). * Fixes some msvcrt tests. CORE-8080 svn path=/trunk/; revision=63273
This commit is contained in:
parent
3904749e7d
commit
065ed0c860
1 changed files with 35 additions and 45 deletions
|
@ -2634,60 +2634,50 @@ char * CDECL fgets(char *s, int size, FILE* file)
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* fgetwc (MSVCRT.@)
|
* 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)
|
wint_t CDECL fgetwc(FILE* file)
|
||||||
{
|
{
|
||||||
int c;
|
wint_t ret;
|
||||||
|
int ch;
|
||||||
|
|
||||||
_lock_file(file);
|
_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;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
j = _filbuf(file);
|
|
||||||
if(file->_cnt<=0)
|
|
||||||
{
|
|
||||||
file->_flag |= (file->_cnt == 0) ? _IOEOF : _IOERR;
|
|
||||||
file->_cnt = 0;
|
|
||||||
|
|
||||||
_unlock_file(file);
|
if((get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16))
|
||||||
return WEOF;
|
|| !(get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
|
||||||
}
|
char *p;
|
||||||
wcp[i] = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_unlock_file(file);
|
for(p=(char*)&ret; (wint_t*)p<&ret+1; p++) {
|
||||||
return wc;
|
ch = fgetc(file);
|
||||||
|
if(ch == EOF) {
|
||||||
|
ret = WEOF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
*p = (char)ch;
|
||||||
|
}
|
||||||
|
}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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!len || mbtowc(&ret, mbs, len)==-1)
|
||||||
|
ret = WEOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
c = fgetc(file);
|
_unlock_file(file);
|
||||||
if ((__mb_cur_max > 1) && isleadbyte(c))
|
return ret;
|
||||||
{
|
|
||||||
FIXME("Treat Multibyte characters\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
_unlock_file(file);
|
|
||||||
if (c == EOF)
|
|
||||||
return WEOF;
|
|
||||||
else
|
|
||||||
return (wint_t)c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|
Loading…
Reference in a new issue