Files
RedBear-OS/tests/grp/getgroups.c
Red Bear OS 1b3e94a20d Red Bear OS relibc baseline
From release 0.1.0 pre-patched archive.
This includes all Red Bear modifications previously maintained
as patches in local/patches/relibc/.
2026-06-27 09:19:26 +03:00

25 lines
593 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <grp.h>
int main() {
gid_t primary_gid = getegid();
struct group *pg = getgrgid(primary_gid);
printf("getegid: %u (%s)\n", primary_gid, pg ? pg->gr_name : "?");
int count = getgroups(0, NULL);
gid_t *list = malloc(sizeof(gid_t) * count);
getgroups(count, list);
printf("getgroups: %d\n", count);
for (int i = 0; i < count; i++) {
struct group *sg = getgrgid(list[i]);
printf(" - %u (%s)\n", list[i], sg ? sg->gr_name : "?");
}
free(list);
return 0;
}