chown(pty->name, getuid(), gp ? gp->gr_gid : -1);
chmod(pty->name, 0600);
#else
- pty->master_fd = open("/dev/ptmx", O_RDWR);
+
+ const int flags = O_RDWR
+#ifdef O_NOCTTY
+ | O_NOCTTY
+#endif
+ ;
+
+#ifdef HAVE_POSIX_OPENPT
+ pty->master_fd = posix_openpt(flags);
+
+ if (pty->master_fd < 0) {
+ perror("posix_openpt");
+ exit(1);
+ }
+#else
+ pty->master_fd = open("/dev/ptmx", flags);
if (pty->master_fd < 0) {
perror("/dev/ptmx: open");
exit(1);
}
+#endif
if (grantpt(pty->master_fd) < 0) {
perror("grantpt");