Mercurial > hg > octave-kai > gnulib-hg
changeset 16067:c4b6df81c7b3
ptsname_r: new module
For now, this replacement focuses solely on compilation
compatibility, and assumes that isatty() and ttyname_r() work
on a master side pty; if this assumption fails, or if
thread-safety is also required, then a later patch can follow
the lead of strerror_r.c in wrapping the system ptsname()
with a lock.
* modules/ptsname_r: New module.
* m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): New file.
* lib/ptsname.c (__ptsname_r): Split...
* lib/ptsname_r.c: ...into new file.
* m4/stdlib_h.m4 (gl_STDLIB_H): Check for decl.
(gl_STDLIB_H_DEFAULTS): Set witness defaults.
* modules/stdlib (Makefile.am): Substitute witnesses.
* lib/stdlib.in.h (ptsname_r): Declare it.
* doc/glibc-functions/ptsname_r.texi (ptsname_r): Document it.
* MODULES.html.sh (Misc): Likewise.
* modules/ptsname (Depends-on): Alter dependency.
* doc/posix-functions/ptsname.texi (ptsname): Mention new module.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Mon, 07 Nov 2011 15:26:08 -0700 |
parents | bfcbd618231e |
children | 512071524b7e |
files | ChangeLog MODULES.html.sh doc/glibc-functions/ptsname_r.texi doc/posix-functions/ptsname.texi lib/ptsname.c lib/ptsname_r.c lib/stdlib.in.h m4/ptsname_r.m4 m4/stdlib_h.m4 modules/ptsname modules/ptsname_r modules/stdlib |
diffstat | 12 files changed, 194 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2011-11-09 Eric Blake <eblake@redhat.com> + + ptsname_r: new module + * modules/ptsname_r: New module. + * m4/ptsname_r.m4 (gl_FUNC_PTSNAME_R): New file. + * lib/ptsname.c (__ptsname_r): Split... + * lib/ptsname_r.c: ...into new file. + * m4/stdlib_h.m4 (gl_STDLIB_H): Check for decl. + (gl_STDLIB_H_DEFAULTS): Set witness defaults. + * modules/stdlib (Makefile.am): Substitute witnesses. + * lib/stdlib.in.h (ptsname_r): Declare it. + * doc/glibc-functions/ptsname_r.texi (ptsname_r): Document it. + * MODULES.html.sh (Misc): Likewise. + * modules/ptsname (Depends-on): Alter dependency. + * doc/posix-functions/ptsname.texi (ptsname): Mention new module. + 2011-11-09 Jim Meyering <meyering@redhat.com> announce-gen: be more concise when there's only one URL+tarball
--- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -3447,6 +3447,7 @@ func_module physmem func_module posixver func_module progname + func_module ptsname_r func_module pty func_module quotearg func_module quote
--- a/doc/glibc-functions/ptsname_r.texi +++ b/doc/glibc-functions/ptsname_r.texi @@ -2,15 +2,17 @@ @subsection @code{ptsname_r} @findex ptsname_r -Gnulib module: --- +Gnulib module: ptsname_r Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, +AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11 2010-11, Cygwin 1.7.9, mingw, +MSVC 9, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -MacOS X 10.5, FreeBSD 6.0, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 11 2010-11, Cygwin, mingw, MSVC 9, BeOS. @end itemize
--- a/doc/posix-functions/ptsname.texi +++ b/doc/posix-functions/ptsname.texi @@ -21,4 +21,11 @@ @item On Solaris 11 2010-11, this function fails on all BSD-style @file{/dev/pty*} device files. +@item +This function is not thread-safe on some platforms: +Cygwin 1.7.9. +Likewise, the gnulib replacement is not thread-safe. @end itemize + +Note that the Gnulib module @code{ptsname_r} is a version of this +function that is more likely to be thread-safe.
--- a/lib/ptsname.c +++ b/lib/ptsname.c @@ -18,30 +18,6 @@ #include <stdlib.h> -#include <errno.h> -#include <string.h> -#include <sys/stat.h> -#include <unistd.h> - -#ifdef _LIBC -# include <paths.h> -#else -# ifndef _PATH_TTY -# define _PATH_TTY "/dev/tty" -# endif -# ifndef _PATH_DEV -# define _PATH_DEV "/dev/" -# endif - -# define __set_errno(e) errno = (e) -# define __isatty isatty -# define __stat stat -# define __ttyname_r ttyname_r - -static int __ptsname_r (int fd, char *buf, size_t buflen); -#endif - - /* Static buffer for `ptsname'. */ static char buffer[64]; @@ -52,48 +28,5 @@ char * ptsname (int fd) { - return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer; + return ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer; } - - -/* Store at most BUFLEN characters of the pathname of the slave pseudo - terminal associated with the master FD is open on in BUF. - Return 0 on success, otherwise an error number. */ -static int -__ptsname_r (int fd, char *buf, size_t buflen) -{ - int save_errno = errno; - int err; - struct stat st; - - if (buf == NULL) - { - __set_errno (EINVAL); - return EINVAL; - } - - if (!__isatty (fd)) - /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ - return errno; - - if (buflen < strlen (_PATH_TTY) + 3) - { - __set_errno (ERANGE); - return ERANGE; - } - - err = __ttyname_r (fd, buf, buflen); - if (err != 0) - { - __set_errno (err); - return errno; - } - - buf[sizeof (_PATH_DEV) - 1] = 't'; - - if (__stat (buf, &st) < 0) - return errno; - - __set_errno (save_errno); - return 0; -}
new file mode 100644 --- /dev/null +++ b/lib/ptsname_r.c @@ -0,0 +1,85 @@ +/* Determine name of the slave side of a pseudo-terminal. + Copyright (C) 1998, 2002, 2010-2011 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/>. */ + +#include <config.h> + +#include <stdlib.h> + +#include <errno.h> +#include <string.h> +#include <sys/stat.h> +#include <unistd.h> + +#ifdef _LIBC +# include <paths.h> +#else +# ifndef _PATH_TTY +# define _PATH_TTY "/dev/tty" +# endif +# ifndef _PATH_DEV +# define _PATH_DEV "/dev/" +# endif + +# define __set_errno(e) errno = (e) +# define __isatty isatty +# define __stat stat +# define __ttyname_r ttyname_r +# define __ptsname_r ptsname_r + +#endif + + +/* Store at most BUFLEN characters of the pathname of the slave pseudo + terminal associated with the master FD is open on in BUF. + Return 0 on success, otherwise an error number. */ +int +__ptsname_r (int fd, char *buf, size_t buflen) +{ + int save_errno = errno; + int err; + struct stat st; + + if (buf == NULL) + { + __set_errno (EINVAL); + return EINVAL; + } + + if (!__isatty (fd)) + /* We rely on isatty to set errno properly (i.e. EBADF or ENOTTY). */ + return errno; + + if (buflen < strlen (_PATH_TTY) + 3) + { + __set_errno (ERANGE); + return ERANGE; + } + + err = __ttyname_r (fd, buf, buflen); + if (err != 0) + { + __set_errno (err); + return errno; + } + + buf[sizeof (_PATH_DEV) - 1] = 't'; + + if (__stat (buf, &st) < 0) + return errno; + + __set_errno (save_errno); + return 0; +}
--- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -455,6 +455,23 @@ # endif #endif +#if @GNULIB_PTSNAME_R@ +/* Set the pathname of the pseudo-terminal slave associated with + the master FD is open on and return 0, or set errno and return + non-zero on errors. */ +# if !@HAVE_PTSNAME_R@ +_GL_FUNCDECL_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); +# endif +_GL_CXXALIAS_SYS (ptsname_r, int, (int fd, char *buf, size_t len)); +_GL_CXXALIASWARN (ptsname_r); +#elif defined GNULIB_POSIXCHECK +# undef ptsname_r +# if HAVE_RAW_DECL_PTSNAME_R +_GL_WARN_ON_USE (ptsname_r, "ptsname_r is not portable - " + "use gnulib module ptsname_r for portability"); +# endif +#endif + #if @GNULIB_PUTENV@ # if @REPLACE_PUTENV@ # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
new file mode 100644 --- /dev/null +++ b/m4/ptsname_r.m4 @@ -0,0 +1,23 @@ +# ptsname_r.m4 serial 1 +dnl Copyright (C) 2010-2011 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_PTSNAME_R], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + + dnl Persuade glibc <stdlib.h> to declare ptsname_r(). + AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([ptsname_r]) + if test $ac_cv_func_ptsname_r = no; then + HAVE_PTSNAME_R=0 + fi +]) + +# Prerequisites of lib/ptsname.c. +AC_DEFUN([gl_PREREQ_PTSNAME_R], [ + : +])
--- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 37 +# stdlib_h.m4 serial 38 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -21,8 +21,8 @@ #endif ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt initstate_r mkdtemp mkostemp mkostemps mkstemp mkstemps posix_openpt - ptsname random_r realpath rpmatch setenv setstate_r srandom_r strtod - strtoll strtoull unlockpt unsetenv]) + ptsname ptsname_r random_r realpath rpmatch setenv setstate_r srandom_r + strtod strtoll strtoull unlockpt unsetenv]) ]) AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], @@ -52,6 +52,7 @@ GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS]) GNULIB_POSIX_OPENPT=0; AC_SUBST([GNULIB_POSIX_OPENPT]) GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME]) + GNULIB_PTSNAME_R=0; AC_SUBST([GNULIB_PTSNAME_R]) GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R]) GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX]) @@ -79,6 +80,7 @@ HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) HAVE_POSIX_OPENPT=1; AC_SUBST([HAVE_POSIX_OPENPT]) HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) + HAVE_PTSNAME_R=1; AC_SUBST([HAVE_PTSNAME_R]) HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H]) HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
--- a/modules/ptsname +++ b/modules/ptsname @@ -8,7 +8,7 @@ Depends-on: stdlib extensions -ttyname_r [test $HAVE_PTSNAME = 0] +ptsname_r [test $HAVE_PTSNAME = 0] configure.ac: gl_FUNC_PTSNAME
new file mode 100644 --- /dev/null +++ b/modules/ptsname_r @@ -0,0 +1,30 @@ +Description: +ptsname_r() function: Determine name of the slave side of a pseudo-terminal. + +Files: +lib/ptsname_r.c +m4/ptsname_r.m4 + +Depends-on: +stdlib +extensions +ttyname_r [test $HAVE_PTSNAME_R = 0] + +configure.ac: +gl_FUNC_PTSNAME_R +if test $HAVE_PTSNAME_R = 0; then + AC_LIBOBJ([ptsname_r]) + gl_PREREQ_PTSNAME_R +fi +gl_STDLIB_MODULE_INDICATOR([ptsname_r]) + +Makefile.am: + +Include: +<stdlib.h> + +License: +LGPLv2+ + +Maintainer: +Bruno Haible, Eric Blake
--- a/modules/stdlib +++ b/modules/stdlib @@ -47,6 +47,7 @@ -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \ -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \ -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \ + -e 's/@''GNULIB_PTSNAME_R''@/$(GNULIB_PTSNAME_R)/g' \ -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \ -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \ -e 's/@''GNULIB_REALLOC_POSIX''@/$(GNULIB_REALLOC_POSIX)/g' \ @@ -74,6 +75,7 @@ -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \ -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ + -e 's|@''HAVE_PTSNAME_R''@|$(HAVE_PTSNAME_R)|g' \ -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \ -e 's|@''HAVE_REALPATH''@|$(HAVE_REALPATH)|g' \