Contents of /trunk/mkinitrd-magellan/klibc/usr/klibc/tests/pipetest.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 646 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 646 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | #include <unistd.h> |
4 | #include <fcntl.h> |
5 | #include <string.h> |
6 | #include <errno.h> |
7 | |
8 | int main(void) |
9 | { |
10 | /* Size of message must be <= PIPE_BUF */ |
11 | const char msg[] = "Hello, World!"; |
12 | char buf[512]; |
13 | int rv; |
14 | int pfd[2]; |
15 | |
16 | if (pipe(pfd)) { |
17 | perror("pipe"); |
18 | return 1; |
19 | } |
20 | |
21 | if (write(pfd[1], msg, sizeof msg) != sizeof msg) { |
22 | perror("write"); |
23 | return 1; |
24 | } |
25 | |
26 | while ((rv = read(pfd[0], buf, sizeof buf)) < sizeof msg) { |
27 | if (rv == -1 && errno == EINTR) |
28 | continue; |
29 | perror("read"); |
30 | return 1; |
31 | } |
32 | |
33 | if (memcmp(msg, buf, sizeof msg)) { |
34 | fprintf(stderr, "Message miscompare!\n"); |
35 | return 1; |
36 | } |
37 | |
38 | return 0; |
39 | } |