diff options
| author | Markus Uhlin <markus@nifty-networks.net> | 2025-10-17 21:25:23 +0200 |
|---|---|---|
| committer | Markus Uhlin <markus@nifty-networks.net> | 2025-10-17 21:25:23 +0200 |
| commit | caf799c956945481977632b9203398e21f95a67f (patch) | |
| tree | 9944cc0b5be88658d172359347276c73213c41f0 | |
| parent | 1bd35c0348a74a343c29e2273e7ba46576eacfa6 (diff) | |
Moved code to a function
| -rw-r--r-- | FICS/copyfile.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/FICS/copyfile.c b/FICS/copyfile.c index 0f9e4ce..73b3195 100644 --- a/FICS/copyfile.c +++ b/FICS/copyfile.c @@ -17,6 +17,34 @@ #define PRINT_CHECKSUMS 0 #define SELF_TEST 0 +static int +do_post_checks(const char *p1, const char *p2) +{ + char buf[2][41]; + char *str[2]; + + str[0] = &buf[0][0]; + str[1] = &buf[1][0]; + + memset(str[0], 0, sizeof(buf[0])); + memset(str[1], 0, sizeof(buf[1])); + + if (SHA1File(p1, str[0]) != NULL && + SHA1File(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 -1; + } + } else + warnx("%s: failed to calculate file digest", __func__); + return 0; +} + bool fics_copyfile(const char *p1, const char *p2, const bool post_checks) { @@ -67,28 +95,8 @@ fics_copyfile(const char *p1, const char *p2, const bool post_checks) warnx("%s: total written mismatch total read", __func__); return false; } else if (post_checks) { - char buf[2][41]; - char *str[2]; - - str[0] = &buf[0][0]; - str[1] = &buf[1][0]; - - memset(str[0], 0, sizeof(buf[0])); - memset(str[1], 0, sizeof(buf[1])); - - if (SHA1File(p1, str[0]) != NULL && - SHA1File(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__); + if (do_post_checks(p1, p2) == -1) + return false; } return true; |
