blob: 0e497216639c093b89ede225e601394822f26c4c (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
int main(void)
{
/* Size of message must be <= PIPE_BUF */
const char msg[] = "Hello, World!";
char buf[512];
int rv;
int pfd[2];
if (pipe(pfd)) {
perror("pipe");
return 1;
}
if (write(pfd[1], msg, sizeof msg) != sizeof msg) {
perror("write");
return 1;
}
while ((rv = read(pfd[0], buf, sizeof buf)) < sizeof msg) {
if (rv == -1 && errno == EINTR)
continue;
perror("read");
return 1;
}
if (memcmp(msg, buf, sizeof msg)) {
fprintf(stderr, "Message miscompare!\n");
return 1;
}
return 0;
}
|