diff src/s/gnu.h @ 365:30d2cfa1092a r21-1-12

Import from CVS: tag r21-1-12
author cvs
date Mon, 13 Aug 2007 11:00:12 +0200
parents c5d627a313b1
children a4f53d9b3154
line wrap: on
line diff
--- a/src/s/gnu.h	Mon Aug 13 10:59:30 2007 +0200
+++ b/src/s/gnu.h	Mon Aug 13 11:00:12 2007 +0200
@@ -50,3 +50,49 @@
 #ifndef NOT_C_CODE
 #include <fcntl.h>
 #endif
+
+#if defined(HAVE_GRANTPT) && defined(HAVE_UNLOCKPT) && defined(HAVE_PTSNAME)
+/* UNIX98 PTYs are available.
+   Added by Florian Weimer <Florian.Weimer@RUS.Uni-Stuttgart.DE>,
+   RUS-CERT, University of Stuttgart.  Based on Emacs code for DGUX. */
+
+#define PTY_ITERATION for (i = 0; i < 1; i++)
+/* no iteration at all */
+
+/* Use getpt() if it's available, because it provides Unix98 PTY
+   emulation for kernels which doesn't support it natively. */
+
+#ifdef HAVE_GETPT
+#define PTY_OPEN                                 \
+  do {                                           \
+    fd = getpt();                             \
+    if (fcntl (fd, F_SETFL, O_NDELAY) == -1)  \
+      fatal ("could not set master PTY to non-block mode"); \
+  } while (0)
+
+#else
+/* the master PTY device */
+#define PTY_NAME_SPRINTF strcpy (pty_name, "/dev/ptmx");
+#endif
+
+/* This sets the name of the slave side of the PTY.  grantpt(3) and
+   unlockpt(3) may fork a subprocess, so keep sigchld_handler() from
+   intercepting that death. */
+
+#define PTY_TTY_NAME_SPRINTF			\
+  {						\
+    char *ptsname(), *ptyname;			\
+						\
+    sigblock(sigmask(SIGCHLD));			\
+    if (grantpt(fd) == -1)			\
+      fatal("could not grant slave pty");	\
+    if (unlockpt(fd) == -1)			\
+      fatal("could not unlock slave pty");	\
+    if (!(ptyname = ptsname(fd)))		\
+      fatal ("could not enable slave pty");	\
+    strncpy(pty_name, ptyname, sizeof(pty_name)); \
+    pty_name[sizeof(pty_name) - 1] = 0;		\
+    sigsetmask(siggetmask() & ~sigmask(SIGCHLD));	\
+  }
+
+#endif