From: Bruno Haible Date: Thu, 14 Aug 2025 19:54:44 +0000 (+0200) Subject: chown: Use issymlink. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3cbc197fcf04a6c0982aceb3cdc3edc80e34727a;p=thirdparty%2Fgnulib.git chown: Use issymlink. * lib/chown.c (rpl_chown): Use issymlink instead of readlink. * modules/chown (Depends-on): Add issymlink. --- diff --git a/ChangeLog b/ChangeLog index 09afcc04c6..4e387893cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2025-08-14 Bruno Haible + + chown: Use issymlink. + * lib/chown.c (rpl_chown): Use issymlink instead of readlink. + * modules/chown (Depends-on): Add issymlink. + 2025-08-14 Bruno Haible issymlink, issymlinkat: New modules. diff --git a/lib/chown.c b/lib/chown.c index 6cfc7e52b8..2ad9972100 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -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); diff --git a/modules/chown b/modules/chown index 7fe9ebfecf..b1aedde85c 100644 --- a/modules/chown +++ b/modules/chown @@ -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]