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

source code of compiler-rt/test/sanitizer_common/TestCases/Linux/getgrouplist.cpp