diff --git a/libtransmission/variant-benc.c b/libtransmission/variant-benc.c index e31af2a0d..45d039e17 100644 --- a/libtransmission/variant-benc.c +++ b/libtransmission/variant-benc.c @@ -13,7 +13,7 @@ #include #include /* isdigit() */ #include -#include /* strtoul(), strtod(), realloc(), qsort(), mkstemp() */ +#include /* strtoul() */ #include /* strlen(), memchr() */ #include diff --git a/libtransmission/variant.c b/libtransmission/variant.c index e5abfd967..2f295654e 100644 --- a/libtransmission/variant.c +++ b/libtransmission/variant.c @@ -13,13 +13,13 @@ #include #include #include /* rename() */ -#include /* strtoul(), strtod(), realloc(), qsort(), mkstemp() */ +#include /* strtod(), realloc(), qsort(), mkstemp() */ #include #ifdef WIN32 /* tr_mkstemp() */ #include - #define _S_IREAD 256 - #define _S_IWRITE 128 + #include + #include #endif #include /* setlocale() */ @@ -1133,12 +1133,25 @@ static int tr_mkstemp (char * template) { #ifdef WIN32 + + const int n = strlen (template) + 1; const int flags = O_RDWR | O_BINARY | O_CREAT | O_EXCL | _O_SHORT_LIVED; const mode_t mode = _S_IREAD | _S_IWRITE; - mktemp (template); - return open (template, flags, mode); + wchar_t templateUTF16[n]; + + if (MultiByteToWideChar(CP_UTF8, 0, template, -1, templateUTF16, n)) + { + _wmktemp(templateUTF16); + WideCharToMultiByte(CP_UTF8, 0, templateUTF16, -1, template, n, NULL, NULL); + return _wopen(chkFilename(templateUTF16), flags, mode); + } + errno = EINVAL; + return -1; + #else + return mkstemp (template); + #endif }