⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 operations.cpp

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 CPP
📖 第 1 页 / 共 4 页
字号:
      BOOST_FILESYSTEM_DECL error_code      create_hard_link_api( const std::wstring & to_ph,        const std::wstring & from_ph )        { return create_hard_link_template( to_ph, from_ph ); }#endif            BOOST_FILESYSTEM_DECL error_code      create_symlink_api( const std::wstring & /*to_ph*/,        const std::wstring & /*from_ph*/ )        { return error_code( ERROR_NOT_SUPPORTED, system_category ); }      BOOST_FILESYSTEM_DECL error_code      remove_api( const std::wstring & ph ) { return remove_template( ph ); }      BOOST_FILESYSTEM_DECL error_code      rename_api( const std::wstring & from, const std::wstring & to )      {        return error_code( ::MoveFileW( from.c_str(), to.c_str() )          ? 0 : ::GetLastError(), system_category );      }      BOOST_FILESYSTEM_DECL error_code      copy_file_api( const std::wstring & from, const std::wstring & to )      {        return error_code( ::CopyFileW( from.c_str(), to.c_str(), /*fail_if_exists=*/true )          ? 0 : ::GetLastError(), system_category );      }      BOOST_FILESYSTEM_DECL bool create_file_api( const std::wstring & ph,        std::ios_base::openmode mode ) // true if succeeds      {        DWORD access(          ((mode & std::ios_base::in) == 0 ? 0 : GENERIC_READ)          | ((mode & std::ios_base::out) == 0 ? 0 : GENERIC_WRITE) );        DWORD disposition(0); // see 27.8.1.3 Table 92        if ( (mode&~std::ios_base::binary)          == (std::ios_base::out|std::ios_base::app) )          disposition = OPEN_ALWAYS;        else if ( (mode&~(std::ios_base::binary|std::ios_base::out))          == std::ios_base::in ) disposition = OPEN_EXISTING;        else if ( ((mode&~(std::ios_base::binary|std::ios_base::trunc))          == std::ios_base::out )          || ((mode&~std::ios_base::binary)          == (std::ios_base::in|std::ios_base::out|std::ios_base::trunc)) )          disposition = CREATE_ALWAYS;        else assert( 0 && "invalid mode argument" );        HANDLE handle ( ::CreateFileW( ph.c_str(), access,          FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 0,          disposition, (mode &std::ios_base::out) != 0          ? FILE_ATTRIBUTE_ARCHIVE : FILE_ATTRIBUTE_NORMAL, 0 ) );        if ( handle == INVALID_HANDLE_VALUE ) return false;        ::CloseHandle( handle );        return true;      }      BOOST_FILESYSTEM_DECL std::string narrow_path_api(        const std::wstring & ph ) // return is empty if fails      {        std::string narrow_short_form;        std::wstring short_form;        for ( DWORD buf_sz( static_cast<DWORD>( ph.size()+1 ));; )        {          boost::scoped_array<wchar_t> buf( new wchar_t[buf_sz] );          DWORD sz( ::GetShortPathNameW( ph.c_str(), buf.get(), buf_sz ) );          if ( sz == 0 ) return narrow_short_form;          if ( sz <= buf_sz )          {            short_form += buf.get();            break;          }          buf_sz = sz + 1;        }        // contributed by Takeshi Mouri:        int narrow_sz( ::WideCharToMultiByte( CP_ACP, 0,          short_form.c_str(), static_cast<int>(short_form.size()), 0, 0, 0, 0 ) );        boost::scoped_array<char> narrow_buf( new char[narrow_sz] );        ::WideCharToMultiByte( CP_ACP, 0,          short_form.c_str(), static_cast<int>(short_form.size()),          narrow_buf.get(), narrow_sz, 0, 0 );        narrow_short_form.assign(narrow_buf.get(), narrow_sz);        return narrow_short_form;      }      BOOST_FILESYSTEM_DECL error_code      dir_itr_first( void *& handle, const std::wstring & dir,        std::wstring & target, file_status & sf, file_status & symlink_sf )      {        // use a form of search Sebastian Martel reports will work with Win98        std::wstring dirpath( dir );        dirpath += (dirpath.empty()          || dirpath[dirpath.size()-1] != L'\\') ? L"\\*" : L"*";        WIN32_FIND_DATAW data;        if ( (handle = ::FindFirstFileW( dirpath.c_str(), &data ))          == INVALID_HANDLE_VALUE )        {           handle = 0;          return error_code( ::GetLastError() == ERROR_FILE_NOT_FOUND            ? 0 : ::GetLastError(), system_category );        }        target = data.cFileName;        if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )          { sf.type( directory_file ); symlink_sf.type( directory_file ); }        else { sf.type( regular_file ); symlink_sf.type( regular_file ); }        return ok;      }        BOOST_FILESYSTEM_DECL error_code      dir_itr_increment( void *& handle, std::wstring & target,        file_status & sf, file_status & symlink_sf )      {        WIN32_FIND_DATAW data;        if ( ::FindNextFileW( handle, &data ) == 0 ) // fails        {          int error = ::GetLastError();          dir_itr_close( handle );          return error_code( error == ERROR_NO_MORE_FILES ? 0 : error, system_category );        }        target = data.cFileName;        if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )          { sf.type( directory_file ); symlink_sf.type( directory_file ); }        else { sf.type( regular_file ); symlink_sf.type( regular_file ); }        return ok;      }#     endif // ifndef BOOST_FILESYSTEM_NARROW_ONLY      // suggested by Walter Landry      BOOST_FILESYSTEM_DECL bool symbolic_link_exists_api( const std::string & )        { return false; }      BOOST_FILESYSTEM_DECL      fs::detail::query_pair is_empty_api( const std::string & ph )        { return is_empty_template( ph ); }      BOOST_FILESYSTEM_DECL      fs::detail::query_pair      equivalent_api( const std::string & ph1, const std::string & ph2 )        { return equivalent_template( ph1, ph2 ); }      BOOST_FILESYSTEM_DECL      fs::detail::uintmax_pair file_size_api( const std::string & ph )        { return file_size_template( ph ); }      BOOST_FILESYSTEM_DECL      fs::detail::space_pair space_api( const std::string & ph )        { return space_template( ph ); }      BOOST_FILESYSTEM_DECL      error_code       get_current_path_api( std::string & ph )        { return get_current_path_template( ph ); }      BOOST_FILESYSTEM_DECL      error_code       set_current_path_api( const std::string & ph )        { return set_current_path_template( ph ); }      BOOST_FILESYSTEM_DECL error_code        get_full_path_name_api( const std::string & ph, std::string & target )         { return get_full_path_name_template( ph, target ); }      BOOST_FILESYSTEM_DECL time_pair        last_write_time_api( const std::string & ph )          { return last_write_time_template( ph ); }       BOOST_FILESYSTEM_DECL error_code        last_write_time_api( const std::string & ph, std::time_t new_value )          { return last_write_time_template( ph, new_value ); }      BOOST_FILESYSTEM_DECL fs::detail::query_pair      create_directory_api( const std::string & ph )        { return create_directory_template( ph ); }#if _WIN32_WINNT >= 0x500      BOOST_FILESYSTEM_DECL error_code      create_hard_link_api( const std::string & to_ph,        const std::string & from_ph )      {         return create_hard_link_template( to_ph, from_ph );      }#endif      BOOST_FILESYSTEM_DECL error_code      create_symlink_api( const std::string & /*to_ph*/,        const std::string & /*from_ph*/ )        { return error_code( ERROR_NOT_SUPPORTED, system_category ); }      BOOST_FILESYSTEM_DECL error_code      remove_api( const std::string & ph ) { return remove_template( ph ); }      BOOST_FILESYSTEM_DECL error_code      rename_api( const std::string & from, const std::string & to )      {        return error_code( ::MoveFileA( from.c_str(), to.c_str() )          ? 0 : ::GetLastError(), system_category );      }      BOOST_FILESYSTEM_DECL error_code      copy_file_api( const std::string & from, const std::string & to )      {        return error_code( ::CopyFileA( from.c_str(), to.c_str(), /*fail_if_exists=*/true )          ? 0 : ::GetLastError(), system_category );      }      BOOST_FILESYSTEM_DECL error_code      dir_itr_first( void *& handle, const std::string & dir,        std::string & target, file_status & sf, file_status & symlink_sf )      // Note: an empty root directory has no "." or ".." entries, so this      // causes a ERROR_FILE_NOT_FOUND error which we do not considered an      // error. It is treated as eof instead.      {        // use a form of search Sebastian Martel reports will work with Win98        std::string dirpath( dir );        dirpath += (dirpath.empty()          || (dirpath[dirpath.size()-1] != '\\'            && dirpath[dirpath.size()-1] != ':')) ? "\\*" : "*";        WIN32_FIND_DATAA data;        if ( (handle = ::FindFirstFileA( dirpath.c_str(), &data ))          == INVALID_HANDLE_VALUE )        {           handle = 0;          return error_code( ::GetLastError() == ERROR_FILE_NOT_FOUND            ? 0 : ::GetLastError(), system_category );        }        target = data.cFileName;        if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )          { sf.type( directory_file ); symlink_sf.type( directory_file ); }        else { sf.type( regular_file ); symlink_sf.type( regular_file ); }        return ok;      }      BOOST_FILESYSTEM_DECL error_code      dir_itr_close( void *& handle )      {        if ( handle != 0 )        {          bool ok = ::FindClose( handle ) != 0;          handle = 0;          return error_code( ok ? 0 : ::GetLastError(), system_category );        }        return ok;      }      BOOST_FILESYSTEM_DECL error_code      dir_itr_increment( void *& handle, std::string & target,        file_status & sf, file_status & symlink_sf )      {        WIN32_FIND_DATAA data;        if ( ::FindNextFileA( handle, &data ) == 0 ) // fails        {          int error = ::GetLastError();          dir_itr_close( handle );          return error_code( error == ERROR_NO_MORE_FILES ? 0 : error, system_category );        }        target = data.cFileName;        if ( data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )          { sf.type( directory_file ); symlink_sf.type( directory_file ); }        else { sf.type( regular_file ); symlink_sf.type( regular_file ); }        return ok;      }#   else // BOOST_POSIX_API      BOOST_FILESYSTEM_DECL fs::file_status      status_api( const std::string & ph, error_code & ec )      {        struct stat path_stat;        if ( ::stat( ph.c_str(), &path_stat ) != 0 )        {          if ( errno == ENOENT || errno == ENOTDIR )          {            ec = ok;            return fs::file_status( fs::file_not_found );          }          ec = error_code( errno, system_category );          return fs::file_status( fs::status_unknown );        }        ec = ok;        if ( S_ISDIR( path_stat.st_mode ) )          return fs::file_status( fs::directory_file );        if ( S_ISREG( path_stat.st_mode ) )          return fs::file_status( fs::regular_file );        if ( S_ISBLK( path_stat.st_mode ) )          return fs::file_status( fs::block_file );        if ( S_ISCHR( path_stat.st_mode ) )          return fs::file_status( fs::character_file );        if ( S_ISFIFO( path_stat.st_mode ) )          return fs::file_status( fs::fifo_file );        if ( S_ISSOCK( path_stat.st_mode ) )          return fs::file_status( fs::socket_file );        return fs::file_status( fs::type_unknown );      }      BOOST_FILESYSTEM_DECL fs::file_status      symlink_status_api( const std::string & ph, error_code & ec )      {        struct stat path_stat;        if ( ::lstat( ph.c_str(), &path_stat ) != 0 )        {          if ( errno == ENOENT || errno == ENOTDIR )          {            ec = ok;            return fs::file_status( fs::file_not_found );          }          ec = error_code( errno, system_category );          return fs::file_status( fs::status_unknown );        }        ec = ok;        if ( S_ISREG( path_stat.st_mode ) )          return fs::file_status( fs::regular_file );        if ( S_ISDIR( path_stat.st_mode ) )          return fs::file_status( fs::directory_file );        if ( S_ISLNK( path_stat.st_mode ) )          return fs::file_status( fs::symlink_file );        if ( S_ISBLK( path_stat.st_mode ) )          return fs::file_status( fs::block_file );        if ( S_ISCHR( path_stat.st_mode ) )          return fs::file_status( fs::character_file );        if ( S_ISFIFO( path_stat.st_mode ) )          return fs::file_status( fs::fifo_file );        if ( S_ISSOCK( path_stat.st_mode ) )          return fs::file_status( fs::socket_file );        return fs::file_status( fs::type_unknown );      }      // suggested by Walter Landry      BOOST_FILESYSTEM_DECL bool      symbolic_link_exists_api( const std::string & ph )      {        struct stat path_stat;        return ::lstat( ph.c_str(), &path_stat ) == 0          && S_ISLNK( path_stat.st_mode );      }      BOOST_FILESYSTEM_DECL query_pair      is_empty_api( const std::string & ph )      {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -