
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co? I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better? Thanks, Christian

On 13/12/2010 01:58, Christian Henning wrote:
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co?
I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better?
Erm, Boost.Filesystem ? KTC

Hi, On Sun, Dec 12, 2010 at 10:28 PM, KTC <ktc@ktchan.info> wrote:
On 13/12/2010 01:58, Christian Henning wrote:
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co?
I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better?
Erm, Boost.Filesystem ?
My interface has to support FILE*, Streams, Strings, and boost::filesystem::path. It seems to me that I can use _wfopen only on Windows machines. In essence I need to do the following? #ifdef _Windows FILE* f = _wfopen( L"test.jpg", L"rb"); #else FILE* f = fopen( L"test.jpg", L"rb"); #endif // _Windows Is that correct? Thanks, Christian

On Sun, 12 Dec 2010 20:58:06 -0500 Christian Henning <chhenning@gmail.com> wrote:
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co? [...]
So far as I know, there isn't one. Linux encodes all Unicode filenames in UTF-8, then uses the standard fopen function. -- Chad Nelson Oak Circle Software, Inc. * * *

On Monday 13 December 2010 06:11:53 Chad Nelson wrote:
On Sun, 12 Dec 2010 20:58:06 -0500
Christian Henning <chhenning@gmail.com> wrote:
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co? [...]
You can use mbstowcs/wcstombs and hope that the environment is setup correctly. I'd suggest looking at Boost.Filesystem though, even if only for inspiration.
So far as I know, there isn't one. Linux encodes all Unicode filenames in UTF-8, then uses the standard fopen function.
This is dangerous half-knowledge. Typical OSs based on Linux are configured to use UTF-8 as encoding for their filesystem. However, if you throw in an old CD burnt with a different encoding, that part of the filesystem will have a different encoding. Also, you can happily create files with any encoding there, you don't have to use UTF-8. The only properties of the path that you can rely on for Linux (and probably other POSIX platforms) is that they are zero-terminated (null byte at the end) and the individual segments are seperated by slashes. In between, you can have anything -- control characters, newlines, spaces, or text in any any encoding. Apple OS X mandates UTF-8, but IIRC it fails when presented with a medium who's encoding it doesn't recognize. MS Windows requires people to use UTF-16. However, it doesn't enforce that either, you can still use broken surrogate sequences to some extent. Media mounted with an unknown encoding are mapped by the OS to something that can be handled somehow, I'm not 100% sure about the mechanics (or when it fails). Good luck! Uli

Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co? There isn't any such thing on Linux or elsewhere. You have to convert
On Sun, 12 Dec 2010 20:58:06 -0500, Christian Henning wrote: the file name using current locale and give it to fopen() and hope for the best.
I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better?
-- VH

On 12/12/2010 05:58 PM, Christian Henning wrote:
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co?
I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better?
I believe that on Linux and other Unix-like platforms, no one attempts to use wchar_t strings to specify paths, and has been noted, officially on Linux path components are just strings of bytes with '/' and '\0' excluded, with no defined encoding (although nowadays it would be unlikely to not use UTF-8). In fact, I believe whcar_t and associated facilities in C/C++ are not very widely used on Linux at all. I believe the most useful behavior when passed a string of char as a path name is to use that path name directly (and not support wchar_t string path names); attempting to do any conversion, such as converting from the current locale to UTF-8 if the current locale is not UTF-8, would likely only be counter-productive, as nowadays it is most common for the current locale to be UTF-8 anyway, and if it is not, there is a good chance the filesystem also contains paths encoded according to the current locale rather than UTF-8.

Hello, Once I had written something called "nowide" http://art-blog.no-ip.info/files/nowide.zip See, this as well: http://comments.gmane.org/gmane.comp.lib.boost.devel/205699 A simple library that does this "in-other-way" i.e. allows to call fopen under windows with UTF-8 string rather then using wide string as on all "normal" platforms. So basically you need to use boost::nowide::fopen with normal utf-8 encoded strings (under windows) or current locale (normally utf-8) under all other platforms. And I would **strongly** recommend never use so called "wide" strings in portable applications. They are very inconsistent (as for UNIXes it us UTF-32 and under Windows they UTF-16) and usually quite useless as wide characters has very few added value over UTF-8 string. And when working with Windows I would recommend converting UTF-8 to Wide string just before passing them to OS functions (like _wfopen for example). Artyom ----- Original Message ----
From: Christian Henning <chhenning@gmail.com> To: boost <boost@lists.boost.org> Sent: Mon, December 13, 2010 3:58:06 AM Subject: [boost] wfopen
Hi there, one of the requirements for me to fix before I include io_new to boost is to support opening files with unicode filenames. As far as I can see there is _wfopen on Windows platforms. What's the one for Linux and co?
I'm a bit puzzled that no boost lib seems to use _wfopen. I searched all files. Is there something better?
Thanks, Christian _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (7)
-
Artyom
-
Chad Nelson
-
Christian Henning
-
Jeremy Maitin-Shepard
-
KTC
-
Ulrich Eckhardt
-
Václav Haisman