在C语言编程中设置和获取代码组数的方法
发布时间:2020-12-16 03:04:14 所属栏目:百科 来源:网络整理
导读:C语言setgroups()函数:设置组代码函数 头文件: #include grp.h 定义函数: int setgroups(size_t size,const gid_t * list); 函数说明:setgroups()用来将list 数组中所标明的组加入到目前进程的组设置中. 参数size 为list()的gid_t 数目,最大值为NGROUP(3
C语言setgroups()函数:设置组代码函数 #include <grp.h> 定义函数: int setgroups(size_t size,const gid_t * list); 函数说明:setgroups()用来将list 数组中所标明的组加入到目前进程的组设置中. 参数size 为list()的gid_t 数目,最大值为NGROUP(32)。 返回值:设置成功则返回0,如有错误则返回-1. 错误代码:
C语言getgroups()函数:获取组代码函数 #include <unistd.h> #include <sys/types.h> 定义函数: int getgroups(int size,gid_t list[]); 函数说明:getgroup() 用来取得目前用户所属的组代码. 参数size 为list() 所能容纳的gid_t 数目. 如果参数size 值为零,此函数仅会返回用户所属的组数。 返回值:返回组识别码,如有错误则返回-1. 错误代码:
范例 #include <unistd.h> #include <sys/types.h> main() { gid_t list[500]; int x,i; x = getgroups(0,list); getgroups(x,list); for(i = 0; i < x; i++) printf("%d:%dn",i,list[i]); } 执行: 0:00 1:01 2:02 3:03 4:04 5:06 6:10 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |