Author: akhaldi
Date: Thu May 22 21:10:16 2014
New Revision: 63418
URL:
http://svn.reactos.org/svn/reactos?rev=63418&view=rev
Log:
[CRT]
* Update ungetwc().
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] Thu May 22 21:10:16 2014
@@ -3824,15 +3824,39 @@
wint_t CDECL ungetwc(wint_t wc, FILE * file)
{
wchar_t mwc = wc;
- char * pp = (char *)&mwc;
- int i;
+
+ if (wc == WEOF)
+ return WEOF;
_lock_file(file);
- for(i=sizeof(wchar_t)-1;i>=0;i--) {
- if(pp[i] != ungetc(pp[i],file)) {
+
+ if((get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16))
+ || !(get_ioinfo(file->_file)->wxflag & WX_TEXT)) {
+ unsigned char * pp = (unsigned char *)&mwc;
+ int i;
+
+ for(i=sizeof(wchar_t)-1;i>=0;i--) {
+ if(pp[i] != ungetc(pp[i],file)) {
+ _unlock_file(file);
+ return WEOF;
+ }
+ }
+ }else {
+ char mbs[MB_LEN_MAX];
+ int len;
+
+ len = wctomb(mbs, mwc);
+ if(len == -1) {
_unlock_file(file);
return WEOF;
}
+
+ for(len--; len>=0; len--) {
+ if(mbs[len] != ungetc(mbs[len], file)) {
+ _unlock_file(file);
+ return WEOF;
+ }
+ }
}
_unlock_file(file);