Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <grp.h>
struct group *getgrgid(gid_t gid);
Provides information about the group specified by gid and its members.
If unsuccessful, getgrgid() returns a NULL pointer.
There are no documented errno values.
⁄* CELEBG08
This example provides the root GID and group name.
*⁄
#define _POSIX_SOURCE
#include <sys⁄types.h>
#include <grp.h>
#include <stdio.h>
#include <sys⁄stat.h> ⁄*FIX: used to be <stat.h>*⁄
main() {
struct stat info;
struct group *grp;
if (stat("⁄", &info) < 0)
perror("stat() error");
else {
printf("The root is owned by gid %d\n", info.st_gid);
if ((grp = getgrgid(info.st_gid)) == NULL)
perror("getgrgid() error");
else
printf("This group name is %s\n", grp->gr_name);
}
}
The root is owned by gid 500
This group name is SYS1