summaryrefslogtreecommitdiff
path: root/src/chown-core.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2005-12-27 07:59:00 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2005-12-27 07:59:00 +0000
commitda4c548bbb8c634c179d7c33f54fea651d1b3619 (patch)
tree00c504631273b4bc2e388a61b1ebfdb7e5a584ae /src/chown-core.c
parent97fe820f88496c222533718348fbf5e4456d20e7 (diff)
downloadcoreutils-da4c548bbb8c634c179d7c33f54fea651d1b3619.tar.xz
(restricted_chown):
Don't try O_WRONLY unless O_RDONLY failed wth EACCES.
Diffstat (limited to 'src/chown-core.c')
-rw-r--r--src/chown-core.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/chown-core.c b/src/chown-core.c
index 562b175c3..e691023cc 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -191,15 +191,13 @@ restricted_chown (char const *file,
{
enum RCH_status status = RC_ok;
struct stat st;
- int o_flags = (O_NONBLOCK | O_NOCTTY);
+ int open_flags = O_NONBLOCK | O_NOCTTY;
- int fd = open (file, O_RDONLY | o_flags);
- if (fd < 0)
- {
- fd = open (file, O_WRONLY | o_flags);
- if (fd < 0)
- return RC_error;
- }
+ int fd = open (file, O_RDONLY | open_flags);
+ if (! (0 <= fd
+ || (errno == EACCES
+ && 0 <= (fd = open (file, O_WRONLY | open_flags)))))
+ return RC_error;
if (fstat (fd, &st) != 0)
{