* 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>
+ 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.
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
--- /dev/null
+/* 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
+}
#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 */
--- /dev/null
+# 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], [
+ :
+])
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],
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])
])
--- /dev/null
+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
Depends-on:
include_next
+c++defs
+warn-on-use
configure.ac:
gl_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 $@
#include "signature.h"
+#if GNULIB_TEST_TCGETSID
+SIGNATURE_CHECK (GNULIB_NAMESPACE::tcgetsid, pid_t, (int));
+#endif
+
+
int
main ()
{