From ae7d2d4c6b53160bfe0beae13dfb36b879451bba Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 17 Jul 2014 11:47:00 +0200 Subject: Only run the merge tool on files with differences If the backup file and the data file are equal, there is no need to run the merge tool. Signed-off-by: Lukas Fleischer --- src/io.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/io.c') diff --git a/src/io.c b/src/io.c index 0ea6bbf..116a362 100644 --- a/src/io.c +++ b/src/io.c @@ -1332,6 +1332,32 @@ int io_file_is_empty(char *file) return -1; } +/* + * 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. */ -- cgit v1.2.3-54-g00ecf