From: Paul Eggert Date: Tue, 27 Dec 2005 07:59:00 +0000 (+0000) Subject: (restricted_chown): X-Git-Tag: v6.0~1022 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da4c548bbb8c634c179d7c33f54fea651d1b3619;p=thirdparty%2Fcoreutils.git (restricted_chown): Don't try O_WRONLY unless O_RDONLY failed wth EACCES. --- diff --git a/src/chown-core.c b/src/chown-core.c index 562b175c39..e691023cc1 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) {