summaryrefslogtreecommitdiffstats
path: root/win/tclWin32Dll.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tclWin32Dll.c')
-rw-r--r--win/tclWin32Dll.c37
1 files changed, 13 insertions, 24 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c
index 599c126..dca6875 100644
--- a/win/tclWin32Dll.c
+++ b/win/tclWin32Dll.c
@@ -471,17 +471,11 @@ Tcl_WinUtfToTChar(
Tcl_DString *dsPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
- TCHAR *wp;
- int size = MultiByteToWideChar(CP_UTF8, 0, string, len, 0, 0);
-
Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, 2*size+2);
- wp = (TCHAR *)Tcl_DStringValue(dsPtr);
- MultiByteToWideChar(CP_UTF8, 0, string, len, wp, size+1);
- if (len == -1) --size; /* account for 0-byte at string end */
- Tcl_DStringSetLength(dsPtr, 2*size);
- wp[size] = 0;
- return wp;
+ if (!string) {
+ return NULL;
+ }
+ return Tcl_UtfToUniCharDString(string, len, dsPtr);
}
char *
@@ -492,21 +486,16 @@ Tcl_WinTCharToUtf(
Tcl_DString *dsPtr) /* Uninitialized or free DString in which the
* converted string is stored. */
{
- char *p;
- int size;
-
- if (len > 0) {
+ Tcl_DStringInit(dsPtr);
+ if (!string) {
+ return NULL;
+ }
+ if (len < 0) {
+ len = wcslen(string);
+ } else {
len /= 2;
}
- size = WideCharToMultiByte(CP_UTF8, 0, string, len, 0, 0, NULL, NULL);
- Tcl_DStringInit(dsPtr);
- Tcl_DStringSetLength(dsPtr, size+1);
- p = (char *)Tcl_DStringValue(dsPtr);
- WideCharToMultiByte(CP_UTF8, 0, string, len, p, size, NULL, NULL);
- if (len == -1) --size; /* account for 0-byte at string end */
- Tcl_DStringSetLength(dsPtr, size);
- p[size] = 0;
- return p;
+ return Tcl_UniCharToUtfDString(string, len, dsPtr);
}
/*
@@ -536,7 +525,7 @@ TclWinCPUID(
#if defined(HAVE_INTRIN_H) && defined(_WIN64)
- __cpuid(regsPtr, index);
+ __cpuid((int *)regsPtr, index);
status = TCL_OK;
#elif defined(__GNUC__)