Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-09-27 04:45:03


Beman,

you use the WinAPI call GetFileAttributesExA only twice in
Boost.Filesystem, in _is_empty and file_size, but that means that the code
won't run on Windows 95:

file is linked to missing export KERNEL32.DLL:GetFileAttributesExA

The msdn docs
http://msdn.microsoft.com/library/en-us/fileio/fs/getfileattributesex.asp
suggest that Win95 support requires only that you grab NewAPIs.h from the
SDK Update Site.

Here's an example of how it should be used:
==========================================================================
http://codeproject.com/win32/harddiskspace.asp?df=100&forumid=15107&exp=0&select=466926

#define COMPILE_NEWAPIS_STUBS
#define WANT_GETDISKFREESPACEEX_WRAPPER

then in the file where you use GetDiskFreeSpaceEx....

#include <newapis.h>
==========================================================================

Alternatively, I append a naïve implementation of the two files using
GetFileAttributes and GetFileSize.

Is any of this useful?

Regards,
Angus

    BOOST_FILESYSTEM_DECL bool _is_empty( const path & ph )
    {
      DWORD const attributes = GetFileAttributes( ph.string().c_str() );
      if ( attributes & INVALID_FILE_ATTRIBUTES )
        boost::throw_exception( filesystem_error(
          "boost::filesystem::is_empty",
          ph, fs::detail::system_error_code() ) );

      if ( attributes & FILE_ATTRIBUTE_DIRECTORY )
        return is_empty_directory( ph );

      DWORD file_size_high =
      DWORD const file_size_low =
        ::GetFileSize( ph.string().c_str(), &file_size_high );

      if ( file_size_low == INVALID_FILE_SIZE ) {
        if ( GetLastError() = NO_ERROR )
          boost::throw_exception( filesystem_error(
          "boost::filesystem::is_empty",
          ph, fs::detail::system_error_code() ) );

      return ( !file_size_high && !file_size_low );
    }

    BOOST_FILESYSTEM_DECL boost::intmax_t file_size( const path & ph )
    {
      DWORD const attributes = GetFileAttributes( ph.string().c_str() );
      if ( attributes & INVALID_FILE_ATTRIBUTES )
        boost::throw_exception( filesystem_error(
          "boost::filesystem::is_empty",
          ph, fs::detail::system_error_code() ) );

      if ( attributes & FILE_ATTRIBUTE_DIRECTORY )
        boost::throw_exception( filesystem_error(
          "boost::filesystem::file_size",
          ph, "invalid: is a directory",
          is_directory_error ) );

      DWORD file_size_high =
      DWORD const file_size_low =
        ::GetFileSize( ph.string().c_str(), &file_size_high );

      if ( file_size_low == INVALID_FILE_SIZE ) {
        if ( GetLastError() = NO_ERROR )
          boost::throw_exception( filesystem_error(
          "boost::filesystem::is_empty",
          ph, fs::detail::system_error_code() ) );

      return (static_cast<boost::intmax_t>( file_size_high )
          << (sizeof( file_size_low )*8))
        + file_size_low
    }


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