Boost logo

Boost :

From: Jorge Lodos (lodos_at_[hidden])
Date: 2005-03-15 14:45:47


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

 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk