gnucash stable: mingw32: Force the C runtime to use the process's code page.

John Ralls jralls at code.gnucash.org
Wed Sep 16 20:19:07 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/e27a3c62 (commit)
	from  https://github.com/Gnucash/gnucash/commit/38754227 (commit)



commit e27a3c6230aac638128c73345a6936e9fe912e77
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Sep 13 15:45:10 2026 -0700

    mingw32: Force the C runtime to use the process's code page.
    
    The process code page is set by the manifest created in the
    previous commit. Left to its own devices msvcrt will set the
    character set to the locale's DOS codepage. This commit overrides
    that by setting the locale charset to the C locale's which is
    always the process one.
    
    ucrt doesn't override the process char set so this isn't necessary
    and will be reverted immediately after merge.
    
    Assisted-by: Claude Code Opus 5
    Signed-off: John Ralls <jralls at ceridwen.us>

diff --git a/gnucash/gnucash-core-app.cpp b/gnucash/gnucash-core-app.cpp
index c9a3715c7d..45acec0f85 100644
--- a/gnucash/gnucash-core-app.cpp
+++ b/gnucash/gnucash-core-app.cpp
@@ -179,6 +179,9 @@ Gnucash::CoreApp::CoreApp (const char* app_name) : m_app_name {app_name}
     #if defined MAC_INTEGRATION || defined __MINGW32__
     sys_locale = set_platform_locale();
     #endif
+    #ifdef __MINGW32__
+    set_platform_ctype_to_acp();
+    #endif
     #if ! defined MAC_INTEGRATION && ! defined __MINGW32__/* setlocale already done */
     sys_locale = g_strdup (setlocale (LC_ALL, ""));
     if (!sys_locale)
diff --git a/gnucash/gnucash-locale-platform.h b/gnucash/gnucash-locale-platform.h
index bfdddc8ff3..c079bbaa44 100644
--- a/gnucash/gnucash-locale-platform.h
+++ b/gnucash/gnucash-locale-platform.h
@@ -31,6 +31,15 @@ extern "C" {
 
 char *set_platform_locale(void);
 
+#ifdef __MINGW32__
+/** Align the CRT's LC_CTYPE with the process's active code page.
+ *
+ * Call after anything that may have called setlocale (LC_ALL, ...),
+ * in particular gtk_init.
+ */
+void set_platform_ctype_to_acp(void);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/gnucash/gnucash-locale-windows.c b/gnucash/gnucash-locale-windows.c
index 6e7666ed4a..a542af2cbb 100644
--- a/gnucash/gnucash-locale-windows.c
+++ b/gnucash/gnucash-locale-windows.c
@@ -24,6 +24,7 @@
 
 #include <Windows.h>
 #include <fcntl.h>
+#include <locale.h>
 #include <glib/gi18n.h>
 #include "gnucash-locale-platform.h"
 
@@ -149,3 +150,10 @@ set_platform_locale(void)
     }
     return g_strdup("C");
 }
+
+void
+set_platform_ctype_to_acp (void)
+{
+    // The C locale is always aligned with ACP.
+    setlocale (LC_CTYPE, "C");
+}
diff --git a/gnucash/gnucash.cpp b/gnucash/gnucash.cpp
index 7bb960fb8b..15c8b60ad0 100644
--- a/gnucash/gnucash.cpp
+++ b/gnucash/gnucash.cpp
@@ -31,6 +31,9 @@
 
 #include "gnucash-commands.hpp"
 #include "gnucash-core-app.hpp"
+#ifdef __MINGW32__
+#include "gnucash-locale-platform.h"
+#endif
 
 #include <glib/gi18n.h>
 #include <dialog-new-user.h>
@@ -300,6 +303,9 @@ main(int argc, char ** argv)
         << "\n";
         return 1;
     }
+#ifdef __MINGW32__
+    set_platform_ctype_to_acp ();
+#endif
 
     application.parse_command_line (argc, argv);
     return application.start (argc, argv);



Summary of changes:
 gnucash/gnucash-core-app.cpp      | 3 +++
 gnucash/gnucash-locale-platform.h | 9 +++++++++
 gnucash/gnucash-locale-windows.c  | 8 ++++++++
 gnucash/gnucash.cpp               | 6 ++++++
 4 files changed, 26 insertions(+)



More information about the gnucash-changes mailing list