| PTSNAME(3) | Library Functions Manual | PTSNAME(3) |
ptsname, ptsname_r
— get the pathname of the slave pseudo-terminal
device
Standard C Library (libc, -lc)
#include
<stdlib.h>
char *
ptsname(int
masterfd);
int
ptsname_r(int
masterfd, char
*buf, size_t
buflen);
The
ptsname()
function returns the pathname of the slave pseudo-terminal device that
corresponds to the master pseudo-terminal device associated with
masterfd. The ptsname()
function is not reentrant or thread-safe.
The
ptsname_r()
function places the pathname of the slave pseudo-terminal device that
corresponds to the master pseudo-terminal device associated with
masterfd int the buf argument
copying up to buflen characters. The
buf is always NUL
terminated.
If successful, ptsname() returns a pointer
to a nul-terminated string containing the pathname of the slave
pseudo-terminal device. If an error occurs ptsname()
will return NULL and errno is
set to indicate the error.
If successful, ptsname_r() places a
nul-terminated string containing the pathname of the slave pseudo-terminal
device in buf and returns 0.
If an error occurs ptsname_r() will return an error
number indicating what went wrong.
The ptsname() and
ptsname_r() functions will fail if:
EACCESS]EBADF]EINVAL]In addition the ptsname_r() function will
return:
The error returns of
ptsname()
are a NetBSD extension. The
ptsname() function is equivalent to:
static struct ptmget pm; return ioctl(masterfd, TIOCPTSNAME, &pm) == -1 ? NULL : pm.sn;
Both the
ptsname()
and ptsname_r() functions will also return the name
of the slave pseudo-terminal if a file descriptor to the slave
pseudo-terminal is passed to masterfd.
This is a convenient extension because it allows one to use the file descriptor obtained by open(2) /dev/tty to obtain the name of the pseudo-terminal for the current process.
The ptsname() function conforms to
IEEE Std 1003.1-2001 (“POSIX.1”). Its
first release was in X/Open Portability Guide
Issue 4, Version 2 (“XPG4.2”).
| January 2, 2022 | NetBSD 11.0 |