From 12e334402dda8c5989c395949ed4a6d1311ca56d Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 17 Sep 2010 03:16:53 +0200 Subject: [PATCH] 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 . (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 | 22 ++++++++++++++++++++ doc/posix-functions/tcgetsid.texi | 8 +++++--- lib/tcgetsid.c | 42 +++++++++++++++++++++++++++++++++++++++ lib/termios.in.h | 28 ++++++++++++++++++++++++++ m4/tcgetsid.m4 | 25 +++++++++++++++++++++++ m4/termios_h.m4 | 9 +++++++++ modules/tcgetsid | 27 +++++++++++++++++++++++++ modules/termios | 8 +++++++- tests/test-termios-c++.cc | 5 +++++ 9 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 lib/tcgetsid.c create mode 100644 m4/tcgetsid.m4 create mode 100644 modules/tcgetsid diff --git a/ChangeLog b/ChangeLog index 26b850512..d86265a15 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,27 @@ 2010-09-16 Bruno Haible + 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 . + (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 + + 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. diff --git a/doc/posix-functions/tcgetsid.texi b/doc/posix-functions/tcgetsid.texi index 2d23e5551..5e1a43bb8 100644 --- a/doc/posix-functions/tcgetsid.texi +++ b/doc/posix-functions/tcgetsid.texi @@ -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 index 000000000..3bf91c84e --- /dev/null +++ b/lib/tcgetsid.c @@ -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 + +#define USE_OLD_TTY /* needed on OpenBSD 4.5, so that TIOCGSID gets defined */ + +/* Specification. */ +#include + +#include +#include + +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 +} diff --git a/lib/termios.in.h b/lib/termios.in.h index 2873bfe3b..a23c5dc1f 100644 --- a/lib/termios.in.h +++ b/lib/termios.in.h @@ -27,8 +27,36 @@ #ifndef _GL_TERMIOS_H #define _GL_TERMIOS_H +#if @GNULIB_TCGETSID@ +/* Get pid_t. */ +# include +#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 index 000000000..11dcc3d59 --- /dev/null +++ b/m4/tcgetsid.m4 @@ -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 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], [ + : +]) diff --git a/m4/termios_h.m4 b/m4/termios_h.m4 index 762151a29..d6b3c062e 100644 --- a/m4/termios_h.m4 +++ b/m4/termios_h.m4 @@ -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 ]], + [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 index 000000000..1b72c8d43 --- /dev/null +++ b/modules/tcgetsid @@ -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: + + +License: +LGPL + +Maintainer: +Bruno Haible diff --git a/modules/termios b/modules/termios index e2deddbd8..e24a8c15c 100644 --- a/modules/termios +++ b/modules/termios @@ -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 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 $@ diff --git a/tests/test-termios-c++.cc b/tests/test-termios-c++.cc index e2ea11a1d..31a5e6536 100644 --- a/tests/test-termios-c++.cc +++ b/tests/test-termios-c++.cc @@ -24,6 +24,11 @@ #include "signature.h" +#if GNULIB_TEST_TCGETSID +SIGNATURE_CHECK (GNULIB_NAMESPACE::tcgetsid, pid_t, (int)); +#endif + + int main () { -- 2.11.0