reader.c

#include <stdio.h>

#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#include "utils.h"

#define FIFO_PATH "/tmp/ex-fifo"

int main(int argc, char *argv[])
{
    char buffer[100];
    int n;
    int fd = open(FIFO_PATH, O_RDONLY);
    exit_if(fd == -1, FIFO_PATH);
    printf("file %s is open for read\n", FIFO_PATH);
    while((n = read(fd, buffer, sizeof(buffer) - 1)) > 0) {
        buffer[n] = 0;
        printf("reader: %s", buffer);
    }
    printf("end of reader\n");
    return 0;
}