git: 99509fcc8733 - stable/14 - tee: minor cleanup

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sat, 26 Apr 2025 03:21:16 UTC
The branch stable/14 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=99509fcc8733022e54bac6a9249a03d2e1489271

commit 99509fcc8733022e54bac6a9249a03d2e1489271
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2025-04-20 16:34:51 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2025-04-26 03:19:48 +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
    
    (cherry picked from commit 414c2b8d1e5abe7186c1aa4dc3ab28147ce46f47)
---
 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 c4fe945d6d12..aeda9c34ac45 100644
--- a/usr.bin/tee/tee.c
+++ b/usr.bin/tee/tee.c
@@ -69,11 +69,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;
@@ -100,13 +98,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");