diff --git a/ext/posix/config.m4 b/ext/posix/config.m4 index 9f1091a3c4521..e6bda42e59009 100644 --- a/ext/posix/config.m4 +++ b/ext/posix/config.m4 @@ -27,24 +27,20 @@ dnl (first argument is not validated and has different error). AS_IF([command -v ldd >/dev/null && ldd --version 2>&1 | grep -q "^musl"],[], [AC_CHECK_FUNCS(pathconf fpathconf)]) - AC_MSG_CHECKING([for working ttyname_r() implementation]) - AC_RUN_IFELSE([AC_LANG_SOURCE([[ -#include - -int main(int argc, char *argv[]) -{ - char buf[64]; - - return !ttyname_r(0, buf, 64); -} - ]])],[ - AC_MSG_RESULT([yes]) - AC_DEFINE(HAVE_TTYNAME_R, 1, [Whether you have a working ttyname_r]) - ],[ - AC_MSG_RESULT([no, posix_ttyname() will be thread-unsafe]) - ], [ - AC_MSG_RESULT([no, cannot detect working ttyname_r() when cross compiling. posix_ttyname() will be thread-unsafe]) - ]) + AC_CACHE_CHECK([for working ttyname_r() implementation], + [php_cv_func_ttyname_r], + [AC_RUN_IFELSE([AC_LANG_PROGRAM([#include ], [[ + char buf[64]; + return !ttyname_r(0, buf, 64); + ]])], + [php_cv_func_ttyname_r=yes], + [php_cv_func_ttyname_r=no], + [AC_CHECK_FUNC([ttyname_r], + [php_cv_func_ttyname_r=yes], [php_cv_func_ttyname_r=no])])]) + AS_VAR_IF([php_cv_func_ttyname_r], [yes], + [AC_DEFINE([HAVE_TTYNAME_R], [1], + [Define to 1 if you have a working ttyname_r.])], + [AC_MSG_NOTICE([posix_ttyname() will be thread-unsafe])]) AC_CHECK_MEMBERS([struct utsname.domainname],,,[ #ifndef _GNU_SOURCE