diff options
| author | Kyle Evans <kevans@FreeBSD.org> | 2021-09-23 05:26:52 +0000 |
|---|---|---|
| committer | Kyle Evans <kevans@FreeBSD.org> | 2021-09-29 18:03:34 +0000 |
| commit | 4e380e8474609875c4cf5277b3755ac29079a8b5 (patch) | |
| tree | e59459a8471e686af8dfb74c1367a7cd027f77c1 /usr.bin/cmp/regular.c | |
| parent | f6787614fd4db2a9d5e649af0e819852ebd5a19d (diff) | |
cmp: add -n, --bytes to limit number of bytes to compare
This is compatible with GNU cmp.
Reviewed by: markj
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D32072
Diffstat (limited to 'usr.bin/cmp/regular.c')
| -rw-r--r-- | usr.bin/cmp/regular.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/usr.bin/cmp/regular.c b/usr.bin/cmp/regular.c index fe639663a560..a60398620282 100644 --- a/usr.bin/cmp/regular.c +++ b/usr.bin/cmp/regular.c @@ -60,7 +60,7 @@ static void segv_handler(int); void c_regular(int fd1, const char *file1, off_t skip1, off_t len1, - int fd2, const char *file2, off_t skip2, off_t len2) + int fd2, const char *file2, off_t skip2, off_t len2, off_t limit) { struct sigaction act, oact; cap_rights_t rights; @@ -86,15 +86,17 @@ c_regular(int fd1, const char *file1, off_t skip1, off_t len1, off2 = ROUNDPAGE(skip2); length = MIN(len1, len2); + if (limit > 0) + length = MIN(length, limit); if ((m1 = remmap(NULL, fd1, off1)) == NULL) { - c_special(fd1, file1, skip1, fd2, file2, skip2); + c_special(fd1, file1, skip1, fd2, file2, skip2, limit); return; } if ((m2 = remmap(NULL, fd2, off2)) == NULL) { munmap(m1, MMAP_CHUNK); - c_special(fd1, file1, skip1, fd2, file2, skip2); + c_special(fd1, file1, skip1, fd2, file2, skip2, limit); return; } |
