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

/*
 * Exemplo de utilização de um FIFO
 * para receber dados de um outro processo
 *
 * Jose Rogado
 */

 #define BUFSIZE 32
char buffer[BUFSIZE];

main(int argc, char *argv[])
{
    FILE *fd;
    char *p;

    if (argc != 2) {
        printf("Wrong arg. count\n");
        exit(1);
    }
    fd = fopen(argv[1], "r");
    if (fd == 0)
        perror("open");

    while(1) {
      p = fgets(buffer, BUFSIZE, fd);
      if (p == NULL)
        break;
      printf("%s\n", buffer);
    }
    exit(0);
}
