138fd1498Szrj // <system_error> implementation file 238fd1498Szrj 338fd1498Szrj // Copyright (C) 2007-2018 Free Software Foundation, Inc. 438fd1498Szrj // 538fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 638fd1498Szrj // software; you can redistribute it and/or modify it under the 738fd1498Szrj // terms of the GNU General Public License as published by the 838fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 938fd1498Szrj // any later version. 1038fd1498Szrj 1138fd1498Szrj // This library is distributed in the hope that it will be useful, 1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1438fd1498Szrj // GNU General Public License for more details. 1538fd1498Szrj 1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 1838fd1498Szrj // 3.1, as published by the Free Software Foundation. 1938fd1498Szrj 2038fd1498Szrj // You should have received a copy of the GNU General Public License and 2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2338fd1498Szrj // <http://www.gnu.org/licenses/>. 2438fd1498Szrj 2538fd1498Szrj 2638fd1498Szrj #define _GLIBCXX_USE_CXX11_ABI 1 2738fd1498Szrj #define __sso_string __sso_stringxxx 2838fd1498Szrj #include <cstring> 2938fd1498Szrj #include <system_error> 3038fd1498Szrj #include <bits/functexcept.h> 3138fd1498Szrj #include <limits> 32*58e805e6Szrj #include <errno.h> 3338fd1498Szrj #undef __sso_string 3438fd1498Szrj 3538fd1498Szrj namespace 3638fd1498Szrj { 3738fd1498Szrj using std::string; 3838fd1498Szrj 3938fd1498Szrj struct generic_error_category : public std::error_category 4038fd1498Szrj { 4138fd1498Szrj virtual const char* name__anon7ae15d420111::generic_error_category4238fd1498Szrj name() const noexcept 4338fd1498Szrj { return "generic"; } 4438fd1498Szrj 4538fd1498Szrj _GLIBCXX_DEFAULT_ABI_TAG 4638fd1498Szrj virtual string message__anon7ae15d420111::generic_error_category4738fd1498Szrj message(int i) const 4838fd1498Szrj { 4938fd1498Szrj // XXX locale issues: how does one get or set loc. 5038fd1498Szrj // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 5138fd1498Szrj return string(strerror(i)); 5238fd1498Szrj } 5338fd1498Szrj }; 5438fd1498Szrj 5538fd1498Szrj struct system_error_category : public std::error_category 5638fd1498Szrj { 5738fd1498Szrj virtual const char* name__anon7ae15d420111::system_error_category5838fd1498Szrj name() const noexcept 5938fd1498Szrj { return "system"; } 6038fd1498Szrj 6138fd1498Szrj _GLIBCXX_DEFAULT_ABI_TAG 6238fd1498Szrj virtual string message__anon7ae15d420111::system_error_category6338fd1498Szrj message(int i) const 6438fd1498Szrj { 6538fd1498Szrj // XXX locale issues: how does one get or set loc. 6638fd1498Szrj // _GLIBCXX_HAVE_STRERROR_L, strerror_l(i, cloc) 6738fd1498Szrj return string(strerror(i)); 6838fd1498Szrj } 69*58e805e6Szrj 70*58e805e6Szrj virtual std::error_condition default_error_condition__anon7ae15d420111::system_error_category71*58e805e6Szrj default_error_condition(int ev) const noexcept 72*58e805e6Szrj { 73*58e805e6Szrj switch (ev) 74*58e805e6Szrj { 75*58e805e6Szrj // List of errno macros from [cerrno.syn]. 76*58e805e6Szrj // C11 only defines EDOM, EILSEQ and ERANGE, the rest are from POSIX. 77*58e805e6Szrj // They expand to integer constant expressions with type int, 78*58e805e6Szrj // and distinct positive values, suitable for use in #if directives. 79*58e805e6Szrj // POSIX adds more macros (but they're not defined on all targets, 80*58e805e6Szrj // see config/os/*/error_constants.h), and POSIX allows 81*58e805e6Szrj // EAGAIN == EWOULDBLOCK and ENOTSUP == EOPNOTSUPP. 82*58e805e6Szrj 83*58e805e6Szrj #ifdef E2BIG 84*58e805e6Szrj case E2BIG: 85*58e805e6Szrj #endif 86*58e805e6Szrj #ifdef EACCES 87*58e805e6Szrj case EACCES: 88*58e805e6Szrj #endif 89*58e805e6Szrj #ifdef EADDRINUSE 90*58e805e6Szrj case EADDRINUSE: 91*58e805e6Szrj #endif 92*58e805e6Szrj #ifdef EADDRNOTAVAIL 93*58e805e6Szrj case EADDRNOTAVAIL: 94*58e805e6Szrj #endif 95*58e805e6Szrj #ifdef EAFNOSUPPORT 96*58e805e6Szrj case EAFNOSUPPORT: 97*58e805e6Szrj #endif 98*58e805e6Szrj #ifdef EAGAIN 99*58e805e6Szrj case EAGAIN: 100*58e805e6Szrj #endif 101*58e805e6Szrj #ifdef EALREADY 102*58e805e6Szrj case EALREADY: 103*58e805e6Szrj #endif 104*58e805e6Szrj #ifdef EBADF 105*58e805e6Szrj case EBADF: 106*58e805e6Szrj #endif 107*58e805e6Szrj #ifdef EBADMSG 108*58e805e6Szrj case EBADMSG: 109*58e805e6Szrj #endif 110*58e805e6Szrj #ifdef EBUSY 111*58e805e6Szrj case EBUSY: 112*58e805e6Szrj #endif 113*58e805e6Szrj #ifdef ECANCELED 114*58e805e6Szrj case ECANCELED: 115*58e805e6Szrj #endif 116*58e805e6Szrj #ifdef ECHILD 117*58e805e6Szrj case ECHILD: 118*58e805e6Szrj #endif 119*58e805e6Szrj #ifdef ECONNABORTED 120*58e805e6Szrj case ECONNABORTED: 121*58e805e6Szrj #endif 122*58e805e6Szrj #ifdef ECONNREFUSED 123*58e805e6Szrj case ECONNREFUSED: 124*58e805e6Szrj #endif 125*58e805e6Szrj #ifdef ECONNRESET 126*58e805e6Szrj case ECONNRESET: 127*58e805e6Szrj #endif 128*58e805e6Szrj #ifdef EDEADLK 129*58e805e6Szrj case EDEADLK: 130*58e805e6Szrj #endif 131*58e805e6Szrj #ifdef EDESTADDRREQ 132*58e805e6Szrj case EDESTADDRREQ: 133*58e805e6Szrj #endif 134*58e805e6Szrj case EDOM: 135*58e805e6Szrj #ifdef EEXIST 136*58e805e6Szrj case EEXIST: 137*58e805e6Szrj #endif 138*58e805e6Szrj #ifdef EFAULT 139*58e805e6Szrj case EFAULT: 140*58e805e6Szrj #endif 141*58e805e6Szrj #ifdef EFBIG 142*58e805e6Szrj case EFBIG: 143*58e805e6Szrj #endif 144*58e805e6Szrj #ifdef EHOSTUNREACH 145*58e805e6Szrj case EHOSTUNREACH: 146*58e805e6Szrj #endif 147*58e805e6Szrj #ifdef EIDRM 148*58e805e6Szrj case EIDRM: 149*58e805e6Szrj #endif 150*58e805e6Szrj case EILSEQ: 151*58e805e6Szrj #ifdef EINPROGRESS 152*58e805e6Szrj case EINPROGRESS: 153*58e805e6Szrj #endif 154*58e805e6Szrj #ifdef EINTR 155*58e805e6Szrj case EINTR: 156*58e805e6Szrj #endif 157*58e805e6Szrj #ifdef EINVAL 158*58e805e6Szrj case EINVAL: 159*58e805e6Szrj #endif 160*58e805e6Szrj #ifdef EIO 161*58e805e6Szrj case EIO: 162*58e805e6Szrj #endif 163*58e805e6Szrj #ifdef EISCONN 164*58e805e6Szrj case EISCONN: 165*58e805e6Szrj #endif 166*58e805e6Szrj #ifdef EISDIR 167*58e805e6Szrj case EISDIR: 168*58e805e6Szrj #endif 169*58e805e6Szrj #ifdef ELOOP 170*58e805e6Szrj case ELOOP: 171*58e805e6Szrj #endif 172*58e805e6Szrj #ifdef EMFILE 173*58e805e6Szrj case EMFILE: 174*58e805e6Szrj #endif 175*58e805e6Szrj #ifdef EMLINK 176*58e805e6Szrj case EMLINK: 177*58e805e6Szrj #endif 178*58e805e6Szrj #ifdef EMSGSIZE 179*58e805e6Szrj case EMSGSIZE: 180*58e805e6Szrj #endif 181*58e805e6Szrj #ifdef ENAMETOOLONG 182*58e805e6Szrj case ENAMETOOLONG: 183*58e805e6Szrj #endif 184*58e805e6Szrj #ifdef ENETDOWN 185*58e805e6Szrj case ENETDOWN: 186*58e805e6Szrj #endif 187*58e805e6Szrj #ifdef ENETRESET 188*58e805e6Szrj case ENETRESET: 189*58e805e6Szrj #endif 190*58e805e6Szrj #ifdef ENETUNREACH 191*58e805e6Szrj case ENETUNREACH: 192*58e805e6Szrj #endif 193*58e805e6Szrj #ifdef ENFILE 194*58e805e6Szrj case ENFILE: 195*58e805e6Szrj #endif 196*58e805e6Szrj #ifdef ENOBUFS 197*58e805e6Szrj case ENOBUFS: 198*58e805e6Szrj #endif 199*58e805e6Szrj #ifdef ENODATA 200*58e805e6Szrj case ENODATA: 201*58e805e6Szrj #endif 202*58e805e6Szrj #ifdef ENODEV 203*58e805e6Szrj case ENODEV: 204*58e805e6Szrj #endif 205*58e805e6Szrj #ifdef ENOENT 206*58e805e6Szrj case ENOENT: 207*58e805e6Szrj #endif 208*58e805e6Szrj #ifdef ENOEXEC 209*58e805e6Szrj case ENOEXEC: 210*58e805e6Szrj #endif 211*58e805e6Szrj #ifdef ENOLCK 212*58e805e6Szrj case ENOLCK: 213*58e805e6Szrj #endif 214*58e805e6Szrj #ifdef ENOLINK 215*58e805e6Szrj case ENOLINK: 216*58e805e6Szrj #endif 217*58e805e6Szrj #ifdef ENOMEM 218*58e805e6Szrj case ENOMEM: 219*58e805e6Szrj #endif 220*58e805e6Szrj #ifdef ENOMSG 221*58e805e6Szrj case ENOMSG: 222*58e805e6Szrj #endif 223*58e805e6Szrj #ifdef ENOPROTOOPT 224*58e805e6Szrj case ENOPROTOOPT: 225*58e805e6Szrj #endif 226*58e805e6Szrj #ifdef ENOSPC 227*58e805e6Szrj case ENOSPC: 228*58e805e6Szrj #endif 229*58e805e6Szrj #ifdef ENOSR 230*58e805e6Szrj case ENOSR: 231*58e805e6Szrj #endif 232*58e805e6Szrj #ifdef ENOSTR 233*58e805e6Szrj case ENOSTR: 234*58e805e6Szrj #endif 235*58e805e6Szrj #ifdef ENOSYS 236*58e805e6Szrj case ENOSYS: 237*58e805e6Szrj #endif 238*58e805e6Szrj #ifdef ENOTCONN 239*58e805e6Szrj case ENOTCONN: 240*58e805e6Szrj #endif 241*58e805e6Szrj #ifdef ENOTDIR 242*58e805e6Szrj case ENOTDIR: 243*58e805e6Szrj #endif 244*58e805e6Szrj #if defined ENOTEMPTY && (!defined EEXIST || ENOTEMPTY != EEXIST) 245*58e805e6Szrj // AIX sometimes uses the same value for EEXIST and ENOTEMPTY 246*58e805e6Szrj case ENOTEMPTY: 247*58e805e6Szrj #endif 248*58e805e6Szrj #ifdef ENOTRECOVERABLE 249*58e805e6Szrj case ENOTRECOVERABLE: 250*58e805e6Szrj #endif 251*58e805e6Szrj #ifdef ENOTSOCK 252*58e805e6Szrj case ENOTSOCK: 253*58e805e6Szrj #endif 254*58e805e6Szrj #ifdef ENOTSUP 255*58e805e6Szrj case ENOTSUP: 256*58e805e6Szrj #endif 257*58e805e6Szrj #ifdef ENOTTY 258*58e805e6Szrj case ENOTTY: 259*58e805e6Szrj #endif 260*58e805e6Szrj #ifdef ENXIO 261*58e805e6Szrj case ENXIO: 262*58e805e6Szrj #endif 263*58e805e6Szrj #if defined EOPNOTSUPP && (!defined ENOTSUP || EOPNOTSUPP != ENOTSUP) 264*58e805e6Szrj case EOPNOTSUPP: 265*58e805e6Szrj #endif 266*58e805e6Szrj #ifdef EOVERFLOW 267*58e805e6Szrj case EOVERFLOW: 268*58e805e6Szrj #endif 269*58e805e6Szrj #ifdef EOWNERDEAD 270*58e805e6Szrj case EOWNERDEAD: 271*58e805e6Szrj #endif 272*58e805e6Szrj #ifdef EPERM 273*58e805e6Szrj case EPERM: 274*58e805e6Szrj #endif 275*58e805e6Szrj #ifdef EPIPE 276*58e805e6Szrj case EPIPE: 277*58e805e6Szrj #endif 278*58e805e6Szrj #ifdef EPROTO 279*58e805e6Szrj case EPROTO: 280*58e805e6Szrj #endif 281*58e805e6Szrj #ifdef EPROTONOSUPPORT 282*58e805e6Szrj case EPROTONOSUPPORT: 283*58e805e6Szrj #endif 284*58e805e6Szrj #ifdef EPROTOTYPE 285*58e805e6Szrj case EPROTOTYPE: 286*58e805e6Szrj #endif 287*58e805e6Szrj case ERANGE: 288*58e805e6Szrj #ifdef EROFS 289*58e805e6Szrj case EROFS: 290*58e805e6Szrj #endif 291*58e805e6Szrj #ifdef ESPIPE 292*58e805e6Szrj case ESPIPE: 293*58e805e6Szrj #endif 294*58e805e6Szrj #ifdef ESRCH 295*58e805e6Szrj case ESRCH: 296*58e805e6Szrj #endif 297*58e805e6Szrj #ifdef ETIME 298*58e805e6Szrj case ETIME: 299*58e805e6Szrj #endif 300*58e805e6Szrj #ifdef ETIMEDOUT 301*58e805e6Szrj case ETIMEDOUT: 302*58e805e6Szrj #endif 303*58e805e6Szrj #ifdef ETXTBSY 304*58e805e6Szrj case ETXTBSY: 305*58e805e6Szrj #endif 306*58e805e6Szrj #if defined EWOULDBLOCK && (!defined EAGAIN || EWOULDBLOCK != EAGAIN) 307*58e805e6Szrj case EWOULDBLOCK: 308*58e805e6Szrj #endif 309*58e805e6Szrj #ifdef EXDEV 310*58e805e6Szrj case EXDEV: 311*58e805e6Szrj #endif 312*58e805e6Szrj return std::error_condition(ev, std::generic_category()); 313*58e805e6Szrj 314*58e805e6Szrj /* Additional system-dependent mappings from non-standard error codes 315*58e805e6Szrj * to one of the POSIX values above would go here, e.g. 316*58e805e6Szrj case EBLAH: 317*58e805e6Szrj return std::error_condition(EINVAL, std::generic_category()); 318*58e805e6Szrj */ 319*58e805e6Szrj 320*58e805e6Szrj default: 321*58e805e6Szrj return std::error_condition(ev, std::system_category()); 322*58e805e6Szrj } 323*58e805e6Szrj } 32438fd1498Szrj }; 32538fd1498Szrj 32638fd1498Szrj const generic_error_category generic_category_instance{}; 32738fd1498Szrj const system_error_category system_category_instance{}; 32838fd1498Szrj } 32938fd1498Szrj 33038fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 33138fd1498Szrj { 33238fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 33338fd1498Szrj 33438fd1498Szrj void __throw_system_error(int __i)33538fd1498Szrj __throw_system_error(int __i __attribute__((unused))) 33638fd1498Szrj { 33738fd1498Szrj _GLIBCXX_THROW_OR_ABORT(system_error(error_code(__i, generic_category()))); 33838fd1498Szrj } 33938fd1498Szrj 34038fd1498Szrj error_category::~error_category() noexcept = default; 34138fd1498Szrj 34238fd1498Szrj const error_category& system_category()34338fd1498Szrj _V2::system_category() noexcept { return system_category_instance; } 34438fd1498Szrj 34538fd1498Szrj const error_category& generic_category()34638fd1498Szrj _V2::generic_category() noexcept { return generic_category_instance; } 34738fd1498Szrj 34838fd1498Szrj system_error::~system_error() noexcept = default; 34938fd1498Szrj 35038fd1498Szrj error_condition default_error_condition(int __i) const35138fd1498Szrj error_category::default_error_condition(int __i) const noexcept 35238fd1498Szrj { return error_condition(__i, *this); } 35338fd1498Szrj 35438fd1498Szrj bool equivalent(int __i,const error_condition & __cond) const35538fd1498Szrj error_category::equivalent(int __i, 35638fd1498Szrj const error_condition& __cond) const noexcept 35738fd1498Szrj { return default_error_condition(__i) == __cond; } 35838fd1498Szrj 35938fd1498Szrj bool equivalent(const error_code & __code,int __i) const36038fd1498Szrj error_category::equivalent(const error_code& __code, int __i) const noexcept 36138fd1498Szrj { return *this == __code.category() && __code.value() == __i; } 36238fd1498Szrj 36338fd1498Szrj error_condition default_error_condition() const36438fd1498Szrj error_code::default_error_condition() const noexcept 36538fd1498Szrj { return category().default_error_condition(value()); } 36638fd1498Szrj 36738fd1498Szrj #if _GLIBCXX_USE_CXX11_ABI 36838fd1498Szrj // Return error_category::message() as a COW string 36938fd1498Szrj __cow_string _M_message(int i) const37038fd1498Szrj error_category::_M_message(int i) const 37138fd1498Szrj { 37238fd1498Szrj string msg = this->message(i); 37338fd1498Szrj return {msg.c_str(), msg.length()}; 37438fd1498Szrj } 37538fd1498Szrj #endif 37638fd1498Szrj 37738fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 37838fd1498Szrj } // namespace 379