6 int forkpty(int *m, char *name, const struct termios *tio, const struct winsize *ws)
8 int s, t, i, istmp[3]={0};
11 if (openpty(m, &s, name, tio, ws) < 0) return -1;
13 /* Ensure before forking that we don't exceed fd limit */
15 if (fcntl(i, F_GETFL) < 0) {
16 t = fcntl(s, F_DUPFD, i);
18 else if (t!=i) close(t);
22 pid = i==3 ? fork() : -1;
26 ioctl(s, TIOCSCTTY, (char *)0);
34 if (istmp[i]) close(i);
36 if (pid < 0) close(*m);