summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2004-08-09 23:33:53 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2004-08-09 23:33:53 +0000
commit1ff6d6ea07aeaf30ba24cded76d426d233185d78 (patch)
treedae3f97d746806ca3e5f3390112b8504260e9d2b /lib
parent3038f02225f3203d8ddc095f40373c9e40bc3bfe (diff)
downloadcoreutils-1ff6d6ea07aeaf30ba24cded76d426d233185d78.tar.xz
(rpl_chown): Work even if the file is writeable but not readable.
Diffstat (limited to 'lib')
-rw-r--r--lib/chown.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/chown.c b/lib/chown.c
index d761c7339..2b6b29d46 100644
--- a/lib/chown.c
+++ b/lib/chown.c
@@ -68,10 +68,11 @@ rpl_chown (const char *file, uid_t uid, gid_t gid)
/* 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))
{