std::experimental::filesystem::hard_link_count
来自 cppreference.cn
< 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 的硬链接数。
[编辑] 异常
不接受 error_code& 参数的重载在底层操作系统 API 错误时抛出 filesystem_error 异常,该异常以 p 作为第一个参数,操作系统错误代码作为错误代码参数构造。 std::bad_alloc 如果内存分配失败,可能会抛出异常。 接受 error_code& 参数的重载在操作系统 API 调用失败时将其设置为操作系统 API 错误代码,如果没有错误发生,则执行 ec.clear()。 此重载具有noexcept 规范:
noexcept
[编辑] 示例
运行此代码
#include <experimental/filesystem> #include <iostream> namespace fs = std::experimental::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
[编辑] 参见
创建硬链接 (函数) |