From 8e8a9568d91dbd6808a993255fd2b21f60e4ee2d Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Sat, 1 Jun 2024 19:56:17 +0200 Subject: [PATCH] Wrap ttyname_r check in AC_CACHE_CHECK This enables cross-compiling to set the php_cv_func_ttyname_r variable for adjusting the configuration manually. In case of cross-compiling the AC_CHECK_FUNCS is additionally used to guess whether the target has the ttyname_r. Current platforms mostly either have working ttyname_r compatible with POSIX or not. --- ext/posix/config.m4 | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) 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