boost::filesystem in Windows 95

Hi We have a code base for Windows that compiles with common settings for all Windows platforms. When using boost::filesystem, this is no longer possible, due to the fact that Windows implementation in operations_posix_windows.cpp uses the API function GetFileAttributesExA, not available in Windows 95. GetFileAttributesExA could be replaced by FindFirstFile, which gives the same information and is available in all Windows platforms. This API is used in two different places, BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ) implementation and BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph ) implementation. Using FindFirstFile instead of GetFileAttributesExA we would get: BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ) { # ifdef BOOST_POSIX ........ # else WIN32_FIND_DATA ; HANDLE hf = ::FindFirstFileA(ph.string().c_str(), &ffd); if (hf == INVALID_HANDLE_VALUE) boost::throw_exception( filesystem_error( "boost::filesystem::is_empty", ph, fs::detail::system_error_code() ) ); CloseHandle(hf); return ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) ? is_empty_directory( ph ) :( !ffd.nFileSizeHigh && !ffd.nFileSizeLow ); # endif } BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph ) { # ifdef BOOST_POSIX ....... # else // by now, intmax_t is 64-bits on all Windows compilers WIN32_FIND_DATA ; HANDLE hf = ::FindFirstFileA(ph.string().c_str(), &ffd); if (hf == INVALID_HANDLE_VALUE) boost::throw_exception( filesystem_error( "boost::filesystem::file_size", ph, fs::detail::system_error_code() ) ); CloseHandle(hf); if ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 ) boost::throw_exception( filesystem_error( "boost::filesystem::file_size", ph, "invalid: is a directory", is_directory_error ) ); return (static_cast<boost::intmax_t>(ffd.nFileSizeHigh) << (sizeof(ffd.nFileSizeLow)*8)) + ffd.nFileSizeLow; # endif } Is there any chance this could be solved in boost::filesystem? Thank you for boost :-) Best regards Jorge

Hi
We have a code base for Windows that compiles with common settings for all Windows platforms. When using boost::filesystem, this is no longer
Well ... except that it doesn't give the same information without at least some work, because of a quirk about root directories. For example, calling FindFirstFile with a UNC path like \\computer\share as input fails. There is a note in the Win32 docs about this. Apparently you'd need to call it with \\computer\share\* . So, at a minimum if you called FindFirstFile instead of GetFileAttributesA, you'd need to append a '*' at the end of it first. Rob. "Jorge Lodos" <lodos@segurmatica.cu> wrote in message news:20050315185100.52ABC12953@Panther.segurmatica.com... possible,
due to the fact that Windows implementation in operations_posix_windows.cpp uses the API function GetFileAttributesExA, not available in Windows 95.
GetFileAttributesExA could be replaced by FindFirstFile, which gives the same information and is available in all Windows platforms.
This API is used in two different places, BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph ) implementation and BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph ) implementation. Using FindFirstFile instead of GetFileAttributesExA we would get:
BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph )
{
# ifdef BOOST_POSIX
........
# else
WIN32_FIND_DATA ;
HANDLE hf = ::FindFirstFileA(ph.string().c_str(), &ffd);
if (hf == INVALID_HANDLE_VALUE)
boost::throw_exception( filesystem_error(
"boost::filesystem::is_empty",
ph, fs::detail::system_error_code() ) );
CloseHandle(hf);
return ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
? is_empty_directory( ph )
:( !ffd.nFileSizeHigh && !ffd.nFileSizeLow );
# endif
}
BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph )
{
# ifdef BOOST_POSIX
.......
# else
// by now, intmax_t is 64-bits on all Windows compilers
WIN32_FIND_DATA ;
HANDLE hf = ::FindFirstFileA(ph.string().c_str(), &ffd);
if (hf == INVALID_HANDLE_VALUE)
boost::throw_exception( filesystem_error(
"boost::filesystem::file_size",
ph, fs::detail::system_error_code() ) );
CloseHandle(hf);
if ( (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) !=0 )
boost::throw_exception( filesystem_error(
"boost::filesystem::file_size",
ph, "invalid: is a directory",
is_directory_error ) );
return (static_cast<boost::intmax_t>(ffd.nFileSizeHigh)
<< (sizeof(ffd.nFileSizeLow)*8))
+ ffd.nFileSizeLow;
# endif
}
Is there any chance this could be solved in boost::filesystem?
Thank you for boost :-)
Best regards
Jorge
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Jorge Lodos
-
Robert Mathews