std::filesystem::hard_link_count
提供: cppreference.com
< cpp | filesystem
ヘッダ <filesystem> で定義 | ||
std::uintmax_t hard_link_count(conststd::filesystem::path& p ); std::uintmax_t hard_link_count(conststd::filesystem::path& p, | (1) | (C++17以上) |
パス p
が表すファイルシステムオブジェクトに対するハードリンクの数を返します。
例外を投げないオーバーロードは、エラーが発生した場合、 static_cast<uintmax_t>(-1) を返します。
目次 |
[編集]引数
p | - | 調べるパス |
ec | - | 例外を投げないオーバーロードでエラーを報告するための出力引数 |
[編集]戻り値
p
に対するハードリンクの数。
[編集]例外
std::error_code& 引数を取らないオーバーロードは、ベースとなる OS の API でエラーが発生した場合、第1パス引数に p
、エラーコード引数に OS のエラーコードを指定して構築された filesystem_error を投げます。 std::error_code& 引数を取るオーバーロードは、 OS の API 呼び出しが失敗した場合、その引数を OS の API のエラーコードに設定し、エラーが発生しない場合は ec.clear() を実行します。 noexcept
指定のないあらゆるオーバーロードは、メモリ確保に失敗した場合 std::bad_alloc を投げる可能性があります。
[編集]例
Run this code
#include <iostream>#include <filesystem>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 parentstd::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 のパブリックメンバ関数) |