標準/拡張機能 | C/C++ | 依存項目 |
---|---|---|
z/OS®UNIX | 両方 |
#define _POSIX_SOURCE
#include <unistd.h>
int getgroupsbyname(char username[], int size, gid_t list[]);
指定された username の補足グループ ID を list 配列に 保管します。size は、list 配列に保管できる gid_t エレメントの数を指定します。
正常に実行された場合、getgroupsbyname() は list に入れる 補足グループ ID の数を戻します。この値は常に l 以上で、かつ NGROUPS_MAX の値以下です。
size がゼロの場合、getgroupsbyname() はプロセスの 補足グループ ID の合計数を戻します。getgroupsbyname() はグループ ID を list に 保管しようとはしません。
⁄* CELEBG11
This example provides a list of the supplementary group IDs for
MVSUSR1.
*⁄
#define _POSIX_SOURCE
#include <sys⁄types.h>
#include <grp.h>
#include <stdio.h>
#include <unistd.h>
#define dim(x) (sizeof(x)⁄sizeof(x[0]))
main() {
gid_t gids[500];
struct group *grp;
int count, curr;
char user[]="MVSUSR1";
if ((count = getgroupsbyname(user, dim(gids), gids)) == -1)
perror("getgroups() error");
else {
printf("The following is the list of %s's supplementary groups:¥n",
user);
for (curr=0; curr<count; curr++) {
if ((grp = getgrgid(gids[curr])) == NULL)
perror("getgrgid() error");
else
printf(" %8s (%d)¥n", grp->gr_name, (int) gids[curr]);
}
}
}
The following is the list of MVSUSR1's supplementary groups:
SYS1 (500)
USERS (523)