Commit b94de51a authored by Max Kellermann's avatar Max Kellermann

system/Error: move code to IsErrno()

parent db024c27
...@@ -148,6 +148,14 @@ FormatErrno(const char *fmt, Args&&... args) noexcept ...@@ -148,6 +148,14 @@ FormatErrno(const char *fmt, Args&&... args) noexcept
} }
gcc_pure gcc_pure
inline bool
IsErrno(const std::system_error &e, int code) noexcept
{
return e.code().category() == ErrnoCategory() &&
e.code().value() == code;
}
gcc_pure
static inline bool static inline bool
IsFileNotFound(const std::system_error &e) noexcept IsFileNotFound(const std::system_error &e) noexcept
{ {
...@@ -155,8 +163,7 @@ IsFileNotFound(const std::system_error &e) noexcept ...@@ -155,8 +163,7 @@ IsFileNotFound(const std::system_error &e) noexcept
return e.code().category() == std::system_category() && return e.code().category() == std::system_category() &&
e.code().value() == ERROR_FILE_NOT_FOUND; e.code().value() == ERROR_FILE_NOT_FOUND;
#else #else
return e.code().category() == ErrnoCategory() && return IsErrno(e, ENOENT);
e.code().value() == ENOENT;
#endif #endif
} }
...@@ -168,8 +175,7 @@ IsPathNotFound(const std::system_error &e) noexcept ...@@ -168,8 +175,7 @@ IsPathNotFound(const std::system_error &e) noexcept
return e.code().category() == std::system_category() && return e.code().category() == std::system_category() &&
e.code().value() == ERROR_PATH_NOT_FOUND; e.code().value() == ERROR_PATH_NOT_FOUND;
#else #else
return e.code().category() == ErrnoCategory() && return IsErrno(e, ENOTDIR);
e.code().value() == ENOTDIR;
#endif #endif
} }
...@@ -181,8 +187,7 @@ IsAccessDenied(const std::system_error &e) noexcept ...@@ -181,8 +187,7 @@ IsAccessDenied(const std::system_error &e) noexcept
return e.code().category() == std::system_category() && return e.code().category() == std::system_category() &&
e.code().value() == ERROR_ACCESS_DENIED; e.code().value() == ERROR_ACCESS_DENIED;
#else #else
return e.code().category() == ErrnoCategory() && return IsErrno(e, EACCES);
e.code().value() == EACCES;
#endif #endif
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment