-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfifo.c
More file actions
56 lines (40 loc) · 986 Bytes
/
fifo.c
File metadata and controls
56 lines (40 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define BUFFER_SIZE 1024
int main(int argc, char **argv)
{
char buffer[BUFFER_SIZE];
unlink("/home/box/in.fifo");
int in;
if (mkfifo("/home/box/in.fifo", 0666) == -1) {
printf("Error mkfifo in");
}
if ((in = open("/home/box/in.fifo", O_RDONLY | O_NONBLOCK, 066)) == -1) {
printf("Error open fifo in");
}
unlink("/home/box/out.fifo");
int out;
if (mkfifo("/home/box/out.fifo", 0666) == -1) {
printf("Error mkfifo out");
}
if ((out = open("/home/box/out.fifo", O_WRONLY, 066)) == -1) {
printf("Error open fifo out");
}
//close(out);
//dup2(in, out);
//close(in);
int res = read(in, (void*)buffer, (size_t)BUFFER_SIZE);
if (res <= 0) {
printf("Error read");
close(in);
close(out);
return 1;
}
res = write(out, buffer, res);
close(in);
close(out);
return 0;
}