summaryrefslogtreecommitdiffstats
path: root/usr/klibc/tests/pipetest.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/tests/pipetest.c')
-rw-r--r--usr/klibc/tests/pipetest.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/usr/klibc/tests/pipetest.c b/usr/klibc/tests/pipetest.c
new file mode 100644
index 0000000..0e49721
--- /dev/null
+++ b/usr/klibc/tests/pipetest.c
@@ -0,0 +1,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;
+}