std::experi..._link_count(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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 examine
  • ec β€” 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