std::filesystem::hard_link_count
From cppreference.com
< cpp | filesystem
| ヘッダー <filesystem> で定義 |
||
| std::uintmax_t hard_link_count( const std::filesystem::path& p ); |
(1) | (C++17以降) |
| std::uintmax_t hard_link_count( const std::filesystem::path& p, std::error_code& ec ) noexcept; |
(2) | (C++17以降) |
パス p によって識別されるファイルシステムオブジェクトのハードリンク数を返します。
例外を投げないオーバーロードは、エラー時に static_cast<uintmax_t>(-1) を返します。
目次 |
[編集] パラメータ
| p | - | 検査するパス |
| エラーコード | - | 例外を投げないオーバーロードでのエラー報告のための出力パラメータ |
[編集] 戻り値
p のハードリンク数。
[編集] 例外
noexcept とマークされていないオーバーロードは、メモリ割り当てが失敗した場合に std::bad_alloc をスローする可能性があります。
1) 基盤となるOS APIエラーが発生した場合、最初のパス引数としてp、エラーコード引数としてOSのエラーコードとともに構築されたstd::filesystem::filesystem_error を投げます。
[編集] 例
このコードを実行
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { // On a POSIX-style filesystem, each directory has at least 2 hard links: // itself and the special member pathname "." fs::path p = fs::current_path(); std::cout << "Number of hard links for current path is " << fs::hard_link_count(p) << '\n'; // Each ".." is a hard link to the parent directory, so the total number // of hard links for any directory is 2 plus number of direct subdirectories p = fs::current_path() / ".."; // Each dot-dot is a hard link to parent std::cout << "Number of hard links for .. is " << fs::hard_link_count(p) << '\n'; }
実行結果の例
Number of hard links for current path is 2 Number of hard links for .. is 3
[編集] 関連項目
| (C++17) |
ハードリンクを作成する (関数) |
| ディレクトリエントリが参照するファイルを参照するハードリンクの数を返します ( std::filesystem::directory_entry の public メンバ関数) |