logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: ec98fcc8ee03157d9da25886729904744a92b1fe
parent 6c1f9819cfc7f30648c1776a7941c9351b86d94c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  1 Mar 2022 14:56:53 +0100

bin/tee: Return non-zero on errorneous write

Diffstat:

Mbin/tee.c6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bin/tee.c b/bin/tee.c @@ -65,11 +65,14 @@ main(int argc, char *argv[]) } // main loop, note that failed writes shouldn't make tee exit + int err = 0; + while((c = fgetc(stdin)) != EOF) { if(fputc(c, stdout) == EOF) { fprintf(stderr, "Error writing ‘<stdout>’: %s\n", strerror(errno)); + err = 1; errno = 0; } @@ -78,6 +81,7 @@ main(int argc, char *argv[]) if(fputc(c, fds[argi]) == EOF) { fprintf(stderr, "Error writing to argument %d: %s\n", argi, strerror(errno)); + err = 1; errno = 0; } } @@ -94,5 +98,5 @@ main(int argc, char *argv[]) cleanup(fds); - return 0; + return err; }