summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReuben Thomas <rrt@sc3d.org>2017-02-04 20:43:56 +0000
committerReuben Thomas <rrt@sc3d.org>2017-02-09 00:28:25 +0000
commiteaef59b49d66c25bc6ae0ad4cc9b7502aa205752 (patch)
tree34b80b94a4ed9deb63ebb3e362cb36001198398b
parentfeea72fe831311ff45e51cb2079a469c8bf07194 (diff)
downloadenchant-eaef59b49d66c25bc6ae0ad4cc9b7502aa205752.tar.gz
Simplify code to fix up code page conversion on Windows
-rw-r--r--tests/enchant-ispell.c18
1 files changed, 6 insertions, 12 deletions
diff --git a/tests/enchant-ispell.c b/tests/enchant-ispell.c
index 0ccedb9..934e253 100644
--- a/tests/enchant-ispell.c
+++ b/tests/enchant-ispell.c
@@ -58,10 +58,10 @@
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-
-static char charset[15] = "CP437";
#endif
+static const char *charset;
+
typedef enum
{
MODE_NONE,
@@ -112,12 +112,7 @@ consume_line (FILE * in, GString * str)
}
if (str->len) {
-#ifdef WIN32
utf = g_convert(str->str, str->len, "UTF-8", charset, &bytes_read, &bytes_written, NULL);
-#else
- utf = g_locale_to_utf8 (str->str, str->len, &bytes_read, &bytes_written, NULL);
-#endif
-
if (utf) {
g_string_assign (str, utf);
g_free (utf);
@@ -558,12 +553,11 @@ int main (int argc, char ** argv)
/* Initialize system locale */
setlocale(LC_ALL, "");
+ g_get_charset(&charset);
#ifdef WIN32
- /* Workaround about glib's "locale" not being the set C locale */
- if (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) != FILE_TYPE_CHAR) {
- sprintf_s(charset,15,"CP%u",GetACP());
- } else {
- sprintf_s(charset,15,"CP%u",GetConsoleCP());
+ /* If reading from stdin, its CP may not be the system CP (which glib's locale gives us) */
+ if (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR) {
+ charset = g_strdup_printf("CP%u", GetConsoleCP());
}
#endif