[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
new module 'tcgetsid'
From: |
Bruno Haible |
Subject: |
new module 'tcgetsid' |
Date: |
Fri, 17 Sep 2010 03:17:45 +0200 |
User-agent: |
KMail/1.9.9 |
Here comes the module 'tcgetsid'. Its main use is that on OpenBSD and
MacOS X 10.3 the functionality is available through an ioctl() but
the function is not present in libc.
Note that tcgetsid(fd) is sometimes, but not always, the same as tcgetpgrp(fd).
2010-09-16 Bruno Haible <address@hidden>
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.
=============================== lib/tcgetsid.c ===============================
/* 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
}
=============================== m4/tcgetsid.m4 ===============================
# 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], [
:
])
============================== modules/tcgetsid ==============================
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
==============================================================================
--- doc/posix-functions/tcgetsid.texi.orig Fri Sep 17 03:11:00 2010
+++ doc/posix-functions/tcgetsid.texi Fri Sep 17 02:59:46 2010
@@ -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
--- lib/termios.in.h.orig Fri Sep 17 03:11:00 2010
+++ lib/termios.in.h Fri Sep 17 02:57:44 2010
@@ -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 address@hidden@
+_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 */
--- m4/termios_h.m4.orig Fri Sep 17 03:11:00 2010
+++ m4/termios_h.m4 Fri Sep 17 02:43:50 2010
@@ -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])
])
--- modules/termios.orig Fri Sep 17 03:11:00 2010
+++ modules/termios Fri Sep 17 02:38:39 2010
@@ -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 address@hidden $@ && \
{ 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; \
} > address@hidden && \
mv address@hidden $@
--- tests/test-termios-c++.cc.orig Fri Sep 17 03:11:00 2010
+++ tests/test-termios-c++.cc Fri Sep 17 02:45:39 2010
@@ -24,6 +24,11 @@
#include "signature.h"
+#if GNULIB_TEST_TCGETSID
+SIGNATURE_CHECK (GNULIB_NAMESPACE::tcgetsid, pid_t, (int));
+#endif
+
+
int
main ()
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- new module 'tcgetsid',
Bruno Haible <=