[filesystem] Linux copy_file api with wpath

It seems that Boost.FileSystem does not implement some methods accepting wpath arguments when compiled with GCC 3.4.3 on Linux. This occurs because BOOST_FILESYSTEM_NARROW_ONLY is defined, which according to the comment in the code occurs for "badly broken compilers or libraries". Ideally, I would like to use the boost::filesystem::copy_file() method on both Windows and Linux, passing wpath arguments in both cases. Is the lack of wpath support simply a problem with GCC 3.4.3, or is wpath never supported for copy_file() with GCC? I can see from the implementation of boost::filesystem::detail::copy_file_api() that open(), read(), and write() are used to copy the file. Since open() accepts only a const char* this may be the limitation. If this is the case, has there been any discussion of providing a copy_file() method which accepts wpath arguments and converts from wchar_t to char before calling copy_file_api(). I do not have a lot of experience with locales and character encodings, so I may be missing something. If this has already been discussed on this mailing list or elsewhere, please point me to the correct discussion, as I have been unable to find it. Thanks. Josh -- Rejoice always. Pray without ceasing. In all circumstances give thanks, for this is the will of God for you in Christ Jesus. -- 1 Thes. 5:16-18 NAB -- I am the living bread that came down from heaven; whoever eats this bread will live forever; and the bread that I will give is my flesh for the life of the world. -- John 6:51 NAB

Joshua Peterson wrote:
It seems that Boost.FileSystem does not implement some methods accepting wpath arguments when compiled with GCC 3.4.3 on Linux. This occurs because BOOST_FILESYSTEM_NARROW_ONLY is defined, which according to the comment in the code occurs for "badly broken compilers or libraries".
Something is amiss. IIRC, BOOST_FILESYSTEM_NARROW_ONLY should only be defined for GCC on Windows/Cygwin, which doesn't have wide character support. Don't all modern versions of GCC on Linux support wide characters? Could you please check to see if BOOST_FILESYSTEM_NARROW_ONLY really is being defined? Thanks, --Beman

It seems that Boost.FileSystem does not implement some methods accepting
wpath arguments when compiled with GCC 3.4.3 on Linux. This occurs because BOOST_FILESYSTEM_NARROW_ONLY is defined, which according to the comment in the code occurs for "badly broken compilers or libraries".
Something is amiss. IIRC, BOOST_FILESYSTEM_NARROW_ONLY should only be defined for GCC on Windows/Cygwin, which doesn't have wide character support. Don't all modern versions of GCC on Linux support wide characters?
Could you please check to see if BOOST_FILESYSTEM_NARROW_ONLY really is being defined?
Well, after a bit more investigation, it seems that the boost::filesystem::detail::copy_file_api(const std::wstring & from, const std::wstring & to) is not only behind BOOST_FILESYSTEM_NARROW_ONLY, but is also behind BOOST_WINDOWS_API, so it is explicitly only available on Windows. So I was incorrect, BOOST_FILESYSTEM_NARROW_ONLY is not defined for GCC 3.4.3, as I do get the wide character path manipulation methods. However, it is that Windows API define that prevents the above copy_file_api definition from being used. Josh -- Rejoice always. Pray without ceasing. In all circumstances give thanks, for this is the will of God for you in Christ Jesus. -- 1 Thes. 5:16-18 NAB -- I am the living bread that came down from heaven; whoever eats this bread will live forever; and the bread that I will give is my flesh for the life of the world. -- John 6:51 NAB

Joshua Peterson wrote:
It seems that Boost.FileSystem does not implement some methods accepting
wpath arguments when compiled with GCC 3.4.3 on Linux. This occurs because BOOST_FILESYSTEM_NARROW_ONLY is defined, which according to the comment in the code occurs for "badly broken compilers or libraries".
Something is amiss. IIRC, BOOST_FILESYSTEM_NARROW_ONLY should only be defined for GCC on Windows/Cygwin, which doesn't have wide character support. Don't all modern versions of GCC on Linux support wide characters?
Could you please check to see if BOOST_FILESYSTEM_NARROW_ONLY really is being defined?
Well, after a bit more investigation, it seems that the boost::filesystem::detail::copy_file_api(const std::wstring & from, const std::wstring & to) is not only behind BOOST_FILESYSTEM_NARROW_ONLY, but is also behind BOOST_WINDOWS_API, so it is explicitly only available on Windows.
So I was incorrect, BOOST_FILESYSTEM_NARROW_ONLY is not defined for GCC 3.4.3, as I do get the wide character path manipulation methods. However, it is that Windows API define that prevents the above copy_file_api definition from being used.

Joshua Peterson wrote:
It seems that Boost.FileSystem does not implement some methods accepting
wpath arguments when compiled with GCC 3.4.3 on Linux. This occurs because BOOST_FILESYSTEM_NARROW_ONLY is defined, which according to the comment in the code occurs for "badly broken compilers or libraries".
Something is amiss. IIRC, BOOST_FILESYSTEM_NARROW_ONLY should only be defined for GCC on Windows/Cygwin, which doesn't have wide character support. Don't all modern versions of GCC on Linux support wide characters?
Could you please check to see if BOOST_FILESYSTEM_NARROW_ONLY really is being defined?
Well, after a bit more investigation, it seems that the boost::filesystem::detail::copy_file_api(const std::wstring & from, const std::wstring & to) is not only behind BOOST_FILESYSTEM_NARROW_ONLY, but is also behind BOOST_WINDOWS_API, so it is explicitly only available on Windows.
That's normal. Windows has both wide and narrow API's but POSIX has only a narrow char API.
So I was incorrect, BOOST_FILESYSTEM_NARROW_ONLY is not defined for GCC 3.4.3, as I do get the wide character path manipulation methods. However, it is that Windows API define that prevents the above copy_file_api definition from being used.
Let's get back to basics. Does this program compile for you? #include <boost/filesystem/operations.hpp> int main() { boost::filesystem::copy_file( L"foo", L"bar" ); return 0; } In compiles fine for me on Ubuntu 8.04.1 and g++ 4.2.1. I haven't had a chance yet to build the libraries to see if it links. I'll do that later tonight or tomorrow. --Beman

Beman Dawes wrote:
Let's get back to basics. Does this program compile for you?
#include <boost/filesystem/operations.hpp>
int main() { boost::filesystem::copy_file( L"foo", L"bar" ); return 0; }
In compiles fine for me on Ubuntu 8.04.1 and g++ 4.2.1. I haven't had a chance yet to build the libraries to see if it links. I'll do that later tonight or tomorrow.
Update: the above compiles, links, and runs fine for me. --Beman

On Mon, Aug 25, 2008 at 6:00 PM, Beman Dawes <bdawes@acm.org> wrote:
Let's get back to basics. Does this program compile for you?
#include <boost/filesystem/operations.hpp>
int main() { boost::filesystem::copy_file( L"foo", L"bar" ); return 0; }
In compiles fine for me on Ubuntu 8.04.1 and g++ 4.2.1. I haven't had a chance yet to build the libraries to see if it links. I'll do that later tonight or tomorrow.
Update: the above compiles, links, and runs fine for me.
Yes, it compiles, links, and runs for me as well. Getting back to basics has isolated the problem I am having. The client code which uses copy_file is compiled using MainWin, implements the Win32 API, and defines _WIN32, WIN32, etc. So the Boost.Filesystem code from the headers is compiling with BOOST_WINDOWS_API defined. However, the Boost.Filesystem library was compiled with GCC natively (i.e. without MainWin), so it has BOOST_POSIX_API defined. These clearly cannot work together. Thanks for the help and suggestions, Beman, I really appreciate it. This has been puzzling me for some time. I'm glad that we have found the problem. Josh
participants (2)
-
Beman Dawes
-
Joshua Peterson