From b34e3963935bb561dc2a4ab29477722ac03da164 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 22 Dec 2010 17:09:26 +0100 Subject: [PATCH] ttyname_r: Work around bug on OSF/1 5.1. * doc/posix-functions/ttyname_r.texi: Mention the OSF/1 bug. * m4/ttyname_r.m4 (gl_FUNC_TTYNAME_R): Detect the OSF/1 bug. Say "no" instead of "guessing no" when the OSF/1 bug or the Solaris bug is present. * lib/ttyname_r.c (ttyname_r): Update comments. --- ChangeLog | 9 +++++++++ doc/posix-functions/ttyname_r.texi | 4 ++++ lib/ttyname_r.c | 5 +++-- m4/ttyname_r.m4 | 16 ++++++++++++---- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2580ec20b..c2141ed0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-12-22 Bruno Haible + ttyname_r: Work around bug on OSF/1 5.1. + * doc/posix-functions/ttyname_r.texi: Mention the OSF/1 bug. + * m4/ttyname_r.m4 (gl_FUNC_TTYNAME_R): Detect the OSF/1 bug. Say "no" + instead of "guessing no" when the OSF/1 bug or the Solaris bug is + present. + * lib/ttyname_r.c (ttyname_r): Update comments. + +2010-12-22 Bruno Haible + round: Implement result sign according to IEEE 754. * lib/round.c (MIN, MINUS_ZERO): New macros. (FLOOR_FREE_ROUND): Return -0.0 for -0.5 < x < 0. diff --git a/doc/posix-functions/ttyname_r.texi b/doc/posix-functions/ttyname_r.texi index 67ca8d49f..e190d2592 100644 --- a/doc/posix-functions/ttyname_r.texi +++ b/doc/posix-functions/ttyname_r.texi @@ -19,6 +19,10 @@ HP-UX 11. This function has an incompatible declaration on some platforms: MacOS X 10.4, Solaris 11 2010-11 (when @code{_POSIX_PTHREAD_SEMANTICS} is not defined). @item +This function ignores the size argument, thus overwriting memory after the +buffer, on some platforms: +OSF/1 5.1. +@item This function refuses to do anything when the output buffer is less than 128 bytes large, on some platforms: Solaris 11 2010-11. diff --git a/lib/ttyname_r.c b/lib/ttyname_r.c index 5b59547ca..1836415ac 100644 --- a/lib/ttyname_r.c +++ b/lib/ttyname_r.c @@ -32,8 +32,9 @@ ttyname_r (int fd, char *buf, size_t buflen) /* When ttyname_r exists, use it. */ #if HAVE_TTYNAME_R /* This code is multithread-safe. */ - /* On Solaris, ttyname_r always fails if buflen < 128. So provide a buffer - that is large enough. */ + /* On Solaris, ttyname_r always fails if buflen < 128. On OSF/1 5.1, + ttyname_r ignores the buffer size and assumes the buffer is large enough. + So provide a buffer that is large enough. */ char largerbuf[512]; # if HAVE_POSIXDECL_TTYNAME_R int err = diff --git a/m4/ttyname_r.m4 b/m4/ttyname_r.m4 index ad760703c..9771c393f 100644 --- a/m4/ttyname_r.m4 +++ b/m4/ttyname_r.m4 @@ -1,4 +1,4 @@ -# ttyname_r.m4 serial 6 +# ttyname_r.m4 serial 7 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, @@ -43,6 +43,8 @@ AC_DEFUN([gl_FUNC_TTYNAME_R], dnl On Solaris 10, both ttyname_r functions (the one with the non-POSIX dnl declaration and the one with the POSIX declaration) refuse to do dnl anything when the output buffer is less than 128 bytes large. + dnl On OSF/1 5.1, ttyname_r ignores the buffer size and assumes the + dnl buffer is large enough. AC_REQUIRE([AC_CANONICAL_HOST]) AC_CACHE_CHECK([whether ttyname_r works with small buffers], [gl_cv_func_ttyname_r_works], @@ -53,6 +55,8 @@ changequote(,)dnl case "$host_os" in # Guess no on Solaris. solaris*) gl_cv_func_ttyname_r_works="guessing no" ;; + # Guess no on OSF/1. + osf*) gl_cv_func_ttyname_r_works="guessing no" ;; # Guess yes otherwise. *) gl_cv_func_ttyname_r_works="guessing yes" ;; esac @@ -70,13 +74,17 @@ main (void) fd = open ("/dev/tty", O_RDONLY); if (fd < 0) - result |= 1; + result |= 16; else if (ttyname_r (fd, buf, sizeof (buf)) != 0) - result |= 2; + result |= 17; + else if (ttyname_r (fd, buf, 1) == 0) + result |= 18; return result; }]])], [gl_cv_func_ttyname_r_works=yes], - [:], + [case $? in + 17 | 18) gl_cv_func_ttyname_r_works=no ;; + esac], [:]) ]) case "$gl_cv_func_ttyname_r_works" in -- 2.11.0