Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow wchar_t constructors of fstreams on Windows when using libstdc++ #172

Merged
merged 1 commit into from
Sep 16, 2023

Conversation

rikyoz
Copy link
Contributor

@rikyoz rikyoz commented Sep 5, 2023

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)

@gulrak gulrak added enhancement New feature or request Windows Windows platform is affected labels Sep 7, 2023
@gulrak
Copy link
Owner

gulrak commented Sep 7, 2023

Nice, I like it and the name is good, at least one knows what it does. 😄

@rikyoz
Copy link
Contributor Author

rikyoz commented Sep 8, 2023

Great, thank you!

By the way, I've also found and implemented a workaround for opening file streams using wide string paths when using old versions of MinGW that do not support GHC_HAS_FSTREAM_OPEN_WITH_WCHAR.

This should fix the support for even more versions of MinGW, which currently can't correctly open files with Unicode characters in the path.

If it's not a problem, I might open another pull request after this is closed!

@gulrak gulrak merged commit 1ab54e5 into gulrak:master Sep 16, 2023
9 of 17 checks passed
@gulrak
Copy link
Owner

gulrak commented Sep 16, 2023

Thanks again for the PR!

@gulrak gulrak added the available on master Fix is done on master branch, issue closed on next release label Sep 16, 2023
@rikyoz rikyoz deleted the glibcxx_wchar_streams branch September 17, 2023 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
available on master Fix is done on master branch, issue closed on next release enhancement New feature or request Windows Windows platform is affected
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants