Add pty module for forkpty and openpty.
authorSimon Josefsson <simon@josefsson.org>
Thu, 10 Dec 2009 13:14:13 +0000 (14:14 +0100)
committerSimon Josefsson <simon@josefsson.org>
Thu, 10 Dec 2009 13:14:13 +0000 (14:14 +0100)
ChangeLog
doc/glibc-functions/forkpty.texi
doc/glibc-functions/openpty.texi
doc/glibc-headers/pty.texi
m4/pty.m4 [new file with mode: 0644]
modules/pty [new file with mode: 0644]
modules/pty-tests [new file with mode: 0644]
tests/test-pty.c [new file with mode: 0644]

index 1af0983..48019d0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-12-07  Simon Josefsson  <simon@josefsson.org>
+
+       * modules/pty: New file.
+       * modules/pty-tests: New file.
+       * m4/pty.m4: New file.
+       * tests/test-pty.c: New file.
+       * doc/glibc-headers/pty.texi: Modified.
+       * doc/glibc-functions/forkpty.texi: Modified.
+       * doc/glibc-functions/openpty.texi: Modified.
+
 2009-12-09  Bruno Haible  <bruno@clisp.org>
 
        Avoid syntax error in C++ mode.
index 2ea9b22..7701a38 100644 (file)
@@ -2,14 +2,10 @@
 @subsection @code{forkpty}
 @findex forkpty
 
-Gnulib module: ---
+Gnulib module: pty
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 One some systems (at least including Cygwin, Interix, OSF/1 4 and 5,
 and Mac OS X) linking with @code{-lutil} is not required.
@@ -21,3 +17,9 @@ The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
 and glibc.  It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
 It is declared in libutil.h on FreeBSD.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+On some systems (at least including Solaris and HP-UX) the function is
+missing.
+@end itemize
index 79b6b33..83975a9 100644 (file)
@@ -2,14 +2,10 @@
 @subsection @code{openpty}
 @findex openpty
 
-Gnulib module: ---
+Gnulib module: pty
 
 Portability problems fixed by Gnulib:
 @itemize
-@end itemize
-
-Portability problems not fixed by Gnulib:
-@itemize
 @item
 One some systems (at least including Cygwin, Interix, OSF/1 4 and 5,
 and Mac OS X) linking with @code{-lutil} is not required.
@@ -21,3 +17,10 @@ The function is declared in pty.h on Cygwin, Interix, OSF/1 4 and 5,
 and glibc.  It is declared in util.h on Mac OS X, OpenBSD and NetBSD.
 It is declared in libutil.h on FreeBSD.
 @end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@item
+On some systems (at least including Solaris and HP-UX) the function is
+missing.
+@end itemize
index 26d7764..4e6884b 100644 (file)
@@ -16,15 +16,20 @@ Documentation:
 @uref{http://www.kernel.org/doc/man-pages/online/pages/man3/openpty.3.html,,man openpty}.
 @end itemize
 
-Gnulib module: ---
+Gnulib module: pty
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This header file is missing on some platforms that declare the
+@code{forkpty} and @code{openpty} functions in @code{util.h} or
+@code{libutil.h} instead: MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0,
+OpenBSD 3.8.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
 This header file is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw, BeOS.
+AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 10, mingw, BeOS.
 @end itemize
diff --git a/m4/pty.m4 b/m4/pty.m4
new file mode 100644 (file)
index 0000000..ba6a8c0
--- /dev/null
+++ b/m4/pty.m4
@@ -0,0 +1,42 @@
+# pty.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# gl_PTY
+# ------
+# Make sure that pty.h provides forkpty, or sets up a replacement header.
+# Also define automake variable PTY_LIB to the library needed (if any).
+AC_DEFUN([gl_PTY],
+[
+  PTY_H=''
+  PTY_LIB=''
+  # First make sure that pty.h provides forkpty, or setup the replacement.
+  AC_CHECK_HEADERS_ONCE([pty.h])
+  if test $ac_cv_header_pty_h != yes; then
+    AC_CHECK_DECL([forkpty],,, [[#include <util.h>]])
+    if test $ac_cv_have_decl_forkpty = no; then
+      AC_CHECK_DECL([forkpty],,, [[#include <libutil.h>]])
+      if test $ac_cv_have_decl_forkpty = no; then
+        AC_MSG_WARN([[Cannot find forkpty, build will likely fail]])
+      else
+        PTY_H='pty.h'
+       PTY_HEADER='libutil.h'
+      fi
+    else
+      PTY_H='pty.h'
+      PTY_HEADER='util.h'
+    fi
+  fi
+  # Second check for the library required for forkpty.
+  save_LIBS="$LIBS"
+  AC_SEARCH_LIBS([forkpty], [util],
+    [if test "$ac_cv_search_forkpty" != "none required"; then
+       PTY_LIB="$ac_cv_search_forkpty"
+     fi])
+  LIBS="$save_LIBS"
+  AC_SUBST([PTY_H])
+  AC_SUBST([PTY_LIB])
+  AC_SUBST([PTY_HEADER])
+])
diff --git a/modules/pty b/modules/pty
new file mode 100644 (file)
index 0000000..66cecef
--- /dev/null
@@ -0,0 +1,33 @@
+Description:
+A <pty.h> for systems that lacks it.
+
+Files:
+m4/pty.m4
+
+configure.ac:
+gl_PTY
+
+Makefile.am:
+BUILT_SOURCES += $(PTY_H)
+
+# We need the following in order to create <pty.h> when the system
+# doesn't have one that works with the given compiler.
+pty.h:
+       $(AM_V_GEN)rm -f $@-t $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         echo '#include <'$(PTY_HEADER)'>'; \
+       } > $@-t && \
+       mv -f $@-t $@
+MOSTLYCLEANFILES += pty.h pty.h-t
+
+Include:
+<pty.h>
+
+Link:
+$(PTY_LIB)
+
+License:
+LGPL
+
+Maintainer:
+Simon Josefsson
diff --git a/modules/pty-tests b/modules/pty-tests
new file mode 100644 (file)
index 0000000..2d8b9c3
--- /dev/null
@@ -0,0 +1,7 @@
+Files:
+tests/test-pty.c
+
+Makefile.am:
+TESTS += test-pty
+check_PROGRAMS += test-pty
+test_pty_LDADD = $(PTY_LIB)
diff --git a/tests/test-pty.c b/tests/test-pty.c
new file mode 100644 (file)
index 0000000..cd24f0d
--- /dev/null
@@ -0,0 +1,55 @@
+/* Test of pty.h and openpty/forkpty functions.
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Simon Josefsson <simon@josefsson.org>, 2009.  */
+
+#include <config.h>
+
+#include <pty.h>
+
+#include <stdio.h>
+
+int
+main ()
+{
+  int res;
+  int amaster;
+  int aslave;
+
+  res = openpty (&amaster, &aslave, NULL, NULL, NULL);
+  if (res != 0)
+    {
+      printf ("openpty returned %d\n", res);
+      return 1;
+    }
+
+  res = forkpty (&amaster, NULL, NULL, NULL);
+  if (res == 0)
+    {
+      /* child process */
+    }
+  else if (res > 0)
+    {
+      /* parent */
+    }
+  else
+    {
+      printf ("forkpty returned %d\n", res);
+      return 1;
+    }
+
+  return 0;
+}