aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/calcurse.c22
-rw-r--r--src/calcurse.h1
-rw-r--r--src/io.c26
3 files changed, 42 insertions, 7 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index e31770c..8ba25ed 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -290,13 +290,21 @@ static inline void key_generic_reload(void)
io_save_todo(path_todo_backup);
io_save_mutex_unlock();
- const char *arg_apts[] = { conf.mergetool, path_apts,
- path_apts_backup, NULL };
- wins_launch_external(arg_apts);
-
- const char *arg_todo[] = { conf.mergetool, path_todo,
- path_todo_backup, NULL };
- wins_launch_external(arg_todo);
+ if (!io_files_equal(path_apts, path_apts_backup)) {
+ const char *arg_apts[] = { conf.mergetool,
+ path_apts,
+ path_apts_backup,
+ NULL };
+ wins_launch_external(arg_apts);
+ }
+
+ if (!io_files_equal(path_todo, path_todo_backup)) {
+ const char *arg_todo[] = { conf.mergetool,
+ path_todo,
+ path_todo_backup,
+ NULL };
+ wins_launch_external(arg_todo);
+ }
xfree(path_apts_backup);
xfree(path_todo_backup);
diff --git a/src/calcurse.h b/src/calcurse.h
index e125021..6d592f7 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -781,6 +781,7 @@ void io_stop_psave_thread(void);
void io_set_lock(void);
unsigned io_dump_pid(char *);
unsigned io_get_pid(char *);
+int io_files_equal(const char *, const char *);
int io_file_is_empty(char *);
int io_file_cp(const char *, const char *);
void io_unset_modified(void);
diff --git a/src/io.c b/src/io.c
index 0ea6bbf..116a362 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1333,6 +1333,32 @@ int io_file_is_empty(char *file)
}
/*
+ * Check whether two files are equal.
+ */
+int io_files_equal(const char *file1, const char *file2)
+{
+ FILE *fp1, *fp2;
+ int ret = 0;
+
+ if (!file1 || !file2)
+ return 0;
+
+ fp1 = fopen(file1, "rb");
+ fp2 = fopen(file2, "rb");
+
+ while (!feof(fp1) && !feof(fp2)) {
+ if (fgetc(fp1) != fgetc(fp2))
+ goto cleanup;
+ }
+
+ ret = 1;
+cleanup:
+ fclose(fp1);
+ fclose(fp2);
+ return ret;
+}
+
+/*
* Copy an existing file to a new location.
*/
int io_file_cp(const char *src, const char *dst)