Workaround for opening file streams using wide string paths on old versions of MinGW #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On old MinGW versions, opening file streams using wide string paths is not supported. This basically makes it impossible to use ghc::filesystem's streams for opening files with a Unicode character in the path since, by default, the narrow path string (UTF-8 encoded) gets interpreted by Windows using the system codepage (unless you force the program to use UTF-8 via a manifest file).
Example:
Output:
However, old versions of MinGW might support the
_wsopen_s
function, a Microsoft extension that allows opening a file using a wide C string path. This, together with an internal function of libstdc++ (__gnu_cxx::stdio_filebuf
), can be used to implement a workaround.The workaround is used only if libstdc++ doesn't natively support opening file streams using wide string paths (#172), which is the preferred way on recent versions of MinGW.
Output with the workaround:
I tested it with both MinGW 7 and 8, which do not support
GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
, but support_wsopen_s
.As a side note, I had to modify the CMake files so that the
-Wa,-mbig-obj
parameter is passed to all the test targets; otherwise, MinGW fails while linking the executables.I hope everything is ok!