3 dnl Copyright (C) 2010-2024 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
8 AC_DEFUN([gl_FUNC_PTSNAME_R],
10 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
12 dnl Persuade glibc <stdlib.h> to declare ptsname_r().
13 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
15 AC_CHECK_FUNCS_ONCE([ptsname_r])
16 if test $ac_cv_func_ptsname_r = no; then
19 dnl On OSF/1 5.1, the type of the third argument is 'int', not 'size_t',
20 dnl and the declaration is missing if _REENTRANT is not defined.
21 AC_CACHE_CHECK([whether ptsname_r has the same signature as in glibc],
22 [gl_cv_func_ptsname_r_signature_ok],
27 /* Test whether ptsname_r is declared at all. */
28 int (*f) (int, char *, size_t) = ptsname_r;
29 /* Test whether it has the same declaration as in glibc. */
35 int ptsname_r (int, char *, size_t);
37 [[return f (0, NULL, 0);]])
39 [gl_cv_func_ptsname_r_signature_ok=yes],
40 [gl_cv_func_ptsname_r_signature_ok=no])
42 if test $gl_cv_func_ptsname_r_signature_ok = no; then
45 AC_DEFINE([HAVE_ESSENTIALLY_WORKING_PTSNAME_R], [1],
46 [Define to 1 if ptsname_r() is essentially working.])
47 dnl On FreeBSD 13.0 and Android 4.3, when ptsname_r fails, it returns -1
48 dnl instead of the error code.
49 AC_REQUIRE([AC_CANONICAL_HOST])
50 AC_CACHE_CHECK([whether ptsname_r returns an error code],
51 [gl_cv_func_ptsname_r_retval_ok],
59 return ptsname_r (-1, buf, sizeof buf) == -1;
61 [gl_cv_func_ptsname_r_retval_ok=yes],
62 [gl_cv_func_ptsname_r_retval_ok=no],
64 dnl Guess no on FreeBSD, Android.
65 freebsd* | dragonfly* | midnightbsd* | linux*-android*)
66 gl_cv_func_ptsname_r_retval_ok="guessing no" ;;
67 dnl Guess yes otherwise.
69 gl_cv_func_ptsname_r_retval_ok="guessing yes" ;;
73 case "$gl_cv_func_ptsname_r_retval_ok" in
75 *) REPLACE_PTSNAME_R=1 ;;
77 dnl On NetBSD 10.0, when ptsname_r fails with ERANGE, it clobbers the
78 dnl result buffer. We don't use an AC_RUN_IFELSE test here, because
79 dnl while the bug exists on all platforms, only NetBSD/i386 has the
80 dnl files /dev/ptyp[01] on which the bug becomes apparent.
82 netbsd*) REPLACE_PTSNAME_R=1 ;;
87 AC_REQUIRE([AC_HEADER_MAJOR])
90 # Prerequisites of lib/ptsname.c.
91 AC_DEFUN([gl_PREREQ_PTSNAME_R], [
92 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
93 AC_CACHE_CHECK([whether isatty sets errno when it fails],
94 [gl_cv_func_isatty_sets_errno],
98 #if defined _WIN32 && ! defined __CYGWIN__
109 [gl_cv_func_isatty_sets_errno=yes],
110 [gl_cv_func_isatty_sets_errno=no],
113 gl_cv_func_isatty_sets_errno="guessing no" ;;
114 # Guess yes on mingw, no on MSVC.
116 AC_EGREP_CPP([Known], [
121 [gl_cv_func_isatty_sets_errno="guessing yes"],
122 [gl_cv_func_isatty_sets_errno="guessing no"])
125 gl_cv_func_isatty_sets_errno="guessing yes" ;;
129 case "$gl_cv_func_isatty_sets_errno" in
132 AC_DEFINE([ISATTY_FAILS_WITHOUT_SETTING_ERRNO], [1],
133 [Define to 1 if isatty() may fail without setting errno.])