$NetBSD: patch-ab,v 1.1 2006/02/19 01:28:53 heinz Exp $

--- Tty.xs.orig	2002-03-06 14:47:32.000000000 +0100
+++ Tty.xs
@@ -300,6 +300,23 @@ open_slave(int *ptyfd, int *ttyfd, char 
 	    if (PL_dowarn)
 		warn("IO::Tty::pty_allocate(nonfatal): grantpt(): %.100s", strerror(errno));
 	}
+
+#if defined(__NetBSD__)
+	/* NetBSD >= 3.0 supports grantpt() but it invalidates the slave
+	   FD (see grantpt(3) on NetBSD) obtained through openpty().
+	   The slave device will be opened again below.
+	 */
+	*ttyfd = -1;
+
+	/* The issue should be really fixed by using posix_openpt() instead of
+	   openpty(). The functions posix_openpt(), grantpt(), unlockpt()
+	   and ptsname() belong together and should be used ahead of
+	   all the other ways to create the master and slave tty, not just
+	   on NetBSD. See also
+	   http://www.opengroup.org/onlinepubs/009695399/functions/posix_openpt.html
+	 */
+#endif
+
 #endif /* HAVE_GRANTPT */
 #if defined(HAVE_UNLOCKPT)
 #if PTY_DEBUG
