New module 'unlockpt'.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Mar 2010 20:09:06 +0000 (21:09 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Mar 2010 22:19:30 +0000 (23:19 +0100)
ChangeLog
config/srclist.txt
doc/posix-functions/unlockpt.texi
lib/stdlib.in.h
lib/unlockpt.c [new file with mode: 0644]
m4/stdlib_h.m4
m4/unlockpt.m4 [new file with mode: 0644]
modules/stdlib
modules/unlockpt [new file with mode: 0644]
tests/test-stdlib-c++.cc

index 92faf92..94a1f45 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-03-21  Bruno Haible  <bruno@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).
+
 2010-03-21  Jim Meyering  <meyering@redhat.com>
 
        maint.mk: prohibit inclusion of "intprops.h" without use
index 31e7a01..41a65b0 100644 (file)
@@ -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
index 4007ae9..e874cb7 100644 (file)
@@ -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
index 9f30181..3a87245 100644 (file)
@@ -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 (file)
index 0000000..f2becab
--- /dev/null
@@ -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 <zack@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
+}
index 7fe01b5..25c9eb4 100644 (file)
@@ -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 (file)
index 0000000..717c622
--- /dev/null
@@ -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 <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])
+])
index 567a807..26ea709 100644 (file)
@@ -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 (file)
index 0000000..4eadff8
--- /dev/null
@@ -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:
+<stdlib.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index f9ea700..c69b35f 100644 (file)
@@ -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