X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fchown.c;h=2d97902e631a5ca42c0a11681b65c1ee5a5ad3a6;hb=894e0221d38190902541ce6ee2803fc375b42683;hp=460e4f623a53a6f464cf3ccde5b641c862c58b87;hpb=c4da5fc90ff7ff8ef395c84be4b14e0a3d404cbb;p=gnulib.git diff --git a/lib/chown.c b/lib/chown.c index 460e4f623..2d97902e6 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -1,6 +1,6 @@ /* provide consistent interface to chown for systems that don't interpret an ID of -1 as meaning `don't change the corresponding ID'. - Copyright (C) 1997, 2004 Free Software Foundation, Inc. + Copyright (C) 1997, 2004, 2005 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* written by Jim Meyering */ @@ -30,15 +30,8 @@ #if HAVE_UNISTD_H # include #endif -#if HAVE_FCNTL_H -# include -#else -# include -#endif +#include #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: @@ -56,7 +49,7 @@ rpl_chown (const char *file, uid_t uid, gid_t gid) /* Stat file to get id(s) that should remain unchanged. */ if (stat (file, &file_stats)) - return 1; + return -1; if (gid == (gid_t) -1) gid = file_stats.st_gid; @@ -71,10 +64,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)) {