X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fchown.c;h=dc351d28cc61b77da53e1c2e0450237ac9d6f0ad;hb=a19e601b42a86b59b4af13aa9f960397f5306c38;hp=2d3b4e8212b2f243e94791235dc1c6b9d6927daf;hpb=02276ef5a15bd1e1264d2857e86c4c9f6132ad12;p=gnulib.git diff --git a/lib/chown.c b/lib/chown.c index 2d3b4e821..dc351d28c 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -19,7 +19,14 @@ /* written by Jim Meyering */ #include + +/* Disable the definition of chown to rpl_chown (from config.h) in this + file. Otherwise, we'd get conflicting prototypes for rpl_chown on + most systems. */ +#undef chown + #include +#include #ifdef HAVE_UNISTD_H # include #endif @@ -27,18 +34,25 @@ /* FIXME: describe. */ int -chown (file, gid, uid) +rpl_chown (file, uid, gid) const char *file; - gid_t git; - uid_t uit; + uid_t uid; + gid_t gid; { if (gid == (gid_t) -1 || uid == (uid_t) -1) { - /* Stat file to get id(s) that will remain unchanged. */ - FIXME - } + struct stat file_stats; -#undef chown + /* Stat file to get id(s) that should remain unchanged. */ + if (stat (file, &file_stats)) + return 1; + + if (gid == (gid_t) -1) + gid = file_stats.st_gid; + + if (uid == (uid_t) -1) + uid = file_stats.st_uid; + } - return chown (file, gid, uid); + return chown (file, uid, gid); }