]> Savannah Git Hosting - gnulib.git/commitdiff
lchmod: port back to AIX 7.2
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 20 Jun 2022 04:30:01 +0000 (23:30 -0500)
committerBruno Haible <bruno@clisp.org>
Wed, 31 Aug 2022 23:14:01 +0000 (01:14 +0200)
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.

ChangeLog
doc/glibc-functions/lchmod.texi
doc/posix-functions/chmod.texi
lib/lchmod.c
m4/lchmod.m4
modules/lchmod

index b675a3c524d8a97449465c5b4da10da902740cdf..5309c33a3aa449fa8e50dc02b7143e45712aa3da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 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
index 8d4fd5b890d3c51420938bd86be3c11695871c75..df535eab346c4dd2fb80753daeafbf8300a2ca07 100644 (file)
@@ -16,6 +16,10 @@ HP-UX 11.31.
 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:
index b425c680be68e4d1bd065d2e3ef4e91c78951fdd..90175fd7b922fd34f9ac49212200f700b7433dc7 100644 (file)
@@ -12,4 +12,8 @@ Portability problems 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
index 0e227592ae657739245c1b00b841fa00f8d5dfd1..424480d2324b3dfe910f74491dc170c222e6a75a 100644 (file)
@@ -25,6 +25,7 @@
 #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.
@@ -75,7 +75,20 @@ lchmod (char const *file, mode_t mode)
   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.  */
 
@@ -84,7 +97,6 @@ lchmod (char const *file, mode_t mode)
       errno = EOPNOTSUPP;
       return -1;
     }
-#endif
 
   /* Fall back on chmod, despite a possible race.  */
   return chmod (file, mode);
index bfc925fbe482054c4d9873fc8f75e7653edaa73e..cd43beed851c9bf5e61da481a005680375551a23 100644 (file)
@@ -1,4 +1,4 @@
-#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
@@ -24,6 +24,5 @@ AC_DEFUN([gl_FUNC_LCHMOD],
 # Prerequisites of lib/lchmod.c.
 AC_DEFUN([gl_PREREQ_LCHMOD],
 [
-  AC_CHECK_FUNCS_ONCE([readlink])
   :
 ])
index dd887542f1989fd00594e3cdfcc9ef3ae6e33c8e..0e384cf910eb9d1428d1a3f8a76964a54e23bfaf 100644 (file)
@@ -12,6 +12,7 @@ extensions
 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]