]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED |
2 | #define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED | |
3 | ||
4 | // Copyright Beman Dawes 2002, 2006 | |
5 | // Copyright (c) Microsoft Corporation 2014 | |
6 | // Copyright 2018 Peter Dimov | |
7 | // | |
8 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | |
9 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
10 | // | |
11 | // See library home page at http://www.boost.org/libs/system | |
12 | ||
13 | #include <boost/system/detail/errc.hpp> | |
14 | #include <boost/winapi/error_codes.hpp> | |
15 | #include <boost/config.hpp> | |
16 | ||
17 | // | |
18 | ||
19 | namespace boost | |
20 | { | |
21 | ||
22 | namespace system | |
23 | { | |
24 | ||
25 | namespace detail | |
26 | { | |
27 | ||
28 | inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT | |
29 | { | |
30 | // When using the Windows Runtime, most system errors are reported as HRESULTs. | |
31 | // We want to map the common Win32 errors to their equivalent error condition, | |
32 | // whether or not they are reported via an HRESULT. | |
33 | ||
34 | #define BOOST_SYSTEM_FAILED(hr) ((hr) < 0) | |
35 | #define BOOST_SYSTEM_HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff) | |
36 | #define BOOST_SYSTEM_HRESULT_CODE(hr) ((hr) & 0xFFFF) | |
37 | #define BOOST_SYSTEM_FACILITY_WIN32 7 | |
38 | ||
39 | if( BOOST_SYSTEM_FAILED( ev ) && BOOST_SYSTEM_HRESULT_FACILITY( ev ) == BOOST_SYSTEM_FACILITY_WIN32 ) | |
40 | { | |
41 | ev = BOOST_SYSTEM_HRESULT_CODE( ev ); | |
42 | } | |
43 | ||
44 | #undef BOOST_SYSTEM_FAILED | |
45 | #undef BOOST_SYSTEM_HRESULT_FACILITY | |
46 | #undef BOOST_SYSTEM_HRESULT_CODE | |
47 | #undef BOOST_SYSTEM_FACILITY_WIN32 | |
48 | ||
49 | using namespace boost::winapi; | |
50 | using namespace errc; | |
51 | ||
52 | // Windows system -> posix_errno decode table | |
53 | // see WinError.h comments for descriptions of errors | |
54 | ||
55 | switch ( ev ) | |
56 | { | |
57 | case 0: return success; | |
58 | ||
59 | case ERROR_ACCESS_DENIED_: return permission_denied; | |
60 | case ERROR_ALREADY_EXISTS_: return file_exists; | |
1e59de90 | 61 | case ERROR_BAD_NETPATH_: return no_such_file_or_directory; |
20effc67 | 62 | case ERROR_BAD_UNIT_: return no_such_device; |
1e59de90 | 63 | case ERROR_BROKEN_PIPE_: return broken_pipe; |
20effc67 TL |
64 | case ERROR_BUFFER_OVERFLOW_: return filename_too_long; |
65 | case ERROR_BUSY_: return device_or_resource_busy; | |
66 | case ERROR_BUSY_DRIVE_: return device_or_resource_busy; | |
67 | case ERROR_CANNOT_MAKE_: return permission_denied; | |
68 | case ERROR_CANTOPEN_: return io_error; | |
69 | case ERROR_CANTREAD_: return io_error; | |
70 | case ERROR_CANTWRITE_: return io_error; | |
71 | case ERROR_CONNECTION_ABORTED_: return connection_aborted; | |
72 | case ERROR_CURRENT_DIRECTORY_: return permission_denied; | |
73 | case ERROR_DEV_NOT_EXIST_: return no_such_device; | |
74 | case ERROR_DEVICE_IN_USE_: return device_or_resource_busy; | |
75 | case ERROR_DIR_NOT_EMPTY_: return directory_not_empty; | |
76 | case ERROR_DIRECTORY_: return invalid_argument; // WinError.h: "The directory name is invalid" | |
77 | case ERROR_DISK_FULL_: return no_space_on_device; | |
78 | case ERROR_FILE_EXISTS_: return file_exists; | |
79 | case ERROR_FILE_NOT_FOUND_: return no_such_file_or_directory; | |
80 | case ERROR_HANDLE_DISK_FULL_: return no_space_on_device; | |
81 | case ERROR_INVALID_ACCESS_: return permission_denied; | |
82 | case ERROR_INVALID_DRIVE_: return no_such_device; | |
83 | case ERROR_INVALID_FUNCTION_: return function_not_supported; | |
84 | case ERROR_INVALID_HANDLE_: return invalid_argument; | |
1e59de90 TL |
85 | case ERROR_INVALID_NAME_: return no_such_file_or_directory; |
86 | case ERROR_INVALID_PARAMETER_: return invalid_argument; | |
20effc67 TL |
87 | case ERROR_LOCK_VIOLATION_: return no_lock_available; |
88 | case ERROR_LOCKED_: return no_lock_available; | |
89 | case ERROR_NEGATIVE_SEEK_: return invalid_argument; | |
90 | case ERROR_NOACCESS_: return permission_denied; | |
91 | case ERROR_NOT_ENOUGH_MEMORY_: return not_enough_memory; | |
92 | case ERROR_NOT_READY_: return resource_unavailable_try_again; | |
93 | case ERROR_NOT_SAME_DEVICE_: return cross_device_link; | |
94 | case ERROR_OPEN_FAILED_: return io_error; | |
95 | case ERROR_OPEN_FILES_: return device_or_resource_busy; | |
96 | case ERROR_OPERATION_ABORTED_: return operation_canceled; | |
97 | case ERROR_OUTOFMEMORY_: return not_enough_memory; | |
98 | case ERROR_PATH_NOT_FOUND_: return no_such_file_or_directory; | |
99 | case ERROR_READ_FAULT_: return io_error; | |
1e59de90 | 100 | case ERROR_REPARSE_TAG_INVALID_: return invalid_argument; |
20effc67 TL |
101 | case ERROR_RETRY_: return resource_unavailable_try_again; |
102 | case ERROR_SEEK_: return io_error; | |
103 | case ERROR_SHARING_VIOLATION_: return permission_denied; | |
1e59de90 | 104 | case ERROR_NOT_SUPPORTED_: return not_supported; // WinError.h: "The request is not supported." |
20effc67 TL |
105 | case ERROR_TOO_MANY_OPEN_FILES_: return too_many_files_open; |
106 | case ERROR_WRITE_FAULT_: return io_error; | |
107 | case ERROR_WRITE_PROTECT_: return permission_denied; | |
108 | ||
109 | case WSAEACCES_: return permission_denied; | |
110 | case WSAEADDRINUSE_: return address_in_use; | |
111 | case WSAEADDRNOTAVAIL_: return address_not_available; | |
112 | case WSAEAFNOSUPPORT_: return address_family_not_supported; | |
113 | case WSAEALREADY_: return connection_already_in_progress; | |
114 | case WSAEBADF_: return bad_file_descriptor; | |
115 | case WSAECONNABORTED_: return connection_aborted; | |
116 | case WSAECONNREFUSED_: return connection_refused; | |
117 | case WSAECONNRESET_: return connection_reset; | |
118 | case WSAEDESTADDRREQ_: return destination_address_required; | |
119 | case WSAEFAULT_: return bad_address; | |
120 | case WSAEHOSTUNREACH_: return host_unreachable; | |
121 | case WSAEINPROGRESS_: return operation_in_progress; | |
122 | case WSAEINTR_: return interrupted; | |
123 | case WSAEINVAL_: return invalid_argument; | |
124 | case WSAEISCONN_: return already_connected; | |
125 | case WSAEMFILE_: return too_many_files_open; | |
126 | case WSAEMSGSIZE_: return message_size; | |
127 | case WSAENAMETOOLONG_: return filename_too_long; | |
128 | case WSAENETDOWN_: return network_down; | |
129 | case WSAENETRESET_: return network_reset; | |
130 | case WSAENETUNREACH_: return network_unreachable; | |
131 | case WSAENOBUFS_: return no_buffer_space; | |
132 | case WSAENOPROTOOPT_: return no_protocol_option; | |
133 | case WSAENOTCONN_: return not_connected; | |
134 | case WSAENOTSOCK_: return not_a_socket; | |
135 | case WSAEOPNOTSUPP_: return operation_not_supported; | |
136 | case WSAEPROTONOSUPPORT_: return protocol_not_supported; | |
137 | case WSAEPROTOTYPE_: return wrong_protocol_type; | |
138 | case WSAETIMEDOUT_: return timed_out; | |
139 | case WSAEWOULDBLOCK_: return operation_would_block; | |
140 | ||
141 | default: return -1; | |
142 | } | |
143 | } | |
144 | ||
145 | } // namespace detail | |
146 | ||
147 | } // namespace system | |
148 | ||
149 | } // namespace boost | |
150 | ||
151 | #endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED |