diff options
author | Tilman Sauerbeck <tilman.sauerbeck@richard-wolf.com> | 2017-01-25 16:41:17 +0100 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-12-31 11:37:27 -0400 |
commit | cd95960319cb668e57241db5543eaa0dfa3e382a (patch) | |
tree | 543cd4ec0efa0e5f365540be9599d3560b2ae2af | |
parent | ab0bda73cdd97fa399bb58856f934c069ccd6596 (diff) | |
download | moreutils-cd95960319cb668e57241db5543eaa0dfa3e382a.tar.gz |
pee: remove buffering of input and outputs.
Previously pee buffered the data processed which may cause unwanted delays.
This change makes it so that data written to pee gets written out immediately.
-rw-r--r-- | pee.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -1,8 +1,10 @@ #include <stdlib.h> #include <stdio.h> +#include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> +#include <errno.h> /* Licensed under the GPL * Copyright (c) Miek Gieben, 2006 @@ -76,11 +78,22 @@ main(int argc, char **argv) { exit(EXIT_FAILURE); } + + setbuf(pipes[i - 1], NULL); } argc--; - while(!feof(stdin) && (!ferror(stdin))) { - r = fread(buf, sizeof(char), BUFSIZ, stdin); + for (;;) { + r = read(STDIN_FILENO, buf, BUFSIZ); + + /* Interrupted by signal? Try again. */ + if (r == -1 && errno == EINTR) + continue; + + /* Other error or EOF. */ + if (r < 1) + break; + for(i = 0; i < argc; i++) { if (inactive_pipe[i]) continue; |