Allow wchar_t constructors of fstreams on Windows when using libstdc++ #172
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.
Hi!
Currently, when using libstdc++ on Windows (e.g., MinGW), ghc::filesystem's streams open the file using the narrow string representation of the path.
However, recent versions of libstdc++ have added support for opening file streams directly using wchar_t paths (gcc-mirror/gcc@b029235).
Using the wide/native string type for opening the file streams is preferred on Windows, especially for supporting paths with Unicode characters.
This PR introduces a new #define called
GHC_HAS_FSTREAM_OPEN_WITH_WCHAR
(I could not find any better name 😅).It is defined when the OS is Windows and either we are not using libstdc++ (e.g., libc++ or Microsoft's STL) or the libstdc++ supports opening files using wchar_t paths.
For checking this latter case, I used the same preprocessor check done in libstdc++ (e.g., https://github.com/gcc-mirror/gcc/blob/b02923592a55b52d796656c5b4f34a964a2604a9/libstdc%2B%2B-v3/include/std/fstream#L536)