aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/diff
Commit message (Collapse)AuthorAgeFilesLines
* diff: Correct fd 0 case on pipeJilles Tjoelker2026-06-031-2/+3
| | | | | | | | | | | | | | After git commit c8d40bf8ecc60cc15e3904410db62065ea681fdc, if fd 0 was not open, it is left with CLOEXEC set and therefore fails. This is an unlikely situation, but fixing it reduces the size of the code (by using posix_spawn_file_actions_adddup2's special case if the two file descriptor numbers are the same). At the same time, check the error code from posix_spawn_file_actions_adddup2. Reviewed by: bapt Differential Revision: https://reviews.freebsd.org/D56910
* diff: use O_CLOEXEC on pipesBaptiste Daroussin2026-03-281-5/+2
| | | | | | This only simplifies the code, no functional changes expected MFC After: 1 week
* diff: handle read(2) failuresBaptiste Daroussin2026-03-261-0/+5
| | | | MFC After: 1 week
* diff: prefer posix_spawn over pdfork/execlBaptiste Daroussin2026-03-261-23/+39
| | | | | | MFC After: 1 week Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D56076
* diff: Add SPDX-License-Identifier tagTuukka Pasanen2026-02-191-0/+2
| | | | | Reviewed by: emaste Sponsored by: The FreeBSD Foundation
* diff: Drop unnecessary casts, fix none algoDag-Erling Smørgrav2026-02-181-6/+7
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55349
* diff: Tweak recursion testsDag-Erling Smørgrav2026-02-131-14/+16
| | | | | | | | | | | | The -r flag is not required to compare two directories; it is only required to compare them recursively, i.e. descend into their common subdirectories. Adjust tests that use -r needlessly, and adjust the dirloop test to verify that these two cases remain distinct. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55262
* diff: Tweak range of -C and -U argumentsDag-Erling Smørgrav2026-02-132-42/+64
| | | | | | | | | | | | | | | | | | | | | POSIX uses the terms “positive decimal integer” for -C and “non-negative decimal integer” for -U, which translates into lower bounds of 1 for -C and 0 for -U. POSIX does not specify a minimum upper bound for either mode, but as of 5fc739eb5949 both our backends support context sizes up to and including INT_MAX, so use that. Having had the opportunity to consult the Unix System Test Suite, the diff test cases found therein happen to precisely match these bounds. While here, switch to using strtonum() to parse numerical arguments, and try to be more consistent in how we report usage errors. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55261
* diff: Improve directory loop detectionDag-Erling Smørgrav2026-02-112-3/+22
| | | | | | | | | | | | | When we're done processing a directory, remove its entry from the tree of visited inodes, ensuring that we only report a loop when we encounter a descendant-to-ancestor link, not when we encounter a cousin-to-cousin or sibling-to-sibling link. MFC after: 1 week Reported by: Bakul Shah <bakul@iitbombay.org> Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D55248
* diff: Bump version numberDag-Erling Smørgrav2026-02-061-1/+1
| | | | | MFC after: 1 week Sponsored by: Klara, Inc.
* diff: Report I/O errors in Stone algorithmDag-Erling Smørgrav2026-02-051-3/+7
| | | | | | | | | | | | | In the legacy Stone algorithm, we do a first pass over the files to check if they're identical before we start diffing them. That code would correctly set the exit status if an I/O error was encountered, but would not emit an error message. Do so. PR: 292198 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj Differential Revision: https://reviews.freebsd.org/D55125
* diff: Correctly declare testsDag-Erling Smørgrav2026-02-051-1/+4
| | | | | | | Sponsored by: Klara, Inc. Fixes: 5fc739eb5949 ("diff: Fix integer overflows in Stone algorithm") Fixes: 270492602b9b ("diff: Add test case for pagination resource leak") Fixes: 590126789c84 ("diff: Don't compare a file or directory to itself")
* diff: Fix buildCy Schubert2026-02-051-0/+2
| | | | | | | | rc must be defined first. Fixes: 590126789c84 MFC after: 1 week X-MFC with: 590126789c84
* diff: Don't compare a file or directory to itselfDag-Erling Smørgrav2026-02-053-8/+28
| | | | | | | | | | | While here, stop abusing struct dirent for something we don't even need to store. PR: 254455 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55113
* diff: Fix pagination leakDag-Erling Smørgrav2026-02-052-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | * Drop an unnecessary variable and rename pidfd to procd. * Rewinding stdout serves no purpose, so stop doing it. * Don't bother freeing memory or setting the global status right before erroring out. * Error out if dup(2) or dup2(2) fail. * In the unlikely case that our pipe is equal to stdout, we need to record that information so we don't close it when cleaning up. * Don't bother closing a descriptor before dup2(2)ing to it. * Don't forget to close the the process descriptor after reaping the child process. PR: 266592 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: kevans, markj Differential Revision: https://reviews.freebsd.org/D55112
* diff: Add test case for pagination resource leakDag-Erling Smørgrav2026-02-051-0/+22
| | | | | | | | | | | The pagination code leaks either processes or descriptors or both, depending on the exact version of the code you have. Add a test case which exercises this leak to facilitate fixing it. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55111
* diff: Fix integer overflows in Stone algorithmDag-Erling Smørgrav2026-02-052-11/+54
| | | | | | | | | | | Fix integer overflows that may occur when the context window is very large and add tests to exercise those conditions. PR: 267032 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55110
* diff: Print an error message on I/O errorDag-Erling Smørgrav2026-02-051-2/+11
| | | | | | | | | | | | If an error occurs while atomizing either file, immediately print an error message using the error code returned by the atomizer, and set the error bit in the exit status. PR: 292198 MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55109
* libdiff: Simplify truncation detectionDag-Erling Smørgrav2026-02-051-4/+0
| | | | | | | | | | | | | | | * Adjust the comment to reflect the fact that SIGBUS can occur not only if the file is truncated, but also if an I/O error occurs while paging in any part of it. * Instead of setting a flag, just return EIO. * Adjust the unit test accordingly. MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: thj, kevans Differential Revision: https://reviews.freebsd.org/D55108
* diff: remove useless include as kevent is not used anymoreBaptiste Daroussin2026-02-021-2/+0
| | | | MFC After: 3 days
* diff: use pdwait(2) instead of homemade oneBaptiste Daroussin2026-02-022-15/+7
| | | | | | MFC After: 3 days Reviewed by: des Differential Revision: https://reviews.freebsd.org/D55053
* diff: fix support for -l with new diff algorithmBaptiste Daroussin2026-02-023-0/+9
| | | | | | MFC After: 3 days Reviewed by: des Differential Revision: https://reviews.freebsd.org/D55052
* libc: Rename fscandir{,_b}() to fdscandir{,_b}().Dag-Erling Smørgrav2025-06-231-1/+1
| | | | | | | | | | | | | This seems to fit the pattern better (e.g. fdopendir()). I've added weak references to ease the transition, but since it's only been a few days, we can remove them (and the ObsoleteFiles entries for the manual pages) before we branch stable/15. Fixes: deeebfdecab5 Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D50980
* diff: Fix gcc build.Dag-Erling Smørgrav2025-06-201-3/+3
| | | | Sponsored by: Klara, Inc.
* diff: Whitespace nits.Dag-Erling Smørgrav2025-06-201-13/+13
| | | | Sponsored by: Klara, Inc.
* diff: Detect loops when diffing directories.Dag-Erling Smørgrav2025-06-202-10/+92
| | | | | | Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D50936
* diff: minor fixes to manual pagePau Amma2025-06-061-8/+12
| | | | | | | | | * Add missing dash before long option name in synopsis. * Remove spurious paragraph break and bullet item. * While there, fix mandoc -T lint complaints. Reviewed by: ziaee, des Differential Revision: https://reviews.freebsd.org/D48388
* diff: Fix device case.Dag-Erling Smørgrav2024-12-231-2/+2
| | | | | | | | | | | | We already fell back to Stone for FIFOs, but we actually need to fall back to Stone for everything except regular files, because libdiff's atomizer needs to know the size of its input in advance, and neither FIFOs nor devices can be trusted to report their size. MFC after: 1 week Reported by: mav Reviewed by: mav, allanjude Differential Revision: https://reviews.freebsd.org/D48181
* libdiff: Implement diff coloring.Dag-Erling Smørgrav2024-10-021-0/+2
| | | | | | | | | | This patch got accidentally left out when libdiff was imported. The rest of the code (command-line option etc.) was present, just not the part that actually prints ANSI color codes. Sponsored by: Klara, Inc. Reviewed by: kevans Differential Revision: https://reviews.freebsd.org/D46873
* diff: Fix integer overflow.Dag-Erling Smørgrav2024-07-291-21/+24
| | | | | | | | | | | | | | | The legacy Stone algorithm uses `int` to represent line numbers, array indices, and array lengths. If given inputs approaching `INT_MAX` lines, it would overflow and attempt to allocate ridiculously large amounts of memory. To avoid this without penalizing non-pathological inputs, switch a few variables to `size_t` and add checks while and immediately after reading both inputs. MFC after: 3 days PR: 280371 Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D46169
* diff: Fix usage message and documentation.Dag-Erling Smørgrav2024-07-292-4/+4
| | | | | | | | | | | The `--ignore-all-space` option was incorrectly documented as `--ignore-all-blanks` in some (but not all) places. MFC after: 3 days PR: 280434 Sponsored by: Klara, Inc. Reviewed by: 0mp, markj Differential Revision: https://reviews.freebsd.org/D46160
* Remove residual blank line at start of MakefileWarner Losh2024-07-151-1/+0
| | | | | | | This is a residual of the $FreeBSD$ removal. MFC After: 3 days (though I'll just run the command on the branches) Sponsored by: Netflix
* diff: Document the --no-dereference option.Dag-Erling Smørgrav2024-06-302-2/+9
| | | | | | | | | Also, --no-dereference should not imply --recurse. MFC after: 3 days Sponsored by: Klara, Inc. Reviewed by: allanjude Differential Revision: https://reviews.freebsd.org/D45779
* diff: Nits in tests.Dag-Erling Smørgrav2024-05-201-1/+0
| | | | Sponsored by: Klara, Inc.
* diff: Warn if the atomizer detected truncation.Dag-Erling Smørgrav2024-05-201-0/+4
| | | | | | Sponsored by: Klara, Inc. Reviewed by: allanjude, markj Differential Revision: https://reviews.freebsd.org/D45219
* diff: honour -B flag with -qEd Maste2024-05-182-1/+13
| | | | | | | PR: 278988 Reviewed by: bapt Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45220
* diff: Sort headers.Dag-Erling Smørgrav2024-05-033-6/+10
| | | | | | | MFC after: 1 week Sponsored by: Klara, Inc. Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D45078
* diff: use getline() instead of fgetln()Martin Tournoij2024-04-191-7/+10
| | | | | | | | | | | | | | | | | | | | | | This replaces fgetln() with getline(). The main reason for this is portability, making things easier for people who want to compile these tools on non-FreeBSD systems. I appreciate that's probably not the top concern for FreeBSD base tools, but fgetln() is impossible to port to most platforms, as concurrent access is essentially impossible to implement fully correct without the line buffer on the FILE struct. Other than this, many generic FreeBSD tools compile fairly cleanly on Linux with a few small changes. Most uses of fgetln() pre-date getline() support (added in 2009 with 69099ba2ec8b), and there's been some previous patches (ee3ca711a898 8c98e6b1a7f3 1a2a4fc8ce1b) for other tools. Obtained from: https://github.com/dcantrell/bsdutils and https://github.com/chimera-linux/chimerautils Signed-off-by: Martin Tournoij <martin@arp242.net> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/893
* diff: Integrate libdiff from OpenBSD GoT.Dag-Erling Smørgrav2024-03-2710-22/+482
| | | | | | | | | | | | | | | | | | | | | | | This adds support for two new diff algorithms, Myers diff and Patience diff. These algorithms perform a different form of search compared to the classic Stone algorithm and support escapes when worst case scenarios are encountered. Add the -A flag to allow selection of the algorithm, but default to using the new Myers diff implementation. The libdiff implementation currently only supports a subset of input and output options supported by diff. When these options are used, but the algorithm is not selected, automatically fallback to the classic Stone algorithm until support for these modes can be added. Based on work originally done by thj@ with contributions from kevans@. Sponsored by: Klara, Inc. Reviewed by: thj Differential Revision: https://reviews.freebsd.org/D44302
* diff: Improve history section.Dag-Erling Smørgrav2024-03-191-6/+8
| | | | | Reviewed by: gbe Differential Revision: https://reviews.freebsd.org/D44409
* diff(1) add FreeBSD HISTORYDavid E. O'Brien2024-03-151-0/+9
|
* diff: Bump manual page date.Dag-Erling Smørgrav2024-02-261-1/+1
| | | | Sponsored by: Klara, Inc.
* diff: Fix --expand-tabs and --side-by-side.Dag-Erling Smørgrav2024-02-263-56/+78
| | | | | | | | | | | | * Overhaul column width and padding calculation. * Rewrite print_space() so it is now a) correct and b) understandable. * Rewrite tab expansion in fetch() for the same reason. This brings us in line with GNU diff for all cases I could think of. Sponsored by: Klara, Inc. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D44014
* diff(1): fix a typoPin-Yi Kuo2023-12-261-1/+1
| | | | | | | | | On the manpage of diff(1), "when" is mistyped to "wen". Event: Advanced UNIX Programming Course (Fall'23) at NTHU. Signed-off-by: Pin-Yi Kuo <kuokuoyiyi@gapp.nthu.edu.tw> Reviewed by: imp, zlei Pull Request: https://github.com/freebsd/freebsd-src/pull/943
* usr.bin: Automated cleanup of cdefs and other formattingWarner Losh2023-11-271-1/+0
| | | | | | | | | | | | | | | | Apply the following automated changes to try to eliminate no-longer-needed sys/cdefs.h includes as well as now-empty blank lines in a row. Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/ Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/ Remove /\n+#if.*\n#endif.*\n+/ Remove /^#if.*\n#endif.*\n/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/ Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/ Sponsored by: Netflix
* usr.bin: Remove ancient SCCS tags.Warner Losh2023-11-273-6/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* Remove $FreeBSD$: one-line nroff patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\.\\"\s*\$FreeBSD\$$\n/
* Remove $FreeBSD$: one-line sh patternWarner Losh2023-08-164-4/+0
| | | | Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-165-10/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Remove $FreeBSD$: one-line .h patternWarner Losh2023-08-161-1/+0
| | | | Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/