- case $REPLACE_FSTATAT,$gl_cv_func_fstatat_zero_flag in
- 1,*yes)
- AC_DEFINE([HAVE_WORKING_FSTATAT_ZERO_FLAG], [1],
- [Define to 1 if fstatat (..., 0) works.
- For example, it does not work in AIX 7.1.])
- ;;
- esac
+ dnl Check for the AT_EMPTY_PATH compatibility issue with null pointers
+ dnl only if not already replacing fstatat.
+ dnl There is no need to AC_DEFINE anything here, as the Gnulib
+ dnl replacement works around the compatibility bug even if the bug
+ dnl is not present, and it is not worth the trouble to tune this.
+ AS_CASE([$REPLACE_FSTATAT],
+ [0],
+ [AC_CACHE_CHECK([whether fstatat+AT_EMPTY_PATH allows null file],
+ [gl_cv_func_fstatat_null_file],
+ [gl_saved_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS -Wno-nonnull"
+ AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stddef.h>
+ #include <fcntl.h>
+ #include <sys/stat.h>
+ #ifndef AT_EMPTY_PATH
+ #define AT_EMPTY_PATH 0
+ #endif
+ #if __GLIBC__ && ! (2 < __GLIBC__ + (41 <= __GLIBC_MINOR__))
+ #error "glibc 2.40 and earlier can fail with null file"
+ #endif
+ ]],
+ [[struct stat st;
+ return
+ (AT_EMPTY_PATH
+ && fstatat (AT_FDCWD, NULL, &st, AT_EMPTY_PATH) < 0);
+ ]])],
+ [gl_cv_func_fstatat_null_file=yes],
+ [gl_cv_func_fstatat_null_file=no],
+ [gl_cv_func_fstatat_null_file="guessing no"])])
+ AS_CASE([$gl_cv_func_fstatat_null_file],
+ [*no],
+ [REPLACE_FSTATAT=1])])