2022-06-19 Paul Eggert <eggert@cs.ucla.edu>
+ lchmod: port back to AIX 7.2
+ Problem reported by Bruno Haible in:
+ https://lists.gnu.org/r/bug-gnulib/2022-06/msg00075.html
+ * lib/lchmod.c: Include string.h, for strlen.
+ (lchmod): Do not depend on HAVE_READLINK since we now depend on
+ the readlink module. Check for AIX 7.2 bug.
+ * m4/lchmod.m4 (gl_PREREQ_LCHMOD): Do not check for readlink
+ since we now depend on the readlink module.
+ * modules/lchmod (Depends-on): Depend on readlink.
+
fchmodat: pacify gcc -Wunused-variable
Problem reported by Bruno Haible in:
https://lists.gnu.org/r/bug-gnulib/2022-06/msg00075.html
This function always fails with @code{errno} set to @code{ENOSYS},
even when the file is not a symbolic link:
GNU/Linux with glibc 2.31.
+@item
+This function does not fail when the file name argument ends in a slash
+and (without the slash) names a non-directory, on some platforms:
+AIX 7.2.
@end itemize
Portability problems not fixed by Gnulib:
Portability problems not fixed by Gnulib:
@itemize
+@item
+This function does not fail when the file name argument ends in a slash
+and (without the slash) names a non-directory, on some platforms:
+AIX 7.2.
@end itemize
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
+#include <string.h>
#include <unistd.h>
#ifdef __osf__
int
lchmod (char const *file, mode_t mode)
{
-#if HAVE_READLINK
char readlink_buf[1];
-# ifdef O_PATH
+#ifdef O_PATH
/* Open a file descriptor with O_NOFOLLOW, to make sure we don't
follow symbolic links, if /proc is mounted. O_PATH is used to
avoid a failure if the file is not readable.
errno = err;
if (0 <= err)
return err == 0 ? 0 : -1;
-# endif
+#endif
+
+ size_t len = strlen (file);
+ if (len && file[len - 1] == '/')
+ {
+ struct stat st;
+ if (lstat (file, &st) < 0)
+ return -1;
+ if (!S_ISDIR (st.st_mode))
+ {
+ errno = ENOTDIR;
+ return -1;
+ }
+ }
/* O_PATH + /proc is not supported. */
errno = EOPNOTSUPP;
return -1;
}
-#endif
/* Fall back on chmod, despite a possible race. */
return chmod (file, mode);
-#serial 9
+#serial 10
dnl Copyright (C) 2005-2006, 2008-2022 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
# Prerequisites of lib/lchmod.c.
AC_DEFUN([gl_PREREQ_LCHMOD],
[
- AC_CHECK_FUNCS_ONCE([readlink])
:
])
fcntl-h [test $HAVE_LCHMOD = 0]
intprops [test $HAVE_LCHMOD = 0]
lstat [test $HAVE_LCHMOD = 0]
+readlink [test $HAVE_LCHMOD = 0]
sys_stat
unistd [test $HAVE_LCHMOD = 0]