1e4b17023SJohn Marino // <system_error> implementation file 2e4b17023SJohn Marino 3e4b17023SJohn Marino // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. 4e4b17023SJohn Marino // 5e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library. This library is free 6e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the 7e4b17023SJohn Marino // terms of the GNU General Public License as published by the 8e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option) 9e4b17023SJohn Marino // any later version. 10e4b17023SJohn Marino 11e4b17023SJohn Marino // This library is distributed in the hope that it will be useful, 12e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of 13e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14e4b17023SJohn Marino // GNU General Public License for more details. 15e4b17023SJohn Marino 16e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional 17e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version 18e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation. 19e4b17023SJohn Marino 20e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and 21e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program; 22e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23e4b17023SJohn Marino // <http://www.gnu.org/licenses/>. 24e4b17023SJohn Marino 25e4b17023SJohn Marino 26e4b17023SJohn Marino #include <cstring> 27e4b17023SJohn Marino #include <system_error> 28e4b17023SJohn Marino #include <bits/functexcept.h> 29e4b17023SJohn Marino #include <limits> 30e4b17023SJohn Marino 31e4b17023SJohn Marino namespace 32e4b17023SJohn Marino { 33e4b17023SJohn Marino using std::string; 34e4b17023SJohn Marino 35e4b17023SJohn Marino struct generic_error_category : public std::error_category 36e4b17023SJohn Marino { 37e4b17023SJohn Marino virtual const char* name__anon95f9b6e50111::generic_error_category38e4b17023SJohn Marino name() const noexcept 39e4b17023SJohn Marino { return "generic"; } 40e4b17023SJohn Marino 41e4b17023SJohn Marino virtual string message__anon95f9b6e50111::generic_error_category42e4b17023SJohn Marino message(int i) const 43e4b17023SJohn Marino { 44e4b17023SJohn Marino // XXX locale issues: how does one get or set loc. 45e4b17023SJohn Marino // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 46e4b17023SJohn Marino return string(strerror(i)); 47e4b17023SJohn Marino } 48e4b17023SJohn Marino }; 49e4b17023SJohn Marino 50e4b17023SJohn Marino struct system_error_category : public std::error_category 51e4b17023SJohn Marino { 52e4b17023SJohn Marino virtual const char* name__anon95f9b6e50111::system_error_category53e4b17023SJohn Marino name() const noexcept 54e4b17023SJohn Marino { return "system"; } 55e4b17023SJohn Marino 56e4b17023SJohn Marino virtual string message__anon95f9b6e50111::system_error_category57e4b17023SJohn Marino message(int i) const 58e4b17023SJohn Marino { 59e4b17023SJohn Marino // XXX locale issues: how does one get or set loc. 60e4b17023SJohn Marino // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 61e4b17023SJohn Marino return string(strerror(i)); 62e4b17023SJohn Marino } 63e4b17023SJohn Marino }; 64e4b17023SJohn Marino 65*95d28233SJohn Marino const generic_error_category generic_category_instance{}; 66*95d28233SJohn Marino const system_error_category system_category_instance{}; 67e4b17023SJohn Marino } 68e4b17023SJohn Marino 69e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default) 70e4b17023SJohn Marino { 71e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_VERSION 72e4b17023SJohn Marino 73e4b17023SJohn Marino error_category::error_category() noexcept = default; 74e4b17023SJohn Marino 75e4b17023SJohn Marino error_category::~error_category() noexcept = default; 76e4b17023SJohn Marino 77e4b17023SJohn Marino const error_category& system_category()78e4b17023SJohn Marino system_category() noexcept { return system_category_instance; } 79e4b17023SJohn Marino 80e4b17023SJohn Marino const error_category& generic_category()81e4b17023SJohn Marino generic_category() noexcept { return generic_category_instance; } 82e4b17023SJohn Marino 83e4b17023SJohn Marino system_error::~system_error() noexcept = default; 84e4b17023SJohn Marino 85e4b17023SJohn Marino error_condition default_error_condition(int __i) const86e4b17023SJohn Marino error_category::default_error_condition(int __i) const noexcept 87e4b17023SJohn Marino { return error_condition(__i, *this); } 88e4b17023SJohn Marino 89e4b17023SJohn Marino bool equivalent(int __i,const error_condition & __cond) const90e4b17023SJohn Marino error_category::equivalent(int __i, 91e4b17023SJohn Marino const error_condition& __cond) const noexcept 92e4b17023SJohn Marino { return default_error_condition(__i) == __cond; } 93e4b17023SJohn Marino 94e4b17023SJohn Marino bool equivalent(const error_code & __code,int __i) const95e4b17023SJohn Marino error_category::equivalent(const error_code& __code, int __i) const noexcept 96e4b17023SJohn Marino { return *this == __code.category() && __code.value() == __i; } 97e4b17023SJohn Marino 98e4b17023SJohn Marino error_condition default_error_condition() const99e4b17023SJohn Marino error_code::default_error_condition() const noexcept 100e4b17023SJohn Marino { return category().default_error_condition(value()); } 101e4b17023SJohn Marino 102e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_VERSION 103e4b17023SJohn Marino } // namespace 104