From 1028cc76ef8b40a933aba58cc531ccf466951771 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 31 May 2014 02:29:28 +0000 Subject: Turn errc and windows_error into enum classes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209957 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/system_error.h | 23 ++--------------------- lib/Support/Unix/Path.inc | 10 +++++----- lib/Support/Windows/Path.inc | 4 ++-- tools/llvm-ar/llvm-ar.cpp | 3 +-- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/include/llvm/Support/system_error.h b/include/llvm/Support/system_error.h index a18b921ac1..9854a9ee85 100644 --- a/include/llvm/Support/system_error.h +++ b/include/llvm/Support/system_error.h @@ -482,9 +482,7 @@ template struct is_error_condition_enum : public std::false_type {}; // Some error codes are not present on all platforms, so we provide equivalents // for them: -//enum class errc -struct errc { -enum _ { +enum class errc { success = 0, address_family_not_supported = EAFNOSUPPORT, address_in_use = EADDRINUSE, @@ -606,16 +604,9 @@ enum _ { wrong_protocol_type = EPROTOTYPE }; - _ v_; - - errc(_ v) : v_(v) {} - operator int() const {return v_;} -}; template <> struct is_error_condition_enum : std::true_type { }; -template <> struct is_error_condition_enum : std::true_type { }; - class error_condition; class error_code; @@ -818,8 +809,7 @@ inline bool operator!=(const error_condition& _x, const error_condition& _y) { // To construct an error_code after an API error: // // error_code( ::GetLastError(), system_category() ) -struct windows_error { -enum _ { +enum class windows_error { success = 0, // These names and values are based on Windows WinError.h // This is not a complete list. Add to this list if you need to explicitly @@ -876,18 +866,9 @@ enum _ { cancel_violation = 173, // ERROR_CANCEL_VIOLATION, already_exists = 183 // ERROR_ALREADY_EXISTS }; - _ v_; - - windows_error(_ v) : v_(v) {} - explicit windows_error(int v) : v_(_(v)) {} - operator int() const {return v_;} -}; - template <> struct is_error_code_enum : std::true_type { }; -template <> struct is_error_code_enum : std::true_type { }; - inline error_code make_error_code(windows_error e) { return error_code(static_cast(e), system_category()); } diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 2925e6457a..fbd7ced209 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -248,7 +248,7 @@ error_code current_path(SmallVectorImpl &result) { while (true) { if (::getcwd(result.data(), result.capacity()) == nullptr) { // See if there was a real error. - if (errno != errc::not_enough_memory) + if (errno != ENOMEM) return error_code(errno, system_category()); // Otherwise there just wasn't enough space. result.reserve(result.capacity() * 2); @@ -265,7 +265,7 @@ error_code create_directory(const Twine &path, bool IgnoreExisting) { StringRef p = path.toNullTerminatedStringRef(path_storage); if (::mkdir(p.begin(), S_IRWXU | S_IRWXG) == -1) { - if (errno != errc::file_exists || !IgnoreExisting) + if (errno != EEXIST || !IgnoreExisting) return error_code(errno, system_category()); } @@ -306,7 +306,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { struct stat buf; if (lstat(p.begin(), &buf) != 0) { - if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (errno != ENOENT || !IgnoreNonExisting) return error_code(errno, system_category()); return error_code(); } @@ -320,7 +320,7 @@ error_code remove(const Twine &path, bool IgnoreNonExisting) { return make_error_code(errc::operation_not_permitted); if (::remove(p.begin()) == -1) { - if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting) + if (errno != ENOENT || !IgnoreNonExisting) return error_code(errno, system_category()); } @@ -355,7 +355,7 @@ error_code exists(const Twine &path, bool &result) { StringRef p = path.toNullTerminatedStringRef(path_storage); if (::access(p.begin(), F_OK) == -1) { - if (errno != errc::no_such_file_or_directory) + if (errno != ENOENT) return error_code(errno, system_category()); result = false; } else diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc index 8baa263cb8..f04900c0dd 100644 --- a/lib/Support/Windows/Path.inc +++ b/lib/Support/Windows/Path.inc @@ -810,7 +810,7 @@ error_code openFileForRead(const Twine &Name, int &ResultFD) { if (EC != windows_error::access_denied) return EC; if (is_directory(Name)) - return error_code(errc::is_a_directory, posix_category()); + return make_error_code(errc::is_a_directory); return EC; } @@ -861,7 +861,7 @@ error_code openFileForWrite(const Twine &Name, int &ResultFD, if (EC != windows_error::access_denied) return EC; if (is_directory(Name)) - return error_code(errc::is_a_directory, posix_category()); + return make_error_code(errc::is_a_directory); return EC; } diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index ed7291ea0c..ea85d5d3c9 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -453,8 +453,7 @@ int NewArchiveIterator::getFD() const { // Linux cannot open directories with open(2), although // cygwin and *bsd can. if (NewStatus.type() == sys::fs::file_type::directory_file) - failIfError(error_code(errc::is_a_directory, posix_category()), - NewFilename); + failIfError(make_error_code(errc::is_a_directory), NewFilename); return NewFD; } -- cgit v1.2.3