std::experi...::equivalent(3)
π¦ std::experimental::filesystem::equivalent π¦
okay so this page lives in the C++ Standard Libary manual, and its page id is std::experi...::equivalent(3) β yes, the title is abbreviated like that, iykyk π
πΈ NAME πΈ
std::experimental::filesystem::equivalent β the same name, doing its little NAME-section echo. We love a consistent queen πβ¨
β¨ Synopsis β¨
the exact synopsis is giving βline breaks are a suggestion,β but here it is verbatim bestie:
Defined in header <experimental/filesystem>
bool equivalent( const path& p1, const path& p2 );
bool equivalent( const path& p1, const path& p2, error_code& ec (1)
(filesystem TS)
);
okay so this checks whether the paths p1 and p2 refer to the same file or directory and have the same file status as determined by status (symlinks are followed) π«Ά
if p1 or p2 does not exist, or if their file type is not file, directory, or symlink (as determined by is_other), an error is reported β οΈ
the non-throwing overload returns false on errors. periodt π
π Parameters π
p1,p2β paths to check for equivalence, bestie. thatβs the whole vibe check πecβ out-parameter for error reporting in the non-throwing overload. it catches the tea so the function doesnβt throw βπ
π Return value π
returns true if p1 and p2 refer to the same file or directory and their file status is the same. returns false otherwise. literally that simple, no cap π
π₯ Exceptions π₯
- the overload that does not take an
error_code¶meter throwsfilesystem_erroron underlying OS API errors, constructed withp1as the first argument,p2as the second argument, and the OS error code as the error code argument π std::bad_allocmay be thrown if memory allocation fails. memory said βnot todayβ π- the overload taking an
error_code¶meter sets it to the OS API error code if an OS API call fails, and executesec.clear()if no errors occur. this overload hasnoexceptspecification:noexceptβ¨
π§ Notes π§
two paths are considered to resolve to the same file system entity if st_dev and st_ino of their POSIX stat structure, obtained as if by POSIX stat, are equal β meaning, the files are located on the same device at the same location π
in particular, all hard links for the same file or directory are equivalent, and a symlink and its target on the same file system are equivalent. iconic behavior honestly π
π Example π
run this code, bestie:
// Run this code
#include <cstdint>
#include <experimental/filesystem>
#include <iostream>
namespace fs = std::experimental::filesystem;
int main()
{
// hard link equivalency
fs::path p1 = ".";
fs::path p2 = fs::current_path();
if (fs::equivalent(p1, p2))
std::cout << p1 << " is equivalent to " << p2 << '\n';
// symlink equivalency
fs::path p3 = "/lib/libc.so.6";
fs::path p4 = p3.parent_path() / fs::read_symlink(p3);
if (fs::equivalent(p3, p4))
std::cout << p3 << " is equivalent to " << p4 << '\n';
}
π Possible output π
"." is equivalent to "/var/tmp/test"
"/lib/libc.so.6" is equivalent to "/lib/libc-2.12.so"
slay, the paths understood the assignment π β¨
π See also π
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
source/version: http://cppreference.com Β· date: 2024.06.10 Β· page id: std::experi...::equivalent(3) β thatβs the cute sign-off, bestie πππ«Ά
π¦ 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