• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    function
    <filesystem>

    std::filesystem::create_hard_link

    namespace std::filesystem {
      void create_hard_link(const path& to, const path& new_hard_link); // (1)
      void create_hard_link(const path& to, const path& new_hard_link,
                            std::error_code& ec) noexcept;              // (2)
    }
    

    概要

    ハードリンクを作成する。

    パスtoのファイルと同じinodeを参照するハードリンクをパスnew_hard_linkに作成する。

    効果

    • POSIX環境では、link()関数を使用して、パスtoのファイルと同じinodeを参照するハードリンクをパスnew_hard_linkに作成する

    戻り値

    なし

    例外

    備考

    • ファイルシステムによっては、この関数で通常ファイル以外に対するハードリンクを作成できない場合がある

    #include <cassert>
    #include <filesystem>
    #include <fstream>
    
    namespace fs = std::filesystem;
    
    int main()
    {
      std::ofstream{"regular.txt"};
    
      // regular.txtと同じinodeを参照するハードリンクregular2.txtを作成する
      fs::create_hard_link("regular.txt", "regular2.txt");
    
      assert(fs::exists("regular2.txt"));
      assert(fs::equivalent("regular.txt", "regular2.txt"));
      assert(fs::hard_link_count("regular.txt") == 2);
      assert(fs::hard_link_count("regular2.txt") == 2);
    }
    

    出力

    バージョン

    言語

    • C++17

    処理系