2 # Copyright (C) 2010-2012 Free Software Foundation, Inc.
3 # This file is free software; the Free Software Foundation
4 # gives unlimited permission to copy and/or distribute it,
5 # with or without modifications, as long as this notice is preserved.
7 # This file is based on gnulib/m4/ttyname_r.m4 serial 8.
11 # gnupg_REPLACE_TTYNAME_R
13 # This macro is an extended version of AC_REPLACE_FUNCS(ttyname_r).
14 # It takes peculiarities in the implementation of ttyname_r in account.
16 # The macro HAVE_TTYNAME_R will be defined to 1 if the function
17 # exists; it will be defined to 0 if it does not exists or no
18 # declaration is available.
20 # The macro HAVE_POSIXDECL_TTYNAME_R is defined if ttyname_r conforms
21 # to the Posix declaration.
23 # The macro HAVE_BROKEN_TTYNAME_R is defined it ttyname_r does not work
24 # correctly with the supplied buffer size. If this is defined the function
25 # will also be replaced.
27 # The macro REPLACE_TTYNAME_R is defined if ttyname_r is a replacement
28 # function. This macro is useful for the definition of the prototype.
30 AC_DEFUN([gnupg_REPLACE_TTYNAME_R],
32 AC_CHECK_HEADERS([unistd.h])
34 AC_CHECK_DECLS_ONCE([ttyname_r])
35 if test $ac_cv_have_decl_ttyname_r = no; then
39 AC_CHECK_FUNCS([ttyname_r])
40 if test $ac_cv_func_ttyname_r = no; then
42 AC_LIBOBJ([ttyname_r])
43 AC_DEFINE([REPLACE_TTYNAME_R],[1],
44 [Define to 1 if ttyname_r is a replacement function.])
47 dnl On MacOS X 10.4 (and Solaris 10 without __EXTENSIONS__)
48 dnl the return type is 'char *', not 'int'.
49 AC_CACHE_CHECK([whether ttyname_r is compatible with its POSIX signature],
50 [gnupg_cv_func_ttyname_r_posix],
54 #include <unistd.h>]],
55 [[*ttyname_r (0, NULL, 0);]])
57 [gnupg_cv_func_ttyname_r_posix=no],
58 [gnupg_cv_func_ttyname_r_posix=yes])
60 if test $gnupg_cv_func_ttyname_r_posix = no; then
61 AC_LIBOBJ([ttyname_r])
62 AC_DEFINE([REPLACE_TTYNAME_R],[1])
64 AC_DEFINE([HAVE_POSIXDECL_TTYNAME_R], [1],
65 [Define if the ttyname_r function has a POSIX compliant declaration.])
66 dnl On Solaris 10, both ttyname_r functions (the one with the non-POSIX
67 dnl declaration and the one with the POSIX declaration) refuse to do
68 dnl anything when the output buffer is less than 128 bytes large.
69 dnl On OSF/1 5.1, ttyname_r ignores the buffer size and assumes the
70 dnl buffer is large enough.
71 AC_REQUIRE([AC_CANONICAL_HOST])
72 AC_CACHE_CHECK([whether ttyname_r works with small buffers],
73 [gnupg_cv_func_ttyname_r_works],
75 dnl Initial guess, used when cross-compiling or when /dev/tty cannot
79 # Guess no on Solaris.
80 solaris*) gnupg_cv_func_ttyname_r_works="guessing no" ;;
82 osf*) gnupg_cv_func_ttyname_r_works="guessing no" ;;
83 # Guess yes otherwise.
84 *) gnupg_cv_func_ttyname_r_works="guessing yes" ;;
96 char buf[31]; /* use any size < 128 here */
98 fd = open ("/dev/tty", O_RDONLY);
101 else if (ttyname_r (fd, buf, sizeof (buf)) != 0)
103 else if (ttyname_r (fd, buf, 1) == 0)
107 [gnupg_cv_func_ttyname_r_works=yes],
109 17 | 18) gnupg_cv_func_ttyname_r_works=no ;;
113 case "$gnupg_cv_func_ttyname_r_works" in
115 *) AC_LIBOBJ([ttyname_r])
116 AC_DEFINE([REPLACE_TTYNAME_R],[1])
117 AC_DEFINE([HAVE_BROKEN_TTYNAME_R], [1],
118 [Define if ttyname_r is does not work with small buffers])