Converts path
pto a canonical absolute path, i.e. an absolute path that has no dot, dot-dot elements or symbolic links in its generic format representation. If
pis not an absolute path, the function behaves as if it is first made absolute by
std::filesystem::absolute(p). The path
pmust exist.
3,4)Returns a path composed by
operator/=from the result of calling
canonical()
with a path argument composed of the leading elements of
pthat exist (as determined by
status(p)or
status(p, ec)), if any, followed by the elements of
pthat do not exist. The resulting path is in
normal form.
[edit] Parameters p - a path which may be absolute or relative; forcanonical
it must be an existing path ec - error code to store error status to [edit] Return value
3,4) A normal path of the form canonical(x)/y, where x is a path composed of the longest leading sequence of elements in p that exist, and y is a path composed of the remaining trailing non-existent elements of p.
[edit] ExceptionsAny overload not marked noexcept
may throw std::bad_alloc if memory allocation fails.
Throws
std::filesystem::filesystem_erroron underlying OS API errors, constructed with
pas the first path argument and the OS error code as the error code argument.
2,4)Sets a
std::error_code¶meter to the OS API error code if an OS API call fails, and executes
ec.clear()if no errors occur.
[edit] NotesThe function canonical()
is modeled after the POSIX realpath
.
The function weakly_canonical()
was introduced to simplify operational semantics of relative()
.
Possible output:
Current path is "/tmp/a/b/c1/d" Canonical path for "../../c2/./e" is "/tmp/a/b/c2/e" Weakly canonical path for "../no-such-file" is "/tmp/a/b/c1/no-such-file" Canonical path for "../no-such-file" threw exception: filesystem error: in canonical: No such file or directory [../no-such-file] [/tmp/a/b/c1/d] Deleted 6 files or directories.[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 2956 C++17canonical
has a spurious base
parameter removed [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4