8 /* Nonstandard, but vastly superior to the standard functions */
10 int openpty(int *pm
, int *ps
, char *name
, const struct termios
*tio
, const struct winsize
*ws
)
15 m
= open("/dev/ptmx", O_RDWR
|O_NOCTTY
);
18 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE
, &cs
);
20 if (ioctl(m
, TIOCSPTLCK
, &n
) || ioctl (m
, TIOCGPTN
, &n
))
23 if (!name
) name
= buf
;
24 snprintf(name
, sizeof buf
, "/dev/pts/%d", n
);
25 if ((s
= open(name
, O_RDWR
|O_NOCTTY
)) < 0)
28 if (tio
) tcsetattr(s
, TCSANOW
, tio
);
29 if (ws
) ioctl(s
, TIOCSWINSZ
, ws
);
34 pthread_setcancelstate(cs
, 0);
38 pthread_setcancelstate(cs
, 0);