Mercurial > hg > octave-nkf > gnulib-hg
changeset 12419:c043358e3949
Add pty module for forkpty and openpty.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Thu, 10 Dec 2009 14:14:13 +0100 |
parents | be5edb878c7a |
children | 5850b9a81029 |
files | ChangeLog doc/glibc-functions/forkpty.texi doc/glibc-functions/openpty.texi doc/glibc-headers/pty.texi m4/pty.m4 modules/pty modules/pty-tests tests/test-pty.c |
diffstat | 8 files changed, 169 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/doc/glibc-functions/forkpty.texi +++ b/doc/glibc-functions/forkpty.texi @@ -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 @@ 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
--- a/doc/glibc-functions/openpty.texi +++ b/doc/glibc-functions/openpty.texi @@ -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 @@ 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
--- a/doc/glibc-headers/pty.texi +++ b/doc/glibc-headers/pty.texi @@ -16,15 +16,20 @@ @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
new file mode 100644 --- /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]) +])
new file mode 100644 --- /dev/null +++ b/modules/pty @@ -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
new file mode 100644 --- /dev/null +++ b/modules/pty-tests @@ -0,0 +1,7 @@ +Files: +tests/test-pty.c + +Makefile.am: +TESTS += test-pty +check_PROGRAMS += test-pty +test_pty_LDADD = $(PTY_LIB)
new file mode 100644 --- /dev/null +++ b/tests/test-pty.c @@ -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; +}