/// @brief Does file exist?
///
/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status exists, false if
-/// it does not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-/// platform specific error_code.
-error_code exists(file_status status, bool &result);
+/// @results True if the file represented by status exists, false if it does
+/// not.
+bool exists(file_status status);
/// @brief Does file exist?
///
/// platform specific error_code.
error_code exists(const Twine &path, bool &result);
+/// @brief Do file_status's represent the same thing?
+///
+/// @param A Input file_status.
+/// @param B Input file_status.
+///
+/// assert(status_known(A) || status_known(B));
+///
+/// @results True if A and B both represent the same file system entity, false
+/// otherwise.
+bool equivalent(file_status A, file_status B);
+
/// @brief Do paths represent the same thing?
///
/// @param A Input path A.
/// @brief Does status represent a directory?
///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a directory,
-/// false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-/// platform specific error_code.
-error_code is_directory(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results status.type() == file_type::directory_file.
+bool is_directory(file_status status);
/// @brief Is path a directory?
///
/// @brief Does status represent a regular file?
///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a regular
-/// file, false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-/// platform specific error_code.
-error_code is_regular_file(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results status_known(status) && status.type() == file_type::regular_file.
+bool is_regular_file(file_status status);
/// @brief Is path a regular file?
///
/// platform specific error_code.
error_code is_regular_file(const Twine &path, bool &result);
-/// @brief Does status represent something that exists but is not a directory,
-/// regular file, or symlink?
+/// @brief Does this status represent something that exists but is not a
+/// directory, regular file, or symlink?
///
-/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status exists, but is
-/// not a directory, regular file, or a symlink, false if it does
-/// not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-/// platform specific error_code.
-error_code is_other(file_status status, bool &result);
+/// @param status A file_status previously returned from status.
+/// @results exists(s) && !is_regular_file(s) && !is_directory(s) &&
+/// !is_symlink(s)
+bool is_other(file_status status);
/// @brief Is path something that exists but is not a directory,
/// regular file, or symlink?
/// @brief Does status represent a symlink?
///
/// @param status A file_status previously returned from stat.
-/// @param result Set to true if the file represented by status is a symlink,
-/// false if it is not. Undefined otherwise.
-/// @results errc::success if result has been successfully set, otherwise a
-/// platform specific error_code.
-error_code is_symlink(file_status status, bool &result);
+/// @param result status.type() == symlink_file.
+bool is_symlink(file_status status);
/// @brief Is path a symlink?
///
/// platform specific error_code.
error_code status(const Twine &path, file_status &result);
+/// @brief Is status available?
+///
+/// @param path Input path.
+/// @results True if status() != status_error.
+bool status_known(file_status s);
+
/// @brief Is status available?
///
/// @param path Input path.
return create_directory(p, existed);
}
+bool exists(file_status status) {
+ return status_known(status) && status.type() != file_type::file_not_found;
+}
+
+bool status_known(file_status s) {
+ return s.type() != file_type::status_error;
+}
+
+bool is_directory(file_status status) {
+ return status.type() == file_type::directory_file;
+}
+
+bool is_regular_file(file_status status) {
+ return status.type() == file_type::regular_file;
+}
+
+bool is_symlink(file_status status) {
+ return status.type() == file_type::symlink_file;
+}
+
+bool is_other(file_status status) {
+ return exists(status) &&
+ !is_regular_file(status) &&
+ !is_directory(status) &&
+ !is_symlink(status);
+}
+
void directory_entry::replace_filename(const Twine &filename, file_status st,
file_status symlink_st) {
SmallString<128> path(Path.begin(), Path.end());