summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chown-core.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/chown-core.c b/src/chown-core.c
index 73568c2c4..265275ac0 100644
--- a/src/chown-core.c
+++ b/src/chown-core.c
@@ -20,6 +20,8 @@
#include <config.h>
#include <stdio.h>
#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
#include "system.h"
#include "error.h"
@@ -27,6 +29,12 @@
#include "quote.h"
#include "savedir.h"
#include "chown-core.h"
+#include "xalloc.h"
+
+#ifndef _POSIX_VERSION
+struct group *getgrnam ();
+struct group *getgrgid ();
+#endif
void
chopt_init (struct Chown_option *chopt)
@@ -39,6 +47,29 @@ chopt_init (struct Chown_option *chopt)
chopt->group_name = 0;
}
+void
+chopt_free (struct Chown_option *chopt)
+{
+ XFREE (chopt->user_name);
+ XFREE (chopt->group_name);
+}
+
+/* FIXME: describe */
+
+char *
+gid_to_name (gid_t gid)
+{
+ struct group *grp = getgrgid (gid);
+ return xstrdup (grp == NULL ? _("<unknown>") : grp->gr_name);
+}
+
+char *
+uid_to_name (uid_t uid)
+{
+ struct passwd *pwd = getpwuid (uid);
+ return xstrdup (pwd == NULL ? _("<unknown>") : pwd->pw_name);
+}
+
/* Tell the user how/if the user and group of FILE have been changed.
If USER is NULL, give the group-oriented messages.
CHANGED describes what (if anything) has happened. */