std::experimental::filesystem:: hard_link_count
From cppreference.net
<
cpp
|
experimental
|
fs
|
ヘッダー
<experimental/filesystem>
で定義
|
||
|
std::
uintmax_t
hard_link_count
(
const
path
&
p
)
;
std:: uintmax_t hard_link_count ( const path & p, error_code & ec ) ; |
(1) | (filesystem TS) |
パス p によって識別されるファイルシステムオブジェクトのハードリンク数を返します。
例外を送出しないオーバーロードは、エラー時に static_cast < uintmax_t > ( - 1 ) を返します。
目次 |
パラメータ
| p | - | 検査対象のパス |
| ec | - | 例外を投げないオーバーロードにおけるエラー報告用出力パラメータ |
戻り値
p のハードリンク数。
例外
The overload that does not take an error_code & parameter throws filesystem_error on underlying OS API errors, constructed with p as the first argument and the OS error code as the error code argument. std:: bad_alloc may be thrown if memory allocation fails. The overload taking an error_code & parameter sets it to the OS API error code if an OS API call fails, and executes ec. clear ( ) if no errors occur. This overload has
noexcept
仕様:
noexcept
例
このコードを実行
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::filesystem; int main() { // POSIXスタイルのファイルシステムでは、各ディレクトリは少なくとも2つのハードリンクを持つ: // 自身と特別なメンバーパス名 "." fs::path p = fs::current_path(); std::cout << "現在のパスのハードリンク数は " << fs::hard_link_count(p) << '\n'; // 各 ".." は親ディレクトリへのハードリンクであるため、 // 任意のディレクトリのハードリンク総数は 2 + 直接のサブディレクトリ数となる p = fs::current_path() / ".."; // 各ドットドットは親へのハードリンク std::cout << ".. のハードリンク数は " << fs::hard_link_count(p) << '\n'; }
出力:
Number of hard links for current path is 2 Number of hard links for .. is 3
関連項目
|
ハードリンクを作成する
(関数) |