p
The
.Fn openpty
function finds an available pseudo-tty and returns file descriptors
for the master and slave in
.Fa amaster
and
.Fa aslave .
If
.Fa name
is non-null, the filename of the slave is returned in
.Fa name .
The length of
.Fa name
is limited to
.Dv PATH_MAX
as any other regular path name, so a buffer of this size should be used.
.Dv 16
characters in the current
.Xr ptm 4
device driver (including the terminating
.Dv NUL )
which limits the maximum to
.Dv 100,000
ptys.
If
.Fa termp
is non-null, the terminal parameters of the slave will be set to the
values in
.Fa termp .
If
.Fa winp
is non-null, the window size of the slave will be set to the values in
.Fa winp .
p The .Fn login_tty function prepares for a login on the tty .Fa fd (which may be a real tty device, or the slave of a pseudo-tty as returned by .Fn openpty ) by creating a new session, making .Fa fd the controlling terminal for the current process, setting .Fa fd to be the standard input, output, and error streams of the current process, and closing .Fa fd .
p The .Fn forkpty function combines .Fn openpty , .Fn fork , and .Fn login_tty to create a new process operating in a pseudo-tty. The file descriptor of the master side of the pseudo-tty is returned (to the parent process only) in .Fa amaster . The filename of the slave is returned (to both the parent and child processes) in .Fa name if .Fa name is non-null. The .Fa termp and .Fa winp parameters, if non-null, will determine the terminal attributes and window size of the slave side of the pseudo-tty. .Sh RETURN VALUES If a call to .Fn openpty , .Fn login_tty , or .Fn forkpty is not successful, -1 is returned and .Va errno is set to indicate the error. Otherwise, .Fn openpty , .Fn login_tty , and the child process of .Fn forkpty return 0, and the parent process of .Fn forkpty returns the process ID of the child process. .Sh FILES l -tag -width /dev/[pt]ty[p-zP-T][0-9a-zA-Z] -compact t Pa /dev/[pt]ty[p-zP-T][0-9a-zA-Z] .El .Sh ERRORS .Fn openpty will fail if: l -tag -width Er t Bq Er ENOENT There are no available ttys. t Bq Er EPERM The caller was not the superuser and the .Xr ptm 4 device is missing or not configured. .El
p .Fn login_tty will fail if .Fn ioctl fails to set .Fa fd to the controlling terminal of the current process. .Fn forkpty will fail if either .Fn openpty or .Fn fork fails. .Sh SEE ALSO .Xr fork 2