Use posix_openpt() for creating pseudo TTY pairs

Use posix_openpt() for creating pseudo TTY pairs, rather than depending
on the presence of /dev/ptmx, which is not a portable assumption
This commit is contained in:
XANTRONIX Development 2020-09-02 21:29:57 -04:00 committed by XANTRONIX Industrial
parent 854d3bc9a7
commit 8f3bcc3d41
2 changed files with 6 additions and 2 deletions

View file

@ -51,7 +51,11 @@ int main(int argc, char **argv) {
usage(argc, argv, "Too many arguments provided");
}
if ((info.fd = open(argv[1], O_RDWR)) < 0) {
info.fd = strcmp(argv[1], "/dev/ptmx") == 0?
posix_openpt(O_RDWR | O_NOCTTY):
open(argv[1], O_RDWR | O_NOCTTY);
if (info.fd < 0) {
fprintf(stderr, "%s: %s: %s: %s\n",
argv[0], "open()", argv[1], strerror(errno));

View file

@ -19,7 +19,7 @@ struct slot {
static int bind_pty(patty_ax25_sock *sock) {
char *pty;
if ((sock->fd = open("/dev/ptmx", O_RDWR)) < 0) {
if ((sock->fd = posix_openpt(O_RDWR | O_NOCTTY)) < 0) {
goto error_open;
}