Skip to content

Commit a6b336a

Browse files
authored
Refactor HAVE_GETIFADDRS checks (#14787)
- AC_CACHE used with php_cv_func_getifaddrs cache variable - Synced #if/ifdef/defined checks for HAVE_GETIFADDRS as it is either defined to 1 or undefined
1 parent 0410bf4 commit a6b336a

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ function getmxrr(string $hostname, &$hosts, &$weights = null): bool {}
21912191

21922192
/* net.c */
21932193

2194-
#if (defined(PHP_WIN32) || HAVE_GETIFADDRS || defined(__PASE__))
2194+
#if (defined(PHP_WIN32) || defined(HAVE_GETIFADDRS) || defined(__PASE__))
21952195
function net_get_interfaces(): array|false {}
21962196
#endif
21972197

ext/standard/basic_functions_arginfo.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/config.m4

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,22 +390,21 @@ AC_CHECK_HEADERS([net/if.h],,, [dnl
390390
#endif
391391
])
392392

393-
AC_MSG_CHECKING([for usable getifaddrs])
394-
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
393+
AC_CACHE_CHECK([for usable getifaddrs], [php_cv_func_getifaddrs],
394+
[AC_LINK_IFELSE([AC_LANG_PROGRAM([
395395
#include <sys/types.h>
396396
#include <ifaddrs.h>
397-
]],[[
397+
], [
398398
struct ifaddrs *interfaces;
399399
if (!getifaddrs(&interfaces)) {
400-
freeifaddrs(interfaces);
400+
freeifaddrs(interfaces);
401401
}
402-
]])], [ac_have_getifaddrs=yes], [ac_have_getifaddrs=no])
403-
if test "$ac_have_getifaddrs" = "yes" ; then
404-
AC_DEFINE(HAVE_GETIFADDRS, 1, [whether getifaddrs is present and usable])
405-
AC_MSG_RESULT(yes)
406-
else
407-
AC_MSG_RESULT(no)
408-
fi
402+
])],
403+
[php_cv_func_getifaddrs=yes],
404+
[php_cv_func_getifaddrs=no])])
405+
AS_VAR_IF([php_cv_func_getifaddrs], [yes],
406+
[AC_DEFINE([HAVE_GETIFADDRS], [1],
407+
[Define to 1 if you have the 'getifaddrs' function.])])
409408

410409
dnl
411410
dnl Setup extension sources

ext/standard/net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ PHP_FUNCTION(net_get_interfaces) {
261261
FREE(pAddresses);
262262
#undef MALLOC
263263
#undef FREE
264-
#elif HAVE_GETIFADDRS || defined(__PASE__) /* !PHP_WIN32 */
264+
#elif defined(HAVE_GETIFADDRS) || defined(__PASE__) /* !PHP_WIN32 */
265265
struct ifaddrs *addrs = NULL, *p;
266266

267267
ZEND_PARSE_PARAMETERS_NONE();

0 commit comments

Comments
 (0)