Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- const char * FIFO_NAME_IN = "/home/box/in.fifo";
- const char * FIFO_NAME_OUT = "/home/box/out.fifo";
- const int MAX_BUF = 80;
- int main()
- {
- int readfd, writefd, n;
- char buf[MAX_BUF];
- mkfifo(FIFO_NAME_IN, 0666);
- mkfifo(FIFO_NAME_OUT, 0666);
- if ((readfd = open(FIFO_NAME_IN, O_RDONLY)) < 0)
- {
- std::cout<<"Cannot open FIFO_IN\n";
- return 0;
- }
- if ((writefd = open(FIFO_NAME_OUT, O_WRONLY)) < 0)
- {
- std::cout<<"Cannot open FIFO_out\n";
- return 0;
- }
- while ( (n = read(readfd, buf, MAX_BUF)) > 0)
- {
- if (write(writefd, buf, n) != n)
- {
- std::cout<<"Output error\n";
- return 0;
- }
- }
- close(readfd);
- close(writefd);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment