]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
chown: Use issymlink.
authorBruno Haible <bruno@clisp.org>
Thu, 14 Aug 2025 19:54:44 +0000 (21:54 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Aug 2025 22:23:14 +0000 (00:23 +0200)
* lib/chown.c (rpl_chown): Use issymlink instead of readlink.
* modules/chown (Depends-on): Add issymlink.

ChangeLog
lib/chown.c
modules/chown

index 09afcc04c61ddc2be49a9e6f8c574b9192a4178a..4e387893cb277ad9f1ff8d9f450a321733605562 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-08-14  Bruno Haible  <bruno@clisp.org>
+
+       chown: Use issymlink.
+       * lib/chown.c (rpl_chown): Use issymlink instead of readlink.
+       * modules/chown (Depends-on): Add issymlink.
+
 2025-08-14  Bruno Haible  <bruno@clisp.org>
 
        issymlink, issymlinkat: New modules.
index 6cfc7e52b817e68781095144a6e44f5340eca078..2ad99721005e12bf79e5ad41023b209d0957eacb 100644 (file)
@@ -87,8 +87,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
      If the file is a symlink, open the file (following symlinks), and
      fchown the resulting descriptor.  Although the open might fail
      due to lack of permissions, it's the best we can easily do.  */
-  char linkbuf[1];
-  if (0 <= readlink (file, linkbuf, sizeof linkbuf))
+  if (issymlink (file) > 0)
     {
       int open_flags = O_NONBLOCK | O_NOCTTY | O_CLOEXEC;
       int fd = open (file, O_RDONLY | open_flags);
index 7fe9ebfecfddf5858247d21f592a2f0e32ec7914..b1aedde85c9ca8916a0c72aded30710b6bdbb72e 100644 (file)
@@ -9,6 +9,7 @@ m4/chown.m4
 Depends-on:
 unistd-h
 fstat           [test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1]
+issymlink       [test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1]
 open            [test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1]
 stat            [test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1]
 bool            [test $HAVE_CHOWN = 0 || test $REPLACE_CHOWN = 1]