home · contact · privacy
Use direction names instead of numbers in player move communication.
[plomrogue] / src / client / interface_conf.c
index e3bfd022a5db6d3c61c1757d1819cb894935849a..853fdaae66ef132b50ed340078e39a52e497f11b 100644 (file)
@@ -16,8 +16,8 @@
                                    * parsetest_too_many_values(),
                                    * parse_id_uniq(), parse_init_entry()
                                    */
-#include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(),
-                                  * try_fwrite()
+#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish(),
+                                  * detect_atomic_leftover(), try_fwrite()
                                   */
 #include "../common/rexit.h" /* exit_err(), exit_trouble() */
 #include "../common/try_malloc.h" /* try_malloc() */
@@ -401,13 +401,8 @@ extern void obey_argv(int argc, char * argv[])
 
 extern void save_interface_conf()
 {
-    char * f_name = "save_interface_conf()";
-    char * path = world.path_interface;
-    size_t size = strlen(path) + 4 + 1;
-    char * path_tmp = try_malloc(size, f_name);
-    int test = snprintf(path_tmp, size, "%s_tmp", path);
-    exit_trouble(test < 0, f_name, "snprintf()");
-    FILE * file = try_fopen(path_tmp, "w", f_name);
+    char * path_tmp;
+    FILE * file = atomic_write_start(world.path_interface, &path_tmp);
     char * str_keybs = "\nKEYBINDINGS ";
     write_def(file, str_keybs, 1, "global", 's');
     write_keybindings(file, &world.kb_global);
@@ -431,8 +426,7 @@ extern void save_interface_conf()
         write_def(file, "HEIGHT ", 0, (char *) &win->target_height, 'i');
         write_keybindings(file, &win->kb);
     }
-    try_fclose_unlink_rename(file, path_tmp, path, f_name);
-    free(path_tmp);
+    atomic_write_finish(file, world.path_interface, path_tmp);
 }
 
 
@@ -446,6 +440,7 @@ extern void load_interface_conf()
     tmp_order    = try_malloc(1, f_name);
     tmp_order[0] = '\0';
     tmp_active   = '\0';
+    detect_atomic_leftover(world.path_interface);
     parse_file(world.path_interface, tokens_into_entries);
     char * err = "Not all expected windows defined in config file.";
     exit_err(strlen(world.winDB.legal_ids) != strlen(world.winDB.ids), err);