#include <stdio.h>
#include <sys/types.h>
#include <sys/types.h>
#include <grp.h>
#include <unistd.h>
#if 0
struct group
{
char *gr_name
;
char *gr_passwd
;
gid_t gr_gid
;
char **gr_mem
;
};
#endif
int main(int argc
, const char *argv
[])
{
int ret
= -1;
struct group
* gp
= NULL;
int i
= 0;
gp
= getgrnam("root");
printf("%s\n", gp
->gr_name
);
printf("%s\n", gp
->gr_passwd
);
printf("%d\n", gp
->gr_gid
);
while(gp
->gr_mem
[i
])
printf("%s\n", gp
->gr_mem
[i
++]);
puts("*****************************************************");
gp
= getgrgid(getgid());
printf("%s\n", gp
->gr_name
);
printf("%s\n", gp
->gr_passwd
);
printf("%d\n", gp
->gr_gid
);
while(gp
->gr_mem
[i
])
printf("%s\n", gp
->gr_mem
[i
++]);
return 0;
}
测试结果
转载请注明原文地址:https://tech.qufami.com/read-9668.html