diff --git a/dlls/msvcr100/msvcr100.spec b/dlls/msvcr100/msvcr100.spec index 21d380e9c0..45a04cfb12 100644 --- a/dlls/msvcr100/msvcr100.spec +++ b/dlls/msvcr100/msvcr100.spec @@ -1408,7 +1408,7 @@ @ cdecl _ungetc_nolock(long ptr) MSVCRT__ungetc_nolock @ cdecl _ungetch(long) @ stub _ungetch_nolock -@ stub _ungetwc_nolock +@ cdecl _ungetwc_nolock(long ptr) MSVCRT__ungetwc_nolock @ stub _ungetwch @ stub _ungetwch_nolock @ cdecl _unlink(str) MSVCRT__unlink diff --git a/dlls/msvcr110/msvcr110.spec b/dlls/msvcr110/msvcr110.spec index c33ce0658b..5fc4ee594d 100644 --- a/dlls/msvcr110/msvcr110.spec +++ b/dlls/msvcr110/msvcr110.spec @@ -1766,7 +1766,7 @@ @ cdecl _ungetc_nolock(long ptr) MSVCRT__ungetc_nolock @ cdecl _ungetch(long) @ stub _ungetch_nolock -@ stub _ungetwc_nolock +@ cdecl _ungetwc_nolock(long ptr) MSVCRT__ungetwc_nolock @ stub _ungetwch @ stub _ungetwch_nolock @ cdecl _unlink(str) MSVCRT__unlink diff --git a/dlls/msvcr120/msvcr120.spec b/dlls/msvcr120/msvcr120.spec index 49d47e669c..c3edd61cc4 100644 --- a/dlls/msvcr120/msvcr120.spec +++ b/dlls/msvcr120/msvcr120.spec @@ -1780,7 +1780,7 @@ @ cdecl _ungetc_nolock(long ptr) MSVCRT__ungetc_nolock @ cdecl _ungetch(long) @ stub _ungetch_nolock -@ stub _ungetwc_nolock +@ cdecl _ungetwc_nolock(long ptr) MSVCRT__ungetwc_nolock @ stub _ungetwch @ stub _ungetwch_nolock @ cdecl _unlink(str) MSVCRT__unlink diff --git a/dlls/msvcr80/msvcr80.spec b/dlls/msvcr80/msvcr80.spec index b9fa3cdf8e..9877784737 100644 --- a/dlls/msvcr80/msvcr80.spec +++ b/dlls/msvcr80/msvcr80.spec @@ -1087,7 +1087,7 @@ @ cdecl _ungetc_nolock(long ptr) MSVCRT__ungetc_nolock @ cdecl _ungetch(long) @ stub _ungetch_nolock -@ stub _ungetwc_nolock +@ cdecl _ungetwc_nolock(long ptr) MSVCRT__ungetwc_nolock @ stub _ungetwch @ stub _ungetwch_nolock @ cdecl _unlink(str) MSVCRT__unlink diff --git a/dlls/msvcr90/msvcr90.spec b/dlls/msvcr90/msvcr90.spec index 24302c34f9..4df9203fde 100644 --- a/dlls/msvcr90/msvcr90.spec +++ b/dlls/msvcr90/msvcr90.spec @@ -1063,7 +1063,7 @@ @ cdecl _ungetc_nolock(long ptr) MSVCRT__ungetc_nolock @ cdecl _ungetch(long) @ stub _ungetch_nolock -@ stub _ungetwc_nolock +@ cdecl _ungetwc_nolock(long ptr) MSVCRT__ungetwc_nolock @ stub _ungetwch @ stub _ungetwch_nolock @ cdecl _unlink(str) MSVCRT__unlink diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c index 9fc26527ff..491942dffb 100644 --- a/dlls/msvcrt/file.c +++ b/dlls/msvcrt/file.c @@ -5053,12 +5053,27 @@ int CDECL MSVCRT__ungetc_nolock(int c, MSVCRT_FILE * file) */ MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file) { - MSVCRT_wchar_t mwc = wc; + MSVCRT_wint_t ret; - if (wc == MSVCRT_WEOF) - return MSVCRT_WEOF; + if(!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_WEOF; MSVCRT__lock_file(file); + ret = MSVCRT__ungetwc_nolock(wc, file); + MSVCRT__unlock_file(file); + + return ret; +} + +/********************************************************************* + * _ungetwc_nolock (MSVCRT.@) + */ +MSVCRT_wint_t CDECL MSVCRT__ungetwc_nolock(MSVCRT_wint_t wc, MSVCRT_FILE * file) +{ + MSVCRT_wchar_t mwc = wc; + + if(!MSVCRT_CHECK_PMT(file != NULL)) return MSVCRT_WEOF; + if (wc == MSVCRT_WEOF) + return MSVCRT_WEOF; if((msvcrt_get_ioinfo(file->_file)->exflag & (EF_UTF8 | EF_UTF16)) || !(msvcrt_get_ioinfo(file->_file)->wxflag & WX_TEXT)) { @@ -5066,30 +5081,23 @@ MSVCRT_wint_t CDECL MSVCRT_ungetwc(MSVCRT_wint_t wc, MSVCRT_FILE * file) int i; for(i=sizeof(MSVCRT_wchar_t)-1;i>=0;i--) { - if(pp[i] != MSVCRT_ungetc(pp[i],file)) { - MSVCRT__unlock_file(file); + if(pp[i] != MSVCRT__ungetc_nolock(pp[i],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); + if(len == -1) return MSVCRT_WEOF; - } for(len--; len>=0; len--) { - if(mbs[len] != MSVCRT_ungetc(mbs[len], file)) { - MSVCRT__unlock_file(file); + if(mbs[len] != MSVCRT__ungetc_nolock(mbs[len], file)) return MSVCRT_WEOF; - } } } - MSVCRT__unlock_file(file); return mwc; } diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index e19928b722..70ac68b53b 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -924,6 +924,7 @@ MSVCRT_wint_t __cdecl MSVCRT_fgetwc(MSVCRT_FILE*); MSVCRT_wint_t __cdecl MSVCRT__fgetwc_nolock(MSVCRT_FILE*); MSVCRT_wint_t __cdecl MSVCRT__fputwc_nolock(MSVCRT_wint_t,MSVCRT_FILE*); MSVCRT_wint_t __cdecl MSVCRT_ungetwc(MSVCRT_wint_t,MSVCRT_FILE*); +MSVCRT_wint_t __cdecl MSVCRT__ungetwc_nolock(MSVCRT_wint_t, MSVCRT_FILE*); int __cdecl MSVCRT__fseeki64_nolock(MSVCRT_FILE*,__int64,int); __int64 __cdecl MSVCRT__ftelli64(MSVCRT_FILE* file); __int64 __cdecl MSVCRT__ftelli64_nolock(MSVCRT_FILE*); diff --git a/include/msvcrt/stdio.h b/include/msvcrt/stdio.h index 19fda941b0..7512efc091 100644 --- a/include/msvcrt/stdio.h +++ b/include/msvcrt/stdio.h @@ -207,6 +207,7 @@ int __cdecl _putws(const wchar_t*); int __cdecl _snwprintf(wchar_t*,size_t,const wchar_t*,...); int __cdecl _snwprintf_s(wchar_t*,size_t,size_t,const wchar_t*,...); int __cdecl _scwprintf(const wchar_t*,...); +wint_t __cdecl _ungetwc_nolock(wint_t,FILE*); int __cdecl _vscwprintf(const wchar_t*,__ms_va_list); int __cdecl _vscwprintf_p_l(const wchar_t*,_locale_t,__ms_va_list); int __cdecl _vsnwprintf(wchar_t*,size_t,const wchar_t*,__ms_va_list);