master e3ec1cb8cce: Fix MinGW build as followup to recent Gnulib changes

Eli Zaretskii <[email protected]> Sat, 18 Jul 2026 02:27:59 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit e3ec1cb8cce7c9449aaf5bee18d6e5c9b67dd0eb
Author: Eli Zaretskii <[email protected]>
Commit: Eli Zaretskii <[email protected]>

    Fix MinGW build as followup to recent Gnulib changes
    
    Gnulib added AT_EMPTY_PATH support to its 'fstatat', but
    the MinGW build must use its own 'fstatat' implementation.
    These changes avoid compiling Gnulib's fstatat.c, and add
    support for AT_EMPTY_PATH to the MinGW implementation.
    * src/w32.c (fstatat): Support AT_EMPTY_PATH.
    
    * nt/inc/unistd.h (AT_EMPTY_PATH): Define.
    * nt/mingw-cfg.site (gl_cv_func_fstatat_null_file): Set to 'yes'
    to avoid compiling Gnulib's fstatat.
---
 nt/inc/unistd.h   | 1 +
 nt/mingw-cfg.site | 1 +
 src/w32.c         | 3 +++
 3 files changed, 5 insertions(+)

diff --git a/nt/inc/unistd.h b/nt/inc/unistd.h
index 8ad8cf213b1..92eedf33997 100644
--- a/nt/inc/unistd.h
+++ b/nt/inc/unistd.h
@@ -29,6 +29,7 @@ extern int faccessat (int, char const *, int, int);
 #define AT_FDCWD (-3041965)
 #define AT_EACCESS 4
 #define AT_SYMLINK_NOFOLLOW 4096
+#define AT_EMPTY_PATH 8192
 
 #define O_IGNORE_CTTY 0
 #define O_NOCTTY 0
diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site
index 7829a9878fe..36d64eca2cc 100644
--- a/nt/mingw-cfg.site
+++ b/nt/mingw-cfg.site
@@ -106,6 +106,7 @@ ac_cv_func_lstat=yes
 gl_cv_func_lstat_dereferences_slashed_symlink=yes
 ac_cv_func_fstatat=yes
 gl_cv_func_fstatat_zero_flag=yes
+gl_cv_func_fstatat_null_file=yes
 ac_cv_func_fchmodat=yes
 gl_cv_func_fchmodat_works="not-needed-so-yes"
 ac_cv_func_lchmod=yes
diff --git a/src/w32.c b/src/w32.c
index 4be30fc5ec4..806d4ec250a 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -5791,6 +5791,9 @@ fstatat (int fd, char const *name, struct stat *st, int flags)
      Gnulib does this and can serve as a model.  */
   char fullname[MAX_UTF8_PATH];
 
+  if (flags & AT_EMPTY_PATH && !name)
+    name = "";
+
   if (fd != AT_FDCWD)
     {
       char lastc = dir_pathname[strlen (dir_pathname) - 1];