UNIX环境高级编程学习之第六章系统数据文件和信息-GID To GroupName
[code lang="cpp"]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
char * gidToGroupName(char *szGroupName, gid_t gid)
{
struct group* gtr;
gtr = getgrgid(gid);
strcpy(szGroupName, gtr->gr_name);
return szGroupName;
}
int main()
{
char szGroupName[32];
memset(szGroupName, '/0', sizeof(szGroupName));
gidToGroupName(szGroupName, 500);
printf("gname = %-10s/n", szGroupName);
}
[/code]
文章评论