From 7dfe90a666ab6b90597e3ee61c141da088da340c Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 24 Feb 2020 18:16:51 +0200 Subject: [PATCH] Adapt the MS-Windows build to 'nofollow' changes * nt/gnulib-cfg.mk (OMIT_GNULIB_MODULE_fchmodat) (OMIT_GNULIB_MODULE_lchmod): Set to true to omit building these modules on MS-Windows. * nt/mingw-cfg.site (ac_cv_func_fchmodat) (gl_cv_func_fchmodat_works, ac_cv_func_lchmod): Disable tests on MS-Windows. * src/w32.c (chmod_worker, lchmod, fchmodat): New functions. (sys_chmod): Move most of the code to chmod_worker. * src/w32.h (fchmodat, lchmod): Add prototypes. --- nt/gnulib-cfg.mk | 2 ++ nt/mingw-cfg.site | 3 +++ src/w32.c | 41 ++++++++++++++++++++++++++++++++++++++--- src/w32.h | 2 ++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/nt/gnulib-cfg.mk b/nt/gnulib-cfg.mk index 08e83e028da..1d120a973d1 100644 --- a/nt/gnulib-cfg.mk +++ b/nt/gnulib-cfg.mk @@ -63,3 +63,5 @@ OMIT_GNULIB_MODULE_sys_time = true OMIT_GNULIB_MODULE_sys_types = true OMIT_GNULIB_MODULE_unistd = true OMIT_GNULIB_MODULE_canonicalize-lgpl = true +OMIT_GNULIB_MODULE_fchmodat = true +OMIT_GNULIB_MODULE_lchmod = true diff --git a/nt/mingw-cfg.site b/nt/mingw-cfg.site index dfdca3926f9..5bd5b834634 100644 --- a/nt/mingw-cfg.site +++ b/nt/mingw-cfg.site @@ -102,6 +102,9 @@ 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 +ac_cv_func_fchmodat=yes +gl_cv_func_fchmodat_works="not-needed-so-yes" +ac_cv_func_lchmod=yes # Aliased to _commit in ms-w32.h ac_cv_func_fsync=yes ac_cv_func_fdatasync=yes diff --git a/src/w32.c b/src/w32.c index a3b9a5683ad..cf1a3b37678 100644 --- a/src/w32.c +++ b/src/w32.c @@ -4320,10 +4320,9 @@ sys_chdir (const char * path) } } -int -sys_chmod (const char * path, int mode) +static int +chmod_worker (const char * path, int mode) { - path = chase_symlinks (map_w32_filename (path, NULL)); if (w32_unicode_filenames) { wchar_t path_w[MAX_PATH]; @@ -4340,6 +4339,20 @@ sys_chmod (const char * path, int mode) } } +int +sys_chmod (const char * path, int mode) +{ + path = chase_symlinks (map_w32_filename (path, NULL)); + return chmod_worker (path, mode); +} + +int +lchmod (const char * path, mode_t mode) +{ + path = map_w32_filename (path, NULL); + return chmod_worker (path, mode); +} + int sys_creat (const char * path, int mode) { @@ -4618,6 +4631,28 @@ fchmod (int fd, mode_t mode) return 0; } +int +fchmodat (int fd, char const *path, mode_t mode, int flags) +{ + /* Rely on a hack: an open directory is modeled as file descriptor 0, + as in fstatat. FIXME: Add proper support for fchmodat. */ + char fullname[MAX_UTF8_PATH]; + + if (fd != AT_FDCWD) + { + if (_snprintf (fullname, sizeof fullname, "%s/%s", dir_pathname, path) + < 0) + { + errno = ENAMETOOLONG; + return -1; + } + path = fullname; + } + + return + flags == AT_SYMLINK_NOFOLLOW ? lchmod (path, mode) : sys_chmod (path, mode); +} + int sys_rename_replace (const char *oldname, const char *newname, BOOL force) { diff --git a/src/w32.h b/src/w32.h index f301b3836ca..cf1dadf64c0 100644 --- a/src/w32.h +++ b/src/w32.h @@ -222,6 +222,8 @@ extern void register_child (pid_t, int); extern void sys_sleep (int); extern int sys_link (const char *, const char *); extern int openat (int, const char *, int, int); +extern int fchmodat (int, char const *, mode_t, int); +extern int lchmod (char const *, mode_t); /* Return total and free memory info. */ extern int w32_memory_info (unsigned long long *, unsigned long long *, -- 2.39.2