Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #define pathname "/tmp/chat_file.data"
- int main(){
- if(mkfifo(pathname, S_IRWXU) == -1){
- perror("something went wrong");
- }
- char * buff = NULL;
- char * readbuff = NULL;
- int res;
- size_t len = 0;
- //FILE * fr = fopen(pathname, "r");
- //FILE * fw = fopen(pathname, "w");
- int fd = open(pathname, O_WRONLY);
- while((res = getline(&buff, &len, stdin)) != -1){
- //fprintf(fw, "%s", buff);
- write(fd, buff, len);
- if((res = getline(&readbuff, &len, fd)) != -1){
- printf("IN: %s", readbuff);
- } else {
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement