Piotr Caban : msvcrt: Added mbrtowc implementation.
Alexandre Julliard
julliard at winehq.org
Thu Nov 29 14:15:44 CST 2012
Module: wine
Branch: master
Commit: 4b67531bf72ee1a8c92029a7be3836c96594150e
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4b67531bf72ee1a8c92029a7be3836c96594150e
Author: Piotr Caban <piotr at codeweavers.com>
Date: Thu Nov 29 09:23:02 2012 +0000
msvcrt: Added mbrtowc implementation.
---
dlls/msvcrt/mbcs.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++-
dlls/msvcrt/msvcrt.spec | 2 +-
2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c
index b083ea1..71b5343 100644
--- a/dlls/msvcrt/mbcs.c
+++ b/dlls/msvcrt/mbcs.c
@@ -1995,7 +1995,7 @@ int CDECL MSVCRT_mbtowc_l(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n,
/* return the number of bytes from src that have been used */
if(!*str)
return 0;
- if(n >= 2 && MSVCRT__isleadbyte_l(*str, locale) && str[1])
+ if(n >= 2 && MSVCRT__isleadbyte_l((unsigned char)*str, locale) && str[1])
return 2;
return 1;
}
@@ -2009,6 +2009,53 @@ int CDECL MSVCRT_mbtowc(MSVCRT_wchar_t *dst, const char* str, MSVCRT_size_t n)
}
/*********************************************************************
+ * mbrtowc(MSVCRT.@)
+ */
+MSVCRT_size_t CDECL MSVCRT_mbrtowc(MSVCRT_wchar_t *dst, const char *str,
+ MSVCRT_size_t n, MSVCRT_mbstate_t *state)
+{
+ MSVCRT_pthreadlocinfo locinfo = get_locinfo();
+ MSVCRT_mbstate_t s = (state ? *state : 0);
+ char tmpstr[2];
+ int len = 0;
+
+ if(dst)
+ *dst = 0;
+
+ if(!n || !str || !*str)
+ return 0;
+
+ if(locinfo->mb_cur_max == 1) {
+ tmpstr[len++] = *str;
+ }else if(!s && MSVCRT_isleadbyte((unsigned char)*str)) {
+ if(n == 1) {
+ s = (unsigned char)*str;
+ len = -2;
+ }else {
+ tmpstr[0] = str[0];
+ tmpstr[1] = str[1];
+ len = 2;
+ }
+ }else if(!s) {
+ tmpstr[len++] = *str;
+ }else {
+ tmpstr[0] = s;
+ tmpstr[1] = *str;
+ len = 2;
+ s = 0;
+ }
+
+ if(len > 0) {
+ if(!MultiByteToWideChar(locinfo->lc_codepage, 0, tmpstr, len, dst, dst ? 1 : 0))
+ len = -1;
+ }
+
+ if(state)
+ *state = s;
+ return len;
+}
+
+/*********************************************************************
* _mbstowcs_l(MSVCRT.@)
*/
MSVCRT_size_t CDECL MSVCRT__mbstowcs_l(MSVCRT_wchar_t *wcstr, const char *mbstr,
diff --git a/dlls/msvcrt/msvcrt.spec b/dlls/msvcrt/msvcrt.spec
index 7957e92..4f2fa9a 100644
--- a/dlls/msvcrt/msvcrt.spec
+++ b/dlls/msvcrt/msvcrt.spec
@@ -1329,7 +1329,7 @@
@ cdecl malloc(long) MSVCRT_malloc
@ cdecl mblen(ptr long) MSVCRT_mblen
@ cdecl mbrlen(ptr long ptr) MSVCRT_mbrlen
-# stub mbrtowc(ptr str long ptr)
+@ cdecl mbrtowc(ptr str long ptr) MSVCRT_mbrtowc
# stub mbsdup_dbg(wstr long ptr long)
# stub mbsrtowcs(ptr ptr long ptr)
# stub mbsrtowcs_s(ptr ptr long ptr long ptr)
More information about the wine-cvs
mailing list