Rafael Espindola | 5c4f829 | 2014-06-11 19:05:50 +0000 | [diff] [blame^] | 1 | //===-- WindowsError.cpp - Support for mapping windows errors to posix-----===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements a mapping from windows errors to posix ones. |
| 11 | // The standard doesn't define what the equivalence is from system |
| 12 | // errors to generic ones. The one implemented in msvc is too conservative |
| 13 | // for llvm, so we do an extra mapping when constructing an error_code |
| 14 | // from an windows error. This allows the rest of llvm to simple checks |
| 15 | // like "EC == std::errc::file_exists" and have it work on both posix and |
| 16 | // windows. |
| 17 | // |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
| 20 | #ifdef _MSC_VER |
| 21 | |
| 22 | #include <winerror.h> |
| 23 | |
| 24 | #include "llvm/Support/WindowsError.h" |
| 25 | |
| 26 | // I'd rather not double the line count of the following. |
| 27 | #define MAP_ERR_TO_COND(x, y) \ |
| 28 | case x: \ |
| 29 | return std::make_error_code(std::errc::y) |
| 30 | |
| 31 | std::error_code llvm::mapWindowsError(unsigned EV) { |
| 32 | switch (EV) { |
| 33 | MAP_ERR_TO_COND(ERROR_ACCESS_DENIED, permission_denied); |
| 34 | MAP_ERR_TO_COND(ERROR_ALREADY_EXISTS, file_exists); |
| 35 | MAP_ERR_TO_COND(ERROR_BAD_UNIT, no_such_device); |
| 36 | MAP_ERR_TO_COND(ERROR_BUFFER_OVERFLOW, filename_too_long); |
| 37 | MAP_ERR_TO_COND(ERROR_BUSY, device_or_resource_busy); |
| 38 | MAP_ERR_TO_COND(ERROR_BUSY_DRIVE, device_or_resource_busy); |
| 39 | MAP_ERR_TO_COND(ERROR_CANNOT_MAKE, permission_denied); |
| 40 | MAP_ERR_TO_COND(ERROR_CANTOPEN, io_error); |
| 41 | MAP_ERR_TO_COND(ERROR_CANTREAD, io_error); |
| 42 | MAP_ERR_TO_COND(ERROR_CANTWRITE, io_error); |
| 43 | MAP_ERR_TO_COND(ERROR_CURRENT_DIRECTORY, permission_denied); |
| 44 | MAP_ERR_TO_COND(ERROR_DEV_NOT_EXIST, no_such_device); |
| 45 | MAP_ERR_TO_COND(ERROR_DEVICE_IN_USE, device_or_resource_busy); |
| 46 | MAP_ERR_TO_COND(ERROR_DIR_NOT_EMPTY, directory_not_empty); |
| 47 | MAP_ERR_TO_COND(ERROR_DIRECTORY, invalid_argument); |
| 48 | MAP_ERR_TO_COND(ERROR_DISK_FULL, no_space_on_device); |
| 49 | MAP_ERR_TO_COND(ERROR_FILE_EXISTS, file_exists); |
| 50 | MAP_ERR_TO_COND(ERROR_FILE_NOT_FOUND, no_such_file_or_directory); |
| 51 | MAP_ERR_TO_COND(ERROR_HANDLE_DISK_FULL, no_space_on_device); |
| 52 | MAP_ERR_TO_COND(ERROR_HANDLE_EOF, value_too_large); |
| 53 | MAP_ERR_TO_COND(ERROR_INVALID_ACCESS, permission_denied); |
| 54 | MAP_ERR_TO_COND(ERROR_INVALID_DRIVE, no_such_device); |
| 55 | MAP_ERR_TO_COND(ERROR_INVALID_FUNCTION, function_not_supported); |
| 56 | MAP_ERR_TO_COND(ERROR_INVALID_HANDLE, invalid_argument); |
| 57 | MAP_ERR_TO_COND(ERROR_INVALID_NAME, invalid_argument); |
| 58 | MAP_ERR_TO_COND(ERROR_LOCK_VIOLATION, no_lock_available); |
| 59 | MAP_ERR_TO_COND(ERROR_LOCKED, no_lock_available); |
| 60 | MAP_ERR_TO_COND(ERROR_NEGATIVE_SEEK, invalid_argument); |
| 61 | MAP_ERR_TO_COND(ERROR_NOACCESS, permission_denied); |
| 62 | MAP_ERR_TO_COND(ERROR_NOT_ENOUGH_MEMORY, not_enough_memory); |
| 63 | MAP_ERR_TO_COND(ERROR_NOT_READY, resource_unavailable_try_again); |
| 64 | MAP_ERR_TO_COND(ERROR_NOT_SAME_DEVICE, cross_device_link); |
| 65 | MAP_ERR_TO_COND(ERROR_OPEN_FAILED, io_error); |
| 66 | MAP_ERR_TO_COND(ERROR_OPEN_FILES, device_or_resource_busy); |
| 67 | MAP_ERR_TO_COND(ERROR_OPERATION_ABORTED, operation_canceled); |
| 68 | MAP_ERR_TO_COND(ERROR_OUTOFMEMORY, not_enough_memory); |
| 69 | MAP_ERR_TO_COND(ERROR_PATH_NOT_FOUND, no_such_file_or_directory); |
| 70 | MAP_ERR_TO_COND(ERROR_BAD_NETPATH, no_such_file_or_directory); |
| 71 | MAP_ERR_TO_COND(ERROR_READ_FAULT, io_error); |
| 72 | MAP_ERR_TO_COND(ERROR_RETRY, resource_unavailable_try_again); |
| 73 | MAP_ERR_TO_COND(ERROR_SEEK, io_error); |
| 74 | MAP_ERR_TO_COND(ERROR_SHARING_VIOLATION, permission_denied); |
| 75 | MAP_ERR_TO_COND(ERROR_TOO_MANY_OPEN_FILES, too_many_files_open); |
| 76 | MAP_ERR_TO_COND(ERROR_WRITE_FAULT, io_error); |
| 77 | MAP_ERR_TO_COND(ERROR_WRITE_PROTECT, permission_denied); |
| 78 | MAP_ERR_TO_COND(ERROR_SEM_TIMEOUT, timed_out); |
| 79 | MAP_ERR_TO_COND(WSAEACCES, permission_denied); |
| 80 | MAP_ERR_TO_COND(WSAEADDRINUSE, address_in_use); |
| 81 | MAP_ERR_TO_COND(WSAEADDRNOTAVAIL, address_not_available); |
| 82 | MAP_ERR_TO_COND(WSAEAFNOSUPPORT, address_family_not_supported); |
| 83 | MAP_ERR_TO_COND(WSAEALREADY, connection_already_in_progress); |
| 84 | MAP_ERR_TO_COND(WSAEBADF, bad_file_descriptor); |
| 85 | MAP_ERR_TO_COND(WSAECONNABORTED, connection_aborted); |
| 86 | MAP_ERR_TO_COND(WSAECONNREFUSED, connection_refused); |
| 87 | MAP_ERR_TO_COND(WSAECONNRESET, connection_reset); |
| 88 | MAP_ERR_TO_COND(WSAEDESTADDRREQ, destination_address_required); |
| 89 | MAP_ERR_TO_COND(WSAEFAULT, bad_address); |
| 90 | MAP_ERR_TO_COND(WSAEHOSTUNREACH, host_unreachable); |
| 91 | MAP_ERR_TO_COND(WSAEINPROGRESS, operation_in_progress); |
| 92 | MAP_ERR_TO_COND(WSAEINTR, interrupted); |
| 93 | MAP_ERR_TO_COND(WSAEINVAL, invalid_argument); |
| 94 | MAP_ERR_TO_COND(WSAEISCONN, already_connected); |
| 95 | MAP_ERR_TO_COND(WSAEMFILE, too_many_files_open); |
| 96 | MAP_ERR_TO_COND(WSAEMSGSIZE, message_size); |
| 97 | MAP_ERR_TO_COND(WSAENAMETOOLONG, filename_too_long); |
| 98 | MAP_ERR_TO_COND(WSAENETDOWN, network_down); |
| 99 | MAP_ERR_TO_COND(WSAENETRESET, network_reset); |
| 100 | MAP_ERR_TO_COND(WSAENETUNREACH, network_unreachable); |
| 101 | MAP_ERR_TO_COND(WSAENOBUFS, no_buffer_space); |
| 102 | MAP_ERR_TO_COND(WSAENOPROTOOPT, no_protocol_option); |
| 103 | MAP_ERR_TO_COND(WSAENOTCONN, not_connected); |
| 104 | MAP_ERR_TO_COND(WSAENOTSOCK, not_a_socket); |
| 105 | MAP_ERR_TO_COND(WSAEOPNOTSUPP, operation_not_supported); |
| 106 | MAP_ERR_TO_COND(WSAEPROTONOSUPPORT, protocol_not_supported); |
| 107 | MAP_ERR_TO_COND(WSAEPROTOTYPE, wrong_protocol_type); |
| 108 | MAP_ERR_TO_COND(WSAETIMEDOUT, timed_out); |
| 109 | MAP_ERR_TO_COND(WSAEWOULDBLOCK, operation_would_block); |
| 110 | default: |
| 111 | return std::error_code(EV, std::system_category()); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | #endif |