27 Input/output library [input.output]

27.10 File systems [filesystems]

27.10.15 Filesystem operation functions [fs.op.funcs]

Filesystem operation functions query or modify files, including directories, in external storage.

Note: Because hardware failures, network failures, file system races ([fs.def.race]), and many other kinds of errors occur frequently in file system operations, users should be aware that any filesystem operation function, no matter how apparently innocuous, may encounter an error; see [fs.err.report].  — end note ]

27.10.15.1 Absolute [fs.op.absolute]

path absolute(const path& p, const path& base = current_path());

Returns: An absolute path ([fs.def.absolute.path]) composed according to Table [tab:absolute.path].

Table 126absolute(const path&, const path&) return value
p.has_root_directory()!p.has_root_directory()
p.has_root_name() p 2.4in p.root_name()
/ absolute(base).root_directory()
/ absolute(base).relative_path()
/ p.relative_path()
!p.has_root_name() absolute(base).root_name() / p absolute(base) / p

Note: For the returned path, rp, rp.is_absolute() is true.  — end note ]

Throws: As specified in [fs.err.report].

27.10.15.2 Canonical [fs.op.canonical]

path canonical(const path& p, const path& base = current_path()); path canonical(const path& p, error_code& ec); path canonical(const path& p, const path& base, error_code& ec);

Effects: Converts p, which must exist, to an absolute path that has no symbolic link, ".", or ".." elements.

Returns: A path that refers to the same file system object as absolute(p, base). For the overload without a base argument, base is current_path(). Signatures with argument ec return path() if an error occurs.

Throws: As specified in [fs.err.report].

Remarks: !exists(p) is an error.

27.10.15.3 Copy [fs.op.copy]

void copy(const path& from, const path& to); void copy(const path& from, const path& to, error_code& ec) noexcept;

Effects: Equivalent to copy(from, to, copy_options::none) or copy(from, to, copy_options::none, ec), respectively.

void copy(const path& from, const path& to, copy_options options); void copy(const path& from, const path& to, copy_options options, error_code& ec) noexcept;

Requires: At most one constant from each option group ([enum.copy_options]) is present in options.

Effects: Before the first use of f and t:

  • If

    (options & copy_options::create_symlinks) != copy_options::none ||
    (options & copy_options::skip_symlinks) != copy_options::none
    

    then auto f = symlink_status(from) and if needed auto t = symlink_status(to).

  • Otherwise, if

    (options & copy_options::copy_symlinks) != copy_options::none
    

    then auto f = symlink_status(from) and if needed auto t = status(to).

  • Otherwise, auto f = status(from) and if needed auto t = status(to).

Effects are then as follows:

  • An error is reported as specified in [fs.err.report] if:

  • Otherwise, if is_symlink(f), then:

    • If (options & copy_options::skip_symlinks) != copy_options::none then return.

    • Otherwise if

      !exists(t) && (options & copy_options::copy_symlinks) != copy_options::none
      

      then copy_symlink(from, to).

    • Otherwise report an error as specified in [fs.err.report].

  • Otherwise, if is_regular_file(f), then:

    • If (options & copy_options::directories_only) != copy_options::none, then return.

    • Otherwise if (options & copy_options::create_symlinks) != copy_options::none, then create a symbolic link to the source file.

    • Otherwise if (options & copy_options::create_hard_links) != copy_options::none, then create a hard link to the source file.

    • Otherwise if is_directory(t), then copy_file(from, to/from.filename(), options).

    • Otherwise, copy_file(from, to, options).

  • Otherwise, if

    is_directory(f) &&
    ((options & copy_options::recursive) != copy_options::none ||
     options == copy_options::none)
    

    then:

    • If !exists(t), then create_directory(to, from).

    • Then, iterate over the files in from, as if by for (const directory_entry& x : directory_iterator(from)), and for each iteration

      copy(x.path(), to/x.path().filename(), options | copy_options::unspecified)
      
  • Otherwise, for the signature with argument ec, ec.clear().

  • Otherwise, no effects.

Throws: As specified in [fs.err.report].

Remarks: For the signature with argument ec, any library functions called by the implementation shall have an error_code argument if applicable.

Example: Given this directory structure:

/dir1
  file1
  file2
  dir2
    file3

Calling copy("/dir1", "/dir3") would result in:

/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2

Alternatively, calling copy("/dir1", "/dir3", copy_options::recursive) would result in:

/dir1
  file1
  file2
  dir2
    file3
/dir3
  file1
  file2
  dir2
    file3

 — end example ]

27.10.15.4 Copy file [fs.op.copy_file]

bool copy_file(const path& from, const path& to); bool copy_file(const path& from, const path& to, error_code& ec) noexcept;

Returns: copy_file(from, to, copy_options::none) or
copy_file(from, to, copy_options::none, ec), respectively.

Throws: As specified in [fs.err.report].

bool copy_file(const path& from, const path& to, copy_options options); bool copy_file(const path& from, const path& to, copy_options options, error_code& ec) noexcept;

Requires: At most one constant from each copy_options option group ([enum.copy_options]) is present in options.

Effects: As follows:

  • Report a file already exists error as specified in [fs.err.report] if:

    • !is_regular_file(from), or

    • exists(to) and !is_regular_file(to), or

    • exists(to) and equivalent(from, to), or

    • exists(to) and (options & (copy_options::skip_existing | copy_options::overwrite_existing | copy_options::update_existing)) == copy_options::none.

  • Otherwise, copy the contents and attributes of the file from resolves to, to the file to resolves to, if:

    • !exists(to), or

    • exists(to) and (options & copy_options::overwrite_existing) != copy_options::none, or

    • exists(to) and (options & copy_options::update_existing) != copy_options::none and from is more recent than to, determined as if by use of the last_write_time function ([fs.op.last_write_time]).

  • Otherwise, no effects.

Returns: true if the from file was copied, otherwise false. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

Complexity: At most one direct or indirect invocation of status(to).

27.10.15.6 Create directories [fs.op.create_directories]

bool create_directories(const path& p); bool create_directories(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition by calling create_directory() for any element of p that does not exist.

Postconditions: is_directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

Complexity: Ο(n) where n is the number of elements of p that do not exist.

27.10.15.7 Create directory [fs.op.create_directory]

bool create_directory(const path& p); bool create_directory(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition by attempting to create the directory p resolves to, as if by POSIX mkdir() with a second argument of static_cast<int>(perms::all). Creation failure because p resolves to an existing directory shall not be treated as an error.

Postconditions: is_directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

bool create_directory(const path& p, const path& existing_p); bool create_directory(const path& p, const path& existing_p, error_code& ec) noexcept;

Effects: Establishes the postcondition by attempting to create the directory p resolves to, with attributes copied from directory existing_p. The set of attributes copied is operating system dependent. Creation failure because p resolves to an existing directory shall not be treated as an error. [ Note: For POSIX-based operating systems, the attributes are those copied by native API stat(existing_p.c_str(), &attributes_stat) followed by mkdir(p.c_str(), attributes_stat.st_mode). For Windows-based operating systems, the attributes are those copied by native API CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0).  — end note ]

Postconditions: is_directory(p).

Returns: true if a new directory was created, otherwise false. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.8 Create directory symlink [fs.op.create_dir_symlk]

void create_directory_symlink(const path& to, const path& new_symlink); void create_directory_symlink(const path& to, const path& new_symlink, error_code& ec) noexcept;

Effects: Establishes the postcondition, as if by POSIX symlink().

Postconditions: new_symlink resolves to a symbolic link file that contains an unspecified representation of to.

Throws: As specified in [fs.err.report].

Note: Some operating systems require symlink creation to identify that the link is to a directory. Portable code should use create_directory_symlink() to create directory symlinks rather than create_symlink()  — end note ]

Note: Some operating systems do not support symbolic links at all or support them only for regular files. Some file systems (such as the FAT file system) do not support symbolic links regardless of the operating system.  — end note ]

27.10.15.9 Create hard link [fs.op.create_hard_lk]

void create_hard_link(const path& to, const path& new_hard_link); void create_hard_link(const path& to, const path& new_hard_link, error_code& ec) noexcept;

Effects: Establishes the postcondition, as if by POSIX link().

Postconditions:

  • exists(to) && exists(new_hard_link) && equivalent(to, new_hard_link)

  • The contents of the file or directory to resolves to are unchanged.

Throws: As specified in [fs.err.report].

Note: Some operating systems do not support hard links at all or support them only for regular files. Some file systems (such as the FAT file system) do not support hard links regardless of the operating system. Some file systems limit the number of links per file.  — end note ]

27.10.15.11 Current path [fs.op.current_path]

path current_path(); path current_path(error_code& ec);

Returns: The absolute path of the current working directory, obtained as if by POSIX getcwd(). The signature with argument ec returns path() if an error occurs.

Throws: As specified in [fs.err.report].

Remarks: The current working directory is the directory, associated with the process, that is used as the starting location in pathname resolution for relative paths.

Note: The current_path() name was chosen to emphasize that the returned value is a path, not just a single directory name.

The current path as returned by many operating systems is a dangerous global variable. It may be changed unexpectedly by a third-party or system library functions, or by another thread.  — end note ]

void current_path(const path& p); void current_path(const path& p, error_code& ec) noexcept;

Effects: Establishes the postcondition, as if by POSIX chdir().

Postconditions: equivalent(p, current_path()).

Throws: As specified in [fs.err.report].

Note: The current path for many operating systems is a dangerous global state. It may be changed unexpectedly by a third-party or system library functions, or by another thread.  — end note ]

27.10.15.12 Equivalent [fs.op.equivalent]

bool equivalent(const path& p1, const path& p2); bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;

Let s1 and s2 be file_statuss, determined as if by status(p1) and status(p2), respectively.

Effects: Determines s1 and s2. If (!exists(s1) && !exists(s2)) || (is_other(s1) && is_other(s2)) an error is reported ([fs.err.report]).

Returns: true, if s1 == s2 and p1 and p2 resolve to the same file system entity, else false. The signature with argument ec returns false if an error occurs.

Two paths are considered to resolve to the same file system entity if two candidate entities reside on the same device at the same location. This is determined as if by the values of the POSIX stat structure, obtained as if by stat() for the two paths, having equal st_dev values and equal st_ino values.

Throws: As specified in ([fs.err.report]).

27.10.15.13 Exists [fs.op.exists]

bool exists(file_status s) noexcept;

Returns: status_known(s) && s.type() != file_type::not_found.

bool exists(const path& p); bool exists(const path& p, error_code& ec) noexcept;

Let s be a file_status, determined as if by status(p) or status(p, ec), respectively.

Effects: The signature with argument ec calls ec.clear() if status_known(s).

Returns: exists(s).

Throws: As specified in [fs.err.report].

27.10.15.14 File size [fs.op.file_size]

uintmax_t file_size(const path& p); uintmax_t file_size(const path& p, error_code& ec) noexcept;

Returns: If !exists(p) || !is_regular_file(p) an error is reported ([fs.err.report]). Otherwise, the size in bytes of the file p resolves to, determined as if by the value of the POSIX stat structure member st_size obtained as if by POSIX stat(). The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.15 Hard link count [fs.op.hard_lk_ct]

uintmax_t hard_link_count(const path& p); uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;

Returns: The number of hard links for p. The signature with argument ec returns static_cast<uintmax_t>(-1) if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.16 Is block file [fs.op.is_block_file]

bool is_block_file(file_status s) noexcept;

Returns: s.type() == file_type::block.

bool is_block_file(const path& p); bool is_block_file(const path& p, error_code& ec) noexcept;

Returns: is_block_file(status(p)) or is_block_file(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.17 Is character file [fs.op.is_char_file]

bool is_character_file(file_status s) noexcept;

Returns: s.type() == file_type::character.

bool is_character_file(const path& p); bool is_character_file(const path& p, error_code& ec) noexcept;

Returns: is_character_file(status(p)) or is_character_file(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.18 Is directory [fs.op.is_directory]

bool is_directory(file_status s) noexcept;

Returns: s.type() == file_type::directory.

bool is_directory(const path& p); bool is_directory(const path& p, error_code& ec) noexcept;

Returns: is_directory(status(p)) or is_directory(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.19 Is empty [fs.op.is_empty]

bool is_empty(const path& p); bool is_empty(const path& p, error_code& ec) noexcept;

Effects:

  • Determine file_status s, as if by status(p) or status(p, ec), respectively.

  • For the signature with argument ec, return false if an error occurred.

  • Otherwise, if is_directory(s):

    • Create directory_iterator itr, as if by directory_iterator(p) or directory_iterator(p, ec), respectively.

    • For the signature with argument ec, return false if an error occurred.

    • Otherwise, return itr == directory_iterator().

  • Otherwise:

    • Determine uintmax_t sz, as if by file_size(p) or file_size(p, ec), respectively.

    • For the signature with argument ec, return false if an error occurred.

    • Otherwise, return sz == 0.

Throws: As specified in [fs.err.report].

27.10.15.20 Is fifo [fs.op.is_fifo]

bool is_fifo(file_status s) noexcept;

Returns: s.type() == file_type::fifo.

bool is_fifo(const path& p); bool is_fifo(const path& p, error_code& ec) noexcept;

Returns: is_fifo(status(p)) or is_fifo(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.21 Is other [fs.op.is_other]

bool is_other(file_status s) noexcept;

Returns: exists(s) && !is_regular_file(s) && !is_directory(s) && !is_symlink(s).

bool is_other(const path& p); bool is_other(const path& p, error_code& ec) noexcept;

Returns: is_other(status(p)) or is_other(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.22 Is regular file [fs.op.is_regular_file]

bool is_regular_file(file_status s) noexcept;

Returns: s.type() == file_type::regular.

bool is_regular_file(const path& p);

Returns: is_regular_file(status(p)).

Throws: filesystem_error if status(p) would throw filesystem_error.

bool is_regular_file(const path& p, error_code& ec) noexcept;

Effects: Sets ec as if by status(p, ec). [ Note: file_type::none, file_type::not_found and file_type::unknown cases set ec to error values. To distinguish between cases, call the status function directly.  — end note ]

Returns: is_regular_file(status(p, ec)). Returns false if an error occurs.

27.10.15.23 Is socket [fs.op.is_socket]

bool is_socket(file_status s) noexcept;

Returns: s.type() == file_type::socket.

bool is_socket(const path& p); bool is_socket(const path& p, error_code& ec) noexcept;

Returns: is_socket(status(p)) or is_socket(status(p, ec)), respectively. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.25 Last write time [fs.op.last_write_time]

file_time_type last_write_time(const path& p); file_time_type last_write_time(const path& p, error_code& ec) noexcept;

Returns: The time of last data modification of p, determined as if by the value of the POSIX stat structure member st_mtime obtained as if by POSIX stat(). The signature with argument ec returns file_time_type::min() if an error occurs.

Throws: As specified in [fs.err.report].

void last_write_time(const path& p, file_time_type new_time); void last_write_time(const path& p, file_time_type new_time, error_code& ec) noexcept;

Effects: Sets the time of last data modification of the file resolved to by p to new_time, as if by POSIX futimens().

Throws: As specified in [fs.err.report].

Note: A postcondition of last_write_time(p) == new_time is not specified since it might not hold for file systems with coarse time granularity.  — end note ]

27.10.15.26 Permissions [fs.op.permissions]

void permissions(const path& p, perms prms); void permissions(const path& p, perms prms, error_code& ec);

Requires: !((prms & perms::add_perms) != perms::none && (prms & perms::remove_perms) != perms::none).

Effects: Applies the effective permissions bits from prms to the file p resolves to, or if that file is a symbolic link and symlink_nofollow is not set in prms, the file that it points to, as if by POSIX fchmodat(). The effective permission bits are determined as specified in Table [tab:fs.op.permissions], where s is the result of (prms & perms::symlink_nofollow) != perms::none ? symlink_status(p) : status(p).

Table 127 — Effects of permission bits
Bits present in prmsEffective bits applied
Neither add_perms nor remove_perms prms & perms::mask
add_perms s.permissions() | (prms & perms::mask)
remove_perms s.permissions() & ~(prms & perms::mask)

Note: Conceptually permissions are viewed as bits, but the actual implementation may use some other mechanism.  — end note ]

Throws: As specified in [fs.err.report].

27.10.15.27 Proximate [fs.op.proximate]

path proximate(const path& p, error_code& ec);

Returns: proximate(p, current_path(), ec).

Throws: As specified in [fs.err.report].

path proximate(const path& p, const path& base = current_path()); path proximate(const path& p, const path& base, error_code& ec);

Returns: For the first form:

weakly_canonical(p).lexically_proximate(weakly_canonical(base));

For the second form:

weakly_canonical(p, ec).lexically_proximate(weakly_canonical(base, ec));

or path() at the first error occurrence, if any.

Throws: As specified in [fs.err.report].

27.10.15.29 Relative [fs.op.relative]

path relative(const path& p, error_code& ec);

Returns: relative(p, current_path(), ec).

Throws: As specified in [fs.err.report].

path relative(const path& p, const path& base = current_path()); path relative(const path& p, const path& base, error_code& ec);

Returns: For the first form:

weakly_canonical(p).lexically_relative(weakly_canonical(base));

For the second form:

weakly_canonical(p, ec).lexically_relative(weakly_canonical(base, ec));

or path() at the first error occurrence, if any.

Throws: As specified in [fs.err.report].

27.10.15.30 Remove [fs.op.remove]

bool remove(const path& p); bool remove(const path& p, error_code& ec) noexcept;

Effects: If exists(symlink_status(p, ec)), the file p is removed as if by POSIX remove(). [ Note: A symbolic link is itself removed, rather than the file it resolves to.  — end note ]

Postconditions: !exists(symlink_status(p)).

Returns: false if p did not exist, otherwise true. The signature with argument ec returns false if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.31 Remove all [fs.op.remove_all]

uintmax_t remove_all(const path& p); uintmax_t remove_all(const path& p, error_code& ec) noexcept;

Effects: Recursively deletes the contents of p if it exists, then deletes file p itself, as if by POSIX remove(). [ Note: A symbolic link is itself removed, rather than the file it resolves to.  — end note ]

Postconditions: !exists(symlink_status(p)).

Returns: The number of files removed. The signature with argument ec returns static_cast< uintmax_t>(-1) if an error occurs.

Throws: As specified in [fs.err.report].

27.10.15.32 Rename [fs.op.rename]

void rename(const path& old_p, const path& new_p); void rename(const path& old_p, const path& new_p, error_code& ec) noexcept;

Effects: Renames old_p to new_p, as if by POSIX rename().

Note:

  • If old_p and new_p resolve to the same existing file, no action is taken.

  • Otherwise, the rename may include the following effects:

    • if new_p resolves to an existing non-directory file, new_p is removed; otherwise,

    • if new_p resolves to an existing directory, new_p is removed if empty on POSIX compliant operating systems but may be an error on other operating systems.

A symbolic link is itself renamed, rather than the file it resolves to.  — end note ]

Throws: As specified in [fs.err.report].

27.10.15.33 Resize file [fs.op.resize_file]

void resize_file(const path& p, uintmax_t new_size); void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;

Postconditions: file_size(p) == new_size.

Throws: As specified in [fs.err.report].

Remarks: Achieves its postconditions as if by POSIX truncate().

27.10.15.34 Space [fs.op.space]

space_info space(const path& p); space_info space(const path& p, error_code& ec) noexcept;

Returns: An object of type space_info. The value of the space_info object is determined as if by using POSIX statvfs to obtain a POSIX struct statvfs, and then multiplying its f_blocks, f_bfree, and f_bavail members by its f_frsize member, and assigning the results to the capacity, free, and available members respectively. Any members for which the value cannot be determined shall be set to static_cast<uintmax_t>(-1). For the signature with argument ec, all members are set to static_cast<uintmax_t>(-1) if an error occurs.

Throws: As specified in [fs.err.report].

Remarks: The value of member space_info::available is operating system dependent. [ Note: available may be less than free.  — end note ]

27.10.15.35 Status [fs.op.status]

file_status status(const path& p);

Effects: As if:

error_code ec;
file_status result = status(p, ec);
if (result.type() == file_type::none)
  throw filesystem_error(implementation-supplied-message, p, ec);
return result;

Returns: See above.

Throws: filesystem_error. [ Note: result values of file_status(file_type::not_found) and file_status(file_type::unknown) are not considered failures and do not cause an exception to be thrown. — end note ]

file_status status(const path& p, error_code& ec) noexcept;

Effects: If possible, determines the attributes of the file p resolves to, as if by using POSIX stat() to obtain a POSIX struct stat. If, during attribute determination, the underlying file system API reports an error, sets ec to indicate the specific error reported. Otherwise, ec.clear(). [ Note: This allows users to inspect the specifics of underlying API errors even when the value returned by status() is not file_status(file_type::none).  — end note ]

Let prms denote the result of (m & perms::mask), where m is determined as if by converting the st_mode member of the obtained struct stat to the type perms.

Returns:

  • If ec != error_code():

    • If the specific error indicates that p cannot be resolved because some element of the path does not exist, returns file_status(file_type::not_found).

    • Otherwise, if the specific error indicates that p can be resolved but the attributes cannot be determined, returns file_status(file_type::unknown).

    • Otherwise, returns file_status(file_type::none).

    Note: These semantics distinguish between p being known not to exist, p existing but not being able to determine its attributes, and there being an error that prevents even knowing if p exists. These distinctions are important to some use cases.  — end note ]

  • Otherwise,

    • If the attributes indicate a regular file, as if by POSIX S_ISREG, returns file_status(file_type::regular, prms). [ Note: file_type::regular implies appropriate <fstream> operations would succeed, assuming no hardware, permission, access, or file system race errors. Lack of file_type::regular does not necessarily imply <fstream> operations would fail on a directory.  — end note ]

    • Otherwise, if the attributes indicate a directory, as if by POSIX S_ISDIR, returns file_status(file_type::directory, prms). [ Note: file_type::directory implies directory_iterator(p) would succeed.  — end note ]

    • Otherwise, if the attributes indicate a block special file, as if by POSIX S_ISBLK, returns file_status(file_type::block, prms).

    • Otherwise, if the attributes indicate a character special file, as if by POSIX S_ISCHR, returns file_status(file_type::character, prms).

    • Otherwise, if the attributes indicate a fifo or pipe file, as if by POSIX S_ISFIFO, returns file_status(file_type::fifo, prms).

    • Otherwise, if the attributes indicate a socket, as if by POSIX S_ISSOCK, returns file_status(file_type::socket, prms).

    • Otherwise, returns file_status(file_type::unknown, prms).

Remarks: If a symbolic link is encountered during pathname resolution, pathname resolution continues using the contents of the symbolic link.

27.10.15.36 Status known [fs.op.status_known]

bool status_known(file_status s) noexcept;

Returns: s.type() != file_type::none.

27.10.15.38 System complete [fs.op.system_complete]

path system_complete(const path& p); path system_complete(const path& p, error_code& ec);

Effects: Composes an absolute path from p, using the same rules used by the operating system to resolve a path passed as the filename argument to standard library open functions.

Returns: The composed path. The signature with argument ec returns path() if an error occurs.

Postconditions: For the returned path, rp, rp.is_absolute() is true.

Throws: As specified in [fs.err.report].

Example: For POSIX-based operating systems, system_complete(p) has the same semantics as absolute(p, current_path()).

For Windows-based operating systems, system_complete(p) has the same semantics as absolute(p, current_path()) if p.is_absolute() || !p.has_root_name() or p and current_path() have the same root_name(). Otherwise system_complete(p) acts as if absolute(p, cwd) is the current directory for the p.root_name() drive. For programs run by the command processor, however, the current directory for the p.root_name() drive may have been set by a prior program, and this may have unintended consequences.  — end example ]

27.10.15.39 Temporary directory path [fs.op.temp_dir_path]

path temp_directory_path(); path temp_directory_path(error_code& ec);

Returns: An unspecifed directory path suitable for temporary files. An error shall be reported if !exists(p) || !is_directory(p), where p is the path to be returned. The signature with argument ec returns path() if an error occurs.

Throws: As specified in [fs.err.report].

Example: For POSIX-based operating systems, an implementation might return the path supplied by the first environment variable found in the list TMPDIR, TMP, TEMP, TEMPDIR, or if none of these are found, "/tmp".

For Windows-based operating systems, an implementation might return the path reported by the Windows GetTempPath API function.  — end example ]

27.10.15.40 Weakly Canonical [fs.op.weakly_canonical]

path weakly_canonical(const path& p); path weakly_canonical(const path& p, error_code& ec);

Returns: p with symlinks resolved and the result normalized ([fs.def.normal.form]).

Effects: Using status(p) or status(p, ec), respectively, to determine existence, return a path composed by operator/= from the result of calling canonical() without a base argument and with a path argument composed of the leading elements of p that exist, if any, followed by the elements of p that do not exist, if any. For the first form, canonical() is called without an error_code argument. For the second form, canonical() is called with ec as an error_code argument, and path() is returned at the first error occurrence, if any.

Postconditions: The returned path is in normal form ([fs.def.normal.form]).

Remarks: Implementations are encouraged to avoid unnecessary normalization such as when canonical() has already been called on the entirety of p.

Throws: As specified in [fs.err.report].