|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1603 (0x643)
Types: TextFile
Notes: UNIX file
Names: »getgrent.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦f4b8d8c84⟧ UNIX Filesystem
└─⟦this⟧ »libc/gen/getgrent.c«
/*
* Coherent I/O Library.
* Routines to get the group file entry.
* (searches by next entry, name or numerical id).
*/
#include <stdio.h>
#include <grp.h>
#define field(x) { x=cp; while (*cp++); }
#define NGRPLINE 256
#define NGRMEM 64 /* Maximum no. of members in a group */
#define GRFILE "/etc/group"
static char grline[NGRPLINE];
static char *grmems[NGRMEM+1];
static struct group gr;
static FILE *grfile = { NULL };
struct group *
getgrnam(name)
char *name;
{
register struct group *grp;
setgrent();
while ((grp = getgrent()) != NULL)
if (streq(name, grp->gr_name))
return (grp);
return (NULL);
}
struct group *
getgrgid(gid)
{
register struct group *grp;
setgrent();
while ((grp = getgrent()) != NULL)
if (gid == grp->gr_gid)
return (grp);
return (NULL);
}
struct group *
getgrent()
{
register char *cp, *xp;
if (grfile == NULL)
if ((grfile = fopen(GRFILE, "r")) == NULL)
return (NULL);
cp = grline;
{
register int c;
while ((c = getc(grfile))!=EOF && c!='\n') {
if (c == ':')
c = '\0';
if (cp < &grline[NGRPLINE-1])
*cp++ = c;
}
if (c == EOF)
return (NULL);
}
*cp = '\0';
cp = grline;
field(gr.gr_name);
field(gr.gr_passwd);
field(xp);
gr.gr_gid = atoi(xp);
{
register char **mp;
gr.gr_mem = mp = grmems;
for (;;) {
if (*cp == '\0')
break;
*mp++ = cp;
while (*cp!=',' && *cp!='\0')
cp++;
if (*cp == ',')
*cp++ = '\0';
}
*mp = NULL;
}
return (&gr);
}
setgrent()
{
if (grfile != NULL)
rewind(grfile);
}
endgrent()
{
if (grfile != NULL) {
fclose(grfile);
grfile = NULL;
}
}