The grantpt, ptsname, unlockpt, and posix_openpt functions allow access to pseudo-terminal devices. The first three functions accept a file descriptor that references the master half of a pseudo-terminal pair. This file descriptor is created with posix_openpt.
The grantpt function is used to establish ownership and permissions of the slave device counterpart to the master device specified with fildes. The slave devices ownership is set to the real user ID of the calling process, and the permissions are set to user readable-writable and group writable. The group owner of the slave device is also set to the group "tty" if it exists on the system; otherwise, it is left untouched.
The ptsname function returns the full pathname of the slave device counterpart to the master device specified with fildes. This value can be used to subsequently open the appropriate slave after posix_openpt and grantpt have been called.
The unlockpt function clears the lock held on the pseudo-terminal pair for the master device specified with fildes.
The posix_openpt function opens the first available master pseudo-terminal device and returns a descriptor to it. The mode argument specifies the flags used for opening the device: