6 int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups)
10 if (*ngroups<1) return -1;
16 while ((gr = getgrent()) && *ngroups < INT_MAX) {
17 for (i=0; gr->gr_mem[i] && strcmp(user, gr->gr_mem[i]); i++);
18 if (!gr->gr_mem[i]) continue;
19 if (++*ngroups <= n) *groups++ = gr->gr_gid;
23 return *ngroups > n ? -1 : *ngroups;