From d8f2c10b7108fff6b7e437291093a1cadc15ab9f Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 6 May 2023 00:39:44 -0400 Subject: refactor --- src/commands/groups.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 src/commands/groups.c (limited to 'src/commands/groups.c') diff --git a/src/commands/groups.c b/src/commands/groups.c deleted file mode 100644 index bd2e5f9..0000000 --- a/src/commands/groups.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "../command.h" - -#include -#include - -COMMAND_EMPTY(groups) { - - uid_t uid; - int ngroups, i; - gid_t* groups; - struct passwd* pw; - - uid = getuid(); - - pw = getpwuid(uid); - if(pw == NULL){ - error("failed to fetch groups: %s", strerror(errno)); - } - - ngroups = 0; - getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups); - - groups = malloc(sizeof(gid_t) * ngroups); - getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); - - for (i = 0; i < ngroups; i++){ - struct group* gr = getgrgid(groups[i]); - - if(gr == NULL) { - free(groups); - error("failed to fetch groups: %s", strerror(errno)); - } - - printf("%s ",gr->gr_name); - } - - printf("\n"); - - free(groups); - - return EXIT_SUCCESS; -} -- cgit v1.2.3-freya