diff options
author | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-18 21:39:06 -0500 |
---|---|---|
committer | Benjamin Barenblat <bbaren@mit.edu> | 2016-02-18 22:15:48 -0500 |
commit | d0f5817f4720b49ffaee9fa9593b2f11446963a0 (patch) | |
tree | d2ad6c43b4ff0ca04c490a5e0487ffb80ee1f272 /src | |
parent | 8716cf918e75c540814d75ccb9fa26ff6085cf63 (diff) |
Add nullary constructor to IoError
The constructor constructs an IoError based on the current errno.
Diffstat (limited to 'src')
-rw-r--r-- | src/posix_extras.cc | 6 | ||||
-rw-r--r-- | src/posix_extras.h | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/posix_extras.cc b/src/posix_extras.cc index d06dc41..c3c841c 100644 --- a/src/posix_extras.cc +++ b/src/posix_extras.cc @@ -50,7 +50,7 @@ std::string IoError::Message(const int number) noexcept { File::File(const char* const path, const int flags) : path_(path) { if ((fd_ = open(path, flags)) == -1) { - throw IoError(errno); + throw IoError(); } } @@ -65,7 +65,7 @@ File::~File() noexcept { struct stat File::Stat() const { struct stat result; if (fstat(fd_, &result) == -1) { - throw IoError(errno); + throw IoError(); } return result; } @@ -77,7 +77,7 @@ struct stat File::LinkStatAt(const char* const path) const { struct stat result; if (fstatat(fd_, path, &result, AT_SYMLINK_NOFOLLOW) == -1) { - throw IoError(errno); + throw IoError(); } return result; } diff --git a/src/posix_extras.h b/src/posix_extras.h index b9c0f12..001968f 100644 --- a/src/posix_extras.h +++ b/src/posix_extras.h @@ -15,6 +15,7 @@ #ifndef POSIX_EXTRAS_H_ #define POSIX_EXTRAS_H_ +#include <cerrno> #include <stdexcept> #include <string> @@ -26,6 +27,8 @@ namespace scoville { class IoError : public std::runtime_error { public: + IoError() : IoError(errno) {} + explicit IoError(const int number) : std::runtime_error(Message(number)), number_(number) {} |