I have created a couple of tiny utils for working with pipes. Don't know if they are even sizable enough to be of interest, or if anyone will find use for them. I wanted something like 'pd' for some things I want to do, and could not find it, so I wrote it, and then I wrote it's antagonist ir.
pd - "pipe discarder" for lack of a better name, it reads stdin write to stdout, simply ignoring sigpipe, so you can place it between some application writing continuous output and a pipe, which you want to look at only some times. ir - "infinite reader" takes file name (intended to be used with FIFOs) as an argument, reads from it non stop ignoring EOF, so you can "multiplex" output that was written into FIFO at different times, that is it can feed some application whatever comes at the pipe, no matter how many times it is closed and opened at the write end. And thats all they do. Maybe someone will find some use for it.
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> int main(int argc, char *argv[]) { char *line = NULL; size_t len = 0; ssize_t read; signal(SIGPIPE, SIG_IGN); while ((read = getline(&line, &len, stdin)) != -1) { write(1, line, read); } if (line) free(line); return 0; }
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <signal.h> int main(int argc, char *argv[]) { char *line = NULL; size_t len = 0; ssize_t read; FILE * rfd; if (argc < 2) { printf("Usage:\nir <file>\n"); return -1; } rfd = fopen(argv[1], "r"); if (rfd == NULL) { printf("Failed to open file: %s\n", argv[1]); return -1; } for (;;) { read = getline(&line, &len, rfd); if (read > 0) { write(1, line, read); } } if (line) free(line); return 0; }