msvcrt: Make fputwc encoding aware.

This commit is contained in:
Piotr Caban 2013-01-11 11:18:44 +01:00 committed by Alexandre Julliard
parent f377591e98
commit ebfa653618
2 changed files with 25 additions and 4 deletions

View File

@ -3376,9 +3376,29 @@ MSVCRT_size_t CDECL MSVCRT_fwrite(const void *ptr, MSVCRT_size_t size, MSVCRT_si
MSVCRT_wint_t CDECL MSVCRT_fputwc(MSVCRT_wint_t wc, MSVCRT_FILE* file)
{
MSVCRT_wchar_t mwc=wc;
if (MSVCRT_fwrite( &mwc, sizeof(mwc), 1, file) != 1)
return MSVCRT_WEOF;
return wc;
ioinfo *fdinfo;
MSVCRT_wint_t ret;
MSVCRT__lock_file(file);
fdinfo = msvcrt_get_ioinfo(file->_file);
if((fdinfo->wxflag&WX_TEXT) && !(fdinfo->exflag&(EF_UTF8|EF_UTF16))) {
char buf[MSVCRT_MB_LEN_MAX];
int char_len;
char_len = wctomb(buf, mwc);
if(char_len!=-1 && MSVCRT_fwrite(buf, char_len, 1, file)==1)
ret = wc;
else
ret = MSVCRT_WEOF;
}else if(MSVCRT_fwrite(&mwc, sizeof(mwc), 1, file) == 1) {
ret = wc;
}else {
ret = MSVCRT_WEOF;
}
MSVCRT__unlock_file(file);
return ret;
}
/*********************************************************************

View File

@ -46,6 +46,7 @@
#define MSVCRT_I64_MAX (((__int64)0x7fffffff << 32) | 0xffffffff)
#define MSVCRT_I64_MIN (-MSVCRT_I64_MAX-1)
#define MSVCRT_UI64_MAX (((unsigned __int64)0xffffffff << 32) | 0xffffffff)
#define MSVCRT_MB_LEN_MAX 2
#define MSVCRT__MAX_DRIVE 3
#define MSVCRT__MAX_DIR 256