• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <filesystem>

    std::filesystem::hard_link_count

    namespace std::filesystem {
      std::uintmax_t hard_link_count(const path& p);                               // (1)
      std::uintmax_t hard_link_count(const path& p, std::error_code& ec) noexcept; // (2)
    }
    

    概要

    ハードリンク数を取得する。

    戻り値

    • パスpのハードリンク数を返す
    • ファイルシステムでエラーが発生した場合、 (1) ではstd::filesystem::filesystem_error例外を送出し、 (2) ではecにエラー情報が設定されてstatic_cast<uintmax_t>(-1)が返る

    例外

    • (1) : ファイルシステムがエラーを報告する場合がある。それに加えて、指定されたファイルが存在しない場合もエラーである。エラーが発生した場合は、std::filesystem::filesystem_error例外を送出する
    • (2) : 投げない

    #include <cassert>
    #include <fstream>
    #include <filesystem>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      std::ofstream{"regular.txt"};
    
      assert(fs::hard_link_count("regular.txt") == 1);
    
      fs::create_hard_link("regular.txt", "regular-2.txt");
    
      assert(fs::hard_link_count("regular.txt") == 2);
      assert(fs::hard_link_count("regular-2.txt") == 2);
    }
    

    出力

    バージョン

    言語

    • C++17

    処理系