summaryrefslogtreecommitdiff
path: root/src/misc
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-20 20:55:13 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-20 20:55:13 -0400
commit4921ce08673d14e53b3931b8536238d944a2c1ce (patch)
treec0a960a492beeddf7fc0a6b32d5cbc17bc6681a9 /src/misc
parentf1ac8a28d8f3c93ef42c20460992f74822975f11 (diff)
downloadmusl-4921ce08673d14e53b3931b8536238d944a2c1ce.tar.gz
implement (nonstandard) forkpty
Diffstat (limited to 'src/misc')
-rw-r--r--src/misc/forkpty.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/misc/forkpty.c b/src/misc/forkpty.c
new file mode 100644
index 00000000..2d1b0ae2
--- /dev/null
+++ b/src/misc/forkpty.c
@@ -0,0 +1,22 @@
+#include <pty.h>
+#include <unistd.h>
+
+int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
+{
+ int s;
+ pid_t pid;
+
+ if (openpty(m, &s, name, tio, ws) < 0) return -1;
+ pid = fork();
+ if (!pid) {
+ close(*m);
+ dup2(s, 0);
+ dup2(s, 1);
+ dup2(s, 2);
+ close(s);
+ return 0;
+ }
+ close(s);
+ if (pid < 0) close(*m);
+ return pid;
+}