X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fchown.c;h=452fdfcac6ef41b488fc25ce25745bb9ebf5d653;hb=468e57cb4025983239ff40bb1c05b7d8e4328185;hp=2d3b4e8212b2f243e94791235dc1c6b9d6927daf;hpb=02276ef5a15bd1e1264d2857e86c4c9f6132ad12;p=gnulib.git diff --git a/lib/chown.c b/lib/chown.c index 2d3b4e821..452fdfcac 100644 --- a/lib/chown.c +++ b/lib/chown.c @@ -19,26 +19,37 @@ /* 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 -#ifdef HAVE_UNISTD_H +#include +#if HAVE_UNISTD_H # include #endif /* FIXME: describe. */ int -chown (file, gid, uid) - const char *file; - gid_t git; - uid_t uit; +rpl_chown (const char *file, 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); }