Mercurial > hg > octave-lojdl > gnulib-hg
changeset 13023:953c5d14818b
New module 'ttyname_r'.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 21 Mar 2010 14:38:25 +0100 |
parents | 63c614c3b5e9 |
children | 6270472b0df6 |
files | ChangeLog doc/posix-functions/ttyname_r.texi lib/ttyname_r.c lib/unistd.in.h m4/ttyname_r.m4 m4/unistd_h.m4 modules/ttyname_r modules/unistd tests/test-unistd-c++.cc |
diffstat | 9 files changed, 142 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2010-03-21 Bruno Haible <bruno@clisp.org> + + New module 'ttyname_r'. + * lib/ttyname_r.c: New file. + * m4/ttyname_r.m4: New file. + * modules/ttyname_r: New file. + * lib/unistd.in.h (ttyname_r): New declaration. + * m4/unistd_h.m4 (gl_UNISTD_H): Check whether ttyname_r is declared. + (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_TTYNAME_R, HAVE_TTYNAME_R. + * modules/unistd (Makefile.am): Substitute GNULIB_TTYNAME_R, + HAVE_TTYNAME_R. + * tests/test-unistd-c++.cc: Check GNULIB_NAMESPACE::ttyname_r. + * doc/posix-functions/ttyname_r.texi: Mention the new module. + 2010-03-20 Bruno Haible <bruno@clisp.org> signal: Undefine macro definitions in C++ mode.
--- a/doc/posix-functions/ttyname_r.texi +++ b/doc/posix-functions/ttyname_r.texi @@ -4,15 +4,14 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/ttyname_r.html} -Gnulib module: --- +Gnulib module: ttyname_r Portability problems fixed by Gnulib: @itemize +This function is missing on some platforms: +NetBSD 3.0, mingw, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -NetBSD 3.0, mingw, BeOS. @end itemize
new file mode 100644 --- /dev/null +++ b/lib/ttyname_r.c @@ -0,0 +1,47 @@ +/* Determine name of a terminal. + + 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. */ + +/* Written by Bruno Haible <bruno@clisp.org>, 2010. */ + +#include <config.h> + +#include <unistd.h> + +#include <errno.h> +#include <string.h> + +int +ttyname_r (int fd, char *buf, size_t buflen) +{ +#if HAVE_TTYNAME + /* Note: This is not multithread-safe. */ + char *name; + size_t namelen; + + name = ttyname (fd); + if (name == NULL) + return errno; + namelen = strlen (name) + 1; + if (namelen > buflen) + return ERANGE; + memcpy (buf, name, namelen); + return 0; +#else + /* Platforms like mingw: no ttys exist at all. */ + return ENOTTY; +#endif +}
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1099,6 +1099,25 @@ #endif +#if @GNULIB_TTYNAME_R@ +/* Store at most BUFLEN characters of the pathname of the terminal FD is + open on in BUF. Return 0 on success, otherwise an error number. */ +# if !@HAVE_TTYNAME_R@ +_GL_FUNCDECL_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2))); +# endif +_GL_CXXALIAS_SYS (ttyname_r, int, + (int fd, char *buf, size_t buflen)); +_GL_CXXALIASWARN (ttyname_r); +#elif defined GNULIB_POSIXCHECK +# undef ttyname_r +# if HAVE_RAW_DECL_TTYNAME_R +_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - " + "use gnulib module ttyname_r for portability"); +# endif +#endif + + #if @GNULIB_UNLINK@ # if @REPLACE_UNLINK@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
new file mode 100644 --- /dev/null +++ b/m4/ttyname_r.m4 @@ -0,0 +1,22 @@ +# ttyname_r.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_TTYNAME_R], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + AC_CHECK_FUNCS([ttyname_r]) + if test $ac_cv_func_ttyname_r = no; then + HAVE_TTYNAME_R=0 + AC_LIBOBJ([ttyname_r]) + gl_PREREQ_TTYNAME_R + fi +]) + +# Prerequisites of lib/ttyname_r.c. +AC_DEFUN([gl_PREREQ_TTYNAME_R], [ + AC_CHECK_FUNCS([ttyname]) +])
--- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 41 +# unistd_h.m4 serial 42 dnl Copyright (C) 2006-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, @@ -39,7 +39,7 @@ fsync ftruncate getcwd getdomainname getdtablesize getgroups gethostname getlogin getlogin_r getpagesize getusershell setusershell endusershell lchown link linkat lseek pipe2 pread readlink readlinkat - rmdir sleep symlink symlinkat unlink unlinkat usleep]) + rmdir sleep symlink symlinkat ttyname_r unlink unlinkat usleep]) ]) AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], @@ -85,6 +85,7 @@ GNULIB_SLEEP=0; AC_SUBST([GNULIB_SLEEP]) GNULIB_SYMLINK=0; AC_SUBST([GNULIB_SYMLINK]) GNULIB_SYMLINKAT=0; AC_SUBST([GNULIB_SYMLINKAT]) + GNULIB_TTYNAME_R=0; AC_SUBST([GNULIB_TTYNAME_R]) GNULIB_UNISTD_H_GETOPT=0; AC_SUBST([GNULIB_UNISTD_H_GETOPT]) GNULIB_UNISTD_H_SIGPIPE=0; AC_SUBST([GNULIB_UNISTD_H_SIGPIPE]) GNULIB_UNLINK=0; AC_SUBST([GNULIB_UNLINK]) @@ -116,13 +117,14 @@ HAVE_SLEEP=1; AC_SUBST([HAVE_SLEEP]) HAVE_SYMLINK=1; AC_SUBST([HAVE_SYMLINK]) HAVE_SYMLINKAT=1; AC_SUBST([HAVE_SYMLINKAT]) + HAVE_TTYNAME_R=1; AC_SUBST([HAVE_TTYNAME_R]) + HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) + HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) HAVE_DECL_ENVIRON=1; AC_SUBST([HAVE_DECL_ENVIRON]) HAVE_DECL_GETLOGIN_R=1; AC_SUBST([HAVE_DECL_GETLOGIN_R]) HAVE_DECL_GETUSERSHELL=1; AC_SUBST([HAVE_DECL_GETUSERSHELL]) HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) - HAVE_UNLINKAT=1; AC_SUBST([HAVE_UNLINKAT]) - HAVE_USLEEP=1; AC_SUBST([HAVE_USLEEP]) REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) REPLACE_DUP=0; AC_SUBST([REPLACE_DUP])
new file mode 100644 --- /dev/null +++ b/modules/ttyname_r @@ -0,0 +1,24 @@ +Description: +ttyname_r() function: Determine name of a terminal. + +Files: +lib/ttyname_r.c +m4/ttyname_r.m4 + +Depends-on: +unistd + +configure.ac: +gl_FUNC_TTYNAME_R +gl_UNISTD_MODULE_INDICATOR([ttyname_r]) + +Makefile.am: + +Include: +<unistd.h> + +License: +LGPL + +Maintainer: +Bruno Haible
--- a/modules/unistd +++ b/modules/unistd @@ -59,6 +59,7 @@ -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \ -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \ -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \ + -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \ -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \ -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \ -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \ @@ -90,6 +91,7 @@ -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \ -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \ -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \ + -e 's|@''HAVE_TTYNAME_R''@|$(HAVE_TTYNAME_R)|g' \ -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \ -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \ -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
--- a/tests/test-unistd-c++.cc +++ b/tests/test-unistd-c++.cc @@ -165,6 +165,11 @@ (char const *, int, char const *)); #endif +#if GNULIB_TTYNAME_R +SIGNATURE_CHECK (GNULIB_NAMESPACE::ttyname_r, int, + (int fd, char *buf, size_t buflen)); +#endif + #if GNULIB_UNLINK SIGNATURE_CHECK (GNULIB_NAMESPACE::unlink, int, (char const *)); #endif