mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Make file saving and loading locale-independent for numbers
This commit is contained in:
parent
7eafa205e7
commit
ef83258e2b
14
src/fileio.c
14
src/fileio.c
@ -148,6 +148,7 @@ 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, x, y;
|
int n, i, j, x, y;
|
||||||
@ -203,6 +204,9 @@ bool load_game (int num)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the formatting of numbers to the POSIX locale
|
||||||
|
prev_locale = 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) {
|
||||||
err_exit("%s: missing header in game file", filename);
|
err_exit("%s: missing header in game file", filename);
|
||||||
@ -287,6 +291,9 @@ bool load_game (int num)
|
|||||||
errno_exit("%s", filename);
|
errno_exit("%s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the formatting of numbers back to the user-supplied locale
|
||||||
|
setlocale(LC_NUMERIC, prev_locale);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
free(filename);
|
free(filename);
|
||||||
return true;
|
return true;
|
||||||
@ -308,6 +315,7 @@ 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;
|
||||||
@ -379,6 +387,9 @@ bool save_game (int num)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the formatting of numbers to the POSIX locale
|
||||||
|
prev_locale = 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);
|
||||||
fprintf(file, "%d\n", crypt_key);
|
fprintf(file, "%d\n", crypt_key);
|
||||||
@ -435,6 +446,9 @@ bool save_game (int num)
|
|||||||
errno_exit("%s", filename);
|
errno_exit("%s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Change the formatting of numbers back to the user-supplied locale
|
||||||
|
setlocale(LC_NUMERIC, prev_locale);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
free(filename);
|
free(filename);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user