29 Input/output library [input.output]

29.11 File systems [filesystems]

29.11.14 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.race.behavior]), 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
 ]

29.11.14.1 Absolute [fs.op.absolute]

path absolute(const path& p); path absolute(const path& p, error_code& ec);
Effects: Composes an absolute path referencing the same file system location as p according to the operating system ([fs.conform.os]).
Returns: The composed path.
The signature with argument ec returns path() if an error occurs.
Note
:
For the returned path, rp, rp.is_­absolute() is true unless an error occurs.
— end note
 ]
Throws: As specified in [fs.err.report].
Note
:
To resolve symlinks, or perform other sanitization which might require queries to secondary storage, such as hard disks, consider canonical ([fs.op.canonical]).
— end note
 ]
Note
:
Implementations are strongly encouraged to not query secondary storage, and not consider !exists(p) an error.
— end note
 ]
Example
:
For POSIX-based operating systems, absolute(p) is simply current_­path()/p.
For Windows-based operating systems, absolute might have the same semantics as GetFullPathNameW.
— end example
 ]

29.11.14.2 Canonical [fs.op.canonical]

path canonical(const path& p); path canonical(const path& p, error_code& ec);
Effects: Converts p to an absolute path that has no symbolic link, dot, or dot-dot elements in its pathname in the generic format.
Returns: A path that refers to the same file system object as absolute(p).
The signature with argument ec returns path() if an error occurs.
Throws: As specified in [fs.err.report].
Remarks: !exists(p) is an error.

29.11.14.3 Copy [fs.op.copy]

void copy(const path& from, const path& to);
Effects: Equivalent to copy(from, to, copy_­options​::​none).
void copy(const path& from, const path& to, error_code& ec);
Effects: Equivalent to copy(from, to, copy_­options​::​none, ec).
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);
Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set 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:
  • If f.type() or t.type() is an implementation-defined file type ([fs.enum.file.type]), then the effects are implementation-defined.
  • Otherwise, an error is reported as specified in [fs.err.report] if:
    • exists(f) is false, or
    • equivalent(from, to) is true, or
    • is_­other(f) || is_­other(t) is true, or
    • is_­directory(f) && is_­regular_­file(t) is true.
  • 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::create_symlinks) != copy_options::none
    
    then report an error with an error_­code argument equal to make_­error_­code(errc​::​is_­a_­directory).
  • Otherwise, if
    is_directory(f) &&
    ((options & copy_options::recursive) != copy_options::none ||
     options == copy_options::none)
    
    then:
    • If exists(t) is false, then create_­directory(to, from).
    • Then, iterate over the files in from, as if by
      for (const directory_entry& x : directory_iterator(from))
        copy(x.path(), to/x.path().filename(),
             options | copy_options::in-recursive-copy);
      
      where in-recursive-copy is a bitmask element of copy_­options that is not one of the elements in [fs.enum.copy.opts].
  • 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
 ]

29.11.14.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);
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);
Preconditions: At most one element from each option group ([fs.enum.copy.opts]) is set in options.
Effects: As follows:
  • Report an error as specified in [fs.err.report] if:
    • is_­regular_­file(from) is false, or
    • exists(to) is true and is_­regular_­file(to) is false, or
    • exists(to) is true and equivalent(from, to) is true, or
    • exists(to) is true 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) is false, or
    • (options & copy_­options​::​overwrite_­existing) != copy_­options​::​none, or
    • (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).

29.11.14.6 Create directories [fs.op.create.directories]

bool create_directories(const path& p); bool create_directories(const path& p, error_code& ec);
Effects: Calls create_­directory() for each element of p that does not exist.
Returns: true if a new directory was created for the directory p resolves to, otherwise false.
Throws: As specified in [fs.err.report].
Complexity: where n is the number of elements of p.

29.11.14.7 Create directory [fs.op.create.directory]

bool create_directory(const path& p); bool create_directory(const path& p, error_code& ec) noexcept;
Effects: Creates the directory p resolves to, as if by POSIX mkdir with a second argument of static_­cast<int>(perms​::​all).
If mkdir fails because p resolves to an existing directory, no error is reported.
Otherwise on failure an error is reported.
Returns: true if a new directory was created, otherwise false.
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: Creates the directory p resolves to, with attributes copied from directory existing_­p.
The set of attributes copied is operating system dependent.
If mkdir fails because p resolves to an existing directory, no error is reported.
Otherwise on failure an error is reported.
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
 ]
Returns: true if a new directory was created with attributes copied from directory existing_­p, otherwise false.
Throws: As specified in [fs.err.report].

29.11.14.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
 ]

29.11.14.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
 ]

29.11.14.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, whose pathname in the native format is 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.
— end note
 ]
Note
:
The current path as returned by many operating systems is a dangerous global variable.
It may be changed unexpectedly by 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
 ]

29.11.14.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;
Returns: true, if p1 and p2 resolve to the same file system entity, otherwise 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.
Note
:
On POSIX platforms, this is determined as if by the values of the POSIX stat class, obtained as if by stat() for the two paths, having equal st_­dev values and equal st_­ino values.
— end note
 ]
Remarks: !exists(p1) || !exists(p2) is an error.
Throws: As specified in [fs.err.report].

29.11.14.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].

29.11.14.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;
Effects: If exists(p) is false, an error is reported ([fs.err.report]).
Returns:
  • If is_­regular_­file(p), the size in bytes of the file p resolves to, determined as if by the value of the POSIX stat class member st_­size obtained as if by POSIX stat().
  • Otherwise, the result is implementation-defined.
The signature with argument ec returns static_­cast<uintmax_­t>(-1) if an error occurs.
Throws: As specified in [fs.err.report].

29.11.14.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].

29.11.14.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].

29.11.14.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].

29.11.14.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].

29.11.14.19 Is empty [fs.op.is.empty]

bool is_empty(const path& p); bool is_empty(const path& p, error_code& ec);
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 a variable itr, as if by directory_­iterator itr(p) or directory_­iterator itr(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].

29.11.14.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].

29.11.14.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].

29.11.14.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.

29.11.14.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].

29.11.14.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 class 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
 ]

29.11.14.26 Permissions [fs.op.permissions]

void permissions(const path& p, perms prms, perm_options opts=perm_options::replace); void permissions(const path& p, perms prms, error_code& ec) noexcept; void permissions(const path& p, perms prms, perm_options opts, error_code& ec);
Preconditions: Exactly one of the perm_­options constants replace, add, or remove is present in opts.
Remarks: The second signature behaves as if it had an additional parameter perm_­options opts with an argument of perm_­options​::​replace.
Effects: Applies the action specified by opts to the file p resolves to, or to file p itself if p is a symbolic link and perm_­options​::​nofollow is set in opts.
The action is applied as if by POSIX fchmodat().
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].

29.11.14.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].

29.11.14.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].

29.11.14.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)) is false.
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].

29.11.14.31 Remove all [fs.op.remove.all]

uintmax_t remove_all(const path& p); uintmax_t remove_all(const path& p, error_code& ec);
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)) is false.
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].

29.11.14.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].

29.11.14.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;
Effects: Causes the size that would be returned by file_­size(p) to be equal to new_­size, as if by POSIX truncate().
Throws: As specified in [fs.err.report].

29.11.14.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
 ]

29.11.14.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 that calling 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, if the attributes indicate an implementation-defined file type ([fs.enum.file.type]), returns file_­status(file_­type​::​A, prms), where A is the constant for the implementation-defined file type.
    • 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.

29.11.14.36 Status known [fs.op.status.known]

bool status_known(file_status s) noexcept;
Returns: s.type() != file_­type​::​none.

29.11.14.37 Symlink status [fs.op.symlink.status]

file_status symlink_status(const path& p); file_status symlink_status(const path& p, error_code& ec) noexcept;
Effects: Same as status(), above, except that the attributes of p are determined as if by using POSIX lstat() to obtain a POSIX struct stat.
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: Same as status(), above, except that if the attributes indicate a symbolic link, as if by POSIX S_­ISLNK, returns file_­status(file_­type​::​symlink, prms).
The signature with argument ec returns file_­status(file_­type​::​none) if an error occurs.
Remarks: Pathname resolution terminates if p names a symbolic link.
Throws: As specified in [fs.err.report].

29.11.14.38 Temporary directory path [fs.op.temp.dir.path]

path temp_directory_path(); path temp_directory_path(error_code& ec);
Let p be an unspecified directory path suitable for temporary files.
Effects: If exists(p) is false or is_­directory(p) is false, an error is reported ([fs.err.report]).
Returns: The path p.
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
 ]

29.11.14.39 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.path.generic]).
Effects: Using status(p) or status(p, ec), respectively, to determine existence, return a path composed by operator/= from the result of calling canonical() 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.path.generic]).
Remarks: Implementations should avoid unnecessary normalization such as when canonical has already been called on the entirety of p.
Throws: As specified in [fs.err.report].