1570af302Sopenharmony_ci#define _GNU_SOURCE 2570af302Sopenharmony_ci#include <grp.h> 3570af302Sopenharmony_ci#include <limits.h> 4570af302Sopenharmony_ci 5570af302Sopenharmony_ciint initgroups(const char *user, gid_t gid) 6570af302Sopenharmony_ci{ 7570af302Sopenharmony_ci gid_t groups[NGROUPS_MAX]; 8570af302Sopenharmony_ci int count = NGROUPS_MAX; 9570af302Sopenharmony_ci if (getgrouplist(user, gid, groups, &count) < 0) return -1; 10570af302Sopenharmony_ci return setgroups(count, groups); 11570af302Sopenharmony_ci} 12