home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/1/91 DJB baseline public domain. todo: cache groups.
- */
-
- /*
-
- int gid2groupname(gid,gnp) int gid; char **gnp; looks up group gid and
- points *gnp to the name for that group (possibly stored in a static area
- interfering with getgrgid()). If gid does not have a system name,
- gid2groupname() uses gid in decimal as the name and returns 1. Normally
- it returns 0.
-
- int groupname2gid(gn,gid); char *gn; int *gid; looks up group name gn
- and sets *gid to the number of that group. If gn is entirely numeric it
- simply sets *gid to that number are returns 1. Otherwise it returns 0.
- If gn is not numeric and not a system group name, groupname2gid returns
- -1 and leaves *gid alone.
-
- */
-
- #include <grp.h>
- #include "groupname.h"
- #include "numeric.h"
-
- int gid2groupname(gid,gnp)
- int gid;
- char **gnp;
- {
- struct group *gr;
- static char gn[20];
-
- if (gr = getgrgid(gid))
- {
- *gnp = gr->gr_name;
- return 0;
- }
- sprintf(gn,"%d",gid);
- *gnp = gn;
- return 1;
- }
-
- int groupname2gid(gn,gid)
- char *gn;
- int *gid;
- {
- struct group *gr;
-
- if (numeric(gn))
- {
- *gid = atoi(gn);
- return 1;
- }
- gr = getgrnam(gn);
- if (!gr)
- return -1; /*XXX*/
- *gid = gr->gr_gid;
- return 0;
- }
-