utimens, utimensat, fdutimensat: Avoid test failures on AIX 7.2.
[gnulib.git] / m4 / ptsname_r.m4
blob5c6d3998450023a20e30b29501c1d37a22e9e775
1 # ptsname_r.m4 serial 7
2 dnl Copyright (C) 2010-2021 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_PTSNAME_R],
9   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
11   dnl Persuade glibc <stdlib.h> to declare ptsname_r().
12   AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
14   AC_CHECK_FUNCS_ONCE([ptsname_r])
15   if test $ac_cv_func_ptsname_r = no; then
16     HAVE_PTSNAME_R=0
17   else
18     dnl On OSF/1 5.1, the type of the third argument is 'int', not 'size_t',
19     dnl and the declaration is missing if _REENTRANT is not defined.
20     AC_CACHE_CHECK([whether ptsname_r has the same signature as in glibc],
21       [gl_cv_func_ptsname_r_signature_ok],
22       [AC_COMPILE_IFELSE(
23          [AC_LANG_PROGRAM(
24             [[#include <stddef.h>
25               #include <stdlib.h>
26               /* Test whether ptsname_r is declared at all.  */
27               int (*f) (int, char *, size_t) = ptsname_r;
28               /* Test whether it has the same declaration as in glibc.  */
29               #undef ptsname_r
30               extern
31               #ifdef __cplusplus
32               "C"
33               #endif
34               int ptsname_r (int, char *, size_t);
35             ]],
36             [[return f (0, NULL, 0);]])
37          ],
38          [gl_cv_func_ptsname_r_signature_ok=yes],
39          [gl_cv_func_ptsname_r_signature_ok=no])
40       ])
41     if test $gl_cv_func_ptsname_r_signature_ok = no; then
42       REPLACE_PTSNAME_R=1
43     else
44       AC_DEFINE([HAVE_ESSENTIALLY_WORKING_PTSNAME_R], [1],
45         [Define to 1 if ptsname_r() is essentially working.])
46       dnl On Android 4.3, when ptsname_r fails, it returns -1 instead of the
47       dnl error code.
48       AC_REQUIRE([AC_CANONICAL_HOST])
49       AC_CACHE_CHECK([whether ptsname_r returns an error code],
50         [gl_cv_func_ptsname_r_retval_ok],
51         [AC_RUN_IFELSE(
52            [AC_LANG_SOURCE([[
53 #include <stdlib.h>
54 int
55 main (void)
57   char buf[80];
58   return ptsname_r (-1, buf, sizeof buf) == -1;
59 }]])],
60            [gl_cv_func_ptsname_r_retval_ok=yes],
61            [gl_cv_func_ptsname_r_retval_ok=no],
62            [case "$host_os" in
63                                dnl Guess no on Android.
64               linux*-android*) gl_cv_func_ptsname_r_retval_ok="guessing no" ;;
65                                dnl Guess yes otherwise.
66               *)               gl_cv_func_ptsname_r_retval_ok="guessing yes" ;;
67             esac
68            ])
69         ])
70       case "$gl_cv_func_ptsname_r_retval_ok" in
71         *yes) ;;
72         *) REPLACE_PTSNAME_R=1 ;;
73       esac
74     fi
75   fi
77   AC_REQUIRE([AC_HEADER_MAJOR])
80 # Prerequisites of lib/ptsname.c.
81 AC_DEFUN([gl_PREREQ_PTSNAME_R], [
82   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
83   AC_CACHE_CHECK([whether isatty sets errno when it fails],
84     [gl_cv_func_isatty_sets_errno],
85     [AC_RUN_IFELSE(
86        [AC_LANG_PROGRAM(
87           [[#include <errno.h>
88             #if defined _WIN32 && ! defined __CYGWIN__
89             # include <io.h>
90             #else
91             # include <unistd.h>
92             #endif
93           ]GL_MDA_DEFINES],
94           [[errno = 0;
95             isatty (-1);
96             return errno == 0;
97           ]])
98        ],
99        [gl_cv_func_isatty_sets_errno=yes],
100        [gl_cv_func_isatty_sets_errno=no],
101        [case "$host_os" in
102           irix* | solaris*)
103             gl_cv_func_isatty_sets_errno="guessing no" ;;
104           mingw*) # Guess yes on mingw, no on MSVC.
105             AC_EGREP_CPP([Known], [
106 #ifdef __MINGW32__
107  Known
108 #endif
109               ],
110               [gl_cv_func_isatty_sets_errno="guessing yes"],
111               [gl_cv_func_isatty_sets_errno="guessing no"])
112             ;;
113           *)
114             gl_cv_func_isatty_sets_errno="guessing yes" ;;
115         esac
116        ])
117     ])
118   case "$gl_cv_func_isatty_sets_errno" in
119     *yes) ;;
120     *)
121       AC_DEFINE([ISATTY_FAILS_WITHOUT_SETTING_ERRNO], [1],
122         [Define to 1 if isatty() may fail without setting errno.])
123       ;;
124   esac