diff options
| author | Markus Uhlin <markus@nifty-networks.net> | 2025-10-17 04:12:34 +0200 |
|---|---|---|
| committer | Markus Uhlin <markus@nifty-networks.net> | 2025-10-17 04:12:34 +0200 |
| commit | 2c9bc4fcc3a7084146e832856f1237ecf5a8fb32 (patch) | |
| tree | 20b66dfae5cc2b7caa9b303fb56778b69f868943 | |
| parent | b968e27b92d119e19dfcb8702cd937adda267ac2 (diff) | |
Added a new parameter to fics_copyfile()
| -rw-r--r-- | FICS/copyfile.c | 22 | ||||
| -rw-r--r-- | FICS/copyfile.h | 2 |
2 files changed, 22 insertions, 2 deletions
diff --git a/FICS/copyfile.c b/FICS/copyfile.c index a2517a5..86ec3bf 100644 --- a/FICS/copyfile.c +++ b/FICS/copyfile.c @@ -18,7 +18,7 @@ #define SELF_TEST 0 bool -fics_copyfile(const char *p1, const char *p2) +fics_copyfile(const char *p1, const char *p2, const bool post_checks) { char tmp[2048] = { '\0' }; int fd[2]; @@ -66,6 +66,26 @@ fics_copyfile(const char *p1, const char *p2) if (total_read != total_written) { warnx("%s: total written mismatch total read", __func__); return false; + } else if (post_checks) { + char buf[2][MD5_DIGEST_STRING_LENGTH + 1]; + char *str[2]; + + str[0] = &buf[0][0]; + str[1] = &buf[1][0]; + + if (MD5File(p1, str[0]) != NULL && + MD5File(p2, str[1]) != NULL) { +#if PRINT_CHECKSUMS + puts(str[0]); + puts(str[1]); +#endif + + if (strcmp(str[0], str[1]) != 0) { + warnx("%s: digest mismatch", __func__); + return false; + } + } else + warnx("%s: failed to calculate file digest", __func__); } return true; diff --git a/FICS/copyfile.h b/FICS/copyfile.h index afe1699..28f8b59 100644 --- a/FICS/copyfile.h +++ b/FICS/copyfile.h @@ -6,7 +6,7 @@ #include "common.h" __FICS_BEGIN_DECLS -bool fics_copyfile(const char *, const char *); +bool fics_copyfile(const char *, const char *, const bool); bool is_regular_file(const char *); __FICS_END_DECLS |
