|
| 1 | +#ifdef _MSC_VER |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +#if _MSC_VER>=1800 && _MSC_VER<1900 |
| 6 | + |
| 7 | +#include <stdexcept> |
| 8 | +#include <cstdlib> |
| 9 | +#include <system_error> |
| 10 | +#pragma warning(disable: 4005) |
| 11 | +#include <windows.h> |
| 12 | + |
| 13 | +namespace std |
| 14 | +{ |
| 15 | + |
| 16 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xbad_alloc()) |
| 17 | + { // report a bad_alloc error |
| 18 | + _THROW_NCEE(_XSTD bad_alloc, _EMPTY_ARGUMENT); |
| 19 | + |
| 20 | + } |
| 21 | + |
| 22 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xinvalid_argument(_In_z_ const char *_Message)) |
| 23 | + { // report an invalid_argument error |
| 24 | + _THROW_NCEE(invalid_argument, _Message); |
| 25 | + } |
| 26 | + |
| 27 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xlength_error(_In_z_ const char *_Message)) |
| 28 | + { // report a length_error |
| 29 | + _THROW_NCEE(length_error, _Message); |
| 30 | + } |
| 31 | + |
| 32 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xout_of_range(_In_z_ const char *_Message)) |
| 33 | + { // report an out_of_range error |
| 34 | + _THROW_NCEE(out_of_range, _Message); |
| 35 | + } |
| 36 | + |
| 37 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xoverflow_error(_In_z_ const char *_Message)) |
| 38 | + { // report an overflow error |
| 39 | + _THROW_NCEE(overflow_error, _Message); |
| 40 | + } |
| 41 | + |
| 42 | +_CRTIMP2_PURE _NO_RETURN(__CLRCALL_PURE_OR_CDECL _Xruntime_error(_In_z_ const char *_Message)) |
| 43 | + { // report a runtime_error |
| 44 | + _THROW_NCEE(runtime_error, _Message); |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +struct _Win_errtab_t |
| 51 | + { // maps Windows error_code to NTBS |
| 52 | + int _Errcode; |
| 53 | + const char *_Name; |
| 54 | + }; |
| 55 | + |
| 56 | +static const _Win_errtab_t _Win_errtab[] = |
| 57 | + { // table of Windows code/name pairs |
| 58 | + ERROR_ACCESS_DENIED, "permission denied", |
| 59 | + ERROR_ALREADY_EXISTS, "file exists", |
| 60 | + ERROR_BAD_UNIT, "no such device", |
| 61 | + ERROR_BUFFER_OVERFLOW, "filename too long", |
| 62 | + ERROR_BUSY, "device or resource busy", |
| 63 | + ERROR_BUSY_DRIVE, "device or resource busy", |
| 64 | + ERROR_CANNOT_MAKE, "permission denied", |
| 65 | + ERROR_CANTOPEN, "io error", |
| 66 | + ERROR_CANTREAD, "io error", |
| 67 | + ERROR_CANTWRITE, "io error", |
| 68 | + ERROR_CURRENT_DIRECTORY, "permission denied", |
| 69 | + ERROR_DEV_NOT_EXIST, "no such device", |
| 70 | + ERROR_DEVICE_IN_USE, "device or resource busy", |
| 71 | + ERROR_DIR_NOT_EMPTY, "directory not empty", |
| 72 | + ERROR_DIRECTORY, "invalid argument", |
| 73 | + ERROR_DISK_FULL, "no space on device", |
| 74 | + ERROR_FILE_EXISTS, "file exists", |
| 75 | + ERROR_FILE_NOT_FOUND, "no such file or directory", |
| 76 | + ERROR_HANDLE_DISK_FULL, "no space on device", |
| 77 | + ERROR_INVALID_ACCESS, "permission denied", |
| 78 | + ERROR_INVALID_DRIVE, "no such device", |
| 79 | + ERROR_INVALID_FUNCTION, "function not supported", |
| 80 | + ERROR_INVALID_HANDLE, "invalid argument", |
| 81 | + ERROR_INVALID_NAME, "invalid argument", |
| 82 | + ERROR_LOCK_VIOLATION, "no lock available", |
| 83 | + ERROR_LOCKED, "no lock available", |
| 84 | + ERROR_NEGATIVE_SEEK, "invalid argument", |
| 85 | + ERROR_NOACCESS, "permission denied", |
| 86 | + ERROR_NOT_ENOUGH_MEMORY, "not enough memory", |
| 87 | + ERROR_NOT_READY, "resource unavailable try again", |
| 88 | + ERROR_NOT_SAME_DEVICE, "cross device link", |
| 89 | + ERROR_OPEN_FAILED, "io error", |
| 90 | + ERROR_OPEN_FILES, "device or resource busy", |
| 91 | + ERROR_OPERATION_ABORTED, "operation canceled", |
| 92 | + ERROR_OUTOFMEMORY, "not enough memory", |
| 93 | + ERROR_PATH_NOT_FOUND, "no such file or directory", |
| 94 | + ERROR_READ_FAULT, "io error", |
| 95 | + ERROR_RETRY, "resource unavailable try again", |
| 96 | + ERROR_SEEK, "io error", |
| 97 | + ERROR_SHARING_VIOLATION, "permission denied", |
| 98 | + ERROR_TOO_MANY_OPEN_FILES, "too many files open", |
| 99 | + ERROR_WRITE_FAULT, "io error", |
| 100 | + ERROR_WRITE_PROTECT, "permission denied", |
| 101 | + WSAEACCES, "permission_denied", |
| 102 | + WSAEADDRINUSE, "address_in_use", |
| 103 | + WSAEADDRNOTAVAIL, "address_not_available", |
| 104 | + WSAEAFNOSUPPORT, "address_family_not_supported", |
| 105 | + WSAEALREADY, "connection_already_in_progress", |
| 106 | + WSAEBADF, "bad_file_descriptor", |
| 107 | + WSAECONNABORTED, "connection_aborted", |
| 108 | + WSAECONNREFUSED, "connection_refused", |
| 109 | + WSAECONNRESET, "connection_reset", |
| 110 | + WSAEDESTADDRREQ, "destination_address_required", |
| 111 | + WSAEFAULT, "bad_address", |
| 112 | + WSAEHOSTUNREACH, "host_unreachable", |
| 113 | + WSAEINPROGRESS, "operation_in_progress", |
| 114 | + WSAEINTR, "interrupted", |
| 115 | + WSAEINVAL, "invalid_argument", |
| 116 | + WSAEISCONN, "already_connected", |
| 117 | + WSAEMFILE, "too_many_files_open", |
| 118 | + WSAEMSGSIZE, "message_size", |
| 119 | + WSAENAMETOOLONG, "filename_too_long", |
| 120 | + WSAENETDOWN, "network_down", |
| 121 | + WSAENETRESET, "network_reset", |
| 122 | + WSAENETUNREACH, "network_unreachable", |
| 123 | + WSAENOBUFS, "no_buffer_space", |
| 124 | + WSAENOPROTOOPT, "no_protocol_option", |
| 125 | + WSAENOTCONN, "not_connected", |
| 126 | + WSAENOTSOCK, "not_a_socket", |
| 127 | + WSAEOPNOTSUPP, "operation_not_supported", |
| 128 | + WSAEPROTONOSUPPORT, "protocol_not_supported", |
| 129 | + WSAEPROTOTYPE, "wrong_protocol_type", |
| 130 | + WSAETIMEDOUT, "timed_out", |
| 131 | + WSAEWOULDBLOCK, "operation_would_block", |
| 132 | + 0, 0 |
| 133 | + }; |
| 134 | + |
| 135 | +const char *_Winerror_map(int _Errcode) |
| 136 | + { // convert to name of Windows error |
| 137 | + const _Win_errtab_t *_Ptr = &_Win_errtab[0]; |
| 138 | + for (; _Ptr->_Name != 0; ++_Ptr) |
| 139 | + if ((int)_Ptr->_Errcode == _Errcode) |
| 140 | + return (_Ptr->_Name); |
| 141 | + return (0); |
| 142 | + } |
| 143 | + |
| 144 | +struct _Sys_errtab_t |
| 145 | + { // maps error_code to NTBS |
| 146 | + generic_errno _Errcode; |
| 147 | + const char *_Name; |
| 148 | + }; |
| 149 | + |
| 150 | +static const _Sys_errtab_t _Sys_errtab[] = |
| 151 | + { // table of Posix code/name pairs |
| 152 | + errc::address_family_not_supported, "address family not supported", |
| 153 | + errc::address_in_use, "address in use", |
| 154 | + errc::address_not_available, "address not available", |
| 155 | + errc::already_connected, "already connected", |
| 156 | + errc::argument_list_too_long, "argument list too long", |
| 157 | + errc::argument_out_of_domain, "argument out of domain", |
| 158 | + errc::bad_address, "bad address", |
| 159 | + errc::bad_file_descriptor, "bad file descriptor", |
| 160 | + errc::bad_message, "bad message", |
| 161 | + errc::broken_pipe, "broken pipe", |
| 162 | + errc::connection_aborted, "connection aborted", |
| 163 | + errc::connection_already_in_progress, "connection already in progress", |
| 164 | + errc::connection_refused, "connection refused", |
| 165 | + errc::connection_reset, "connection reset", |
| 166 | + errc::cross_device_link, "cross device link", |
| 167 | + errc::destination_address_required, "destination address required", |
| 168 | + errc::device_or_resource_busy, "device or resource busy", |
| 169 | + errc::directory_not_empty, "directory not empty", |
| 170 | + errc::executable_format_error, "executable format error", |
| 171 | + errc::file_exists, "file exists", |
| 172 | + errc::file_too_large, "file too large", |
| 173 | + errc::filename_too_long, "filename too long", |
| 174 | + errc::function_not_supported, "function not supported", |
| 175 | + errc::host_unreachable, "host unreachable", |
| 176 | + errc::identifier_removed, "identifier removed", |
| 177 | + errc::illegal_byte_sequence, "illegal byte sequence", |
| 178 | + errc::inappropriate_io_control_operation, |
| 179 | + "inappropriate io control operation", |
| 180 | + errc::interrupted, "interrupted", |
| 181 | + errc::invalid_argument, "invalid argument", |
| 182 | + errc::invalid_seek, "invalid seek", |
| 183 | + errc::io_error, "io error", |
| 184 | + errc::is_a_directory, "is a directory", |
| 185 | + errc::message_size, "message size", |
| 186 | + errc::network_down, "network down", |
| 187 | + errc::network_reset, "network reset", |
| 188 | + errc::network_unreachable, "network unreachable", |
| 189 | + errc::no_buffer_space, "no buffer space", |
| 190 | + errc::no_child_process, "no child process", |
| 191 | + errc::no_link, "no link", |
| 192 | + errc::no_lock_available, "no lock available", |
| 193 | + errc::no_message_available, "no message available", |
| 194 | + errc::no_message, "no message", |
| 195 | + errc::no_protocol_option, "no protocol option", |
| 196 | + errc::no_space_on_device, "no space on device", |
| 197 | + errc::no_stream_resources, "no stream resources", |
| 198 | + errc::no_such_device_or_address, "no such device or address", |
| 199 | + errc::no_such_device, "no such device", |
| 200 | + errc::no_such_file_or_directory, "no such file or directory", |
| 201 | + errc::no_such_process, "no such process", |
| 202 | + errc::not_a_directory, "not a directory", |
| 203 | + errc::not_a_socket, "not a socket", |
| 204 | + errc::not_a_stream, "not a stream", |
| 205 | + errc::not_connected, "not connected", |
| 206 | + errc::not_enough_memory, "not enough memory", |
| 207 | + errc::not_supported, "not supported", |
| 208 | + errc::operation_canceled, "operation canceled", |
| 209 | + errc::operation_in_progress, "operation in progress", |
| 210 | + errc::operation_not_permitted, "operation not permitted", |
| 211 | + errc::operation_not_supported, "operation not supported", |
| 212 | + errc::operation_would_block, "operation would block", |
| 213 | + errc::owner_dead, "owner dead", |
| 214 | + errc::permission_denied, "permission denied", |
| 215 | + errc::protocol_error, "protocol error", |
| 216 | + errc::protocol_not_supported, "protocol not supported", |
| 217 | + errc::read_only_file_system, "read only file system", |
| 218 | + errc::resource_deadlock_would_occur, "resource deadlock would occur", |
| 219 | + errc::resource_unavailable_try_again, "resource unavailable try again", |
| 220 | + errc::result_out_of_range, "result out of range", |
| 221 | + errc::state_not_recoverable, "state not recoverable", |
| 222 | + errc::stream_timeout, "stream timeout", |
| 223 | + errc::text_file_busy, "text file busy", |
| 224 | + errc::timed_out, "timed out", |
| 225 | + errc::too_many_files_open_in_system, "too many files open in system", |
| 226 | + errc::too_many_files_open, "too many files open", |
| 227 | + errc::too_many_links, "too many links", |
| 228 | + errc::too_many_symbolic_link_levels, "too many symbolic link levels", |
| 229 | + errc::value_too_large, "value too large", |
| 230 | + errc::wrong_protocol_type, "wrong protocol type", |
| 231 | + (generic_errno)0, 0 |
| 232 | + }; |
| 233 | + |
| 234 | +const char *__cdecl _Syserror_map(int _Errcode) |
| 235 | + { // convert to name of generic error |
| 236 | + const _Sys_errtab_t *_Ptr = &_Sys_errtab[0]; |
| 237 | + for (; _Ptr->_Name != 0; ++_Ptr) |
| 238 | + if ((int)_Ptr->_Errcode == _Errcode) |
| 239 | + return (_Ptr->_Name); |
| 240 | + return (0); |
| 241 | + } |
| 242 | +} |
| 243 | +#endif |
| 244 | + |
| 245 | + |
| 246 | +#endif |
0 commit comments