From 4921ce08673d14e53b3931b8536238d944a2c1ce Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 20 Apr 2011 20:55:13 -0400 Subject: implement (nonstandard) forkpty --- src/misc/forkpty.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/misc/forkpty.c (limited to 'src') 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 +#include + +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; +} -- cgit v1.2.3-70-g09d2