#include "../command.h" #include #include COMMAND_EMPTY(groups) { uid_t uid = getuid(); struct passwd* pw = getpwuid(uid); if(pw == NULL){ error("failed to fetch groups: %s", strerror(errno)); } int ngroups = 0; getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups); gid_t groups[ngroups]; getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); for (int i = 0; i < ngroups; i++){ struct group* gr = getgrgid(groups[i]); if(gr == NULL){ error("failed to fetch groups: %s", strerror(errno)); } printf("%s ",gr->gr_name); } printf("\n"); return EXIT_SUCCESS; }