From owner-svn-src-all@freebsd.org Mon Apr 27 22:33:33 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id D50A22C8C6B; Mon, 27 Apr 2020 22:33:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49B0195Kzsz3JyR; Mon, 27 Apr 2020 22:33:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B26BB1A01C; Mon, 27 Apr 2020 22:33:33 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03RMXXvR031925; Mon, 27 Apr 2020 22:33:33 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03RMXWgA031919; Mon, 27 Apr 2020 22:33:32 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202004272233.03RMXWgA031919@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 27 Apr 2020 22:33:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r360404 - stable/12/usr.bin/diff X-SVN-Group: stable-12 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/12/usr.bin/diff X-SVN-Commit-Revision: 360404 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Apr 2020 22:33:33 -0000 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 @@ -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 * Copyright (c) 1995 Tatu Ylonen , 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;