aboutsummaryrefslogtreecommitdiffstats
path: root/etc.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--etc.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/etc.c b/etc.c
index e7606aa..142ce74 100644
--- a/etc.c
+++ b/etc.c
@@ -1,4 +1,4 @@
-/* $Id: etc.c,v 1.52 2003/01/17 17:06:57 ukai Exp $ */
+/* $Id: etc.c,v 1.53 2003/01/22 16:10:28 ukai Exp $ */
#include "fm.h"
#include <pwd.h>
#include "myctype.h"
@@ -1339,6 +1339,58 @@ setup_child(int child, int i, int f)
fmInitialized = FALSE;
}
+pid_t
+open_pipe_rw(FILE **fr, FILE **fw)
+{
+ int fdr[2];
+ int fdw[2];
+ pid_t pid;
+
+ if (fr && pipe(fdr) < 0)
+ goto err0;
+ if (fw && pipe(fdw) < 0)
+ goto err1;
+
+ flush_tty();
+ pid = fork();
+ if (pid < 0)
+ goto err2;
+ if (pid == 0) {
+ /* child */
+ if (fr) {
+ close(fdr[0]);
+ dup2(fdr[1], 1);
+ }
+ if (fw) {
+ close(fdw[1]);
+ dup2(fdw[0], 0);
+ }
+ }
+ else {
+ if (fr) {
+ close(fdr[1]);
+ *fr = fdopen(fdr[0], "r");
+ }
+ if (fw) {
+ close(fdw[0]);
+ *fw = fdopen(fdw[1], "w");
+ }
+ }
+ return pid;
+ err2:
+ if (fw) {
+ close(fdw[0]);
+ close(fdw[1]);
+ }
+ err1:
+ if (fr) {
+ close(fdr[0]);
+ close(fdr[1]);
+ }
+ err0:
+ return (pid_t) -1;
+}
+
void
myExec(char *command)
{