These functions, derived from BSD, are available in the separate `libutil' library, and declared in `pty.h'.
*name. If termp is not a null pointer,
the terminal attributes of the slave are set to the ones specified in
the structure that termp points to (see section Terminal Modes).
Likewise, if the winp is not a null pointer, the screen size of
the slave is set to the values specified in the structure that
winp points to.
The normal return value from openpty is @math{0}; a value of
@math{-1} is returned in case of failure. The following errno
conditions are defined for this function:
ENOENT
Warning: Using the openpty function with name not
set to NULL is very dangerous because it provides no
protection against overflowing the string name. You should use
the ttyname function on the file descriptor returned in
*slave to find out the file name of the slave pseudo-terminal
device instead.
openpty function, but in
addition, forks a new process (see section Creating a Process) and makes the
newly opened slave pseudo-terminal device the controlling terminal
(see section Controlling Terminal of a Process) for the child process.
If the operation is successful, there are then both parent and child
processes and both see forkpty return, but with different values:
it returns a value of @math{0} in the child process and returns the child's
process ID in the parent process.
If the allocation of a pseudo-terminal pair or the process creation
failed, forkpty returns a value of @math{-1} in the parent
process.
Warning: The forkpty function has the same problems with
respect to the name argument as openpty.
Go to the first, previous, next, last section, table of contents.