* parsetest_too_many_values(),
* parse_id_uniq(), parse_init_entry()
*/
-#include "../common/readwrite.h" /* atomic_write_start(), atomic_write_finish()
- * 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() */
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);
+/* Return "path" + suffix "_tmp". Value is malloc'd, must be free externally. */
+static char * build_temp_path(char * path);
+
+
+
+static char * build_temp_path(char * path)
+{
+ char * f_name = "build_temp_path";
+ char * suffix_tmp = "_tmp";
+ uint16_t size = strlen(path) + strlen(suffix_tmp) + 1;
+ char * path_tmp = try_malloc(size, f_name);
+ int test = sprintf(path_tmp, "%s%s", path, suffix_tmp);
+ exit_trouble(test < 0, f_name, "sprintf()");
+ return path_tmp;
+}
+
+
+
extern FILE * try_fopen(char * path, char * mode, char * f)
{
char * f_name = "try_fopen()";
extern FILE * atomic_write_start(char * path, char ** path_tmp)
{
char * f_name = "atomic_write_start()";
- char * suffix_tmp = "_tmp";
- uint16_t size = strlen(path) + strlen(suffix_tmp) + 1;
- *path_tmp = try_malloc(size, f_name);
- int test = sprintf(*path_tmp, "%s%s", path, suffix_tmp);
- exit_trouble(test < 0, f_name, "sprintf()");
+ *path_tmp = build_temp_path(path);
return try_fopen(*path_tmp, "w", f_name);
}
+extern void detect_atomic_leftover(char * path)
+{
+ char * f_name = "detect_atomic_leftover()";
+ char * path_tmp = build_temp_path(path);
+ char * part1 = "Found file '";
+ char * part2 = "' that may be a leftover from an aborted previous attempt "
+ "to write '";
+ char * part3 = "'. Aborting until the matter is solved by (re-)moving it.";
+ uint32_t size = strlen(part1) + strlen(path_tmp) + strlen(part2)
+ + strlen(path) + strlen(part3) + 1;
+ char * msg = try_malloc(size, f_name);
+ int test = sprintf(msg, "%s%s%s%s%s", part1, path_tmp, part2, path, part3);
+ exit_trouble(test < 0, f_name, "sprintf()");
+ exit_err(!access(path_tmp, F_OK), msg);
+ free(msg);
+ free(path_tmp);
+}
+
+
+
extern uint32_t textfile_width(FILE * file)
{
char * f_name = "textfile_width()";
#include <time.h> /* time() */
#include <unistd.h> /* optarg, getopt(), access(), unlink(), getpid() */
#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_width(),
- * try_fgets(), try_fwrite()
+ * try_fgets(), try_fwrite(),
+ * detect_atomic_leftover()
*/
#include "../common/rexit.h" /* exit_err(), exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
extern void run_game()
{
char * f_name = "run_game()";
+ detect_atomic_leftover(s[S_PATH_SAVE]);
+ detect_atomic_leftover(s[S_PATH_RECORD]);
if (world.replay)
{
replay_game();