bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

commit 556d0844e9342ad62ed3dc9e3f9479d8db9d11e8
parent 95eba9d5537fac80bf17fcab8a482592aea9a487
Author: phoebos <ben@bvnf.space>
Date:   Sat, 26 Feb 2022 19:20:33 +0000

tee: adhere to POSIX when write fails

POSIX requires tee to continue to write to other files even if one write fails

Diffstat:
Mtee.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tee.c b/tee.c @@ -10,6 +10,7 @@ int tee(int *fds, int len) { + int ret = 0; unsigned char buf[BUF_SIZE]; ssize_t n; while ((n = read(0, buf, BUF_SIZE)) > 0) { @@ -17,19 +18,20 @@ tee(int *fds, int len) { for (; i < len; i++) { if (write(fds[i], buf, n) == -1) { fprintf(stderr, "tee: write: %s\n", strerror(errno)); - return 1; + ret = 1; + continue; } } if (write(1, buf, n) == -1) { fprintf(stderr, "tee: write: %s\n", strerror(errno)); - return 1; + ret = 1; } } if (n == -1) { fprintf(stderr, "tee: read: %s\n", strerror(errno)); - return 1; + ret = 1; } - return 0; + return ret; } int