- filesystem[meta header]
- std::filesystem[meta namespace]
- function[meta id-type]
- cpp17[meta cpp]
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)
}
- path[link path.md]
ハードリンクを作成する。
パスto
のファイルと同じinodeを参照するハードリンクをパスnew_hard_link
に作成する。
- POSIX環境では、
link()
関数を使用して、パスto
のファイルと同じinodeを参照するハードリンクをパスnew_hard_link
に作成する
なし
- (1) : ファイルシステムがエラーを報告する場合がある。エラーが発生した場合は、
std::filesystem::filesystem_error
例外を送出する - (2) : 投げない
- ファイルシステムによっては、この関数で通常ファイル以外に対するハードリンクを作成できない場合がある
#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);
}
- fs::create_hard_link[color ff0000]
- fs::exists[link exists.md]
- fs::equivalent[link equivalent.md]
- fs::hard_link_count[link hard_link_count.md]
- C++17
- Clang: 7.0 [mark verified]
- GCC: 8.1 [mark verified]
- Visual C++: