X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fchown.c;h=2b6b29d461d807eb29e738ee42cfd5c05ea346e2;hb=d6913e92bfd13a918b19223fb676e9c0f136400e;hp=460e4f623a53a6f464cf3ccde5b641c862c58b87;hpb=c4da5fc90ff7ff8ef395c84be4b14e0a3d404cbb;p=gnulib.git diff --git a/lib/chown.c b/lib/chown.c index 460e4f623..2b6b29d46 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -36,9 +36,6 @@ # include #endif #include -#ifndef errno -extern int errno; -#endif /* Provide a more-closely POSIX-conforming version of chown on systems with one or both of the following problems: @@ -71,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)) {