- if (!MultiByteToWideChar
- (CP_ACP, 0, extdir, len_0, (WCHAR *)wdir, len_0))
+ int sz = 0;
+ UINT cp;
+
+ do {
+# ifdef CP_UTF8
+ if ((sz = MultiByteToWideChar((cp = CP_UTF8), 0, extdir, len_0,
+ NULL, 0)) > 0 ||
+ GetLastError() != ERROR_NO_UNICODE_TRANSLATION)
+ break;
+# endif
+ sz = MultiByteToWideChar((cp = CP_ACP), 0, extdir, len_0,
+ NULL, 0);
+ } while (0);
+
+ if (sz > 0) {
+ wdir = _alloca(sz * sizeof(TCHAR));
+ if (!MultiByteToWideChar(cp, 0, extdir, len_0, wdir, sz)) {
+ if (extdirbuf != NULL) {
+ free(extdirbuf);
+ }
+ free(*ctx);
+ *ctx = NULL;
+ errno = EINVAL;
+ return 0;
+ }
+ } else