+ else
+ AC_DEFINE([HAVE_POSIXDECL_TTYNAME_R], [1],
+ [Define if the ttyname_r function has a POSIX compliant declaration.])
+ 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.
+ AC_REQUIRE([AC_CANONICAL_HOST])
+ AC_CACHE_CHECK([whether ttyname_r works with small buffers],
+ [gl_cv_func_ttyname_r_works],
+ [
+ dnl Initial guess, used when cross-compiling or when /dev/tty cannot
+ dnl be opened.
+changequote(,)dnl
+ case "$host_os" in
+ # Guess no on Solaris.
+ solaris*) gl_cv_func_ttyname_r_works="guessing no" ;;
+ # Guess yes otherwise.
+ *) gl_cv_func_ttyname_r_works="guessing yes" ;;
+ esac
+changequote([,])dnl
+ AC_TRY_RUN([
+#include <fcntl.h>
+#include <unistd.h>
+int
+main (void)
+{
+ int fd;
+ char buf[31]; /* use any size < 128 here */
+
+ fd = open ("/dev/tty", O_RDONLY);
+ if (fd < 0)
+ return 1;
+ if (ttyname_r (fd, buf, sizeof (buf)) != 0)
+ return 1;
+ return 0;
+}], [gl_cv_func_ttyname_r_works=yes], [:], [:])
+ ])
+ case "$gl_cv_func_ttyname_r_works" in
+ *yes) ;;
+ *) REPLACE_TTYNAME_R=1 ;;
+ esac