New module 'tcgetsid'.
authorBruno Haible <bruno@clisp.org>
Fri, 17 Sep 2010 01:16:53 +0000 (03:16 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 17 Sep 2010 01:16:53 +0000 (03:16 +0200)
* lib/tcgetsid.c: New file.
* m4/tcgetsid.m4: New file.
* modules/tcgetsid: New file.
* modules/termios (Depends-on): Add c++defs, warn-on-use.
(Makefile.am): Ensure c++defs.h, warn-on-use.h get included. Substitute
GNULIB_TCGETSID, HAVE_TCGETSID.
* lib/termios.in.h: Include <sys/types.h>.
(tcgetsid): New declaration.
* m4/termios_h.m4 (gl_TERMIOS_H): Check whether tcgetsid is declared.
(gl_TERMIOS_H_DEFAULTS): Initialize GNULIB_TCGETSID, HAVE_TCGETSID.
* doc/posix-functions/tcgetsid.texi: Mention the new module.
* tests/test-termios-c++.cc: Check GNULIB_NAMESPACE::tcgetsid.

ChangeLog
doc/posix-functions/tcgetsid.texi
lib/tcgetsid.c [new file with mode: 0644]
lib/termios.in.h
m4/tcgetsid.m4 [new file with mode: 0644]
m4/termios_h.m4
modules/tcgetsid [new file with mode: 0644]
modules/termios
tests/test-termios-c++.cc

index 26b8505..d86265a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,27 @@
 2010-09-16  Bruno Haible  <bruno@clisp.org>
 
+       New module 'tcgetsid'.
+       * lib/tcgetsid.c: New file.
+       * m4/tcgetsid.m4: New file.
+       * modules/tcgetsid: New file.
+       * modules/termios (Depends-on): Add c++defs, warn-on-use.
+       (Makefile.am): Ensure c++defs.h, warn-on-use.h get included. Substitute
+       GNULIB_TCGETSID, HAVE_TCGETSID.
+       * lib/termios.in.h: Include <sys/types.h>.
+       (tcgetsid): New declaration.
+       * m4/termios_h.m4 (gl_TERMIOS_H): Check whether tcgetsid is declared.
+       (gl_TERMIOS_H_DEFAULTS): Initialize GNULIB_TCGETSID, HAVE_TCGETSID.
+       * doc/posix-functions/tcgetsid.texi: Mention the new module.
+       * tests/test-termios-c++.cc: Check GNULIB_NAMESPACE::tcgetsid.
+
+2010-09-16  Bruno Haible  <bruno@clisp.org>
+
+       Tests for module 'termios'.
+       * modules/termios-c++-tests: New file.
+       * modules/termios-tests: New file.
+       * tests/test-termios-c++.cc: New file.
+       * tests/test-termios.c: New file.
+
        New module 'termios'.
        * modules/termios: New file.
        * lib/termios.in.h: New file.
index 2d23e55..5e1a43b 100644 (file)
@@ -4,15 +4,17 @@
 
 POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html}
 
-Gnulib module: ---
+Gnulib module: tcgetsid
 
 Portability problems fixed by Gnulib:
 @itemize
+This function is missing on some platforms:
+MacOS X 10.3, FreeBSD 6.0, OpenBSD 4.5, Cygwin, mingw, Interix 3.5, BeOS.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-MacOS X 10.3, FreeBSD 6.0, OpenBSD 3.8, Cygwin, mingw, Interix 3.5, BeOS.
+This function always fails on some platforms:
+FreeBSD 6.0, Cygwin, mingw, Interix 3.5, BeOS.
 @end itemize
diff --git a/lib/tcgetsid.c b/lib/tcgetsid.c
new file mode 100644 (file)
index 0000000..3bf91c8
--- /dev/null
@@ -0,0 +1,42 @@
+/* Determine the session ID of the controlling terminal of the current process.
+   Copyright (C) 2010 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 2, 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, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#define USE_OLD_TTY /* needed on OpenBSD 4.5, so that TIOCGSID gets defined */
+
+/* Specification.  */
+#include <termios.h>
+
+#include <errno.h>
+#include <sys/ioctl.h>
+
+pid_t
+tcgetsid (int fd)
+{
+#ifdef TIOCGSID /* MacOS X, OpenBSD */
+  int sid;
+
+  if (ioctl (fd, TIOCGSID, &sid) < 0)
+    return -1; /* errno is set here */
+
+  return sid;
+#else /* FreeBSD, Cygwin, mingw */
+  errno = ENOSYS;
+  return -1;
+#endif
+}
index 2873bfe..a23c5dc 100644 (file)
 #ifndef _GL_TERMIOS_H
 #define _GL_TERMIOS_H
 
+#if @GNULIB_TCGETSID@
+/* Get pid_t.  */
+# include <sys/types.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
 
 /* Declare overridden functions.  */
 
+#if @GNULIB_TCGETSID@
+/* Return the session ID of the controlling terminal of the current process.
+   The argument is a descriptor if this controlling terminal.
+   Return -1, with errno set, upon failure.  errno = ENOSYS means that the
+   function is unsupported.  */
+# if !@HAVE_TCGETSID@
+_GL_FUNCDECL_SYS (tcgetsid, pid_t, (int fd));
+# endif
+_GL_CXXALIAS_SYS (tcgetsid, pid_t, (int fd));
+_GL_CXXALIASWARN (tcgetsid);
+#elif defined GNULIB_POSIXCHECK
+# undef tcgetsid
+# if HAVE_RAW_DECL_TCGETSID
+_GL_WARN_ON_USE (tcgetsid, "tcgetsid is not portable - "
+                 "use gnulib module tcgetsid for portability");
+# endif
+#endif
+
+
 #endif /* _GL_TERMIOS_H */
 #endif /* _GL_TERMIOS_H */
diff --git a/m4/tcgetsid.m4 b/m4/tcgetsid.m4
new file mode 100644 (file)
index 0000000..11dcc3d
--- /dev/null
@@ -0,0 +1,25 @@
+# tcgetsid.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_TCGETSID],
+[
+  AC_REQUIRE([gl_TERMIOS_H_DEFAULTS])
+
+  dnl Persuade glibc <termios.h> to declare tcgetsid().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS([tcgetsid])
+  if test $ac_cv_func_tcgetsid = no; then
+    HAVE_TCGETSID=0
+    AC_LIBOBJ([tcgetsid])
+    gl_PREREQ_TCGETSID
+  fi
+])
+
+# Prerequisites of lib/tcgetsid.c.
+AC_DEFUN([gl_PREREQ_TCGETSID], [
+  :
+])
index 762151a..d6b3c06 100644 (file)
@@ -11,6 +11,12 @@ AC_DEFUN([gl_TERMIOS_H],
   AC_REQUIRE([gl_TERMIOS_H_DEFAULTS])
 
   gl_CHECK_NEXT_HEADERS([termios.h])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use, and which is not
+  dnl guaranteed by C89.
+  gl_WARN_ON_USE_PREPARE([[#include <termios.h>]],
+    [tcgetsid])
 ])
 
 AC_DEFUN([gl_TERMIOS_MODULE_INDICATOR],
@@ -24,4 +30,7 @@ AC_DEFUN([gl_TERMIOS_MODULE_INDICATOR],
 
 AC_DEFUN([gl_TERMIOS_H_DEFAULTS],
 [
+  GNULIB_TCGETSID=0;      AC_SUBST([GNULIB_TCGETSID])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_TCGETSID=1;        AC_SUBST([HAVE_TCGETSID])
 ])
diff --git a/modules/tcgetsid b/modules/tcgetsid
new file mode 100644 (file)
index 0000000..1b72c8d
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+tcgetsid() function: Determine the session ID of the controlling terminal of
+the current process.
+
+Files:
+lib/tcgetsid.c
+m4/tcgetsid.m4
+
+Depends-on:
+termios
+extensions
+sys_ioctl
+
+configure.ac:
+gl_FUNC_TCGETSID
+gl_TERMIOS_MODULE_INDICATOR([tcgetsid])
+
+Makefile.am:
+
+Include:
+<termios.h>
+
+License:
+LGPL
+
+Maintainer:
+Bruno Haible
index e2deddb..e24a8c1 100644 (file)
@@ -7,6 +7,8 @@ m4/termios_h.m4
 
 Depends-on:
 include_next
+c++defs
+warn-on-use
 
 configure.ac:
 gl_TERMIOS_H
@@ -16,12 +18,16 @@ BUILT_SOURCES += termios.h
 
 # We need the following in order to create <termios.h> when the system
 # version does not have all declarations.
-termios.h: termios.in.h
+termios.h: termios.in.h $(CXXDEFS_H) $(WARN_ON_USE_H)
        $(AM_V_GEN)rm -f $@-t $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
          sed -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_TERMIOS_H''@|$(NEXT_TERMIOS_H)|g' \
+             -e 's|@''GNULIB_TCGETSID''@|$(GNULIB_TCGETSID)|g' \
+             -e 's|@''HAVE_TCGETSID''@|$(HAVE_TCGETSID)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
            < $(srcdir)/termios.in.h; \
        } > $@-t && \
        mv $@-t $@
index e2ea11a..31a5e65 100644 (file)
 #include "signature.h"
 
 
+#if GNULIB_TEST_TCGETSID
+SIGNATURE_CHECK (GNULIB_NAMESPACE::tcgetsid, pid_t, (int));
+#endif
+
+
 int
 main ()
 {