std::experi..._link_count(3)
π NAME π
okay so bestie, this is the std::experi..._link_count(3) page from the C++ Standard Libary manual β yes, that's the manual name, spelling and all β¨. The NAME line is std::experimental::filesystem::hard_link_count - std::experimental::filesystem::hard_link_count, so we're doing the double-name thing. iconic.
β¨ Synopsis β¨
Two overloads, no cap:
Defined in header <experimental/filesystem>
std::uintmax_t hard_link_count( const path& p ); (1)
(filesystem TS)
std::uintmax_t hard_link_count( const path& p, error_code& ec );
This one returns the number of hard links for the filesystem object identified by path p. The non-throwing overload returns static_cast<uintmax_t>(-1) on errors β literally that value, bestie.
π Parameters π
pβ path to examineecβ out-parameter for error reporting in the non-throwing overload
π« Return value π«
The number of hard links for p. That's the whole mood. π«Ά
π¨ Exceptions π¨
Okay pay attention, this part is real:
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 specification: noexcept.
π» Example π»
// Run this code β go off, bestie:
#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';
}
π¨οΈ Output π¨οΈ
Number of hard links for current path is 2
Number of hard links for .. is 3
π See also π
create_hard_linkβ creates a hard link (function)
ποΈ Categories ποΈ
- Noindexed pages
- unconditionally noexcept
π Hidden categories π
- Pages with unreviewed unconditional noexcept template
- Pages with unreviewed noexcept template
okay bye bestie, this one came from http://cppreference.com, version/date tag 2024.06.10, and the footer title is std::experi..._link_count(3). periodt π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms