diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c --- a/usr.bin/tee/tee.c +++ b/usr.bin/tee/tee.c @@ -60,7 +60,7 @@ struct entry *p; int n, fd, rval, wval; char *bp; - int append, ch, exitval; + int append, ch, exitval, oflags; char *buf; #define BSIZE (8 * 1024) @@ -88,13 +88,19 @@ 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 add(fd, *argv); + } if (caph_enter() < 0) err(EXIT_FAILURE, "unable to enter capability mode");