+
+ 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;