git: 414c2b8d1e5a - main - tee: minor cleanup

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sun, 20 Apr 2025 16:35:47 UTC
The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=414c2b8d1e5abe7186c1aa4dc3ab28147ce46f47

commit 414c2b8d1e5abe7186c1aa4dc3ab28147ce46f47
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-04-20 16:34:51 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-04-20 16:35:33 +0000

    tee: minor cleanup
    
    Pull the open flags out of the loop into a local var.  They won't be
    changing, so this is marginally more readable.
    
    Adds some extra brackets around the loop in preparation for a future
    change that may try to fallback to opening the path as a socket if we
    get an EOPNOTSUPP.
    
    No functional change.
    
    Reviewed by:    asomers, des, emaste, ngie
    Differential Revision:  https://reviews.freebsd.org/D48196
---
 usr.bin/tee/tee.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c
index 384fabf40f33..f1d192ff315f 100644
--- a/usr.bin/tee/tee.c
+++ b/usr.bin/tee/tee.c
@@ -57,11 +57,9 @@ static void usage(void) __dead2;
 int
 main(int argc, char *argv[])
 {
+	char *bp, *buf;
 	struct entry *p;
-	int n, fd, rval, wval;
-	char *bp;
-	int append, ch, exitval;
-	char *buf;
+	int append, ch, exitval, fd, n, oflags, rval, wval;
 #define	BSIZE (8 * 1024)
 
 	append = 0;
@@ -88,13 +86,20 @@ main(int argc, char *argv[])
 
 	add(STDOUT_FILENO, "stdout");
 
-	for (exitval = 0; *argv; ++argv)
-		if ((fd = open(*argv, append ? O_WRONLY|O_CREAT|O_APPEND :
-		    O_WRONLY|O_CREAT|O_TRUNC, DEFFILEMODE)) < 0) {
+	oflags = O_WRONLY | O_CREAT;
+	if (append)
+		oflags |= O_APPEND;
+	else
+		oflags |= O_TRUNC;
+
+	for (exitval = 0; *argv; ++argv) {
+		if ((fd = open(*argv, oflags, DEFFILEMODE)) < 0) {
 			warn("%s", *argv);
 			exitval = 1;
-		} else
+		} else {
 			add(fd, *argv);
+		}
+	}
 
 	if (caph_enter() < 0)
 		err(EXIT_FAILURE, "unable to enter capability mode");