grantpt() — Grant access to the slave pseudoterminal device
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE_EXTENDED 1
#include <stdlib.h>
int grantpt(int fildes);
General description
The grantpt() function changes the mode and ownership of the slave pseudoterminal device. fildes should be the file descriptor of the corresponding master pseudoterminal. The user ID of the slave is set to the real UID of the calling process and the group ID is set to the group ID associated with the group name specified by the installation in the TTYGROUP() initialization parameter. The permission mode of the slave pseudoterminal is set to readable and writable by the owner, and writable by the group.
You can provide secure connections by either using grantpt() and unlockpt(), or by simply issuing the first open against the slave pseudoterminal from the first userid or process that opened the master terminal.
Returned value
If successful, grantpt() returns 0.
- Error Code
- Description
- EACCES
- The slave pseudoterminal was opened before grantpt(), or a grantpt() was already issued. In either case, slave pseudoterminal permissions and ownership have already been updated. If you use grantpt() to change slave pseudoterminal permissions, you must issue grantpt() between the master open and the first pseudoterminal open, and grantpt() can only be issued once.
- EBADF
- The fildes argument is not a valid open file descriptor.
- EINVAL
- The fildes argument is not associated with a master pseudoterminal device.
- ENOENT
- The slave pseudoterminal device was not found during lookup.