Advertisement
d1cor

fifo_lector.c

May 30th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. /*******************************************
  2. * Author     : Diego Cordoba / @d1cor      *
  3. * Purpose    : juncotic.com @juncotic      *
  4. *******************************************/
  5.  
  6. #include<stdio.h>
  7. #include<stdlib.h>
  8. #include<sys/types.h>
  9. #include<sys/stat.h>
  10. #include<unistd.h>
  11. #include<string.h>
  12. #include<fcntl.h>
  13. #include<errno.h>
  14.  
  15. #define BUF_SIZE 256
  16.  
  17. int main(int argc, char** argv) {
  18.  
  19.     char *error;
  20.     char cadena[BUF_SIZE];
  21.     int count,i;
  22.     int tuberia;    //file descriptor del fifo
  23.  
  24.     if(mkfifo(*(argv+1),0777)<0){
  25.         error="mkfifo";
  26.         goto err;
  27.     }
  28.  
  29.     if((tuberia=open(*(argv+1),O_RDONLY))<0){
  30.         error="open";
  31.         goto err;
  32.     }
  33.  
  34.     printf("LECTOR\tLeyendo...\n");
  35.  
  36.     while(count=read(tuberia,cadena,BUF_SIZE)){
  37.         *(cadena+count)='\0';
  38.         printf("LECTOR\t%s\n",cadena);
  39.     }
  40.  
  41.     close(tuberia);
  42.  
  43.  
  44.     unlink(*(argv+1));
  45.  
  46.     return 0;
  47.  
  48. err:
  49.     fprintf(stderr,"%s: %d-%s\n",error,errno,strerror(errno));
  50.     exit(1);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement