X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fserver%2Fio.c;h=c8f5167a24a3a2bf4e5dddc849063e3ed83ca0a5;hb=6ac951c41a091ffc723840894ddf1e774739511d;hp=c703f0e68929a9c879c84bb8ced011875f27874d;hpb=02faa5bf7e77b6bbf111819164f9a15e3792215a;p=plomrogue diff --git a/src/server/io.c b/src/server/io.c index c703f0e..c8f5167 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -11,7 +11,7 @@ #include /* strlen(), memcpy(), memset() */ #include /* time_t */ #include /* time(), nanosleep() */ -#include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(), +#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish(), * try_fwrite(), try_fputc(), try_fgetc() */ #include "../common/rexit.h" /* exit_trouble() */ @@ -180,11 +180,8 @@ static void read_file_into_queue() static void update_worldstate_file() { char * f_name = "update_worldstate_file()"; - uint16_t size = strlen(s[S_PATH_WORLDSTATE])+strlen(s[S_PATH_SUFFIX_TMP])+1; - char * path_tmp = try_malloc(size, f_name); - int test=sprintf(path_tmp,"%s%s",s[S_PATH_WORLDSTATE],s[S_PATH_SUFFIX_TMP]); - exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]); - FILE * file = try_fopen(path_tmp, "w", f_name); + char * path_tmp; + FILE * file = atomic_write_start(s[S_PATH_WORLDSTATE], &path_tmp); struct Thing * player = get_player(); write_value_as_line(world.turn, file); write_value_as_line(player->lifepoints, file); @@ -197,8 +194,7 @@ static void update_worldstate_file() { try_fwrite(world.log, strlen(world.log), 1, file, f_name); } - try_fclose_unlink_rename(file, path_tmp, s[S_PATH_WORLDSTATE], f_name); - free(path_tmp); + atomic_write_finish(file, s[S_PATH_WORLDSTATE], path_tmp); set_cleanup_flag(CLEANUP_WORLDSTATE); char * dot = ".\n";; try_fwrite(dot, strlen(dot), 1, world.file_out, f_name); @@ -331,8 +327,8 @@ extern char * io_round() extern void save_world() { char * f_name = "save_world()"; - char * path = s[S_PATH_SAVE]; - FILE * file = try_fopen(path, "w", f_name); + char * path_tmp; + FILE * file = atomic_write_start(s[S_PATH_SAVE], &path_tmp); write_key_value(file, s[S_CMD_DO_FOV], 0); try_fputc('\n', file, f_name); write_key_value(file, s[S_CMD_SEED_MAP], world.seed_map); @@ -345,5 +341,5 @@ extern void save_world() write_thing(file, t); } write_key_value(file, s[S_CMD_DO_FOV], 1); - try_fclose(file, f_name); + atomic_write_finish(file, s[S_PATH_SAVE], path_tmp); }