This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Hi, I have implemented a small patch that mirrors Microsoft's STL extension, where one can use wide strings as an argument to std::(w)fstream. This is very useful on Windows, where, without this extension, there is no way to open an fstream for a filename containing non-ASCII characters not in the Windows local codepage. The workaround would be to subclass a streambuf to accept a wchar_t* filename, but I think a lower-level fix (ie on library level) is much more suitable, and provides more robustness. In the C API provided by Microsoft in their MSVCRT (catered for by MinGW(-w64)), a function _wfopen, which imitates plain fopen, but accepts wchar_t* arguments for the exact purpose I use it in my patch. Documentation for _wfopen is here: http://msdn.microsoft.com/en-us/library/yeby3zcb%28v=VS.100%29.aspx No extra #includes are necessary, and for now I #ifdef'ed the extra code with #if _WIN32. Perhaps cleaner would be a configure check for OS or CRT used and a __GLIBCXX* macro to enable this functionality. I understand the patch is not complete (no Changelog, etc...), but I would like to know your thoughts on how I implemented this functionality. The changes: - libstdc++-v3/config/io/basic_file_stdio.cc: wfopen_mode: new function, copy of fopen_mode, but returns wchar_t* - libstdc++-v3/config/io/basic_file_stdio.cc: __basic_file<char>::open: new overload, taking wchar_t* argument, and uses new wfopen_mode and Windows' _wfopen instead of plain fopen. - libstdc++-v3/config/io/basic_file_stdio.h: open: new overload taking wchar_t* argument - libstdc++-v3/include/bits/fstream.tcc: open: new overloads, taking wchar_t* argument - libstdc++-v3/include/std/fstream: open: new overloads taking wchar_t* and if C++0x is enabled, also overloads taking a std::wstring - libstdc++-v3/config/abi/pre/gnu.ver: modify regex statements to also include new symbols. Simple testing of the functionality works as it should. I first modified GCC trunk, created a patch, and applied that to the 4.6 branch. Conclusion: this change should work for GCC 4.6 and up for sure, maybe even 4.5. As it stands, only Windows is affected, and should be affected. Perhaps systems where Unicode filenames aren't UTF-8 (oh wait: that's pretty much Windows only) could also benefit from this. Any thoughts/remarks/improvements/commits are very welcome! Thanks, Ruben
Attachment:
fstream_wchar_t.patch
Description: Binary data
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |