Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::experi...::canonical(3)  C++ Standard Libary std::experi...::canonical(3)

NAME
       std::experimental::filesystem::canonical	 - std::experimental::filesys-
       tem::canonical

Synopsis
	  Defined in header <experimental/filesystem>
	  path canonical( const	path& p, const path& base = current_path() (1)
       (filesystem TS)
	  );
	  path canonical( const	path& p, error_code& ec	);		   (2)
       (filesystem TS)
	  path canonical( const	path& p, const path& base, error_code& ec  (3)
       (filesystem TS)
	  );

	  Converts path	p to a canonical absolute path,	i.e. an	absolute  path
       that has	no dot,
	  dot-dot elements or symbolic links.

	  If p is not an absolute path,	the function behaves as	if it is first
       made absolute
	  by absolute(p, base) or absolute(p) for (2)

	  The path p must exist.

Parameters
	  p	-  a path which	may be absolute	or relative to base, and which
       must be an
		 existing path
	  base - base path to be used in case p	is relative
	  ec   - error code to store error status to

Return value
	  An absolute path that	resolves to the	same file as absolute(p, base)
       (or absolute(p)
	  for (2)).

Exceptions
	  The overload that does  not  take  a	error_code&  parameter	throws
       filesystem_error	on
	  underlying  OS API errors, constructed with p	as the first argument,
       base as the
	  second argument, and the OS error code as the	error  code  argument.
       std::bad_alloc
	  may  be thrown if memory allocation fails. The overload taking a er-
       ror_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

	  This function	is modeled after the POSIX realpath.

Example
       // Run this code

	#include <iostream>
	#include <experimental/filesystem>
	namespace fs = std::experimental::filesystem;
	int main()
	{
	    fs::path p = fs::path("..")	/ ".." / "AppData";
	    std::cout << "Current path is " << fs::current_path() << '\n'
		      <<  "Canonical  path for " << p << " is "	<< fs::canoni-
       cal(p) << '\n';
	}

Possible output:
	Current	path is	"C:\Users\abcdef\AppData\Local\Temp"
	Canonical path for "..\..\AppData" is "C:\Users\abcdef\AppData"

See also
	  path		  represents a path
			  (class)
	  absolute	  composes an absolute path
	  system_complete converts a path to an	absolute path replicating  OS-
       specific	behavior
			  (function)

http://cppreference.com		  2022.07.31	  std::experi...::canonical(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::experimental::filesystem::canonical&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help