From f9cfd40fa25f0bd071e65deb684dd04c75364d1c Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Tue, 6 Feb 2024 23:21:42 +0100 Subject: [PATCH] Refactor utsname.domainname struct member Autoconf check (#13336) * Refactor utsname.domainname struct member Autoconf check Autoconf's AC_CHECK_MEMBERS macro (available since Autoconf 2.50) can be used instead of the compile check. This was originally implemented for IRIX compatibility, when Autoconf 2.13 didn't have the struct members checking macro yet. Macro by default here defines the HAVE_STRUCT_UTSNAME_DOMAINNAME symbol. * Remove also redundant DARWIN symbol check Checking in the configuration step also correctly detects missing struct member on Darwin systems (macos...). --- UPGRADING.INTERNALS | 1 + ext/posix/config.m4 | 21 +++++---------------- ext/posix/posix.c | 2 +- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index bce87b5be44..a7bf2197006 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -50,6 +50,7 @@ PHP 8.4 INTERNALS UPGRADE NOTES - The configure option --with-zlib-dir has been removed. - COOKIE_IO_FUNCTIONS_T symbol has been removed (use cookie_io_functions_t). - HAVE_SOCKADDR_UN_SUN_LEN symbol renamed to HAVE_STRUCT_SOCKADDR_UN_SUN_LEN. + - HAVE_UTSNAME_DOMAINNAME symbol renamed to HAVE_STRUCT_UTSNAME_DOMAINNAME. - PHP_CHECK_IN_ADDR_T M4 macro and 'in_addr_t' fallback definition to 'u_int' removed (use AC_CHECK_TYPES Autoconf macro instead). - HAVE_ODBC2 symbol has been removed in ext/odbc. diff --git a/ext/posix/config.m4 b/ext/posix/config.m4 index 72deacc42ed..8d5ad1ce69f 100644 --- a/ext/posix/config.m4 +++ b/ext/posix/config.m4 @@ -36,21 +36,10 @@ int main(int argc, char *argv[]) AC_MSG_RESULT([no, cannot detect working ttyname_r() when cross compiling. posix_ttyname() will be thread-unsafe]) ]) - AC_CACHE_CHECK([for utsname.domainname], ac_cv_have_utsname_domainname, [ - AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ - #ifndef _GNU_SOURCE - #define _GNU_SOURCE - #endif - #include - ]],[[ - return sizeof(((struct utsname *)0)->domainname); - ]])],[ - ac_cv_have_utsname_domainname=yes - ],[ - ac_cv_have_utsname_domainname=no - ]) + AC_CHECK_MEMBERS([struct utsname.domainname],,,[ + #ifndef _GNU_SOURCE + #define _GNU_SOURCE + #endif + #include ]) - if test "$ac_cv_have_utsname_domainname" = yes; then - AC_DEFINE(HAVE_UTSNAME_DOMAINNAME, 1, [Whether struct utsname has domainname]) - fi fi diff --git a/ext/posix/posix.c b/ext/posix/posix.c index 8c111ea5acf..aa17cc95d80 100644 --- a/ext/posix/posix.c +++ b/ext/posix/posix.c @@ -358,7 +358,7 @@ PHP_FUNCTION(posix_uname) add_assoc_string(return_value, "version", u.version); add_assoc_string(return_value, "machine", u.machine); -#if defined(_GNU_SOURCE) && !defined(DARWIN) && defined(HAVE_UTSNAME_DOMAINNAME) +#if defined(_GNU_SOURCE) && defined(HAVE_STRUCT_UTSNAME_DOMAINNAME) add_assoc_string(return_value, "domainname", u.domainname); #endif }