svn commit: r360404 - stable/12/usr.bin/diff

Kyle Evans kevans at FreeBSD.org
Mon Apr 27 22:33:33 UTC 2020


Author: kevans
Date: Mon Apr 27 22:33:32 2020
New Revision: 360404
URL: https://svnweb.freebsd.org/changeset/base/360404

Log:
  MFC r356723-r356725, r357649, r357652: diff(1) catch-up
  
  r356723:
  mkstemp returns -1
  
  r356724:
  asprintf returns -1, not an arbitrary value < 0. Also upon error the
  (very sloppy specification) leaves an undefined value in *ret, so it is
  wrong to inspect it, the error condition is enough.
  
  r356725:
  When system calls indicate an error they return -1, not some arbitrary
  value < 0.  errno is only updated in this case.
  
  r357649:
  Update diff(1) TODO removing what has been implemented
  
  r357652:
  Fix most of the style warnings

Modified:
  stable/12/usr.bin/diff/TODO
  stable/12/usr.bin/diff/diff.1
  stable/12/usr.bin/diff/diff.c
  stable/12/usr.bin/diff/diffreg.c
  stable/12/usr.bin/diff/xmalloc.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.bin/diff/TODO
==============================================================================
--- stable/12/usr.bin/diff/TODO	Mon Apr 27 22:32:16 2020	(r360403)
+++ stable/12/usr.bin/diff/TODO	Mon Apr 27 22:33:32 2020	(r360404)
@@ -1,9 +1,3 @@
--y:
-  * soc implemented it via calling sdiff directly, but some options are
-  incompatible so it is fragile
-  * just recommend the user to run sdiff directly and do not implement it
-  * make a libsdiff and use that directly to avoid duplicating the code
-
 to be implemented:
 --horizon-lines
 --ignore-tab-expansion
@@ -13,5 +7,3 @@ Will probably be not implemented:
 --GTYPE-group-format (partially implement - minimal)
 --LTYPE-line-format
 --help (We have a manpage already)
---suppress-common-lines: depends on -y (won't be implemented, as it conflicts
-the way sdiff expects it and in any case we have sdiff for that feature)

Modified: stable/12/usr.bin/diff/diff.1
==============================================================================
--- stable/12/usr.bin/diff/diff.1	Mon Apr 27 22:32:16 2020	(r360403)
+++ stable/12/usr.bin/diff/diff.1	Mon Apr 27 22:33:32 2020	(r360404)
@@ -30,7 +30,7 @@
 .\"     @(#)diff.1	8.1 (Berkeley) 6/30/93
 .\" $FreeBSD$
 .\"
-.Dd February 07, 2020
+.Dd February 7, 2020
 .Dt DIFF 1
 .Os
 .Sh NAME
@@ -232,7 +232,7 @@ are marked with
 those added to
 .Ar file2
 are marked
-.Sq \+\ \& .
+.Sq +\ \& .
 Lines which are changed from one file to the other are marked in
 both files with
 .Sq !\ \& .
@@ -300,11 +300,12 @@ However, unlike with
 all lines to be changed (added and/or removed) are present in
 a single section.
 .It Fl y Fl -side-by-side
-Output in two columns with a marker between them. The marker can be one 
+Output in two columns with a marker between them.
+The marker can be one
 of the following:
 .Pp
 .Bl -tag -width Ds -offset indent -compact
-.It space 
+.It space
 Corresponding lines are identical.
 .It '|'
 Corresponding lines are different.
@@ -318,9 +319,7 @@ Files differ and only the second file contains the lin
 Comparison options:
 .Bl -tag -width Ds
 .It Fl a -text
-Treat all files as
-.Tn ASCII
-text.
+Treat all files as ASCII text.
 Normally
 .Nm
 will simply print
@@ -394,7 +393,8 @@ will compare equal to
 .It Fl W Ar number Fl -width Ar number
 Output at most
 .Ar number
-columns when using side by side format. The default value is 130.
+columns when using side by side format.
+The default value is 130.
 .It Fl -changed-group-format Ar GFMT
 Format input groups in the provided
 .Pp
@@ -473,9 +473,8 @@ Binary files which differ,
 common subdirectories, and files which appear in only one directory
 are described as such.
 In directory mode only regular files and directories are compared.
-If a non-regular file such as a device special file or
-.Tn FIFO
-is encountered, a diagnostic message is printed.
+If a non-regular file such as a device special file or FIFO is encountered,
+a diagnostic message is printed.
 .Pp
 If only one of
 .Ar file1
@@ -596,7 +595,7 @@ pairs (where num1 = num2) are abbreviated as a single
 number.
 .Sh FILES
 .Bl -tag -width /tmp/diff.XXXXXXXX -compact
-.It Pa /tmp/diff. Ns Ar XXXXXXXX
+.It Pa /tmp/diff.XXXXXXXX
 Temporary file used when comparing a device or the standard input.
 Note that the temporary file is unlinked as soon as it is created
 so it will not show up in a directory listing.

Modified: stable/12/usr.bin/diff/diff.c
==============================================================================
--- stable/12/usr.bin/diff/diff.c	Mon Apr 27 22:32:16 2020	(r360403)
+++ stable/12/usr.bin/diff/diff.c	Mon Apr 27 22:33:32 2020	(r360404)
@@ -1,4 +1,4 @@
-/*	$OpenBSD: diff.c,v 1.65 2015/12/29 19:04:46 gsoares Exp $	*/
+/*	$OpenBSD: diff.c,v 1.67 2019/06/28 13:35:00 deraadt Exp $	*/
 
 /*
  * Copyright (c) 2003 Todd C. Miller <Todd.Miller at courtesan.com>
@@ -357,12 +357,12 @@ main(int argc, char **argv)
 	} else {
 		if (S_ISDIR(stb1.st_mode)) {
 			argv[0] = splice(argv[0], argv[1]);
-			if (stat(argv[0], &stb1) < 0)
+			if (stat(argv[0], &stb1) == -1)
 				err(2, "%s", argv[0]);
 		}
 		if (S_ISDIR(stb2.st_mode)) {
 			argv[1] = splice(argv[1], argv[0]);
-			if (stat(argv[1], &stb2) < 0)
+			if (stat(argv[1], &stb2) == -1)
 				err(2, "%s", argv[1]);
 		}
 		print_status(diffreg(argv[0], argv[1], dflags, 1), argv[0],

Modified: stable/12/usr.bin/diff/diffreg.c
==============================================================================
--- stable/12/usr.bin/diff/diffreg.c	Mon Apr 27 22:32:16 2020	(r360403)
+++ stable/12/usr.bin/diff/diffreg.c	Mon Apr 27 22:33:32 2020	(r360404)
@@ -1,4 +1,4 @@
-/*	$OpenBSD: diffreg.c,v 1.91 2016/03/01 20:57:35 natano Exp $	*/
+/*	$OpenBSD: diffreg.c,v 1.93 2019/06/28 13:35:00 deraadt Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -297,7 +297,7 @@ diffreg(char *file1, char *file2, int flags, int capsi
 	else {
 		if (!S_ISREG(stb1.st_mode)) {
 			if ((f1 = opentemp(file1)) == NULL ||
-			    fstat(fileno(f1), &stb1) < 0) {
+			    fstat(fileno(f1), &stb1) == -1) {
 				warn("%s", file1);
 				status |= 2;
 				goto closem;
@@ -318,7 +318,7 @@ diffreg(char *file1, char *file2, int flags, int capsi
 	else {
 		if (!S_ISREG(stb2.st_mode)) {
 			if ((f2 = opentemp(file2)) == NULL ||
-			    fstat(fileno(f2), &stb2) < 0) {
+			    fstat(fileno(f2), &stb2) == -1) {
 				warn("%s", file2);
 				status |= 2;
 				goto closem;
@@ -466,12 +466,12 @@ opentemp(const char *f)
 
 	if (strcmp(f, "-") == 0)
 		ifd = STDIN_FILENO;
-	else if ((ifd = open(f, O_RDONLY, 0644)) < 0)
+	else if ((ifd = open(f, O_RDONLY, 0644)) == -1)
 		return (NULL);
 
 	(void)strlcpy(tempfile, _PATH_TMP "/diff.XXXXXXXX", sizeof(tempfile));
 
-	if ((ofd = mkstemp(tempfile)) < 0) {
+	if ((ofd = mkstemp(tempfile)) == -1) {
 		close(ifd);
 		return (NULL);
 	}
@@ -1002,7 +1002,7 @@ preadline(int fd, size_t rlen, off_t off)
 	ssize_t nr;
 
 	line = xmalloc(rlen + 1);
-	if ((nr = pread(fd, line, rlen, off)) < 0)
+	if ((nr = pread(fd, line, rlen, off)) == -1)
 		err(2, "preadline");
 	if (nr > 0 && line[nr-1] == '\n')
 		nr--;

Modified: stable/12/usr.bin/diff/xmalloc.c
==============================================================================
--- stable/12/usr.bin/diff/xmalloc.c	Mon Apr 27 22:32:16 2020	(r360403)
+++ stable/12/usr.bin/diff/xmalloc.c	Mon Apr 27 22:33:32 2020	(r360404)
@@ -1,4 +1,4 @@
-/* $OpenBSD: xmalloc.c,v 1.9 2015/11/17 18:25:02 tobias Exp $ */
+/* $OpenBSD: xmalloc.c,v 1.10 2019/06/28 05:44:09 deraadt Exp $ */
 /*
  * Author: Tatu Ylonen <ylo at cs.hut.fi>
  * Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -81,7 +81,7 @@ xasprintf(char **ret, const char *fmt, ...)
 	i = vasprintf(ret, fmt, ap);
 	va_end(ap);
 
-	if (i < 0 || *ret == NULL)
+	if (i == -1)
 		err(2, "xasprintf");
 
 	return i;


More information about the svn-src-all mailing list