# HG changeset patch # User Paul Eggert # Date 1092113344 0 # Node ID 43b6cc039c4910bd9a1d6fa13f727efc0d144172 # Parent 496d490f0b30aadba6de787851bbac602b06babc (rpl_chown): Work even if the file is writeable but not readable. diff --git a/lib/chown.c b/lib/chown.c --- a/lib/chown.c +++ b/lib/chown.c @@ -68,10 +68,11 @@ /* Handle the case in which the system-supplied chown function does *not* follow symlinks. Instead, it changes permissions on the symlink itself. To work around that, we open the - file (but this can fail due to lack of read permission) and + file (but this can fail due to lack of read or write permission) and use fchown on the resulting descriptor. */ int fd = open (file, O_RDONLY | O_NONBLOCK | O_NOCTTY); - if (fd == -1) + if (fd < 0 + && (fd = open (file, O_WRONLY | O_NONBLOCK | O_NOCTTY)) < 0) return -1; if (fchown (fd, uid, gid)) {