std::experi...read_symlink(3)

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

okay so this is the std::experi...read_symlink(3) page from the C++ Standard Libary manual β€” yes, the title’s got that truncated std::experi... moment, but the actual function is std::experimental::filesystem::read_symlink, and we’re gonna read a symlink’s target together bestie πŸ’…βœ¨

πŸ’… NAME

The NAME line is literally std::experi...read_symlink β€” std::experi...read_symlink (same truncated name twice, dash between, iconic). In normal words: this is the std::experimental::filesystem::read_symlink function.

✨ Synopsis ✨

Defined in header <experimental/filesystem>:

path read_symlink( const path& p );                  (filesystem TS)
path read_symlink( const path& p, error_code& ec );

If the path p refers to a symbolic link, this returns a new path object which refers to the target of that symbolic link.

It is an error if p does not refer to a symbolic link.

The non-throwing overload returns an empty path on errors.

πŸŽ€ Parameters πŸŽ€

  • p β€” path to a symlink
  • ec β€” out-parameter for error reporting in the non-throwing overload

πŸ’– Return value πŸ’–

The target of the symlink β€” which may not necessarily exist πŸ‘€

πŸ”₯ Exceptions πŸ”₯

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 this noexcept specification:

noexcept

🌸 Example 🌸

// Run this code

#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;

int main()
{
    // on a typical Linux system, /lib/libc.so.6 is a symlink
    fs::path p = "/lib/libc.so.6";
    if (exists(p) && is_symlink(p))
        std::cout << p << " -> " << read_symlink(p) << '\n';
    else
        std::cout << p << " does not exist or is not a symlink\n";
}

Possible output:

"/lib/libc.so.6" -> "libc-2.12.so"

πŸ¦‹ See also πŸ¦‹

  • is_symlink β€” checks whether the argument refers to a symbolic link (function)
  • create_symlink β€” creates a symbolic link
  • create_directory_symlink β€” (function)
  • copy_symlink β€” copies a symbolic link (function)
  • status β€” determines file attributes
  • symlink_status β€” determines file attributes, checking the symlink target (function)

πŸ‘‘ Categories πŸ‘‘

  • Noindexed pages
  • unconditionally noexcept

🧚 Hidden categories 🧚

  • Pages with unreviewed unconditional noexcept template
  • Pages with unreviewed noexcept template

that’s the whole page, bestie β€” source/version is http://cppreference.com, dated 2024.06.10 πŸ«ΆπŸ’– mwah!

πŸ“¦ where this page comes from