llvm.org GIT mirror llvm / 1028cc7
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 Rafael Espindola 6 years ago
4 changed file(s) with 10 addition(s) and 30 deletion(s). Raw diff Collapse all Expand all
481481 // Some error codes are not present on all platforms, so we provide equivalents
482482 // for them:
483483
484 //enum class errc
485 struct errc {
486 enum _ {
484 enum class errc {
487485 success = 0,
488486 address_family_not_supported = EAFNOSUPPORT,
489487 address_in_use = EADDRINUSE,
605603 wrong_protocol_type = EPROTOTYPE
606604 };
607605
608 _ v_;
609
610 errc(_ v) : v_(v) {}
611 operator int() const {return v_;}
612 };
613606
614607 template <> struct is_error_condition_enum : std::true_type { };
615
616 template <> struct is_error_condition_enum : std::true_type { };
617608
618609 class error_condition;
619610 class error_code;
817808 // To construct an error_code after an API error:
818809 //
819810 // error_code( ::GetLastError(), system_category() )
820 struct windows_error {
821 enum _ {
811 enum class windows_error {
822812 success = 0,
823813 // These names and values are based on Windows WinError.h
824814 // This is not a complete list. Add to this list if you need to explicitly
875865 cancel_violation = 173, // ERROR_CANCEL_VIOLATION,
876866 already_exists = 183 // ERROR_ALREADY_EXISTS
877867 };
878 _ v_;
879
880 windows_error(_ v) : v_(v) {}
881 explicit windows_error(int v) : v_(_(v)) {}
882 operator int() const {return v_;}
883 };
884
885868
886869 template <> struct is_error_code_enum : std::true_type { };
887
888 template <> struct is_error_code_enum : std::true_type { };
889870
890871 inline error_code make_error_code(windows_error e) {
891872 return error_code(static_cast(e), system_category());
247247 while (true) {
248248 if (::getcwd(result.data(), result.capacity()) == nullptr) {
249249 // See if there was a real error.
250 if (errno != errc::not_enough_memory)
250 if (errno != ENOMEM)
251251 return error_code(errno, system_category());
252252 // Otherwise there just wasn't enough space.
253253 result.reserve(result.capacity() * 2);
264264 StringRef p = path.toNullTerminatedStringRef(path_storage);
265265
266266 if (::mkdir(p.begin(), S_IRWXU | S_IRWXG) == -1) {
267 if (errno != errc::file_exists || !IgnoreExisting)
267 if (errno != EEXIST || !IgnoreExisting)
268268 return error_code(errno, system_category());
269269 }
270270
305305
306306 struct stat buf;
307307 if (lstat(p.begin(), &buf) != 0) {
308 if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
308 if (errno != ENOENT || !IgnoreNonExisting)
309309 return error_code(errno, system_category());
310310 return error_code();
311311 }
319319 return make_error_code(errc::operation_not_permitted);
320320
321321 if (::remove(p.begin()) == -1) {
322 if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
322 if (errno != ENOENT || !IgnoreNonExisting)
323323 return error_code(errno, system_category());
324324 }
325325
354354 StringRef p = path.toNullTerminatedStringRef(path_storage);
355355
356356 if (::access(p.begin(), F_OK) == -1) {
357 if (errno != errc::no_such_file_or_directory)
357 if (errno != ENOENT)
358358 return error_code(errno, system_category());
359359 result = false;
360360 } else
809809 if (EC != windows_error::access_denied)
810810 return EC;
811811 if (is_directory(Name))
812 return error_code(errc::is_a_directory, posix_category());
812 return make_error_code(errc::is_a_directory);
813813 return EC;
814814 }
815815
860860 if (EC != windows_error::access_denied)
861861 return EC;
862862 if (is_directory(Name))
863 return error_code(errc::is_a_directory, posix_category());
863 return make_error_code(errc::is_a_directory);
864864 return EC;
865865 }
866866
452452 // Linux cannot open directories with open(2), although
453453 // cygwin and *bsd can.
454454 if (NewStatus.type() == sys::fs::file_type::directory_file)
455 failIfError(error_code(errc::is_a_directory, posix_category()),
456 NewFilename);
455 failIfError(make_error_code(errc::is_a_directory), NewFilename);
457456
458457 return NewFD;
459458 }