1313#include < fmt/ostream.h>
1414#include < fmt/printf.h>
1515
16- #if defined(_WIN32) && defined(DEBUG)
17- #include < windows.h> // For functions used by launchDebugger
16+ #if defined(_WIN32)
17+ #define WIN32_LEAN_AND_MEAN
18+ #include < windows.h>
19+
20+ std::wstring ConvertToUTF16 (std::string str) {
21+ std::wstring result;
22+ int len = MultiByteToWideChar (CP_UTF8, 0 , str.c_str (), static_cast <int >(str.length ()), NULL , 0 );
23+ if (len > 0 )
24+ {
25+ result.resize (len);
26+ MultiByteToWideChar (CP_UTF8, 0 , str.c_str (), static_cast <int >(str.length ()), &result[0 ], len);
27+ }
28+ return result;
29+ }
1830#endif
1931
2032// -------------------------------------------------------------------------------------------------
@@ -111,7 +123,11 @@ InputStream::InputStream(const std::string& filepath, Reporter& report) :
111123 stdinBuffer << std::cin.rdbuf ();
112124 activeStream = &stdinBuffer;
113125 } else {
126+ #if defined(_WIN32)
127+ file.open (ConvertToUTF16 (filepath).c_str (), std::ios::binary | std::ios::in);
128+ #else
114129 file.open (filepath, std::ios::binary | std::ios::in);
130+ #endif
115131 if (!file)
116132 report.fatal (rc::IO_FAILURE, " Could not open input file \" {}\" : {}." , filepath, errnoMessage ());
117133 activeStream = &file;
@@ -134,7 +150,11 @@ OutputStream::OutputStream(const std::string& filepath, Reporter& report) :
134150 #endif
135151 file = stdout;
136152 } else {
153+ #if defined(_WIN32)
154+ file = _wfopen (ConvertToUTF16 (filepath).c_str (), L" wb" );
155+ #else
137156 file = std::fopen (filepath.c_str (), " wb" );
157+ #endif
138158 if (!file)
139159 report.fatal (rc::IO_FAILURE, " Could not open output file \" {}\" : {}." , filepath, errnoMessage ());
140160 }
0 commit comments