Mercurial > hg > octave-lyh > gnulib-hg
changeset 13689:af3a7152efba
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.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 17 Sep 2010 03:16:53 +0200 |
parents | 045fc677dc80 |
children | 4a7853b78e64 |
files | ChangeLog doc/posix-functions/tcgetsid.texi lib/tcgetsid.c lib/termios.in.h m4/tcgetsid.m4 m4/termios_h.m4 modules/tcgetsid modules/termios tests/test-termios-c++.cc |
diffstat | 9 files changed, 170 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- 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
new file mode 100644 --- /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 <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 +}
--- 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 <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 */
new file mode 100644 --- /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 <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], [ + : +])
--- a/m4/termios_h.m4 +++ b/m4/termios_h.m4 @@ -11,6 +11,12 @@ 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_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]) ])
new file mode 100644 --- /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: +<termios.h> + +License: +LGPL + +Maintainer: +Bruno Haible
--- a/modules/termios +++ b/modules/termios @@ -7,6 +7,8 @@ Depends-on: include_next +c++defs +warn-on-use configure.ac: gl_TERMIOS_H @@ -16,12 +18,16 @@ # 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 $@