1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-10-27 18:20:13 -04:00

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.
This commit is contained in:
John Zaitseff 2011-07-21 22:22:50 +10:00
parent c5500e1bb3
commit 71486357c1

View File

@ -145,7 +145,6 @@ bool load_game (int num)
char *buf, *filename; char *buf, *filename;
FILE *file; FILE *file;
int saved_errno, lineno; int saved_errno, lineno;
char *prev_locale;
int crypt_key; int crypt_key;
int n, i, j; int n, i, j;
@ -197,7 +196,7 @@ bool load_game (int num)
} }
// Change the formatting of numbers to the POSIX locale for consistency // 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 // Read the game file header
if (fgets(buf, BUFSIZE, file) == NULL) { if (fgets(buf, BUFSIZE, file) == NULL) {
@ -284,8 +283,8 @@ bool load_game (int num)
errno_exit("%s", filename); errno_exit("%s", filename);
} }
// Change the formatting of numbers back to the user-supplied locale // Restore the user-supplied locale
setlocale(LC_NUMERIC, prev_locale); setlocale(LC_ALL, "");
free(buf); free(buf);
free(filename); free(filename);
@ -302,7 +301,6 @@ bool save_game (int num)
char *buf, *filename; char *buf, *filename;
FILE *file; FILE *file;
int saved_errno; int saved_errno;
char *prev_locale;
struct stat statbuf; struct stat statbuf;
int crypt_key; int crypt_key;
int i, j, x, y; 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 // 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 // Write out the game file header and encryption key
fprintf(file, "%s\n" "%s\n", GAME_FILE_HEADER, GAME_FILE_API_VERSION); 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); errno_exit("%s", filename);
} }
// Change the formatting of numbers back to the user-supplied locale // Restore the user-supplied locale
setlocale(LC_NUMERIC, prev_locale); setlocale(LC_ALL, "");
free(buf); free(buf);
free(filename); free(filename);