clang on native Windows gives me this warning:

gllib\dirchownmod.c(98,27): warning: implicit declaration of function 'fchown' 
is invalid in C99 [-Wimplicit-function-declaration]

This patch should fix it.


2024-08-27  Bruno Haible  <br...@clisp.org>

        mkdir-p: Don't reference an undefined function on native Windows.
        * m4/mkdir-p.m4 (gl_MKDIR_PARENTS): Test whether fchown exists.
        * lib/dirchownmod.c (fchown): Define to a fallback if the system does
        not have fchown.
        (dirchownmod): Test HAVE_FCHOWN.

diff --git a/lib/dirchownmod.c b/lib/dirchownmod.c
index 633e6cb5da..d5f7b5432a 100644
--- a/lib/dirchownmod.c
+++ b/lib/dirchownmod.c
@@ -34,6 +34,12 @@
 # define fchmod(fd, mode) (-1)
 #endif
 
+#ifndef HAVE_FCHOWN
+# define HAVE_FCHOWN 0
+# undef fchown
+# define fchown(fd, owner, group) (-1)
+#endif
+
 /* Change the ownership and mode bits of a directory.  If FD is
    nonnegative, it should be a file descriptor associated with the
    directory; close it before returning.  DIR is the name of the
@@ -94,7 +100,7 @@ dirchownmod (int fd, char const *dir, mode_t mkdir_mode,
           if ((owner != (uid_t) -1 && owner != st.st_uid)
               || (group != (gid_t) -1 && group != st.st_gid))
             {
-              result = (0 <= fd
+              result = (HAVE_FCHOWN && 0 <= fd
                         ? fchown (fd, owner, group)
                         : mkdir_mode != (mode_t) -1
                         ? lchown (dir, owner, group)
diff --git a/m4/mkdir-p.m4 b/m4/mkdir-p.m4
index 1c8b02c535..351a86ff02 100644
--- a/m4/mkdir-p.m4
+++ b/m4/mkdir-p.m4
@@ -1,5 +1,5 @@
 # mkdir-p.m4
-# serial 15
+# serial 16
 dnl Copyright (C) 2002-2006, 2009-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,5 +8,5 @@
 AC_DEFUN([gl_MKDIR_PARENTS],
 [
   dnl Prerequisites of lib/dirchownmod.c.
-  AC_CHECK_FUNCS_ONCE([fchmod])
+  AC_CHECK_FUNCS_ONCE([fchmod fchown])
 ])




Reply via email to