From 71486357c11f981189960d7f3dfe831571ee1f56 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Thu, 21 Jul 2011 22:22:50 +1000 Subject: [PATCH] Bug fix: restore locale settings correctly For some reason, changing the locale to "C" for LC_NUMERIC, then restoring just that part of the locale to the old user-supplied one does not work. Simply reinstating the whole locale using setlocale(LC_ALL, ""), however, DOES work, so do that. --- src/fileio.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 01ab594..255e244 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -145,7 +145,6 @@ bool load_game (int num) char *buf, *filename; FILE *file; int saved_errno, lineno; - char *prev_locale; int crypt_key; int n, i, j; @@ -197,7 +196,7 @@ bool load_game (int num) } // Change the formatting of numbers to the POSIX locale for consistency - prev_locale = setlocale(LC_NUMERIC, "C"); + setlocale(LC_NUMERIC, "C"); // Read the game file header if (fgets(buf, BUFSIZE, file) == NULL) { @@ -284,8 +283,8 @@ bool load_game (int num) errno_exit("%s", filename); } - // Change the formatting of numbers back to the user-supplied locale - setlocale(LC_NUMERIC, prev_locale); + // Restore the user-supplied locale + setlocale(LC_ALL, ""); free(buf); free(filename); @@ -302,7 +301,6 @@ bool save_game (int num) char *buf, *filename; FILE *file; int saved_errno; - char *prev_locale; struct stat statbuf; int crypt_key; int i, j, x, y; @@ -371,7 +369,7 @@ bool save_game (int num) } // Change the formatting of numbers to the POSIX locale for consistency - prev_locale = setlocale(LC_NUMERIC, "C"); + setlocale(LC_NUMERIC, "C"); // Write out the game file header and encryption key fprintf(file, "%s\n" "%s\n", GAME_FILE_HEADER, GAME_FILE_API_VERSION); @@ -431,8 +429,8 @@ bool save_game (int num) errno_exit("%s", filename); } - // Change the formatting of numbers back to the user-supplied locale - setlocale(LC_NUMERIC, prev_locale); + // Restore the user-supplied locale + setlocale(LC_ALL, ""); free(buf); free(filename);