aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2024-02-24 16:05:43 +0100
committerMartin Mares <mj@ucw.cz>2024-02-24 20:47:05 +0100
commit64155dd0405d68b258512c386aa52ea42549d946 (patch)
tree6dd62281ca9a6439868e326ffa4d33ac1e44da65
parent3f13452c5b2388271edf11cfdc5713633b561e69 (diff)
downloadpciutils-64155dd0405d68b258512c386aa52ea42549d946.tar.gz
windows: Try to return error message from win32_strerror() in US English language
The default LANG_NEUTRAL language is the system language, not the "C" locale.
-rw-r--r--lib/win32-helpers.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/win32-helpers.c b/lib/win32-helpers.c
index e12de1a..d370d5c 100644
--- a/lib/win32-helpers.c
+++ b/lib/win32-helpers.c
@@ -63,6 +63,12 @@ typedef BOOL (WINAPI *SetSecurityDescriptorControlProt)(PSECURITY_DESCRIPTOR pSe
typedef BOOL (WINAPI *SetThreadErrorModeProt)(DWORD dwNewMode, LPDWORD lpOldMode);
+static DWORD
+format_message_from_system(DWORD win32_error_id, DWORD lang_id, LPSTR buffer, DWORD size)
+{
+ return FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, win32_error_id, lang_id, buffer, size, NULL);
+}
+
const char *
win32_strerror(DWORD win32_error_id)
{
@@ -73,7 +79,15 @@ win32_strerror(DWORD win32_error_id)
static char buffer[4096];
DWORD len;
- len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, win32_error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer), NULL);
+ /*
+ * If it is possible show error messages in US English language.
+ * International Windows editions do not have to provide error
+ * messages in English language, so fallback to the language
+ * which system provides (neutral).
+ */
+ len = format_message_from_system(win32_error_id, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), buffer, sizeof(buffer));
+ if (!len)
+ len = format_message_from_system(win32_error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buffer, sizeof(buffer));
/* FormatMessage() automatically appends ".\r\n" to the error message. */
if (len && buffer[len-1] == '\n')