From 44896ceee9fbf6719fb772bd69c2d289275148e6 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 27 Aug 2024 22:28:36 +0200 Subject: [PATCH] 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. --- ChangeLog | 8 ++++++++ lib/dirchownmod.c | 8 +++++++- m4/mkdir-p.m4 | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2238efe015..852c705a31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2024-08-27 Bruno Haible + + 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. + 2024-08-27 Bruno Haible fts: Don't assume that a pointer is as wide as a 'long'. 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 70676eaa5c..35dd209f79 100644 --- a/m4/mkdir-p.m4 +++ b/m4/mkdir-p.m4 @@ -1,4 +1,4 @@ -# mkdir-p.m4 serial 15 +# mkdir-p.m4 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, @@ -7,5 +7,5 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_MKDIR_PARENTS], [ dnl Prerequisites of lib/dirchownmod.c. - AC_CHECK_FUNCS_ONCE([fchmod]) + AC_CHECK_FUNCS_ONCE([fchmod fchown]) ]) -- 2.39.5