Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. #include <stdlib.h>
  6. #include <fcntl.h>
  7.  
  8.  
  9. #define pathname "/tmp/chat_file.data"
  10.  
  11. int main(){
  12.  
  13.  
  14.     if(mkfifo(pathname, S_IRWXU) == -1){
  15.         perror("something went wrong");
  16.     }
  17.  
  18.     char * buff = NULL;
  19.     char * readbuff = NULL;
  20.     int res;
  21.     size_t len = 0;
  22.    
  23.     //FILE * fr = fopen(pathname, "r");
  24.     //FILE * fw = fopen(pathname, "w");
  25.    
  26.     int fd = open(pathname, O_WRONLY);
  27.    
  28.     while((res = getline(&buff, &len, stdin)) != -1){
  29.         //fprintf(fw, "%s", buff);
  30.         write(fd, buff, len);
  31.        
  32.         if((res = getline(&readbuff, &len, fd)) != -1){
  33.             printf("IN: %s", readbuff);
  34.         } else {
  35.             break;
  36.         }
  37.     }
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement