1 # ttyname_r.m4 serial 6
2 dnl Copyright (C) 2010 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_TTYNAME_R],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11 dnl Persuade Solaris <unistd.h> to provide the POSIX compliant declaration of
13 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_DECLS_ONCE([ttyname_r])
16 if test $ac_cv_have_decl_ttyname_r = no; then
20 AC_CHECK_FUNCS([ttyname_r])
21 if test $ac_cv_func_ttyname_r = no; then
25 dnl On MacOS X 10.4 (and Solaris 10 without gl_USE_SYSTEM_EXTENSIONS)
26 dnl the return type is 'char *', not 'int'.
27 AC_CACHE_CHECK([whether ttyname_r is compatible with its POSIX signature],
28 [gl_cv_func_ttyname_r_posix],
32 #include <unistd.h>]],
33 [[*ttyname_r (0, NULL, 0);]])
35 [gl_cv_func_ttyname_r_posix=no],
36 [gl_cv_func_ttyname_r_posix=yes])
38 if test $gl_cv_func_ttyname_r_posix = no; then
41 AC_DEFINE([HAVE_POSIXDECL_TTYNAME_R], [1],
42 [Define if the ttyname_r function has a POSIX compliant declaration.])
43 dnl On Solaris 10, both ttyname_r functions (the one with the non-POSIX
44 dnl declaration and the one with the POSIX declaration) refuse to do
45 dnl anything when the output buffer is less than 128 bytes large.
46 AC_REQUIRE([AC_CANONICAL_HOST])
47 AC_CACHE_CHECK([whether ttyname_r works with small buffers],
48 [gl_cv_func_ttyname_r_works],
50 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
54 # Guess no on Solaris.
55 solaris*) gl_cv_func_ttyname_r_works="guessing no" ;;
56 # Guess yes otherwise.
57 *) gl_cv_func_ttyname_r_works="guessing yes" ;;
69 char buf[31]; /* use any size < 128 here */
71 fd = open ("/dev/tty", O_RDONLY);
74 else if (ttyname_r (fd, buf, sizeof (buf)) != 0)
78 [gl_cv_func_ttyname_r_works=yes],
82 case "$gl_cv_func_ttyname_r_works" in
84 *) REPLACE_TTYNAME_R=1 ;;
88 if test $HAVE_TTYNAME_R = 0 || test $REPLACE_TTYNAME_R = 1; then
89 AC_LIBOBJ([ttyname_r])
94 # Prerequisites of lib/ttyname_r.c.
95 AC_DEFUN([gl_PREREQ_TTYNAME_R], [
96 AC_CHECK_FUNCS([ttyname])