提交 91e836fd 编写于 作者: R Rich Felker

implement getgrouplist (for initgroups), formerly dummied-out

上级 3f44f298
#include <grp.h>
/* FIXME */
#include <string.h>
#include <limits.h>
int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
{
size_t n, i;
struct group *gr;
if (*ngroups<1) return -1;
*groups = gid;
n = *ngroups;
*groups++ = gid;
*ngroups = 1;
return 0;
setgrent();
while ((gr = getgrent()) && *ngroups < INT_MAX) {
for (i=0; gr->gr_mem[i] && strcmp(user, gr->gr_mem[i]); i++);
if (!gr->gr_mem[i]) continue;
if (++*ngroups <= n) *groups++ = gr->gr_gid;
}
endgrent();
return *ngroups > n ? -1 : *ngroups;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册