From 2c22cac0cace65fa07d45da654a60b9ff8369bdf Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 11 Nov 2016 12:01:34 -0500 Subject: [PATCH] convert error_code to macos error. --- macos/errors.cpp | 23 +++++++++++++++++++++++ macos/errors.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/macos/errors.cpp b/macos/errors.cpp index 609b1e9..121466a 100644 --- a/macos/errors.cpp +++ b/macos/errors.cpp @@ -917,6 +917,27 @@ namespace MacOS { return macos_error_from_errno(errno); } + + macos_error macos_error_from_errno(const std::error_code &ec) { + if (!ec) return noErr; + + // generic_category is a posix errno. + // system_category is the native error (eg posix errno or windows error) + // but will default_error_condition() to a generic_category, if possible. + + if (ec.category() == std::generic_category()) + return macos_error_from_errno(ec.value()); + + if (ec.category() == macos_system_category()) return (macos_error)ec.value(); + + std::error_condition econd = ec.default_error_condition(); + if (econd.category() == std::generic_category()) + return macos_error_from_errno(econd.value()); + + return ioErr; + } + + macos_error macos_error_from_errno(int error) { switch(error) @@ -938,7 +959,9 @@ namespace MacOS { case EBUSY: return fBsyErr; case ENOTEMPTY: return fBsyErr; +#ifdef EDQUOT case EDQUOT: return dskFulErr; +#endif case ENOSPC: return dskFulErr; case ENOMEM: return mFulErr; case ENFILE: return tmfoErr; diff --git a/macos/errors.h b/macos/errors.h index 7a7f967..5cdddc8 100644 --- a/macos/errors.h +++ b/macos/errors.h @@ -565,6 +565,8 @@ namespace MacOS { macos_error macos_error_from_errno(); macos_error macos_error_from_errno(int error); + macos_error macos_error_from_errno(const std::error_code &ec); + // c++11 error stuff const std::error_category& macos_system_category();