summaryrefslogtreecommitdiff
path: root/do/pipe
diff options
context:
space:
mode:
Diffstat (limited to 'do/pipe')
-rw-r--r--do/pipe52
1 files changed, 52 insertions, 0 deletions
diff --git a/do/pipe b/do/pipe
new file mode 100644
index 0000000000..b3a6216d73
--- /dev/null
+++ b/do/pipe
@@ -0,0 +1,52 @@
+#ifdef HAS_PIPE
+void
+do_pipe(TARG, rstab, wstab)
+STR *TARG;
+STAB *rstab;
+STAB *wstab;
+{
+ register STIO *rstio;
+ register STIO *wstio;
+ int fd[2];
+
+ if (!rstab)
+ goto badexit;
+ if (!wstab)
+ goto badexit;
+
+ rstio = stab_io(rstab);
+ wstio = stab_io(wstab);
+
+ if (!rstio)
+ rstio = stab_io(rstab) = stio_new();
+ else if (rstio->ifp)
+ do_close(rstab,FALSE);
+ if (!wstio)
+ wstio = stab_io(wstab) = stio_new();
+ else if (wstio->ifp)
+ do_close(wstab,FALSE);
+
+ if (pipe(fd) < 0)
+ goto badexit;
+ rstio->ifp = fdopen(fd[0], "r");
+ wstio->ofp = fdopen(fd[1], "w");
+ wstio->ifp = wstio->ofp;
+ rstio->type = '<';
+ wstio->type = '>';
+ if (!rstio->ifp || !wstio->ofp) {
+ if (rstio->ifp) fclose(rstio->ifp);
+ else close(fd[0]);
+ if (wstio->ofp) fclose(wstio->ofp);
+ else close(fd[1]);
+ goto badexit;
+ }
+
+ str_sset(TARG,&str_yes);
+ return;
+
+badexit:
+ str_sset(TARG,&str_undef);
+ return;
+}
+#endif
+