Commit 6122c2ba authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Convert data to multibyte encoding in ungetwc if needed.

parent 71687bef
...@@ -4730,18 +4730,39 @@ int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file) ...@@ -4730,18 +4730,39 @@ int CDECL MSVCRT_ungetc(int c, MSVCRT_FILE * file)
MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file) MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file)
{ {
MSVCRT_wchar_t mwc = wc; MSVCRT_wchar_t mwc = wc;
unsigned char * pp = (unsigned char *)&mwc;
int i;
if (wc == MSVCRT_WEOF) if (wc == MSVCRT_WEOF)
return MSVCRT_WEOF; return MSVCRT_WEOF;
MSVCRT__lock_file(file); MSVCRT__lock_file(file);
for(i=sizeof(MSVCRT_wchar_t)-1;i>=0;i--) {
if(pp[i] != MSVCRT_ungetc(pp[i],file)) { if((msvcrt_get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16))
|| !(msvcrt_get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
unsigned char * pp = (unsigned char *)&mwc;
int i;
for(i=sizeof(MSVCRT_wchar_t)-1;i>=0;i--) {
if(pp[i] != MSVCRT_ungetc(pp[i],file)) {
MSVCRT__unlock_file(file);
return MSVCRT_WEOF;
}
}
}else {
char mbs[MSVCRT_MB_LEN_MAX];
int len;
len = MSVCRT_wctomb(mbs, mwc);
if(len == -1) {
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
return MSVCRT_WEOF; return MSVCRT_WEOF;
} }
for(len--; len>=0; len--) {
if(mbs[len] != MSVCRT_ungetc(mbs[len], file)) {
MSVCRT__unlock_file(file);
return MSVCRT_WEOF;
}
}
} }
MSVCRT__unlock_file(file); MSVCRT__unlock_file(file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment