diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2004-08-10 04:49:04 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2004-08-10 04:49:04 +0000 |
commit | 17c3e95e58ee80cd93037161057d7e29e6e2f8f5 (patch) | |
tree | 47a90a625ce0ca128a947e86fe0e91969a4ef453 /lib/chown.c | |
parent | b584e9626b183c8cde12923dff864b68d22ef9da (diff) | |
download | gnulib-17c3e95e58ee80cd93037161057d7e29e6e2f8f5.tar.gz |
(rpl_chown): Work even if the file is writeable but not readable.
Diffstat (limited to 'lib/chown.c')
-rw-r--r-- | lib/chown.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/chown.c b/lib/chown.c index d761c73399..2b6b29d461 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)) { |