xref: /llvm-project/compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp (revision 49f282b5496600d9a9bc3ea311cf718e892ddf2c)
1 // RUN: %clangxx -O0 -g %s -o %t && %run %t
2 
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <grp.h>
6 
main(void)7 int main(void) {
8   gid_t *groups;
9   group *root;
10   int ngroups;
11 
12   ngroups = sysconf(_SC_NGROUPS_MAX);
13   groups = (gid_t *)malloc(ngroups * sizeof(gid_t));
14   if (!groups)
15     exit(1);
16 
17   if (!(root = getgrnam("root")))
18     exit(2);
19 
20   if (getgrouplist("root", root->gr_gid, groups, &ngroups) == -1)
21     exit(3);
22 
23   if (groups && ngroups) {
24     free(groups);
25     exit(0);
26   }
27 
28   return -1;
29 }
30