diff --git a/flang/runtime/file.cpp b/flang/runtime/file.cpp index 5cf91b8d64c86..5c7a1b54ba0d2 100644 --- a/flang/runtime/file.cpp +++ b/flang/runtime/file.cpp @@ -33,19 +33,19 @@ void OpenFile::set_path(OwningPtr &&path, std::size_t bytes) { static int openfile_mkstemp(IoErrorHandler &handler) { #ifdef _WIN32 const unsigned int uUnique{0}; - // GetTempFileNameA needs a directory name < MAX_PATH-14 characters in length. - // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea - char tempDirName[MAX_PATH - 14]; - char tempFileName[MAX_PATH]; + // GetTempFileNameW needs a directory name < MAX_PATH-14 characters in length. + // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamew + wchar_t tempDirName[MAX_PATH - 14]; + wchar_t tempFileName[MAX_PATH]; unsigned long nBufferLength{sizeof(tempDirName)}; - nBufferLength = ::GetTempPathA(nBufferLength, tempDirName); + nBufferLength = ::GetTempPathW(nBufferLength, tempDirName); if (nBufferLength > sizeof(tempDirName) || nBufferLength == 0) { return -1; } - if (::GetTempFileNameA(tempDirName, "Fortran", uUnique, tempFileName) == 0) { + if (::GetTempFileNameW(tempDirName, L"Fortran", uUnique, tempFileName) == 0) { return -1; } - int fd{::_open(tempFileName, _O_CREAT | _O_BINARY | _O_TEMPORARY | _O_RDWR, + int fd{::_wopen(tempFileName, _O_CREAT | _O_BINARY | _O_TEMPORARY | _O_RDWR, _S_IREAD | _S_IWRITE)}; #else char path[]{"/tmp/Fortran-Scratch-XXXXXX"};