projects
/
gnulib.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
.
[gnulib.git]
/
lib
/
chown.c
diff --git
a/lib/chown.c
b/lib/chown.c
index
2d3b4e8
..
452fdfc
100644
(file)
--- a/
lib/chown.c
+++ b/
lib/chown.c
@@
-19,26
+19,37
@@
/* written by Jim Meyering */
#include <config.h>
/* written by Jim Meyering */
#include <config.h>
+
+/* 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 <sys/types.h>
#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
+#include <sys/stat.h>
+#if HAVE_UNISTD_H
# include <unistd.h>
#endif
/* FIXME: describe. */
int
# include <unistd.h>
#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)
{
{
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, u
id);
+ return chown (file,
uid, g
id);
}
}