summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-02-22 22:47:06 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2020-02-23 00:13:39 -0800
commitad0024b3fefea56629941e6533705fa3a4820064 (patch)
tree36791b17bb870341a5919072300a79c59a8e830c /m4
parenta7f76250e6cbbf24e710a8b1f25c1596c97b02c0 (diff)
downloadgnulib-ad0024b3fefea56629941e6533705fa3a4820064.tar.gz
fchmodat, lchmod: simplify
It appears that we may have overengineered lchmod and fchmodat, in that the code was prepared for some hypothetical platforms but was so complicated that it was hard to understand. I attempted to improve the situation by simplifying the code when this simplification should not hurt on real platforms; we can re-add complexity later to port to platforms I didn’t know about. * lib/fchmodat.c (fchmodat): * lib/lchmod.c (lchmod): Put the ‘defined __linux__ || defined __ANDROID__’ #ifdef only around the /proc code that needs it. * lib/fchmodat.c (fchmodat): Coalese calls to orig_fchmodat. * lib/lchmod.c (__need_system_sys_stat_h): Omit; no longer needed. Do not include <config.h> twice. (orig_lchmod) [HAVE_LCHMOD]: Remove, since we need not wrap lchmod on any known hosts. (lchmod): Do not defer to fchmodat, so that the lchmod module need not depend on the fchmodat module (which is a circular dependency). Do not use openat, since ‘open’ suffices. Coalesce calls to lchmod/chmod. * lib/lchmod.c, lib/sys_stat.in.h (lchmod): * m4/sys_stat_h.m4 (REPLACE_FSTAT): * modules/lchmod (Depends-on, configure.ac): * modules/sys_stat (Depends-on): Do not worry about replacing lchmod, since that shouldn’t happen. * m4/lchmod.m4 (gl_FUNC_LCHMOD): Do not check for fchmodat. Do not worry about whether lchmod works on non-symlinks, since every known lchmod works on non-symlinks. * modules/lchmod (Depends-on): Remove circular dependency on fchmodat.
Diffstat (limited to 'm4')
-rw-r--r--m4/lchmod.m457
-rw-r--r--m4/sys_stat_h.m41
2 files changed, 2 insertions, 56 deletions
diff --git a/m4/lchmod.m4 b/m4/lchmod.m4
index 61e3f11228..b9e8a97cb3 100644
--- a/m4/lchmod.m4
+++ b/m4/lchmod.m4
@@ -1,4 +1,4 @@
-#serial 6
+#serial 7
dnl Copyright (C) 2005-2006, 2008-2020 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
@@ -17,62 +17,9 @@ AC_DEFUN([gl_FUNC_LCHMOD],
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
- AC_CHECK_FUNCS_ONCE([fchmodat lchmod lstat])
+ AC_CHECK_FUNCS_ONCE([lchmod lstat])
if test "$ac_cv_func_lchmod" = no; then
HAVE_LCHMOD=0
- else
- AC_CACHE_CHECK([whether lchmod works on non-symlinks],
- [gl_cv_func_lchmod_works],
- [AC_RUN_IFELSE(
- [AC_LANG_PROGRAM(
- [
- AC_INCLUDES_DEFAULT[
- #ifndef S_IRUSR
- #define S_IRUSR 0400
- #endif
- #ifndef S_IWUSR
- #define S_IWUSR 0200
- #endif
- #ifndef S_IRWXU
- #define S_IRWXU 0700
- #endif
- #ifndef S_IRWXG
- #define S_IRWXG 0070
- #endif
- #ifndef S_IRWXO
- #define S_IRWXO 0007
- #endif
- ]],
- [[
- int permissive = S_IRWXU | S_IRWXG | S_IRWXO;
- int desired = S_IRUSR | S_IWUSR;
- static char const f[] = "conftest.lchmod";
- struct stat st;
- if (creat (f, permissive) < 0)
- return 1;
- if (lchmod (f, desired) != 0)
- return 1;
- if (stat (f, &st) != 0)
- return 1;
- return ! ((st.st_mode & permissive) == desired);
- ]])],
- [gl_cv_func_lchmod_works=yes],
- [gl_cv_func_lchmod_works=no],
- [case "$host_os" in
- dnl Guess no on Linux with glibc, yes otherwise.
- linux-gnu*) gl_cv_func_lchmod_works="guessing no" ;;
- *) gl_cv_func_lchmod_works="$gl_cross_guess_normal" ;;
- esac
- ])
- rm -f conftest.lchmod])
- case $gl_cv_func_lchmod_works in
- *yes) ;;
- *)
- AC_DEFINE([NEED_LCHMOD_NONSYMLINK_FIX], [1],
- [Define to 1 if lchmod does not work right on non-symlinks.])
- REPLACE_LCHMOD=1
- ;;
- esac
fi
])
diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4
index 30d60d920f..3efba5a7b9 100644
--- a/m4/sys_stat_h.m4
+++ b/m4/sys_stat_h.m4
@@ -94,7 +94,6 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
REPLACE_FSTAT=0; AC_SUBST([REPLACE_FSTAT])
REPLACE_FSTATAT=0; AC_SUBST([REPLACE_FSTATAT])
REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
- REPLACE_LCHMOD=0; AC_SUBST([REPLACE_LCHMOD])
REPLACE_LSTAT=0; AC_SUBST([REPLACE_LSTAT])
REPLACE_MKDIR=0; AC_SUBST([REPLACE_MKDIR])
REPLACE_MKFIFO=0; AC_SUBST([REPLACE_MKFIFO])