Skip to content

Commit 8112889

Browse files
authored
Wrap ttyname_r check in AC_CACHE_CHECK (php#14417)
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.
1 parent bc6f333 commit 8112889

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

ext/posix/config.m4

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,20 @@ dnl (first argument is not validated and has different error).
2727
AS_IF([command -v ldd >/dev/null && ldd --version 2>&1 | grep -q "^musl"],[],
2828
[AC_CHECK_FUNCS(pathconf fpathconf)])
2929

30-
AC_MSG_CHECKING([for working ttyname_r() implementation])
31-
AC_RUN_IFELSE([AC_LANG_SOURCE([[
32-
#include <unistd.h>
33-
34-
int main(int argc, char *argv[])
35-
{
36-
char buf[64];
37-
38-
return !ttyname_r(0, buf, 64);
39-
}
40-
]])],[
41-
AC_MSG_RESULT([yes])
42-
AC_DEFINE(HAVE_TTYNAME_R, 1, [Whether you have a working ttyname_r])
43-
],[
44-
AC_MSG_RESULT([no, posix_ttyname() will be thread-unsafe])
45-
], [
46-
AC_MSG_RESULT([no, cannot detect working ttyname_r() when cross compiling. posix_ttyname() will be thread-unsafe])
47-
])
30+
AC_CACHE_CHECK([for working ttyname_r() implementation],
31+
[php_cv_func_ttyname_r],
32+
[AC_RUN_IFELSE([AC_LANG_PROGRAM([#include <unistd.h>], [[
33+
char buf[64];
34+
return !ttyname_r(0, buf, 64);
35+
]])],
36+
[php_cv_func_ttyname_r=yes],
37+
[php_cv_func_ttyname_r=no],
38+
[AC_CHECK_FUNC([ttyname_r],
39+
[php_cv_func_ttyname_r=yes], [php_cv_func_ttyname_r=no])])])
40+
AS_VAR_IF([php_cv_func_ttyname_r], [yes],
41+
[AC_DEFINE([HAVE_TTYNAME_R], [1],
42+
[Define to 1 if you have a working ttyname_r.])],
43+
[AC_MSG_NOTICE([posix_ttyname() will be thread-unsafe])])
4844

4945
AC_CHECK_MEMBERS([struct utsname.domainname],,,[
5046
#ifndef _GNU_SOURCE

0 commit comments

Comments
 (0)