From: Karel Zak Date: Mon, 1 Nov 2021 11:50:33 +0000 (+0100) Subject: Merge branch 'topic/hardlink' X-Git-Tag: v2.38-rc1~196 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3320cd80dce7b42d1e5586189d282f151c35d482;p=thirdparty%2Futil-linux.git Merge branch 'topic/hardlink' --- 3320cd80dce7b42d1e5586189d282f151c35d482 diff --cc misc-utils/hardlink.c index bf179859af,ed49b0a7f5..b1ba70c680 --- a/misc-utils/hardlink.c +++ b/misc-utils/hardlink.c @@@ -552,76 -552,8 +553,8 @@@ static int file_xattrs_equal(const stru { return TRUE; } -#endif /* HAVE_SYS_XATTR_H */ +#endif /* USE_XATTR */ - /** - * file_contents_equal - Compare contents of two files for equality - * @a: The first file - * @b: The second file - * - * Compare the contents of the files for equality - */ - static int file_contents_equal(const struct file *a, const struct file *b) - { - FILE *fa = NULL; - FILE *fb = NULL; - int cmp = 0; /* zero => equal */ - off_t off = 0; /* current offset */ - - assert(a->links != NULL); - assert(b->links != NULL); - - jlog(JLOG_VERBOSE1, _("Comparing %s to %s"), a->links->path, - b->links->path); - - stats.comparisons++; - - if ((fa = fopen(a->links->path, "rb")) == NULL) - goto err; - if ((fb = fopen(b->links->path, "rb")) == NULL) - goto err; - - #if defined(POSIX_FADV_SEQUENTIAL) && defined(HAVE_POSIX_FADVISE) - ignore_result( posix_fadvise(fileno(fa), 0, 0, POSIX_FADV_SEQUENTIAL) ); - ignore_result( posix_fadvise(fileno(fb), 0, 0, POSIX_FADV_SEQUENTIAL) ); - #endif - - while (!handle_interrupt() && cmp == 0) { - size_t ca; - size_t cb; - - ca = fread(buf_a, 1, opts.bufsiz, fa); - if (ca < sizeof(buf_a) && ferror(fa)) - goto err; - - cb = fread(buf_b, 1, opts.bufsiz, fb); - if (cb < sizeof(buf_b) && ferror(fb)) - goto err; - - off += ca; - - if ((ca != cb || ca == 0)) { - cmp = CMP(ca, cb); - break; - } - cmp = memcmp(buf_a, buf_b, ca); - } - out: - if (fa != NULL) - fclose(fa); - if (fb != NULL) - fclose(fb); - return !handle_interrupt() && cmp == 0; - err: - if (fa == NULL || fb == NULL) - warn(_("cannot open %s"), fa ? b->links->path : a->links->path); - else - warn(_("cannot read %s"), - ferror(fa) ? a->links->path : b->links->path); - cmp = 1; - goto out; - } - /** * file_may_link_to - Check whether a file may replace another one * @a: The first file