POSIX_OPENPT(3) | Library Functions Manual | POSIX_OPENPT(3) |
posix_openpt
—
#include <stdlib.h>
#include <fcntl.h>
int
posix_openpt
(int
oflag);
posix_openpt
() function searches for an unused
master pseudo-terminal device, opens it, and returns a file descriptor
associated with the now used pseudo-terminal device. The
oflag argument has the same meaning as in the
open(2) call.
posix_openpt
() returns a non-negative
integer, which corresponds to a file descriptor pointing to the master
pseudo-terminal device. Otherwise, a value of -1 is returned and
errno is set to indicate the error.
Note that unlike implementations on some other operating systems,
posix_openpt
() does not return
EINVAL
if a flag supplied in
oflag would be deemed invalid, instead it is simply
ignored. This means it is not possible to dynamically test which
open(2) flags are possible to
set, and apply a fallback if EINVAL
is received.
However, this is unlikely to be a concern in practice, as flags such as
O_NONBLOCK
and O_CLOEXEC
are
supported.
int posix_openpt(int oflag) { return open("/dev/ptmx", oflag); }
posix_openpt
() function conforms to
IEEE Std 1003.1-2001 (“POSIX.1”).
November 15, 2022 | NetBSD 10.0 |