From e6c527d59af1fd07e33830f72c8c93e31cfd3738 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 21 Mar 2010 21:09:06 +0100 Subject: [PATCH] New module 'unlockpt'. --- ChangeLog | 15 ++++++++++++++ config/srclist.txt | 1 + doc/posix-functions/unlockpt.texi | 8 ++++---- lib/stdlib.in.h | 16 +++++++++++++++ lib/unlockpt.c | 41 +++++++++++++++++++++++++++++++++++++++ m4/stdlib_h.m4 | 7 +++++-- m4/unlockpt.m4 | 25 ++++++++++++++++++++++++ modules/stdlib | 2 ++ modules/unlockpt | 27 ++++++++++++++++++++++++++ tests/test-stdlib-c++.cc | 4 ++++ 10 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 lib/unlockpt.c create mode 100644 m4/unlockpt.m4 create mode 100644 modules/unlockpt diff --git a/ChangeLog b/ChangeLog index 92faf920e..94a1f45ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2010-03-21 Bruno Haible + + New module 'unlockpt'. + * lib/unlockpt.c: New file, from glibc with modifications. + * m4/unlockpt.m4: New file. + * modules/unlockpt: New file. + * lib/stdlib.in.h (unlockpt): New declaration. + * m4/stdlib_h.m4 (gl_STDLIB_H): Check whether unlockpt is declared. + (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_UNLOCKPT, HAVE_UNLOCKPT. + * modules/stdlib (Makefile.am): Substitute GNULIB_UNLOCKPT, + HAVE_UNLOCKPT. + * doc/posix-functions/unlockpt.texi: Mention the new module. + * tests/test-stdlib-c++.cc: Check GNULIB_NAMESPACE::unlockpt. + * config/srclist.txt: Add unlockpt.c (commented). + 2010-03-21 Jim Meyering maint.mk: prohibit inclusion of "intprops.h" without use diff --git a/config/srclist.txt b/config/srclist.txt index 31e7a01ba..41a65b0a1 100644 --- a/config/srclist.txt +++ b/config/srclist.txt @@ -217,6 +217,7 @@ $LIBCSRC/stdlib/strtoul.c lib gpl #$LIBCSRC/sysdeps/posix/tempname.c lib gpl #$LIBCSRC/sysdeps/unix/bsd/poll.c lib gpl #$LIBCSRC/sysdeps/unix/bsd/ptsname.c lib gpl +#$LIBCSRC/sysdeps/unix/bsd/unlockpt.c lib gpl #$LIBCSRC/sysdeps/unix/dirfd.c lib gpl #$LIBCSRC/sysdeps/unix/grantpt.c lib gpl #$LIBCSRC/sysdeps/unix/rmdir.c lib gpl diff --git a/doc/posix-functions/unlockpt.texi b/doc/posix-functions/unlockpt.texi index 4007ae97e..e874cb735 100644 --- a/doc/posix-functions/unlockpt.texi +++ b/doc/posix-functions/unlockpt.texi @@ -4,15 +4,15 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html} -Gnulib module: --- +Gnulib module: unlockpt Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +MacOS X 10.3, OpenBSD 3.8, mingw, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -MacOS X 10.3, OpenBSD 3.8, mingw, BeOS. @end itemize diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 9f301815b..3a87245eb 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -638,6 +638,22 @@ _GL_WARN_ON_USE (strtoull, "strtoull is unportable - " # endif #endif +#if @GNULIB_UNLOCKPT@ +/* Unlock the slave side of the pseudo-terminal whose master side is specified + by FD, so that it can be opened. */ +# if !@HAVE_UNLOCKPT@ +_GL_FUNCDECL_SYS (unlockpt, int, (int fd)); +# endif +_GL_CXXALIAS_SYS (unlockpt, int, (int fd)); +_GL_CXXALIASWARN (unlockpt); +#elif defined GNULIB_POSIXCHECK +# undef unlockpt +# if HAVE_RAW_DECL_UNLOCKPT +_GL_WARN_ON_USE (ptsname, "unlockpt is not portable - " + "use gnulib module unlockpt for portability"); +# endif +#endif + #if @GNULIB_UNSETENV@ /* Remove the variable NAME from the environment. */ # if @REPLACE_UNSETENV@ diff --git a/lib/unlockpt.c b/lib/unlockpt.c new file mode 100644 index 000000000..f2becab23 --- /dev/null +++ b/lib/unlockpt.c @@ -0,0 +1,41 @@ +/* Unlock the slave side of a pseudo-terminal from its master side. + Copyright (C) 1998, 2010 Free Software Foundation, Inc. + Contributed by Zack Weinberg , 1998. + + 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 . */ + +#include + +#include + +#include + +int +unlockpt (int fd) +{ + /* Platforms which have the TIOCSPTLCK ioctl (Linux) already have the + unlockpt function. */ +#if HAVE_REVOKE + /* MacOS X 10.3, OpenBSD 3.8 do not have the unlockpt function, but they + have revoke(). */ + char *name = ptsname (fd); + if (name == NULL) + return -1; + return revoke (name); +#else + /* Assume that the slave side of a pseudo-terminal is already unlocked + by default. */ + return 0; +#endif +} diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 7fe01b580..25c9eb403 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 25 +# stdlib_h.m4 serial 26 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -35,7 +35,8 @@ AC_DEFUN([gl_STDLIB_H], #endif ]], [atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r - setstate_r realpath rpmatch setenv strtod strtoll strtoull unsetenv]) + setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt + unsetenv]) ]) AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], @@ -71,6 +72,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD]) GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL]) GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL]) + GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT]) GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV]) dnl Assume proper GNU behavior unless another module says otherwise. HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) @@ -95,6 +97,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL]) HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA]) HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H]) + HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT]) HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) diff --git a/m4/unlockpt.m4 b/m4/unlockpt.m4 new file mode 100644 index 000000000..717c6228d --- /dev/null +++ b/m4/unlockpt.m4 @@ -0,0 +1,25 @@ +# unlockpt.m4 serial 1 +dnl Copyright (C) 2010 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. + +AC_DEFUN([gl_FUNC_UNLOCKPT], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc to declare unlockpt(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS([unlockpt]) + if test $ac_cv_func_unlockpt = no; then + HAVE_UNLOCKPT=0 + AC_LIBOBJ([unlockpt]) + gl_PREREQ_UNLOCKPT + fi +]) + +# Prerequisites of lib/unlockpt.c. +AC_DEFUN([gl_PREREQ_UNLOCKPT], [ + AC_CHECK_FUNCS([revoke]) +]) diff --git a/modules/stdlib b/modules/stdlib index 567a80754..26ea709f7 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -50,6 +50,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \ -e 's|@''GNULIB_STRTOLL''@|$(GNULIB_STRTOLL)|g' \ -e 's|@''GNULIB_STRTOULL''@|$(GNULIB_STRTOULL)|g' \ + -e 's|@''GNULIB_UNLOCKPT''@|$(GNULIB_UNLOCKPT)|g' \ -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ @@ -74,6 +75,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_STRTOULL''@|$(HAVE_STRTOULL)|g' \ -e 's|@''HAVE_STRUCT_RANDOM_DATA''@|$(HAVE_STRUCT_RANDOM_DATA)|g' \ -e 's|@''HAVE_SYS_LOADAVG_H''@|$(HAVE_SYS_LOADAVG_H)|g' \ + -e 's|@''HAVE_UNLOCKPT''@|$(HAVE_UNLOCKPT)|g' \ -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ diff --git a/modules/unlockpt b/modules/unlockpt new file mode 100644 index 000000000..4eadff852 --- /dev/null +++ b/modules/unlockpt @@ -0,0 +1,27 @@ +Description: +unlockpt() function: Unlock the slave side of a pseudo-terminal from its master +side. + +Files: +lib/unlockpt.c +m4/unlockpt.m4 + +Depends-on: +stdlib +extensions +ptsname + +configure.ac: +gl_FUNC_UNLOCKPT +gl_STDLIB_MODULE_INDICATOR([unlockpt]) + +Makefile.am: + +Include: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/tests/test-stdlib-c++.cc b/tests/test-stdlib-c++.cc index f9ea7004e..c69b35fc7 100644 --- a/tests/test-stdlib-c++.cc +++ b/tests/test-stdlib-c++.cc @@ -135,6 +135,10 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::strtoull, unsigned long long, (const char *, char **, int)); #endif +#if GNULIB_UNLOCKPT +SIGNATURE_CHECK (GNULIB_NAMESPACE::unlockpt, int, (int)); +#endif + #if GNULIB_UNSETENV SIGNATURE_CHECK (GNULIB_NAMESPACE::unsetenv, int, (const char *)); #endif -- 2.11.0