From: Jim Meyering Date: Sat, 9 Dec 2000 20:31:34 +0000 (+0000) Subject: Include , , and "xalloc.h". X-Git-Tag: TEXTUTILS-2_0_10~20 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=40d911bc459bc7a0e62576d30382481ab9e4118a;p=thirdparty%2Fcoreutils.git Include , , and "xalloc.h". [!_POSIX_VERSION]: Declare getgrnam and getgrgid. (gid_to_name): New function. (uid_to_name): Likewise. (chopt_free): Likewise. --- diff --git a/src/chown-core.c b/src/chown-core.c index 73568c2c46..265275ac04 100644 --- a/src/chown-core.c +++ b/src/chown-core.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #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 ? _("") : grp->gr_name); +} + +char * +uid_to_name (uid_t uid) +{ + struct passwd *pwd = getpwuid (uid); + return xstrdup (pwd == NULL ? _("") : 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. */