]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
meson: add compile test for scandirat()
authorKarel Zak <kzak@redhat.com>
Wed, 24 Jun 2026 09:56:34 +0000 (11:56 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 24 Jun 2026 09:56:34 +0000 (11:56 +0200)
The link-only has_function() check is not sufficient on macOS where
scandirat() may exist in the SDK but is gated behind availability
annotations (e.g. macOS 26.4+). When the deployment target is older,
clang emits -Wunguarded-availability-new which -Werror turns into a
build failure.

Add a compile+link verification after the bulk function check to
detect this and disable HAVE_SCANDIRAT when the function is not
actually usable.

Signed-off-by: Karel Zak <kzak@redhat.com>
meson.build

index 0595aead9c5ba9084be38bc2aa457a4ce994b080..2768cb87985be2e9c7c84f0ca166c534ae23a99f 100644 (file)
@@ -732,6 +732,17 @@ foreach func: funcs
   conf.set('HAVE_' + func.to_upper(), have ? 1 : false)
 endforeach
 
+# scandirat() may exist in the SDK but be gated behind availability
+# annotations (e.g. macOS); verify it is actually usable at compile time.
+if conf.get('HAVE_SCANDIRAT') in [1]
+  if not cc.links('''
+      #include <dirent.h>
+      int main(void) { return scandirat(0, ".", (void*)0, (void*)0, (void*)0); }
+    ''', args : ['-D_GNU_SOURCE', '-Werror'], name : 'scandirat (compile test)')
+    conf.set('HAVE_SCANDIRAT', false)
+  endif
+endif
+
 have_mempcpy = cc.has_function('mempcpy', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
 conf.set('HAVE_MEMPCPY', have_mempcpy ? 1 : false)