1 // <system_error> implementation file
3 // Copyright (C) 2007-2018 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
26 #define _GLIBCXX_USE_CXX11_ABI 1
27 #define __sso_string __sso_stringxxx
29 #include <system_error>
30 #include <bits/functexcept.h>
39 struct generic_error_category : public std::error_category
45 _GLIBCXX_DEFAULT_ABI_TAG
49 // XXX locale issues: how does one get or set loc.
50 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
51 return string(strerror(i));
55 struct system_error_category : public std::error_category
61 _GLIBCXX_DEFAULT_ABI_TAG
65 // XXX locale issues: how does one get or set loc.
66 // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc)
67 return string(strerror(i));
70 virtual std::error_condition
71 default_error_condition(int ev) const noexcept
75 // List of errno macros from [cerrno.syn].
76 // C11 only defines EDOM, EILSEQ and ERANGE, the rest are from POSIX.
77 // They expand to integer constant expressions with type int,
78 // and distinct positive values, suitable for use in #if directives.
79 // POSIX adds more macros (but they're not defined on all targets,
80 // see config/os/*/error_constants.h), and POSIX allows
81 // EAGAIN == EWOULDBLOCK and ENOTSUP == EOPNOTSUPP.
244 #if defined ENOTEMPTY && (!defined EEXIST || ENOTEMPTY != EEXIST)
245 // AIX sometimes uses the same value for EEXIST and ENOTEMPTY
248 #ifdef ENOTRECOVERABLE
249 case ENOTRECOVERABLE:
263 #if defined EOPNOTSUPP && (!defined ENOTSUP || EOPNOTSUPP != ENOTSUP)
281 #ifdef EPROTONOSUPPORT
282 case EPROTONOSUPPORT:
306 #if defined EWOULDBLOCK && (!defined EAGAIN || EWOULDBLOCK != EAGAIN)
312 return std::error_condition(ev, std::generic_category());
314 /* Additional system-dependent mappings from non-standard error codes
315 * to one of the POSIX values above would go here, e.g.
317 return std::error_condition(EINVAL, std::generic_category());
321 return std::error_condition(ev, std::system_category());
326 const generic_error_category generic_category_instance{};
327 const system_error_category system_category_instance{};
330 namespace std _GLIBCXX_VISIBILITY(default)
332 _GLIBCXX_BEGIN_NAMESPACE_VERSION
335 __throw_system_error(int __i __attribute__((unused)))
337 _GLIBCXX_THROW_OR_ABORT(system_error(error_code(__i, generic_category())));
340 error_category::~error_category() noexcept = default;
342 const error_category&
343 _V2::system_category() noexcept { return system_category_instance; }
345 const error_category&
346 _V2::generic_category() noexcept { return generic_category_instance; }
348 system_error::~system_error() noexcept = default;
351 error_category::default_error_condition(int __i) const noexcept
352 { return error_condition(__i, *this); }
355 error_category::equivalent(int __i,
356 const error_condition& __cond) const noexcept
357 { return default_error_condition(__i) == __cond; }
360 error_category::equivalent(const error_code& __code, int __i) const noexcept
361 { return *this == __code.category() && __code.value() == __i; }
364 error_code::default_error_condition() const noexcept
365 { return category().default_error_condition(value()); }
367 #if _GLIBCXX_USE_CXX11_ABI
368 // Return error_category::message() as a COW string
370 error_category::_M_message(int i) const
372 string msg = this->message(i);
373 return {msg.c_str(), msg.length()};
377 _GLIBCXX_END_NAMESPACE_VERSION