]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Include <pwd.h>, <grp.h>, and "xalloc.h".
authorJim Meyering <jim@meyering.net>
Sat, 9 Dec 2000 20:31:34 +0000 (20:31 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 9 Dec 2000 20:31:34 +0000 (20:31 +0000)
[!_POSIX_VERSION]: Declare getgrnam and getgrgid.
(gid_to_name): New function.
(uid_to_name): Likewise.
(chopt_free): Likewise.

src/chown-core.c

index 73568c2c4655aa0e4f613e9a3472f9717e9499be..265275ac0471103fbaf0d49e11cc5ad3d88cbfd0 100644 (file)
@@ -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"
 #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. */