std::experi...read_symlink(3)
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 symlinkecβ 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 linkcreate_directory_symlinkβ (function)copy_symlinkβ copies a symbolic link (function)statusβ determines file attributessymlink_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
- 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