From: Rich Felker Date: Thu, 21 Apr 2011 00:55:13 +0000 (-0400) Subject: implement (nonstandard) forkpty X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=commitdiff_plain;h=4921ce08673d14e53b3931b8536238d944a2c1ce implement (nonstandard) forkpty --- diff --git a/include/pty.h b/include/pty.h index 9444e5ec..46a99f47 100644 --- a/include/pty.h +++ b/include/pty.h @@ -9,6 +9,7 @@ extern "C" { #include int openpty(int *, int *, char *, const struct termios *, const struct winsize *); +int forkpty(int *, char *, const struct termios *, const struct winsize *); #ifdef __cplusplus extern } 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; +}