#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

enum { buf_size = 4096 };

enum exit_codes {
    exit_success,
    exit_failure,
    exit_arguments,
    exit_process,
    exit_signal,
    exit_file
};

void terminate(const char *msg, int code)
{
    perror(msg);
    exit(code);
}

int main()
{
    int fd, rc, r;
    char buf[buf_size];

    r = mkfifo("fifo.t", 0666);
    if (r == -1)
        terminate("mkfifo", exit_failure);

    fd = open("fifo.t", O_RDONLY);
    if (fd == -1)
        terminate("fifo.t", exit_file);
    while ((rc = read(fd, buf, buf_size)) != 0)
        write(1, buf, rc);
    return 0;
}
