Chris@102
|
1 // error_code support implementation file ----------------------------------//
|
Chris@102
|
2
|
Chris@102
|
3 // Copyright Beman Dawes 2002, 2006
|
Chris@102
|
4 // Copyright (c) Microsoft Corporation 2014
|
Chris@102
|
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Chris@102
|
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
7
|
Chris@102
|
8 // See library home page at http://www.boost.org/libs/system
|
Chris@102
|
9
|
Chris@102
|
10 //----------------------------------------------------------------------------//
|
Chris@102
|
11
|
Chris@102
|
12 #include <boost/config/warning_disable.hpp>
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/system/config.hpp>
|
Chris@102
|
15 #include <boost/system/error_code.hpp>
|
Chris@102
|
16 #include <boost/cerrno.hpp>
|
Chris@102
|
17 #include <vector>
|
Chris@102
|
18 #include <cstdlib>
|
Chris@102
|
19 #include <cassert>
|
Chris@102
|
20
|
Chris@102
|
21 #include <cstring> // for strerror/strerror_r
|
Chris@102
|
22
|
Chris@102
|
23 # if defined( BOOST_WINDOWS_API )
|
Chris@102
|
24 # include <windows.h>
|
Chris@102
|
25 # if !BOOST_PLAT_WINDOWS_RUNTIME
|
Chris@102
|
26 # include <boost/system/detail/local_free_on_destruction.hpp>
|
Chris@102
|
27 # endif
|
Chris@102
|
28 # ifndef ERROR_INCORRECT_SIZE
|
Chris@102
|
29 # define ERROR_INCORRECT_SIZE ERROR_BAD_ARGUMENTS
|
Chris@102
|
30 # endif
|
Chris@102
|
31 # endif
|
Chris@102
|
32
|
Chris@102
|
33 //----------------------------------------------------------------------------//
|
Chris@102
|
34 namespace boost
|
Chris@102
|
35 {
|
Chris@102
|
36 namespace system
|
Chris@102
|
37 {
|
Chris@102
|
38
|
Chris@102
|
39 namespace
|
Chris@102
|
40 {
|
Chris@102
|
41
|
Chris@102
|
42 // standard error categories ---------------------------------------------//
|
Chris@102
|
43
|
Chris@102
|
44 class generic_error_category : public error_category
|
Chris@102
|
45 {
|
Chris@102
|
46 public:
|
Chris@102
|
47 generic_error_category(){}
|
Chris@102
|
48 const char * name() const BOOST_SYSTEM_NOEXCEPT;
|
Chris@102
|
49 std::string message( int ev ) const;
|
Chris@102
|
50 };
|
Chris@102
|
51
|
Chris@102
|
52 class system_error_category : public error_category
|
Chris@102
|
53 {
|
Chris@102
|
54 public:
|
Chris@102
|
55 system_error_category(){}
|
Chris@102
|
56 const char * name() const BOOST_SYSTEM_NOEXCEPT;
|
Chris@102
|
57 std::string message( int ev ) const;
|
Chris@102
|
58 error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT;
|
Chris@102
|
59 };
|
Chris@102
|
60
|
Chris@102
|
61 // generic_error_category implementation ---------------------------------//
|
Chris@102
|
62
|
Chris@102
|
63 const char * generic_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
Chris@102
|
64 {
|
Chris@102
|
65 return "generic";
|
Chris@102
|
66 }
|
Chris@102
|
67
|
Chris@102
|
68 std::string generic_error_category::message( int ev ) const
|
Chris@102
|
69 {
|
Chris@102
|
70 using namespace boost::system::errc;
|
Chris@102
|
71 #if defined(__PGI)
|
Chris@102
|
72 using boost::system::errc::invalid_argument;
|
Chris@102
|
73 #endif
|
Chris@102
|
74
|
Chris@102
|
75 static std::string unknown_err( "Unknown error" );
|
Chris@102
|
76 // strerror_r is preferred because it is always thread safe,
|
Chris@102
|
77 // however, we fallback to strerror in certain cases because:
|
Chris@102
|
78 // -- Windows doesn't provide strerror_r.
|
Chris@102
|
79 // -- HP and Sun do provide strerror_r on newer systems, but there is
|
Chris@102
|
80 // no way to tell if is available at runtime and in any case their
|
Chris@102
|
81 // versions of strerror are thread safe anyhow.
|
Chris@102
|
82 // -- Linux only sometimes provides strerror_r.
|
Chris@102
|
83 // -- Tru64 provides strerror_r only when compiled -pthread.
|
Chris@102
|
84 // -- VMS doesn't provide strerror_r, but on this platform, strerror is
|
Chris@102
|
85 // thread safe.
|
Chris@102
|
86 # if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\
|
Chris@102
|
87 || (defined(__linux) && (!defined(__USE_XOPEN2K) || defined(BOOST_SYSTEM_USE_STRERROR)))\
|
Chris@102
|
88 || (defined(__osf__) && !defined(_REENTRANT))\
|
Chris@102
|
89 || (defined(__INTEGRITY))\
|
Chris@102
|
90 || (defined(__vms))\
|
Chris@102
|
91 || (defined(__QNXNTO__))
|
Chris@102
|
92 const char * c_str = std::strerror( ev );
|
Chris@102
|
93 return c_str
|
Chris@102
|
94 ? std::string( c_str )
|
Chris@102
|
95 : unknown_err;
|
Chris@102
|
96 # else // use strerror_r
|
Chris@102
|
97 char buf[64];
|
Chris@102
|
98 char * bp = buf;
|
Chris@102
|
99 std::size_t sz = sizeof(buf);
|
Chris@102
|
100 # if defined(__CYGWIN__) || defined(__USE_GNU)
|
Chris@102
|
101 // Oddball version of strerror_r
|
Chris@102
|
102 const char * c_str = strerror_r( ev, bp, sz );
|
Chris@102
|
103 return c_str
|
Chris@102
|
104 ? std::string( c_str )
|
Chris@102
|
105 : unknown_err;
|
Chris@102
|
106 # else
|
Chris@102
|
107 // POSIX version of strerror_r
|
Chris@102
|
108 int result;
|
Chris@102
|
109 for (;;)
|
Chris@102
|
110 {
|
Chris@102
|
111 // strerror_r returns 0 on success, otherwise ERANGE if buffer too small,
|
Chris@102
|
112 // invalid_argument if ev not a valid error number
|
Chris@102
|
113 # if defined (__sgi)
|
Chris@102
|
114 const char * c_str = strerror( ev );
|
Chris@102
|
115 result = 0;
|
Chris@102
|
116 return c_str
|
Chris@102
|
117 ? std::string( c_str )
|
Chris@102
|
118 : unknown_err;
|
Chris@102
|
119 # else
|
Chris@102
|
120 result = strerror_r( ev, bp, sz );
|
Chris@102
|
121 # endif
|
Chris@102
|
122 if (result == 0 )
|
Chris@102
|
123 break;
|
Chris@102
|
124 else
|
Chris@102
|
125 {
|
Chris@102
|
126 # if defined(__linux)
|
Chris@102
|
127 // Linux strerror_r returns -1 on error, with error number in errno
|
Chris@102
|
128 result = errno;
|
Chris@102
|
129 # endif
|
Chris@102
|
130 if ( result != ERANGE ) break;
|
Chris@102
|
131 if ( sz > sizeof(buf) ) std::free( bp );
|
Chris@102
|
132 sz *= 2;
|
Chris@102
|
133 if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
|
Chris@102
|
134 return std::string( "ENOMEM" );
|
Chris@102
|
135 }
|
Chris@102
|
136 }
|
Chris@102
|
137 std::string msg;
|
Chris@102
|
138 # ifndef BOOST_NO_EXCEPTIONS
|
Chris@102
|
139 try
|
Chris@102
|
140 # endif
|
Chris@102
|
141 {
|
Chris@102
|
142 msg = ( ( result == invalid_argument ) ? "Unknown error" : bp );
|
Chris@102
|
143 }
|
Chris@102
|
144
|
Chris@102
|
145 # ifndef BOOST_NO_EXCEPTIONS
|
Chris@102
|
146 // See ticket #2098
|
Chris@102
|
147 catch(...)
|
Chris@102
|
148 {
|
Chris@102
|
149 // just eat the exception
|
Chris@102
|
150 }
|
Chris@102
|
151 # endif
|
Chris@102
|
152
|
Chris@102
|
153 if ( sz > sizeof(buf) ) std::free( bp );
|
Chris@102
|
154 sz = 0;
|
Chris@102
|
155 return msg;
|
Chris@102
|
156 # endif // else POSIX version of strerror_r
|
Chris@102
|
157 # endif // else use strerror_r
|
Chris@102
|
158 }
|
Chris@102
|
159 // system_error_category implementation --------------------------------//
|
Chris@102
|
160
|
Chris@102
|
161 const char * system_error_category::name() const BOOST_SYSTEM_NOEXCEPT
|
Chris@102
|
162 {
|
Chris@102
|
163 return "system";
|
Chris@102
|
164 }
|
Chris@102
|
165
|
Chris@102
|
166 error_condition system_error_category::default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
|
Chris@102
|
167 {
|
Chris@102
|
168 using namespace boost::system::errc;
|
Chris@102
|
169 #if defined(__PGI)
|
Chris@102
|
170 using boost::system::errc::invalid_argument;
|
Chris@102
|
171 #endif
|
Chris@102
|
172
|
Chris@102
|
173 # if defined(BOOST_WINDOWS_API)
|
Chris@102
|
174 # if defined(WINAPI_FAMILY) && ((WINAPI_FAMILY & WINAPI_PARTITION_APP) != 0)
|
Chris@102
|
175 // When using the Windows Runtime, most system errors are reported as HRESULTs.
|
Chris@102
|
176 // We want to map the common Win32 errors to their equivalent error condition,
|
Chris@102
|
177 // whether or not they are reported via an HRESULT.
|
Chris@102
|
178 if ( ev < 0 ) // Check for failed HRESULTs only.
|
Chris@102
|
179 if ( HRESULT_FACILITY( ev ) == FACILITY_WIN32 )
|
Chris@102
|
180 ev = HRESULT_CODE( ev );
|
Chris@102
|
181 # endif
|
Chris@102
|
182 # endif
|
Chris@102
|
183
|
Chris@102
|
184 switch ( ev )
|
Chris@102
|
185 {
|
Chris@102
|
186 case 0: return make_error_condition( success );
|
Chris@102
|
187 # if defined(BOOST_POSIX_API)
|
Chris@102
|
188 // POSIX-like O/S -> posix_errno decode table ---------------------------//
|
Chris@102
|
189 case E2BIG: return make_error_condition( argument_list_too_long );
|
Chris@102
|
190 case EACCES: return make_error_condition( permission_denied );
|
Chris@102
|
191 case EADDRINUSE: return make_error_condition( address_in_use );
|
Chris@102
|
192 case EADDRNOTAVAIL: return make_error_condition( address_not_available );
|
Chris@102
|
193 case EAFNOSUPPORT: return make_error_condition( address_family_not_supported );
|
Chris@102
|
194 case EAGAIN: return make_error_condition( resource_unavailable_try_again );
|
Chris@102
|
195 # if EALREADY != EBUSY // EALREADY and EBUSY are the same on QNX Neutrino
|
Chris@102
|
196 case EALREADY: return make_error_condition( connection_already_in_progress );
|
Chris@102
|
197 # endif
|
Chris@102
|
198 case EBADF: return make_error_condition( bad_file_descriptor );
|
Chris@102
|
199 case EBADMSG: return make_error_condition( bad_message );
|
Chris@102
|
200 case EBUSY: return make_error_condition( device_or_resource_busy );
|
Chris@102
|
201 case ECANCELED: return make_error_condition( operation_canceled );
|
Chris@102
|
202 case ECHILD: return make_error_condition( no_child_process );
|
Chris@102
|
203 case ECONNABORTED: return make_error_condition( connection_aborted );
|
Chris@102
|
204 case ECONNREFUSED: return make_error_condition( connection_refused );
|
Chris@102
|
205 case ECONNRESET: return make_error_condition( connection_reset );
|
Chris@102
|
206 case EDEADLK: return make_error_condition( resource_deadlock_would_occur );
|
Chris@102
|
207 case EDESTADDRREQ: return make_error_condition( destination_address_required );
|
Chris@102
|
208 case EDOM: return make_error_condition( argument_out_of_domain );
|
Chris@102
|
209 case EEXIST: return make_error_condition( file_exists );
|
Chris@102
|
210 case EFAULT: return make_error_condition( bad_address );
|
Chris@102
|
211 case EFBIG: return make_error_condition( file_too_large );
|
Chris@102
|
212 case EHOSTUNREACH: return make_error_condition( host_unreachable );
|
Chris@102
|
213 case EIDRM: return make_error_condition( identifier_removed );
|
Chris@102
|
214 case EILSEQ: return make_error_condition( illegal_byte_sequence );
|
Chris@102
|
215 case EINPROGRESS: return make_error_condition( operation_in_progress );
|
Chris@102
|
216 case EINTR: return make_error_condition( interrupted );
|
Chris@102
|
217 case EINVAL: return make_error_condition( invalid_argument );
|
Chris@102
|
218 case EIO: return make_error_condition( io_error );
|
Chris@102
|
219 case EISCONN: return make_error_condition( already_connected );
|
Chris@102
|
220 case EISDIR: return make_error_condition( is_a_directory );
|
Chris@102
|
221 case ELOOP: return make_error_condition( too_many_symbolic_link_levels );
|
Chris@102
|
222 case EMFILE: return make_error_condition( too_many_files_open );
|
Chris@102
|
223 case EMLINK: return make_error_condition( too_many_links );
|
Chris@102
|
224 case EMSGSIZE: return make_error_condition( message_size );
|
Chris@102
|
225 case ENAMETOOLONG: return make_error_condition( filename_too_long );
|
Chris@102
|
226 case ENETDOWN: return make_error_condition( network_down );
|
Chris@102
|
227 case ENETRESET: return make_error_condition( network_reset );
|
Chris@102
|
228 case ENETUNREACH: return make_error_condition( network_unreachable );
|
Chris@102
|
229 case ENFILE: return make_error_condition( too_many_files_open_in_system );
|
Chris@102
|
230 case ENOBUFS: return make_error_condition( no_buffer_space );
|
Chris@102
|
231 case ENODATA: return make_error_condition( no_message_available );
|
Chris@102
|
232 case ENODEV: return make_error_condition( no_such_device );
|
Chris@102
|
233 case ENOENT: return make_error_condition( no_such_file_or_directory );
|
Chris@102
|
234 case ENOEXEC: return make_error_condition( executable_format_error );
|
Chris@102
|
235 case ENOLCK: return make_error_condition( no_lock_available );
|
Chris@102
|
236 case ENOLINK: return make_error_condition( no_link );
|
Chris@102
|
237 case ENOMEM: return make_error_condition( not_enough_memory );
|
Chris@102
|
238 case ENOMSG: return make_error_condition( no_message );
|
Chris@102
|
239 case ENOPROTOOPT: return make_error_condition( no_protocol_option );
|
Chris@102
|
240 case ENOSPC: return make_error_condition( no_space_on_device );
|
Chris@102
|
241 case ENOSR: return make_error_condition( no_stream_resources );
|
Chris@102
|
242 case ENOSTR: return make_error_condition( not_a_stream );
|
Chris@102
|
243 case ENOSYS: return make_error_condition( function_not_supported );
|
Chris@102
|
244 case ENOTCONN: return make_error_condition( not_connected );
|
Chris@102
|
245 case ENOTDIR: return make_error_condition( not_a_directory );
|
Chris@102
|
246 # if ENOTEMPTY != EEXIST // AIX treats ENOTEMPTY and EEXIST as the same value
|
Chris@102
|
247 case ENOTEMPTY: return make_error_condition( directory_not_empty );
|
Chris@102
|
248 # endif // ENOTEMPTY != EEXIST
|
Chris@102
|
249 # if ENOTRECOVERABLE != ECONNRESET // the same on some Broadcom chips
|
Chris@102
|
250 case ENOTRECOVERABLE: return make_error_condition( state_not_recoverable );
|
Chris@102
|
251 # endif // ENOTRECOVERABLE != ECONNRESET
|
Chris@102
|
252 case ENOTSOCK: return make_error_condition( not_a_socket );
|
Chris@102
|
253 case ENOTSUP: return make_error_condition( not_supported );
|
Chris@102
|
254 case ENOTTY: return make_error_condition( inappropriate_io_control_operation );
|
Chris@102
|
255 case ENXIO: return make_error_condition( no_such_device_or_address );
|
Chris@102
|
256 # if EOPNOTSUPP != ENOTSUP
|
Chris@102
|
257 case EOPNOTSUPP: return make_error_condition( operation_not_supported );
|
Chris@102
|
258 # endif // EOPNOTSUPP != ENOTSUP
|
Chris@102
|
259 case EOVERFLOW: return make_error_condition( value_too_large );
|
Chris@102
|
260 # if EOWNERDEAD != ECONNABORTED // the same on some Broadcom chips
|
Chris@102
|
261 case EOWNERDEAD: return make_error_condition( owner_dead );
|
Chris@102
|
262 # endif // EOWNERDEAD != ECONNABORTED
|
Chris@102
|
263 case EPERM: return make_error_condition( operation_not_permitted );
|
Chris@102
|
264 case EPIPE: return make_error_condition( broken_pipe );
|
Chris@102
|
265 case EPROTO: return make_error_condition( protocol_error );
|
Chris@102
|
266 case EPROTONOSUPPORT: return make_error_condition( protocol_not_supported );
|
Chris@102
|
267 case EPROTOTYPE: return make_error_condition( wrong_protocol_type );
|
Chris@102
|
268 case ERANGE: return make_error_condition( result_out_of_range );
|
Chris@102
|
269 case EROFS: return make_error_condition( read_only_file_system );
|
Chris@102
|
270 case ESPIPE: return make_error_condition( invalid_seek );
|
Chris@102
|
271 case ESRCH: return make_error_condition( no_such_process );
|
Chris@102
|
272 case ETIME: return make_error_condition( stream_timeout );
|
Chris@102
|
273 case ETIMEDOUT: return make_error_condition( timed_out );
|
Chris@102
|
274 case ETXTBSY: return make_error_condition( text_file_busy );
|
Chris@102
|
275 # if EAGAIN != EWOULDBLOCK
|
Chris@102
|
276 case EWOULDBLOCK: return make_error_condition( operation_would_block );
|
Chris@102
|
277 # endif // EAGAIN != EWOULDBLOCK
|
Chris@102
|
278 case EXDEV: return make_error_condition( cross_device_link );
|
Chris@102
|
279 #else
|
Chris@102
|
280 // Windows system -> posix_errno decode table ---------------------------//
|
Chris@102
|
281 // see WinError.h comments for descriptions of errors
|
Chris@102
|
282 case ERROR_ACCESS_DENIED: return make_error_condition( permission_denied );
|
Chris@102
|
283 case ERROR_ALREADY_EXISTS: return make_error_condition( file_exists );
|
Chris@102
|
284 case ERROR_BAD_UNIT: return make_error_condition( no_such_device );
|
Chris@102
|
285 case ERROR_BUFFER_OVERFLOW: return make_error_condition( filename_too_long );
|
Chris@102
|
286 case ERROR_BUSY: return make_error_condition( device_or_resource_busy );
|
Chris@102
|
287 case ERROR_BUSY_DRIVE: return make_error_condition( device_or_resource_busy );
|
Chris@102
|
288 case ERROR_CANNOT_MAKE: return make_error_condition( permission_denied );
|
Chris@102
|
289 case ERROR_CANTOPEN: return make_error_condition( io_error );
|
Chris@102
|
290 case ERROR_CANTREAD: return make_error_condition( io_error );
|
Chris@102
|
291 case ERROR_CANTWRITE: return make_error_condition( io_error );
|
Chris@102
|
292 case ERROR_CURRENT_DIRECTORY: return make_error_condition( permission_denied );
|
Chris@102
|
293 case ERROR_DEV_NOT_EXIST: return make_error_condition( no_such_device );
|
Chris@102
|
294 case ERROR_DEVICE_IN_USE: return make_error_condition( device_or_resource_busy );
|
Chris@102
|
295 case ERROR_DIR_NOT_EMPTY: return make_error_condition( directory_not_empty );
|
Chris@102
|
296 case ERROR_DIRECTORY: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid"
|
Chris@102
|
297 case ERROR_DISK_FULL: return make_error_condition( no_space_on_device );
|
Chris@102
|
298 case ERROR_FILE_EXISTS: return make_error_condition( file_exists );
|
Chris@102
|
299 case ERROR_FILE_NOT_FOUND: return make_error_condition( no_such_file_or_directory );
|
Chris@102
|
300 case ERROR_HANDLE_DISK_FULL: return make_error_condition( no_space_on_device );
|
Chris@102
|
301 case ERROR_INVALID_ACCESS: return make_error_condition( permission_denied );
|
Chris@102
|
302 case ERROR_INVALID_DRIVE: return make_error_condition( no_such_device );
|
Chris@102
|
303 case ERROR_INVALID_FUNCTION: return make_error_condition( function_not_supported );
|
Chris@102
|
304 case ERROR_INVALID_HANDLE: return make_error_condition( invalid_argument );
|
Chris@102
|
305 case ERROR_INVALID_NAME: return make_error_condition( invalid_argument );
|
Chris@102
|
306 case ERROR_LOCK_VIOLATION: return make_error_condition( no_lock_available );
|
Chris@102
|
307 case ERROR_LOCKED: return make_error_condition( no_lock_available );
|
Chris@102
|
308 case ERROR_NEGATIVE_SEEK: return make_error_condition( invalid_argument );
|
Chris@102
|
309 case ERROR_NOACCESS: return make_error_condition( permission_denied );
|
Chris@102
|
310 case ERROR_NOT_ENOUGH_MEMORY: return make_error_condition( not_enough_memory );
|
Chris@102
|
311 case ERROR_NOT_READY: return make_error_condition( resource_unavailable_try_again );
|
Chris@102
|
312 case ERROR_NOT_SAME_DEVICE: return make_error_condition( cross_device_link );
|
Chris@102
|
313 case ERROR_OPEN_FAILED: return make_error_condition( io_error );
|
Chris@102
|
314 case ERROR_OPEN_FILES: return make_error_condition( device_or_resource_busy );
|
Chris@102
|
315 case ERROR_OPERATION_ABORTED: return make_error_condition( operation_canceled );
|
Chris@102
|
316 case ERROR_OUTOFMEMORY: return make_error_condition( not_enough_memory );
|
Chris@102
|
317 case ERROR_PATH_NOT_FOUND: return make_error_condition( no_such_file_or_directory );
|
Chris@102
|
318 case ERROR_READ_FAULT: return make_error_condition( io_error );
|
Chris@102
|
319 case ERROR_RETRY: return make_error_condition( resource_unavailable_try_again );
|
Chris@102
|
320 case ERROR_SEEK: return make_error_condition( io_error );
|
Chris@102
|
321 case ERROR_SHARING_VIOLATION: return make_error_condition( permission_denied );
|
Chris@102
|
322 case ERROR_TOO_MANY_OPEN_FILES: return make_error_condition( too_many_files_open );
|
Chris@102
|
323 case ERROR_WRITE_FAULT: return make_error_condition( io_error );
|
Chris@102
|
324 case ERROR_WRITE_PROTECT: return make_error_condition( permission_denied );
|
Chris@102
|
325 case WSAEACCES: return make_error_condition( permission_denied );
|
Chris@102
|
326 case WSAEADDRINUSE: return make_error_condition( address_in_use );
|
Chris@102
|
327 case WSAEADDRNOTAVAIL: return make_error_condition( address_not_available );
|
Chris@102
|
328 case WSAEAFNOSUPPORT: return make_error_condition( address_family_not_supported );
|
Chris@102
|
329 case WSAEALREADY: return make_error_condition( connection_already_in_progress );
|
Chris@102
|
330 case WSAEBADF: return make_error_condition( bad_file_descriptor );
|
Chris@102
|
331 case WSAECONNABORTED: return make_error_condition( connection_aborted );
|
Chris@102
|
332 case WSAECONNREFUSED: return make_error_condition( connection_refused );
|
Chris@102
|
333 case WSAECONNRESET: return make_error_condition( connection_reset );
|
Chris@102
|
334 case WSAEDESTADDRREQ: return make_error_condition( destination_address_required );
|
Chris@102
|
335 case WSAEFAULT: return make_error_condition( bad_address );
|
Chris@102
|
336 case WSAEHOSTUNREACH: return make_error_condition( host_unreachable );
|
Chris@102
|
337 case WSAEINPROGRESS: return make_error_condition( operation_in_progress );
|
Chris@102
|
338 case WSAEINTR: return make_error_condition( interrupted );
|
Chris@102
|
339 case WSAEINVAL: return make_error_condition( invalid_argument );
|
Chris@102
|
340 case WSAEISCONN: return make_error_condition( already_connected );
|
Chris@102
|
341 case WSAEMFILE: return make_error_condition( too_many_files_open );
|
Chris@102
|
342 case WSAEMSGSIZE: return make_error_condition( message_size );
|
Chris@102
|
343 case WSAENAMETOOLONG: return make_error_condition( filename_too_long );
|
Chris@102
|
344 case WSAENETDOWN: return make_error_condition( network_down );
|
Chris@102
|
345 case WSAENETRESET: return make_error_condition( network_reset );
|
Chris@102
|
346 case WSAENETUNREACH: return make_error_condition( network_unreachable );
|
Chris@102
|
347 case WSAENOBUFS: return make_error_condition( no_buffer_space );
|
Chris@102
|
348 case WSAENOPROTOOPT: return make_error_condition( no_protocol_option );
|
Chris@102
|
349 case WSAENOTCONN: return make_error_condition( not_connected );
|
Chris@102
|
350 case WSAENOTSOCK: return make_error_condition( not_a_socket );
|
Chris@102
|
351 case WSAEOPNOTSUPP: return make_error_condition( operation_not_supported );
|
Chris@102
|
352 case WSAEPROTONOSUPPORT: return make_error_condition( protocol_not_supported );
|
Chris@102
|
353 case WSAEPROTOTYPE: return make_error_condition( wrong_protocol_type );
|
Chris@102
|
354 case WSAETIMEDOUT: return make_error_condition( timed_out );
|
Chris@102
|
355 case WSAEWOULDBLOCK: return make_error_condition( operation_would_block );
|
Chris@102
|
356 #endif
|
Chris@102
|
357 default: return error_condition( ev, system_category() );
|
Chris@102
|
358 }
|
Chris@102
|
359 }
|
Chris@102
|
360
|
Chris@102
|
361 # if !defined( BOOST_WINDOWS_API )
|
Chris@102
|
362
|
Chris@102
|
363 std::string system_error_category::message( int ev ) const
|
Chris@102
|
364 {
|
Chris@102
|
365 return generic_category().message( ev );
|
Chris@102
|
366 }
|
Chris@102
|
367 # else
|
Chris@102
|
368
|
Chris@102
|
369 std::string system_error_category::message( int ev ) const
|
Chris@102
|
370 {
|
Chris@102
|
371 #if defined(UNDER_CE) || BOOST_PLAT_WINDOWS_RUNTIME || defined(BOOST_NO_ANSI_APIS)
|
Chris@102
|
372 std::wstring buf(128, wchar_t());
|
Chris@102
|
373 for (;;)
|
Chris@102
|
374 {
|
Chris@102
|
375 DWORD retval = ::FormatMessageW(
|
Chris@102
|
376 FORMAT_MESSAGE_FROM_SYSTEM |
|
Chris@102
|
377 FORMAT_MESSAGE_IGNORE_INSERTS,
|
Chris@102
|
378 NULL,
|
Chris@102
|
379 ev,
|
Chris@102
|
380 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
Chris@102
|
381 &buf[0],
|
Chris@102
|
382 buf.size(),
|
Chris@102
|
383 NULL
|
Chris@102
|
384 );
|
Chris@102
|
385
|
Chris@102
|
386 if (retval > 0)
|
Chris@102
|
387 {
|
Chris@102
|
388 buf.resize(retval);
|
Chris@102
|
389 break;
|
Chris@102
|
390 }
|
Chris@102
|
391 else if ( ::GetLastError() != ERROR_INSUFFICIENT_BUFFER )
|
Chris@102
|
392 {
|
Chris@102
|
393 return std::string("Unknown error");
|
Chris@102
|
394 }
|
Chris@102
|
395 else
|
Chris@102
|
396 {
|
Chris@102
|
397 buf.resize(buf.size() + buf.size() / 2);
|
Chris@102
|
398 }
|
Chris@102
|
399 }
|
Chris@102
|
400
|
Chris@102
|
401 int num_chars = (buf.size() + 1) * 2;
|
Chris@102
|
402 LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
|
Chris@102
|
403 if (::WideCharToMultiByte(CP_ACP, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
|
Chris@102
|
404 {
|
Chris@102
|
405 return std::string("Unknown error");
|
Chris@102
|
406 }
|
Chris@102
|
407
|
Chris@102
|
408 std::string str( narrow_buffer );
|
Chris@102
|
409 #else
|
Chris@102
|
410 LPVOID lpMsgBuf = 0;
|
Chris@102
|
411 DWORD retval = ::FormatMessageA(
|
Chris@102
|
412 FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
Chris@102
|
413 FORMAT_MESSAGE_FROM_SYSTEM |
|
Chris@102
|
414 FORMAT_MESSAGE_IGNORE_INSERTS,
|
Chris@102
|
415 NULL,
|
Chris@102
|
416 ev,
|
Chris@102
|
417 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
|
Chris@102
|
418 (LPSTR) &lpMsgBuf,
|
Chris@102
|
419 0,
|
Chris@102
|
420 NULL
|
Chris@102
|
421 );
|
Chris@102
|
422 detail::local_free_on_destruction lfod(lpMsgBuf);
|
Chris@102
|
423 if (retval == 0)
|
Chris@102
|
424 return std::string("Unknown error");
|
Chris@102
|
425
|
Chris@102
|
426 std::string str( static_cast<LPCSTR>(lpMsgBuf) );
|
Chris@102
|
427 # endif
|
Chris@102
|
428 while ( str.size()
|
Chris@102
|
429 && (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
|
Chris@102
|
430 str.erase( str.size()-1 );
|
Chris@102
|
431 if ( str.size() && str[str.size()-1] == '.' )
|
Chris@102
|
432 { str.erase( str.size()-1 ); }
|
Chris@102
|
433 return str;
|
Chris@102
|
434 }
|
Chris@102
|
435 # endif
|
Chris@102
|
436
|
Chris@102
|
437 } // unnamed namespace
|
Chris@102
|
438
|
Chris@102
|
439
|
Chris@102
|
440 # ifndef BOOST_SYSTEM_NO_DEPRECATED
|
Chris@102
|
441 BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code;
|
Chris@102
|
442 // note that it doesn't matter if this
|
Chris@102
|
443 // isn't initialized before use since
|
Chris@102
|
444 // the only use is to take its
|
Chris@102
|
445 // address for comparison purposes
|
Chris@102
|
446 # endif
|
Chris@102
|
447
|
Chris@102
|
448 # ifdef BOOST_ERROR_CODE_HEADER_ONLY
|
Chris@102
|
449 # define BOOST_SYSTEM_LINKAGE inline
|
Chris@102
|
450 # else
|
Chris@102
|
451 # define BOOST_SYSTEM_LINKAGE BOOST_SYSTEM_DECL
|
Chris@102
|
452 # endif
|
Chris@102
|
453
|
Chris@102
|
454 BOOST_SYSTEM_LINKAGE const error_category & system_category() BOOST_SYSTEM_NOEXCEPT
|
Chris@102
|
455 {
|
Chris@102
|
456 static const system_error_category system_category_const;
|
Chris@102
|
457 return system_category_const;
|
Chris@102
|
458 }
|
Chris@102
|
459
|
Chris@102
|
460 BOOST_SYSTEM_LINKAGE const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT
|
Chris@102
|
461 {
|
Chris@102
|
462 static const generic_error_category generic_category_const;
|
Chris@102
|
463 return generic_category_const;
|
Chris@102
|
464 }
|
Chris@102
|
465
|
Chris@102
|
466 } // namespace system
|
Chris@102
|
467 } // namespace boost
|