| 212 | |
| 213 | #if _WIN32 |
| 214 | std::string WinErrorMessage(int errnum) { |
| 215 | constexpr DWORD max_n_chars = 1024; |
| 216 | WCHAR utf16_message[max_n_chars]; |
| 217 | auto n_utf16_chars = |
| 218 | FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, |
| 219 | errnum, 0, utf16_message, max_n_chars, NULL); |
| 220 | if (n_utf16_chars == 0) { |
| 221 | // Fallback |
| 222 | std::stringstream ss; |
| 223 | ss << "Windows error #" << errnum; |
| 224 | return ss.str(); |
| 225 | } |
| 226 | auto utf8_message_result = |
| 227 | arrow::util::WideStringToUTF8(std::wstring(utf16_message, n_utf16_chars)); |
| 228 | if (!utf8_message_result.ok()) { |
| 229 | std::stringstream ss; |
| 230 | ss << "Windows error #" << errnum; |
| 231 | ss << "; failed to convert error message to UTF-8: " << utf8_message_result.status(); |
| 232 | return ss.str(); |
| 233 | } |
| 234 | return *utf8_message_result; |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | namespace { |
no test coverage detected