Skip to content

Commit 0a57ba0

Browse files
committed
build: Ensure strchrnul() is available in header
The strchrnul() function is also introduced in macOS 15.4, however, for macOS build, a compiler may default to building for an older macOS version (such as 15.0). The configure script can wrongly assume the function may be used. Fix the configure script's detection of strchrnul() by ensuring it's actually available through the header. Fixes: #1659 Signed-off-by: Kang-Che Sung <[email protected]>
1 parent da7bb15 commit 0a57ba0

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

configure.ac

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,28 @@ AC_CHECK_FUNCS([ \
371371
readlinkat \
372372
sched_getscheduler \
373373
sched_setscheduler \
374-
strchrnul \
375374
])
376375

376+
# strchrnul is available in macOS since 15.4, but the user may specify an older
377+
# macOS version ('-mmacos-version-min') to build for. We need to ensure it is
378+
# actually exposed in the header.
379+
htop_save_CFLAGS=$CFLAGS
380+
CFLAGS="$CFLAGS -Werror"
381+
382+
AC_MSG_CHECKING([for strchrnul])
383+
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
384+
#include <string.h>
385+
]], [[
386+
static char ch;
387+
char* ptr = strchrnul(&ch, 0);
388+
return ptr != &ch; /* Should be 0 (exit success) */
389+
]])],
390+
[AC_MSG_RESULT(yes)
391+
AC_DEFINE([HAVE_STRCHRNUL], [1], [Define to 1 if you have the 'strchrnul' function.])],
392+
[AC_MSG_RESULT(no)])
393+
394+
CFLAGS=$htop_save_CFLAGS
395+
377396
if test "$my_htop_platform" = darwin; then
378397
AC_CHECK_FUNCS([host_statistics64], [
379398
AC_CHECK_TYPES([struct vm_statistics64], [], [], [[#include <mach/vm_statistics.h>]])

0 commit comments

Comments
 (0)