The next piece of openpty is the unlockpt() function. This one is easier, because on many systems, it does not need to do anything.
2010-03-21 Bruno Haible <br...@clisp.org> 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). =============================== lib/unlockpt.c =============================== /* Unlock the slave side of a pseudo-terminal from its master side. Copyright (C) 1998, 2010 Free Software Foundation, Inc. Contributed by Zack Weinberg <z...@rabi.phys.columbia.edu>, 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 <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdlib.h> #include <unistd.h> 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 } =============================== m4/unlockpt.m4 =============================== # 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 <stdlib.h> 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]) ]) ============================== modules/unlockpt ============================== 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: <stdlib.h> License: LGPL Maintainer: Bruno Haible ============================================================================== --- lib/stdlib.in.h.orig Sun Mar 21 20:46:09 2010 +++ lib/stdlib.in.h Sun Mar 21 20:22:45 2010 @@ -638,6 +638,22 @@ # 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@ --- m4/stdlib_h.m4.orig Sun Mar 21 20:46:09 2010 +++ m4/stdlib_h.m4 Sun Mar 21 20:24:13 2010 @@ -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 @@ #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 @@ 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 @@ 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]) --- modules/stdlib.orig Sun Mar 21 20:46:09 2010 +++ modules/stdlib Sun Mar 21 20:24:42 2010 @@ -50,6 +50,7 @@ -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 @@ -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' \ --- doc/posix-functions/unlockpt.texi.orig Sun Mar 21 20:46:09 2010 +++ doc/posix-functions/unlockpt.texi Sun Mar 21 20:18:31 2010 @@ -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 --- tests/test-stdlib-c++.cc.orig Sun Mar 21 20:46:09 2010 +++ tests/test-stdlib-c++.cc Sun Mar 21 20:25:07 2010 @@ -135,6 +135,10 @@ (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 --- config/srclist.txt.orig Sun Mar 21 20:46:09 2010 +++ config/srclist.txt Sun Mar 21 20:41:15 2010 @@ -217,6 +217,7 @@ #$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