1*4684ddb6SLionel Sambuc// -*- C++ -*- 2*4684ddb6SLionel Sambuc//===---------------------------- system_error ----------------------------===// 3*4684ddb6SLionel Sambuc// 4*4684ddb6SLionel Sambuc// The LLVM Compiler Infrastructure 5*4684ddb6SLionel Sambuc// 6*4684ddb6SLionel Sambuc// This file is dual licensed under the MIT and the University of Illinois Open 7*4684ddb6SLionel Sambuc// Source Licenses. See LICENSE.TXT for details. 8*4684ddb6SLionel Sambuc// 9*4684ddb6SLionel Sambuc//===----------------------------------------------------------------------===// 10*4684ddb6SLionel Sambuc 11*4684ddb6SLionel Sambuc#ifndef _LIBCPP_SYSTEM_ERROR 12*4684ddb6SLionel Sambuc#define _LIBCPP_SYSTEM_ERROR 13*4684ddb6SLionel Sambuc 14*4684ddb6SLionel Sambuc/* 15*4684ddb6SLionel Sambuc system_error synopsis 16*4684ddb6SLionel Sambuc 17*4684ddb6SLionel Sambucnamespace std 18*4684ddb6SLionel Sambuc{ 19*4684ddb6SLionel Sambuc 20*4684ddb6SLionel Sambucclass error_category 21*4684ddb6SLionel Sambuc{ 22*4684ddb6SLionel Sambucpublic: 23*4684ddb6SLionel Sambuc virtual ~error_category() noexcept; 24*4684ddb6SLionel Sambuc 25*4684ddb6SLionel Sambuc constexpr error_category(); 26*4684ddb6SLionel Sambuc error_category(const error_category&) = delete; 27*4684ddb6SLionel Sambuc error_category& operator=(const error_category&) = delete; 28*4684ddb6SLionel Sambuc 29*4684ddb6SLionel Sambuc virtual const char* name() const noexcept = 0; 30*4684ddb6SLionel Sambuc virtual error_condition default_error_condition(int ev) const noexcept; 31*4684ddb6SLionel Sambuc virtual bool equivalent(int code, const error_condition& condition) const noexcept; 32*4684ddb6SLionel Sambuc virtual bool equivalent(const error_code& code, int condition) const noexcept; 33*4684ddb6SLionel Sambuc virtual string message(int ev) const = 0; 34*4684ddb6SLionel Sambuc 35*4684ddb6SLionel Sambuc bool operator==(const error_category& rhs) const noexcept; 36*4684ddb6SLionel Sambuc bool operator!=(const error_category& rhs) const noexcept; 37*4684ddb6SLionel Sambuc bool operator<(const error_category& rhs) const noexcept; 38*4684ddb6SLionel Sambuc}; 39*4684ddb6SLionel Sambuc 40*4684ddb6SLionel Sambucconst error_category& generic_category() noexcept; 41*4684ddb6SLionel Sambucconst error_category& system_category() noexcept; 42*4684ddb6SLionel Sambuc 43*4684ddb6SLionel Sambuctemplate <class T> struct is_error_code_enum 44*4684ddb6SLionel Sambuc : public false_type {}; 45*4684ddb6SLionel Sambuc 46*4684ddb6SLionel Sambuctemplate <class T> struct is_error_condition_enum 47*4684ddb6SLionel Sambuc : public false_type {}; 48*4684ddb6SLionel Sambuc 49*4684ddb6SLionel Sambucclass error_code 50*4684ddb6SLionel Sambuc{ 51*4684ddb6SLionel Sambucpublic: 52*4684ddb6SLionel Sambuc // constructors: 53*4684ddb6SLionel Sambuc error_code() noexcept; 54*4684ddb6SLionel Sambuc error_code(int val, const error_category& cat) noexcept; 55*4684ddb6SLionel Sambuc template <class ErrorCodeEnum> 56*4684ddb6SLionel Sambuc error_code(ErrorCodeEnum e) noexcept; 57*4684ddb6SLionel Sambuc 58*4684ddb6SLionel Sambuc // modifiers: 59*4684ddb6SLionel Sambuc void assign(int val, const error_category& cat) noexcept; 60*4684ddb6SLionel Sambuc template <class ErrorCodeEnum> 61*4684ddb6SLionel Sambuc error_code& operator=(ErrorCodeEnum e) noexcept; 62*4684ddb6SLionel Sambuc void clear() noexcept; 63*4684ddb6SLionel Sambuc 64*4684ddb6SLionel Sambuc // observers: 65*4684ddb6SLionel Sambuc int value() const noexcept; 66*4684ddb6SLionel Sambuc const error_category& category() const noexcept; 67*4684ddb6SLionel Sambuc error_condition default_error_condition() const noexcept; 68*4684ddb6SLionel Sambuc string message() const; 69*4684ddb6SLionel Sambuc explicit operator bool() const noexcept; 70*4684ddb6SLionel Sambuc}; 71*4684ddb6SLionel Sambuc 72*4684ddb6SLionel Sambuc// non-member functions: 73*4684ddb6SLionel Sambucbool operator<(const error_code& lhs, const error_code& rhs) noexcept; 74*4684ddb6SLionel Sambuctemplate <class charT, class traits> 75*4684ddb6SLionel Sambuc basic_ostream<charT,traits>& 76*4684ddb6SLionel Sambuc operator<<(basic_ostream<charT,traits>& os, const error_code& ec); 77*4684ddb6SLionel Sambuc 78*4684ddb6SLionel Sambucclass error_condition 79*4684ddb6SLionel Sambuc{ 80*4684ddb6SLionel Sambucpublic: 81*4684ddb6SLionel Sambuc // constructors: 82*4684ddb6SLionel Sambuc error_condition() noexcept; 83*4684ddb6SLionel Sambuc error_condition(int val, const error_category& cat) noexcept; 84*4684ddb6SLionel Sambuc template <class ErrorConditionEnum> 85*4684ddb6SLionel Sambuc error_condition(ErrorConditionEnum e) noexcept; 86*4684ddb6SLionel Sambuc 87*4684ddb6SLionel Sambuc // modifiers: 88*4684ddb6SLionel Sambuc void assign(int val, const error_category& cat) noexcept; 89*4684ddb6SLionel Sambuc template <class ErrorConditionEnum> 90*4684ddb6SLionel Sambuc error_condition& operator=(ErrorConditionEnum e) noexcept; 91*4684ddb6SLionel Sambuc void clear() noexcept; 92*4684ddb6SLionel Sambuc 93*4684ddb6SLionel Sambuc // observers: 94*4684ddb6SLionel Sambuc int value() const noexcept; 95*4684ddb6SLionel Sambuc const error_category& category() const noexcept; 96*4684ddb6SLionel Sambuc string message() const noexcept; 97*4684ddb6SLionel Sambuc explicit operator bool() const noexcept; 98*4684ddb6SLionel Sambuc}; 99*4684ddb6SLionel Sambuc 100*4684ddb6SLionel Sambucbool operator<(const error_condition& lhs, const error_condition& rhs) noexcept; 101*4684ddb6SLionel Sambuc 102*4684ddb6SLionel Sambucclass system_error 103*4684ddb6SLionel Sambuc : public runtime_error 104*4684ddb6SLionel Sambuc{ 105*4684ddb6SLionel Sambucpublic: 106*4684ddb6SLionel Sambuc system_error(error_code ec, const string& what_arg); 107*4684ddb6SLionel Sambuc system_error(error_code ec, const char* what_arg); 108*4684ddb6SLionel Sambuc system_error(error_code ec); 109*4684ddb6SLionel Sambuc system_error(int ev, const error_category& ecat, const string& what_arg); 110*4684ddb6SLionel Sambuc system_error(int ev, const error_category& ecat, const char* what_arg); 111*4684ddb6SLionel Sambuc system_error(int ev, const error_category& ecat); 112*4684ddb6SLionel Sambuc 113*4684ddb6SLionel Sambuc const error_code& code() const noexcept; 114*4684ddb6SLionel Sambuc const char* what() const noexcept; 115*4684ddb6SLionel Sambuc}; 116*4684ddb6SLionel Sambuc 117*4684ddb6SLionel Sambucenum class errc 118*4684ddb6SLionel Sambuc{ 119*4684ddb6SLionel Sambuc address_family_not_supported, // EAFNOSUPPORT 120*4684ddb6SLionel Sambuc address_in_use, // EADDRINUSE 121*4684ddb6SLionel Sambuc address_not_available, // EADDRNOTAVAIL 122*4684ddb6SLionel Sambuc already_connected, // EISCONN 123*4684ddb6SLionel Sambuc argument_list_too_long, // E2BIG 124*4684ddb6SLionel Sambuc argument_out_of_domain, // EDOM 125*4684ddb6SLionel Sambuc bad_address, // EFAULT 126*4684ddb6SLionel Sambuc bad_file_descriptor, // EBADF 127*4684ddb6SLionel Sambuc bad_message, // EBADMSG 128*4684ddb6SLionel Sambuc broken_pipe, // EPIPE 129*4684ddb6SLionel Sambuc connection_aborted, // ECONNABORTED 130*4684ddb6SLionel Sambuc connection_already_in_progress, // EALREADY 131*4684ddb6SLionel Sambuc connection_refused, // ECONNREFUSED 132*4684ddb6SLionel Sambuc connection_reset, // ECONNRESET 133*4684ddb6SLionel Sambuc cross_device_link, // EXDEV 134*4684ddb6SLionel Sambuc destination_address_required, // EDESTADDRREQ 135*4684ddb6SLionel Sambuc device_or_resource_busy, // EBUSY 136*4684ddb6SLionel Sambuc directory_not_empty, // ENOTEMPTY 137*4684ddb6SLionel Sambuc executable_format_error, // ENOEXEC 138*4684ddb6SLionel Sambuc file_exists, // EEXIST 139*4684ddb6SLionel Sambuc file_too_large, // EFBIG 140*4684ddb6SLionel Sambuc filename_too_long, // ENAMETOOLONG 141*4684ddb6SLionel Sambuc function_not_supported, // ENOSYS 142*4684ddb6SLionel Sambuc host_unreachable, // EHOSTUNREACH 143*4684ddb6SLionel Sambuc identifier_removed, // EIDRM 144*4684ddb6SLionel Sambuc illegal_byte_sequence, // EILSEQ 145*4684ddb6SLionel Sambuc inappropriate_io_control_operation, // ENOTTY 146*4684ddb6SLionel Sambuc interrupted, // EINTR 147*4684ddb6SLionel Sambuc invalid_argument, // EINVAL 148*4684ddb6SLionel Sambuc invalid_seek, // ESPIPE 149*4684ddb6SLionel Sambuc io_error, // EIO 150*4684ddb6SLionel Sambuc is_a_directory, // EISDIR 151*4684ddb6SLionel Sambuc message_size, // EMSGSIZE 152*4684ddb6SLionel Sambuc network_down, // ENETDOWN 153*4684ddb6SLionel Sambuc network_reset, // ENETRESET 154*4684ddb6SLionel Sambuc network_unreachable, // ENETUNREACH 155*4684ddb6SLionel Sambuc no_buffer_space, // ENOBUFS 156*4684ddb6SLionel Sambuc no_child_process, // ECHILD 157*4684ddb6SLionel Sambuc no_link, // ENOLINK 158*4684ddb6SLionel Sambuc no_lock_available, // ENOLCK 159*4684ddb6SLionel Sambuc no_message_available, // ENODATA 160*4684ddb6SLionel Sambuc no_message, // ENOMSG 161*4684ddb6SLionel Sambuc no_protocol_option, // ENOPROTOOPT 162*4684ddb6SLionel Sambuc no_space_on_device, // ENOSPC 163*4684ddb6SLionel Sambuc no_stream_resources, // ENOSR 164*4684ddb6SLionel Sambuc no_such_device_or_address, // ENXIO 165*4684ddb6SLionel Sambuc no_such_device, // ENODEV 166*4684ddb6SLionel Sambuc no_such_file_or_directory, // ENOENT 167*4684ddb6SLionel Sambuc no_such_process, // ESRCH 168*4684ddb6SLionel Sambuc not_a_directory, // ENOTDIR 169*4684ddb6SLionel Sambuc not_a_socket, // ENOTSOCK 170*4684ddb6SLionel Sambuc not_a_stream, // ENOSTR 171*4684ddb6SLionel Sambuc not_connected, // ENOTCONN 172*4684ddb6SLionel Sambuc not_enough_memory, // ENOMEM 173*4684ddb6SLionel Sambuc not_supported, // ENOTSUP 174*4684ddb6SLionel Sambuc operation_canceled, // ECANCELED 175*4684ddb6SLionel Sambuc operation_in_progress, // EINPROGRESS 176*4684ddb6SLionel Sambuc operation_not_permitted, // EPERM 177*4684ddb6SLionel Sambuc operation_not_supported, // EOPNOTSUPP 178*4684ddb6SLionel Sambuc operation_would_block, // EWOULDBLOCK 179*4684ddb6SLionel Sambuc owner_dead, // EOWNERDEAD 180*4684ddb6SLionel Sambuc permission_denied, // EACCES 181*4684ddb6SLionel Sambuc protocol_error, // EPROTO 182*4684ddb6SLionel Sambuc protocol_not_supported, // EPROTONOSUPPORT 183*4684ddb6SLionel Sambuc read_only_file_system, // EROFS 184*4684ddb6SLionel Sambuc resource_deadlock_would_occur, // EDEADLK 185*4684ddb6SLionel Sambuc resource_unavailable_try_again, // EAGAIN 186*4684ddb6SLionel Sambuc result_out_of_range, // ERANGE 187*4684ddb6SLionel Sambuc state_not_recoverable, // ENOTRECOVERABLE 188*4684ddb6SLionel Sambuc stream_timeout, // ETIME 189*4684ddb6SLionel Sambuc text_file_busy, // ETXTBSY 190*4684ddb6SLionel Sambuc timed_out, // ETIMEDOUT 191*4684ddb6SLionel Sambuc too_many_files_open_in_system, // ENFILE 192*4684ddb6SLionel Sambuc too_many_files_open, // EMFILE 193*4684ddb6SLionel Sambuc too_many_links, // EMLINK 194*4684ddb6SLionel Sambuc too_many_symbolic_link_levels, // ELOOP 195*4684ddb6SLionel Sambuc value_too_large, // EOVERFLOW 196*4684ddb6SLionel Sambuc wrong_protocol_type // EPROTOTYPE 197*4684ddb6SLionel Sambuc}; 198*4684ddb6SLionel Sambuc 199*4684ddb6SLionel Sambuctemplate <> struct is_error_condition_enum<errc> 200*4684ddb6SLionel Sambuc : true_type { } 201*4684ddb6SLionel Sambuc 202*4684ddb6SLionel Sambucerror_code make_error_code(errc e) noexcept; 203*4684ddb6SLionel Sambucerror_condition make_error_condition(errc e) noexcept; 204*4684ddb6SLionel Sambuc 205*4684ddb6SLionel Sambuc// Comparison operators: 206*4684ddb6SLionel Sambucbool operator==(const error_code& lhs, const error_code& rhs) noexcept; 207*4684ddb6SLionel Sambucbool operator==(const error_code& lhs, const error_condition& rhs) noexcept; 208*4684ddb6SLionel Sambucbool operator==(const error_condition& lhs, const error_code& rhs) noexcept; 209*4684ddb6SLionel Sambucbool operator==(const error_condition& lhs, const error_condition& rhs) noexcept; 210*4684ddb6SLionel Sambucbool operator!=(const error_code& lhs, const error_code& rhs) noexcept; 211*4684ddb6SLionel Sambucbool operator!=(const error_code& lhs, const error_condition& rhs) noexcept; 212*4684ddb6SLionel Sambucbool operator!=(const error_condition& lhs, const error_code& rhs) noexcept; 213*4684ddb6SLionel Sambucbool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept; 214*4684ddb6SLionel Sambuc 215*4684ddb6SLionel Sambuctemplate <> struct hash<std::error_code>; 216*4684ddb6SLionel Sambuc 217*4684ddb6SLionel Sambuc} // std 218*4684ddb6SLionel Sambuc 219*4684ddb6SLionel Sambuc*/ 220*4684ddb6SLionel Sambuc 221*4684ddb6SLionel Sambuc#include <__config> 222*4684ddb6SLionel Sambuc#include <cerrno> 223*4684ddb6SLionel Sambuc#include <type_traits> 224*4684ddb6SLionel Sambuc#include <stdexcept> 225*4684ddb6SLionel Sambuc#include <__functional_base> 226*4684ddb6SLionel Sambuc 227*4684ddb6SLionel Sambuc#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 228*4684ddb6SLionel Sambuc#pragma GCC system_header 229*4684ddb6SLionel Sambuc#endif 230*4684ddb6SLionel Sambuc 231*4684ddb6SLionel Sambuc_LIBCPP_BEGIN_NAMESPACE_STD 232*4684ddb6SLionel Sambuc 233*4684ddb6SLionel Sambuc// is_error_code_enum 234*4684ddb6SLionel Sambuc 235*4684ddb6SLionel Sambuctemplate <class _Tp> 236*4684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_code_enum 237*4684ddb6SLionel Sambuc : public false_type {}; 238*4684ddb6SLionel Sambuc 239*4684ddb6SLionel Sambuc// is_error_condition_enum 240*4684ddb6SLionel Sambuc 241*4684ddb6SLionel Sambuctemplate <class _Tp> 242*4684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum 243*4684ddb6SLionel Sambuc : public false_type {}; 244*4684ddb6SLionel Sambuc 245*4684ddb6SLionel Sambuc// Some error codes are not present on all platforms, so we provide equivalents 246*4684ddb6SLionel Sambuc// for them: 247*4684ddb6SLionel Sambuc 248*4684ddb6SLionel Sambuc//enum class errc 249*4684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM(errc) 250*4684ddb6SLionel Sambuc{ 251*4684ddb6SLionel Sambuc address_family_not_supported = EAFNOSUPPORT, 252*4684ddb6SLionel Sambuc address_in_use = EADDRINUSE, 253*4684ddb6SLionel Sambuc address_not_available = EADDRNOTAVAIL, 254*4684ddb6SLionel Sambuc already_connected = EISCONN, 255*4684ddb6SLionel Sambuc argument_list_too_long = E2BIG, 256*4684ddb6SLionel Sambuc argument_out_of_domain = EDOM, 257*4684ddb6SLionel Sambuc bad_address = EFAULT, 258*4684ddb6SLionel Sambuc bad_file_descriptor = EBADF, 259*4684ddb6SLionel Sambuc bad_message = EBADMSG, 260*4684ddb6SLionel Sambuc broken_pipe = EPIPE, 261*4684ddb6SLionel Sambuc connection_aborted = ECONNABORTED, 262*4684ddb6SLionel Sambuc connection_already_in_progress = EALREADY, 263*4684ddb6SLionel Sambuc connection_refused = ECONNREFUSED, 264*4684ddb6SLionel Sambuc connection_reset = ECONNRESET, 265*4684ddb6SLionel Sambuc cross_device_link = EXDEV, 266*4684ddb6SLionel Sambuc destination_address_required = EDESTADDRREQ, 267*4684ddb6SLionel Sambuc device_or_resource_busy = EBUSY, 268*4684ddb6SLionel Sambuc directory_not_empty = ENOTEMPTY, 269*4684ddb6SLionel Sambuc executable_format_error = ENOEXEC, 270*4684ddb6SLionel Sambuc file_exists = EEXIST, 271*4684ddb6SLionel Sambuc file_too_large = EFBIG, 272*4684ddb6SLionel Sambuc filename_too_long = ENAMETOOLONG, 273*4684ddb6SLionel Sambuc function_not_supported = ENOSYS, 274*4684ddb6SLionel Sambuc host_unreachable = EHOSTUNREACH, 275*4684ddb6SLionel Sambuc identifier_removed = EIDRM, 276*4684ddb6SLionel Sambuc illegal_byte_sequence = EILSEQ, 277*4684ddb6SLionel Sambuc inappropriate_io_control_operation = ENOTTY, 278*4684ddb6SLionel Sambuc interrupted = EINTR, 279*4684ddb6SLionel Sambuc invalid_argument = EINVAL, 280*4684ddb6SLionel Sambuc invalid_seek = ESPIPE, 281*4684ddb6SLionel Sambuc io_error = EIO, 282*4684ddb6SLionel Sambuc is_a_directory = EISDIR, 283*4684ddb6SLionel Sambuc message_size = EMSGSIZE, 284*4684ddb6SLionel Sambuc network_down = ENETDOWN, 285*4684ddb6SLionel Sambuc network_reset = ENETRESET, 286*4684ddb6SLionel Sambuc network_unreachable = ENETUNREACH, 287*4684ddb6SLionel Sambuc no_buffer_space = ENOBUFS, 288*4684ddb6SLionel Sambuc no_child_process = ECHILD, 289*4684ddb6SLionel Sambuc no_link = ENOLINK, 290*4684ddb6SLionel Sambuc no_lock_available = ENOLCK, 291*4684ddb6SLionel Sambuc#ifdef ENODATA 292*4684ddb6SLionel Sambuc no_message_available = ENODATA, 293*4684ddb6SLionel Sambuc#else 294*4684ddb6SLionel Sambuc no_message_available = ENOMSG, 295*4684ddb6SLionel Sambuc#endif 296*4684ddb6SLionel Sambuc no_message = ENOMSG, 297*4684ddb6SLionel Sambuc no_protocol_option = ENOPROTOOPT, 298*4684ddb6SLionel Sambuc no_space_on_device = ENOSPC, 299*4684ddb6SLionel Sambuc#ifdef ENOSR 300*4684ddb6SLionel Sambuc no_stream_resources = ENOSR, 301*4684ddb6SLionel Sambuc#else 302*4684ddb6SLionel Sambuc no_stream_resources = ENOMEM, 303*4684ddb6SLionel Sambuc#endif 304*4684ddb6SLionel Sambuc no_such_device_or_address = ENXIO, 305*4684ddb6SLionel Sambuc no_such_device = ENODEV, 306*4684ddb6SLionel Sambuc no_such_file_or_directory = ENOENT, 307*4684ddb6SLionel Sambuc no_such_process = ESRCH, 308*4684ddb6SLionel Sambuc not_a_directory = ENOTDIR, 309*4684ddb6SLionel Sambuc not_a_socket = ENOTSOCK, 310*4684ddb6SLionel Sambuc#ifdef ENOSTR 311*4684ddb6SLionel Sambuc not_a_stream = ENOSTR, 312*4684ddb6SLionel Sambuc#else 313*4684ddb6SLionel Sambuc not_a_stream = EINVAL, 314*4684ddb6SLionel Sambuc#endif 315*4684ddb6SLionel Sambuc not_connected = ENOTCONN, 316*4684ddb6SLionel Sambuc not_enough_memory = ENOMEM, 317*4684ddb6SLionel Sambuc not_supported = ENOTSUP, 318*4684ddb6SLionel Sambuc operation_canceled = ECANCELED, 319*4684ddb6SLionel Sambuc operation_in_progress = EINPROGRESS, 320*4684ddb6SLionel Sambuc operation_not_permitted = EPERM, 321*4684ddb6SLionel Sambuc operation_not_supported = EOPNOTSUPP, 322*4684ddb6SLionel Sambuc operation_would_block = EWOULDBLOCK, 323*4684ddb6SLionel Sambuc owner_dead = EOWNERDEAD, 324*4684ddb6SLionel Sambuc permission_denied = EACCES, 325*4684ddb6SLionel Sambuc protocol_error = EPROTO, 326*4684ddb6SLionel Sambuc protocol_not_supported = EPROTONOSUPPORT, 327*4684ddb6SLionel Sambuc read_only_file_system = EROFS, 328*4684ddb6SLionel Sambuc resource_deadlock_would_occur = EDEADLK, 329*4684ddb6SLionel Sambuc resource_unavailable_try_again = EAGAIN, 330*4684ddb6SLionel Sambuc result_out_of_range = ERANGE, 331*4684ddb6SLionel Sambuc state_not_recoverable = ENOTRECOVERABLE, 332*4684ddb6SLionel Sambuc#ifdef ETIME 333*4684ddb6SLionel Sambuc stream_timeout = ETIME, 334*4684ddb6SLionel Sambuc#else 335*4684ddb6SLionel Sambuc stream_timeout = ETIMEDOUT, 336*4684ddb6SLionel Sambuc#endif 337*4684ddb6SLionel Sambuc text_file_busy = ETXTBSY, 338*4684ddb6SLionel Sambuc timed_out = ETIMEDOUT, 339*4684ddb6SLionel Sambuc too_many_files_open_in_system = ENFILE, 340*4684ddb6SLionel Sambuc too_many_files_open = EMFILE, 341*4684ddb6SLionel Sambuc too_many_links = EMLINK, 342*4684ddb6SLionel Sambuc too_many_symbolic_link_levels = ELOOP, 343*4684ddb6SLionel Sambuc value_too_large = EOVERFLOW, 344*4684ddb6SLionel Sambuc wrong_protocol_type = EPROTOTYPE 345*4684ddb6SLionel Sambuc}; 346*4684ddb6SLionel Sambuc_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc) 347*4684ddb6SLionel Sambuc 348*4684ddb6SLionel Sambuctemplate <> 349*4684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc> 350*4684ddb6SLionel Sambuc : true_type { }; 351*4684ddb6SLionel Sambuc 352*4684ddb6SLionel Sambuc#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS 353*4684ddb6SLionel Sambuctemplate <> 354*4684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY is_error_condition_enum<errc::__lx> 355*4684ddb6SLionel Sambuc : true_type { }; 356*4684ddb6SLionel Sambuc#endif 357*4684ddb6SLionel Sambuc 358*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS error_condition; 359*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS error_code; 360*4684ddb6SLionel Sambuc 361*4684ddb6SLionel Sambuc// class error_category 362*4684ddb6SLionel Sambuc 363*4684ddb6SLionel Sambucclass _LIBCPP_HIDDEN __do_message; 364*4684ddb6SLionel Sambuc 365*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS error_category 366*4684ddb6SLionel Sambuc{ 367*4684ddb6SLionel Sambucpublic: 368*4684ddb6SLionel Sambuc virtual ~error_category() _NOEXCEPT; 369*4684ddb6SLionel Sambuc 370*4684ddb6SLionel Sambuc#ifdef _LIBCPP_BUILDING_SYSTEM_ERROR 371*4684ddb6SLionel Sambuc error_category() _NOEXCEPT; 372*4684ddb6SLionel Sambuc#else 373*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 374*4684ddb6SLionel Sambuc _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT; 375*4684ddb6SLionel Sambuc#endif 376*4684ddb6SLionel Sambucprivate: 377*4684ddb6SLionel Sambuc error_category(const error_category&);// = delete; 378*4684ddb6SLionel Sambuc error_category& operator=(const error_category&);// = delete; 379*4684ddb6SLionel Sambuc 380*4684ddb6SLionel Sambucpublic: 381*4684ddb6SLionel Sambuc virtual const char* name() const _NOEXCEPT = 0; 382*4684ddb6SLionel Sambuc virtual error_condition default_error_condition(int __ev) const _NOEXCEPT; 383*4684ddb6SLionel Sambuc virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT; 384*4684ddb6SLionel Sambuc virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT; 385*4684ddb6SLionel Sambuc virtual string message(int __ev) const = 0; 386*4684ddb6SLionel Sambuc 387*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 388*4684ddb6SLionel Sambuc bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;} 389*4684ddb6SLionel Sambuc 390*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 391*4684ddb6SLionel Sambuc bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);} 392*4684ddb6SLionel Sambuc 393*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 394*4684ddb6SLionel Sambuc bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;} 395*4684ddb6SLionel Sambuc 396*4684ddb6SLionel Sambuc friend class _LIBCPP_HIDDEN __do_message; 397*4684ddb6SLionel Sambuc}; 398*4684ddb6SLionel Sambuc 399*4684ddb6SLionel Sambucclass _LIBCPP_HIDDEN __do_message 400*4684ddb6SLionel Sambuc : public error_category 401*4684ddb6SLionel Sambuc{ 402*4684ddb6SLionel Sambucpublic: 403*4684ddb6SLionel Sambuc virtual string message(int ev) const; 404*4684ddb6SLionel Sambuc}; 405*4684ddb6SLionel Sambuc 406*4684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT; 407*4684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT; 408*4684ddb6SLionel Sambuc 409*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS error_condition 410*4684ddb6SLionel Sambuc{ 411*4684ddb6SLionel Sambuc int __val_; 412*4684ddb6SLionel Sambuc const error_category* __cat_; 413*4684ddb6SLionel Sambucpublic: 414*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 415*4684ddb6SLionel Sambuc error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {} 416*4684ddb6SLionel Sambuc 417*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 418*4684ddb6SLionel Sambuc error_condition(int __val, const error_category& __cat) _NOEXCEPT 419*4684ddb6SLionel Sambuc : __val_(__val), __cat_(&__cat) {} 420*4684ddb6SLionel Sambuc 421*4684ddb6SLionel Sambuc template <class _Ep> 422*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 423*4684ddb6SLionel Sambuc error_condition(_Ep __e, 424*4684ddb6SLionel Sambuc typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0 425*4684ddb6SLionel Sambuc ) _NOEXCEPT 426*4684ddb6SLionel Sambuc {*this = make_error_condition(__e);} 427*4684ddb6SLionel Sambuc 428*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 429*4684ddb6SLionel Sambuc void assign(int __val, const error_category& __cat) _NOEXCEPT 430*4684ddb6SLionel Sambuc { 431*4684ddb6SLionel Sambuc __val_ = __val; 432*4684ddb6SLionel Sambuc __cat_ = &__cat; 433*4684ddb6SLionel Sambuc } 434*4684ddb6SLionel Sambuc 435*4684ddb6SLionel Sambuc template <class _Ep> 436*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 437*4684ddb6SLionel Sambuc typename enable_if 438*4684ddb6SLionel Sambuc < 439*4684ddb6SLionel Sambuc is_error_condition_enum<_Ep>::value, 440*4684ddb6SLionel Sambuc error_condition& 441*4684ddb6SLionel Sambuc >::type 442*4684ddb6SLionel Sambuc operator=(_Ep __e) _NOEXCEPT 443*4684ddb6SLionel Sambuc {*this = make_error_condition(__e); return *this;} 444*4684ddb6SLionel Sambuc 445*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 446*4684ddb6SLionel Sambuc void clear() _NOEXCEPT 447*4684ddb6SLionel Sambuc { 448*4684ddb6SLionel Sambuc __val_ = 0; 449*4684ddb6SLionel Sambuc __cat_ = &generic_category(); 450*4684ddb6SLionel Sambuc } 451*4684ddb6SLionel Sambuc 452*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 453*4684ddb6SLionel Sambuc int value() const _NOEXCEPT {return __val_;} 454*4684ddb6SLionel Sambuc 455*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 456*4684ddb6SLionel Sambuc const error_category& category() const _NOEXCEPT {return *__cat_;} 457*4684ddb6SLionel Sambuc string message() const; 458*4684ddb6SLionel Sambuc 459*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 460*4684ddb6SLionel Sambuc _LIBCPP_EXPLICIT 461*4684ddb6SLionel Sambuc operator bool() const _NOEXCEPT {return __val_ != 0;} 462*4684ddb6SLionel Sambuc}; 463*4684ddb6SLionel Sambuc 464*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 465*4684ddb6SLionel Sambucerror_condition 466*4684ddb6SLionel Sambucmake_error_condition(errc __e) _NOEXCEPT 467*4684ddb6SLionel Sambuc{ 468*4684ddb6SLionel Sambuc return error_condition(static_cast<int>(__e), generic_category()); 469*4684ddb6SLionel Sambuc} 470*4684ddb6SLionel Sambuc 471*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 472*4684ddb6SLionel Sambucbool 473*4684ddb6SLionel Sambucoperator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT 474*4684ddb6SLionel Sambuc{ 475*4684ddb6SLionel Sambuc return __x.category() < __y.category() 476*4684ddb6SLionel Sambuc || (__x.category() == __y.category() && __x.value() < __y.value()); 477*4684ddb6SLionel Sambuc} 478*4684ddb6SLionel Sambuc 479*4684ddb6SLionel Sambuc// error_code 480*4684ddb6SLionel Sambuc 481*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS error_code 482*4684ddb6SLionel Sambuc{ 483*4684ddb6SLionel Sambuc int __val_; 484*4684ddb6SLionel Sambuc const error_category* __cat_; 485*4684ddb6SLionel Sambucpublic: 486*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 487*4684ddb6SLionel Sambuc error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {} 488*4684ddb6SLionel Sambuc 489*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 490*4684ddb6SLionel Sambuc error_code(int __val, const error_category& __cat) _NOEXCEPT 491*4684ddb6SLionel Sambuc : __val_(__val), __cat_(&__cat) {} 492*4684ddb6SLionel Sambuc 493*4684ddb6SLionel Sambuc template <class _Ep> 494*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 495*4684ddb6SLionel Sambuc error_code(_Ep __e, 496*4684ddb6SLionel Sambuc typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0 497*4684ddb6SLionel Sambuc ) _NOEXCEPT 498*4684ddb6SLionel Sambuc {*this = make_error_code(__e);} 499*4684ddb6SLionel Sambuc 500*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 501*4684ddb6SLionel Sambuc void assign(int __val, const error_category& __cat) _NOEXCEPT 502*4684ddb6SLionel Sambuc { 503*4684ddb6SLionel Sambuc __val_ = __val; 504*4684ddb6SLionel Sambuc __cat_ = &__cat; 505*4684ddb6SLionel Sambuc } 506*4684ddb6SLionel Sambuc 507*4684ddb6SLionel Sambuc template <class _Ep> 508*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 509*4684ddb6SLionel Sambuc typename enable_if 510*4684ddb6SLionel Sambuc < 511*4684ddb6SLionel Sambuc is_error_code_enum<_Ep>::value, 512*4684ddb6SLionel Sambuc error_code& 513*4684ddb6SLionel Sambuc >::type 514*4684ddb6SLionel Sambuc operator=(_Ep __e) _NOEXCEPT 515*4684ddb6SLionel Sambuc {*this = make_error_code(__e); return *this;} 516*4684ddb6SLionel Sambuc 517*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 518*4684ddb6SLionel Sambuc void clear() _NOEXCEPT 519*4684ddb6SLionel Sambuc { 520*4684ddb6SLionel Sambuc __val_ = 0; 521*4684ddb6SLionel Sambuc __cat_ = &system_category(); 522*4684ddb6SLionel Sambuc } 523*4684ddb6SLionel Sambuc 524*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 525*4684ddb6SLionel Sambuc int value() const _NOEXCEPT {return __val_;} 526*4684ddb6SLionel Sambuc 527*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 528*4684ddb6SLionel Sambuc const error_category& category() const _NOEXCEPT {return *__cat_;} 529*4684ddb6SLionel Sambuc 530*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 531*4684ddb6SLionel Sambuc error_condition default_error_condition() const _NOEXCEPT 532*4684ddb6SLionel Sambuc {return __cat_->default_error_condition(__val_);} 533*4684ddb6SLionel Sambuc 534*4684ddb6SLionel Sambuc string message() const; 535*4684ddb6SLionel Sambuc 536*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 537*4684ddb6SLionel Sambuc _LIBCPP_EXPLICIT 538*4684ddb6SLionel Sambuc operator bool() const _NOEXCEPT {return __val_ != 0;} 539*4684ddb6SLionel Sambuc}; 540*4684ddb6SLionel Sambuc 541*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 542*4684ddb6SLionel Sambucerror_code 543*4684ddb6SLionel Sambucmake_error_code(errc __e) _NOEXCEPT 544*4684ddb6SLionel Sambuc{ 545*4684ddb6SLionel Sambuc return error_code(static_cast<int>(__e), generic_category()); 546*4684ddb6SLionel Sambuc} 547*4684ddb6SLionel Sambuc 548*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 549*4684ddb6SLionel Sambucbool 550*4684ddb6SLionel Sambucoperator<(const error_code& __x, const error_code& __y) _NOEXCEPT 551*4684ddb6SLionel Sambuc{ 552*4684ddb6SLionel Sambuc return __x.category() < __y.category() 553*4684ddb6SLionel Sambuc || (__x.category() == __y.category() && __x.value() < __y.value()); 554*4684ddb6SLionel Sambuc} 555*4684ddb6SLionel Sambuc 556*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 557*4684ddb6SLionel Sambucbool 558*4684ddb6SLionel Sambucoperator==(const error_code& __x, const error_code& __y) _NOEXCEPT 559*4684ddb6SLionel Sambuc{ 560*4684ddb6SLionel Sambuc return __x.category() == __y.category() && __x.value() == __y.value(); 561*4684ddb6SLionel Sambuc} 562*4684ddb6SLionel Sambuc 563*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 564*4684ddb6SLionel Sambucbool 565*4684ddb6SLionel Sambucoperator==(const error_code& __x, const error_condition& __y) _NOEXCEPT 566*4684ddb6SLionel Sambuc{ 567*4684ddb6SLionel Sambuc return __x.category().equivalent(__x.value(), __y) 568*4684ddb6SLionel Sambuc || __y.category().equivalent(__x, __y.value()); 569*4684ddb6SLionel Sambuc} 570*4684ddb6SLionel Sambuc 571*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 572*4684ddb6SLionel Sambucbool 573*4684ddb6SLionel Sambucoperator==(const error_condition& __x, const error_code& __y) _NOEXCEPT 574*4684ddb6SLionel Sambuc{ 575*4684ddb6SLionel Sambuc return __y == __x; 576*4684ddb6SLionel Sambuc} 577*4684ddb6SLionel Sambuc 578*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 579*4684ddb6SLionel Sambucbool 580*4684ddb6SLionel Sambucoperator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT 581*4684ddb6SLionel Sambuc{ 582*4684ddb6SLionel Sambuc return __x.category() == __y.category() && __x.value() == __y.value(); 583*4684ddb6SLionel Sambuc} 584*4684ddb6SLionel Sambuc 585*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 586*4684ddb6SLionel Sambucbool 587*4684ddb6SLionel Sambucoperator!=(const error_code& __x, const error_code& __y) _NOEXCEPT 588*4684ddb6SLionel Sambuc{return !(__x == __y);} 589*4684ddb6SLionel Sambuc 590*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 591*4684ddb6SLionel Sambucbool 592*4684ddb6SLionel Sambucoperator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT 593*4684ddb6SLionel Sambuc{return !(__x == __y);} 594*4684ddb6SLionel Sambuc 595*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 596*4684ddb6SLionel Sambucbool 597*4684ddb6SLionel Sambucoperator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT 598*4684ddb6SLionel Sambuc{return !(__x == __y);} 599*4684ddb6SLionel Sambuc 600*4684ddb6SLionel Sambucinline _LIBCPP_INLINE_VISIBILITY 601*4684ddb6SLionel Sambucbool 602*4684ddb6SLionel Sambucoperator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT 603*4684ddb6SLionel Sambuc{return !(__x == __y);} 604*4684ddb6SLionel Sambuc 605*4684ddb6SLionel Sambuctemplate <> 606*4684ddb6SLionel Sambucstruct _LIBCPP_TYPE_VIS_ONLY hash<error_code> 607*4684ddb6SLionel Sambuc : public unary_function<error_code, size_t> 608*4684ddb6SLionel Sambuc{ 609*4684ddb6SLionel Sambuc _LIBCPP_INLINE_VISIBILITY 610*4684ddb6SLionel Sambuc size_t operator()(const error_code& __ec) const _NOEXCEPT 611*4684ddb6SLionel Sambuc { 612*4684ddb6SLionel Sambuc return static_cast<size_t>(__ec.value()); 613*4684ddb6SLionel Sambuc } 614*4684ddb6SLionel Sambuc}; 615*4684ddb6SLionel Sambuc 616*4684ddb6SLionel Sambuc// system_error 617*4684ddb6SLionel Sambuc 618*4684ddb6SLionel Sambucclass _LIBCPP_TYPE_VIS system_error 619*4684ddb6SLionel Sambuc : public runtime_error 620*4684ddb6SLionel Sambuc{ 621*4684ddb6SLionel Sambuc error_code __ec_; 622*4684ddb6SLionel Sambucpublic: 623*4684ddb6SLionel Sambuc system_error(error_code __ec, const string& __what_arg); 624*4684ddb6SLionel Sambuc system_error(error_code __ec, const char* __what_arg); 625*4684ddb6SLionel Sambuc system_error(error_code __ec); 626*4684ddb6SLionel Sambuc system_error(int __ev, const error_category& __ecat, const string& __what_arg); 627*4684ddb6SLionel Sambuc system_error(int __ev, const error_category& __ecat, const char* __what_arg); 628*4684ddb6SLionel Sambuc system_error(int __ev, const error_category& __ecat); 629*4684ddb6SLionel Sambuc ~system_error() _NOEXCEPT; 630*4684ddb6SLionel Sambuc 631*4684ddb6SLionel Sambuc _LIBCPP_ALWAYS_INLINE 632*4684ddb6SLionel Sambuc const error_code& code() const _NOEXCEPT {return __ec_;} 633*4684ddb6SLionel Sambuc 634*4684ddb6SLionel Sambucprivate: 635*4684ddb6SLionel Sambuc static string __init(const error_code&, string); 636*4684ddb6SLionel Sambuc}; 637*4684ddb6SLionel Sambuc 638*4684ddb6SLionel Sambuc_LIBCPP_FUNC_VIS void __throw_system_error(int ev, const char* what_arg); 639*4684ddb6SLionel Sambuc 640*4684ddb6SLionel Sambuc_LIBCPP_END_NAMESPACE_STD 641*4684ddb6SLionel Sambuc 642*4684ddb6SLionel Sambuc#endif // _LIBCPP_SYSTEM_ERROR 643