X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fmisc.c;h=6f8c6c766ac1b0807b64e73a8524e4c8fb3c1f19;hb=59ae6cee193bc675cb6f7e80fde3055348c5dc82;hp=ab9963f9af491bc892cb3dce6fdb92582b2b9bb4;hpb=b37024737a3660b7eeec66738db87ccba6c1ecdb;p=plomrogue
diff --git a/src/misc.c b/src/misc.c
index ab9963f..6f8c6c7 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -114,12 +114,28 @@ extern uint16_t center_offset(uint16_t pos, uint16_t mapsize,
extern void turn_over(struct World * world, char action)
{
+ char * err_open = "Error recording move: "
+ "Unable to open file 'record_tmp' for appending.";
+ char * err_write = "Error recording move: "
+ "Trouble writing to opened file 'record_tmp'.";
+ char * err_close = "Error recording move: "
+ "Unable to close opened file 'record_tmp'.";
+ char * err_unl = "Error recording move: "
+ "Unable to unlink old file 'record'.";
+ char * err_move = "Error recording move: "
+ "Unable to rename file 'record_tmp' to 'record'.";
+ char * recordfile_tmp = "record_tmp";
+ char * recordfile = "record";
if (1 == world->interactive)
{
- FILE * file = fopen("record", "a");
- exit_err(write_uint8(action, file), world, "Record writing failure.");
- fclose(file);
+ FILE * file = fopen(recordfile_tmp, "a");
+ exit_err(0 == file, world, err_open);
+ exit_err(write_uint8(action, file), world, err_write);
+ exit_err(fclose(file), world, err_close);
+ exit_err(unlink(recordfile), world, err_unl);
+ exit_err(rename(recordfile_tmp, recordfile), world, err_move);
}
+
world->turn++;
rrand_seed(world->seed * world->turn);
struct Monster * monster;
@@ -136,15 +152,15 @@ extern void turn_over(struct World * world, char action)
extern void save_game(struct World * world)
{
char * err_open = "Error saving game: "
- "Unable to open 'savefile_new' for writing.";
+ "Unable to open file 'savefile_tmp' for writing.";
char * err_write = "Error saving game: "
- "Trouble writing to opened 'savefile_new'.";
+ "Trouble writing to opened file 'savefile_tmp'.";
char * err_close = "Error saving game: "
- "Unable to close opened 'savefile_new'.";
+ "Unable to close opened file 'savefile_tmp'.";
char * err_unl = "Error saving game: "
- "Unable to unlink old 'savefile'.";
+ "Unable to unlink old 'savefile' file.";
char * err_move = "Error saving game: "
- "Unable to rename 'savefile_tmp' to 'savefile'.";
+ "Unable to rename 'file savefile_tmp' to 'savefile'.";
char * savefile_tmp = "savefile_tmp";
char * savefile = "savefile";
FILE * file = fopen(savefile_tmp, "w");