summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-12-09 20:31:34 +0000
committerJim Meyering <jim@meyering.net>2000-12-09 20:31:34 +0000
commit40d911bc459bc7a0e62576d30382481ab9e4118a (patch)
treef62fb15af810faaf45298467c498757e3568a925 /src
parent748db39d02e1833ed607177d7f1b3e11a8860e31 (diff)
downloadcoreutils-40d911bc459bc7a0e62576d30382481ab9e4118a.tar.xz
Include <pwd.h>, <grp.h>, and "xalloc.h".
[!_POSIX_VERSION]: Declare getgrnam and getgrgid. (gid_to_name): New function. (uid_to_name): Likewise. (chopt_free): Likewise.
Diffstat (limited to 'src')
-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. */