X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/ledger2?a=blobdiff_plain;f=src%2Fserver%2Fio.c;h=761655cf9877206e30f9c0636676038f195810fd;hb=e4ae4fc25ee35e0dcbba7331e7a4fe1eb4818422;hp=c703f0e68929a9c879c84bb8ced011875f27874d;hpb=02faa5bf7e77b6bbf111819164f9a15e3792215a;p=plomrogue diff --git a/src/server/io.c b/src/server/io.c index c703f0e..761655c 100644 --- a/src/server/io.c +++ b/src/server/io.c @@ -331,8 +331,11 @@ 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); + uint16_t size = strlen(s[S_PATH_SAVE]) + 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_SAVE], s[S_PATH_SUFFIX_TMP]); + exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]); + FILE * file = try_fopen(path_tmp, "w", f_name); 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 +348,6 @@ extern void save_world() write_thing(file, t); } write_key_value(file, s[S_CMD_DO_FOV], 1); - try_fclose(file, f_name); + try_fclose_unlink_rename(file, path_tmp, s[S_PATH_SAVE], f_name); + free(path_tmp); }