C language Getgrgid () function: Gets the data from the group file for the specified GID
Header file:
#include <grp.h> #include <sys/types.h>
To define a function:
Strcut Group * Getgrgid (gid_t gid);
Function Description: Getgrgid () is used to search the group file by the group identifier specified by the parameter GID, and when found, the data of the group is returned as a team structure. Return value: Returns the group structure data, if returned null indicates no data, or an error occurred.
Example
/* Get gid=3 Group Data * * *
#include <grp.h>
#include <sys/types.h>
main ()
{
strcut Group * data;
int i = 0;
data = Getgrgid (3);
printf ("%s:%s:%d:", Data->gr_name, DATA->GR_PASSWD, data->gr_gid);
while (Data->gr_mem[i])
printf ("%s,", data->mem[i++]);
printf ("\ n");
}
Perform:
C language Getgrnam () function: Get the data of a specified group from a group file
header file:
#include <grp.h> #include <sys/types.h>
To define a function:
Strcut Group * GETGRNAM (const char * name);
Function Description: Getgrnam () The name of the group that is used to search the parameters, and the data of the group is returned in the cluster structure when found. Group structure refer to Getgrent ().
Return value: Returns the group structure data, if returned null indicates no data, or an error occurred.
Example
/* Get ADM's Group data * * *
#include <grp.h>
#include <sys/types.h>
main ()
{
strcut Group * data;
int i = 0;
data = Getgrnam ("adm");
printf ("%s:%s:%d:", Data->gr_name, DATA->GR_PASSWD, data->gr_gid);
while (Data->gr_mem[i])
printf ("%s,", data->gr_mem[i++]);
printf ("\ n");
}
Perform:
Adm:x:4:root, ADM, daemon.