summaryrefslogtreecommitdiff
path: root/chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-12 14:07:37 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2017-07-17 10:29:26 +0000
commitec02ee4181c49b61fce1c8fb99292dbb8139cc90 (patch)
tree25cde714b2b71eb639d1cd53f5a22e9ba76e14ef /chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp
parentbb09965444b5bb20b096a291445170876225268d (diff)
downloadqtwebengine-chromium-ec02ee4181c49b61fce1c8fb99292dbb8139cc90.tar.gz
BASELINE: Update Chromium to 59.0.3071.134
Change-Id: Id02ef6fb2204c5fd21668a1c3e6911c83b17585a Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp')
-rw-r--r--chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp70
1 files changed, 69 insertions, 1 deletions
diff --git a/chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp b/chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp
index 3023e200aa3..cbbbb5dcd15 100644
--- a/chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp
+++ b/chromium/buildtools/third_party/libc++/trunk/src/system_error.cpp
@@ -13,16 +13,27 @@
#include "system_error"
#include "include/config_elast.h"
+#include "cerrno"
#include "cstring"
+#include "cstdio"
+#include "cstdlib"
#include "string"
+#include "string.h"
+#include "__debug"
+
+#if defined(__ANDROID__)
+#include <android/api-level.h>
+#endif
_LIBCPP_BEGIN_NAMESPACE_STD
// class error_category
+#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
error_category::error_category() _NOEXCEPT
{
}
+#endif
error_category::~error_category() _NOEXCEPT
{
@@ -46,10 +57,66 @@ error_category::equivalent(const error_code& code, int condition) const _NOEXCEP
return *this == code.category() && code.value() == condition;
}
+#if !defined(_LIBCPP_HAS_NO_THREADS)
+namespace {
+
+// GLIBC also uses 1024 as the maximum buffer size internally.
+constexpr size_t strerror_buff_size = 1024;
+
+string do_strerror_r(int ev);
+
+#if defined(_LIBCPP_MSVCRT)
+string do_strerror_r(int ev) {
+ char buffer[strerror_buff_size];
+ if (::strerror_s(buffer, strerror_buff_size, ev) == 0)
+ return string(buffer);
+ std::snprintf(buffer, strerror_buff_size, "unknown error %d", ev);
+ return string(buffer);
+}
+#elif defined(__linux__) && !defined(_LIBCPP_HAS_MUSL_LIBC) && \
+ (!defined(__ANDROID__) || __ANDROID_API__ >= 23)
+// GNU Extended version
+string do_strerror_r(int ev) {
+ char buffer[strerror_buff_size];
+ char* ret = ::strerror_r(ev, buffer, strerror_buff_size);
+ return string(ret);
+}
+#else
+// POSIX version
+string do_strerror_r(int ev) {
+ char buffer[strerror_buff_size];
+ const int old_errno = errno;
+ int ret;
+ if ((ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) {
+ // If `ret == -1` then the error is specified using `errno`, otherwise
+ // `ret` represents the error.
+ const int new_errno = ret == -1 ? errno : ret;
+ errno = old_errno;
+ if (new_errno == EINVAL) {
+ std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
+ return string(buffer);
+ } else {
+ _LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerr_r");
+ // FIXME maybe? 'strerror_buff_size' is likely to exceed the
+ // maximum error size so ERANGE shouldn't be returned.
+ std::abort();
+ }
+ }
+ return string(buffer);
+}
+#endif
+
+} // end namespace
+#endif
+
string
__do_message::message(int ev) const
{
- return string(strerror(ev));
+#if defined(_LIBCPP_HAS_NO_THREADS)
+ return string(::strerror(ev));
+#else
+ return do_strerror_r(ev);
+#endif
}
class _LIBCPP_HIDDEN __generic_error_category
@@ -203,6 +270,7 @@ __throw_system_error(int ev, const char* what_arg)
#else
(void)ev;
(void)what_arg;
+ _VSTD::abort();
#endif
}