implement (nonstandard) forkpty
[musl] / src / misc / forkpty.c
1 #include <pty.h>
2 #include <unistd.h>
3
4 int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
5 {
6         int s;
7         pid_t pid;
8
9         if (openpty(m, &s, name, tio, ws) < 0) return -1;
10         pid = fork();
11         if (!pid) {
12                 close(*m);
13                 dup2(s, 0);
14                 dup2(s, 1);
15                 dup2(s, 2);
16                 close(s);
17                 return 0;
18         }
19         close(s);
20         if (pid < 0) close(*m);
21         return pid;
22 }