#if defined(_WIN32) && !defined(__CYGWIN__)
char* buf = nullptr;
auto len
- = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
- | FORMAT_MESSAGE_ALLOCATE_BUFFER,
- nullptr,
- i,
- LANG_USER_DEFAULT,
- reinterpret_cast<LPTSTR>(&buf),
- 0,
- nullptr);
+ = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_ALLOCATE_BUFFER
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ nullptr,
+ i,
+ LANG_USER_DEFAULT,
+ reinterpret_cast<LPTSTR>(&buf),
+ 0,
+ nullptr);
if (len > 0)
{
struct deleter {
void operator()(void* p) const { ::LocalFree(p); }
};
std::unique_ptr<char[], deleter> guard(buf);
- if (len > 3 && !__builtin_memcmp(buf + len - 3, ".\r\n", 3)) [[likely]]
- len -= 3;
+ if (len > 2 && !__builtin_memcmp (buf + len - 2, "\r\n", 2)) [[likely]]
+ len -= 2 + (buf[len - 3] == '.');
return string(buf, len);
}
return string("Unknown error code");
#include <locale>
#include <testsuite_hooks.h>
+#if defined __MINGW32__ || defined __MINGW64__
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
void
test01()
{
const std::error_category& cat = std::system_category();
std::error_condition cond;
-#if defined __MING32__ || defined __MINGW64__
+#if defined __MINGW32__ || defined __MINGW64__
cond = cat.default_error_condition(8); // ERROR_NOT_ENOUGH_MEMORY
VERIFY( cond.value() == ENOMEM );
VERIFY( cond.category() == std::generic_category() );
// set "C" locale to get expected message
auto loc = std::locale::global(std::locale::classic());
-#if defined __MING32__ || defined __MINGW64__
+#if defined __MINGW32__ || defined __MINGW64__
+ // On Windows, set thread preferred UI languages to "en-US"
+ // to get expected message
+ ULONG num_langs = 1;
+ SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME, L"en-US\0", &num_langs);
+
std::string msg = std::system_category().message(5); // ERROR_ACCESS_DENIED
- VERIFY(msg == "Access denied");
+ // Windows returns "Access is denied" but Wine returns "Access denied".
+ VERIFY(msg == "Access is denied" || msg == "Access denied");
+
+ SetThreadPreferredUILanguages(MUI_RESET_FILTERS, nullptr, nullptr);
#else
std::string msg = std::system_category().message(EBADF);
VERIFY( msg.find("file") != std::string::npos );