#include <grp.h> struct group *getgrgid(gid_t gid);Service Program Name: QSYPAPI
The getgrgid() function returns a pointer to an object of type struct group containing an entry from the user database with a matching GID.
*READ authority is required to the user profile associated with the gid. If the user does not have *READ authority, only the name of the group and the group ID values are returned.
char * | gr_name | Name of the group |
gid_t | gr_gid | Group ID |
char ** | gr_mem | A null-terminated list of pointers to the individual member profile names. If the group profile does not have any members or if the caller does not have *READ authority to the group profile, the list will be empty. |
If getgrgid() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.
Error condition | Additional information |
---|---|
[EAGAIN] |
The user profile associated with the GID is currently locked by another process. |
[EC2] |
Detected pointer that is not valid. |
[EINVAL] |
Value is not valid. Check the job log for messages. |
[ENOENT] | The user profile associated with the GID was not found. |
[ENOMEM] |
The user profile associated with the GID has exceeded its storage limit. |
[ENOSPC] |
Machine storage limit exceeded. |
See Code disclaimer information for information pertaining to code examples.
The following example gets the group information for the gid of 91. The group name is GROUP1. There are two group members, CLIFF and PATRICK.
#include <grp.h> #include <stdio.h> main() { struct group *grp; short int lp; if (NULL == (grp = getgrgid(91))) perror("getgrgid() error."); else { printf("The group name is: %s\n", grp->gr_name); printf("The gid is: %u\n", grp->gr_gid); for (lp = 1; NULL != *(grp->gr_mem); lp++, (grp->gr_mem)++) printf("Group member %d is: %s\n", lp, *(grp->gr_mem)); } }
Output:
The group name is: GROUP1 The gid is: 91 Group member 1 is: CLIFF Group member 2 is: PATRICK
Top | UNIX-Type APIs | APIs by category |