From e735ad6710a82604a206ad29f6cbcdd7dc4b024c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 14 May 2023 21:43:02 -0400 Subject: refactor and add su --- command/groups.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'command/groups.c') diff --git a/command/groups.c b/command/groups.c index cb950be..f95ee80 100644 --- a/command/groups.c +++ b/command/groups.c @@ -1,13 +1,12 @@ -#include "args.h" #include "command.h" #include "lslib.h" -#include #include #include #include #include #include +#include static void help (void) { printf("Usage: groups [USER]\n\n"); @@ -34,14 +33,14 @@ COMMAND(groups) { if (errno == 0) { error("user not found"); } else { - error("failed to fetch groups: %s", strerror(errno)); + error("failed to fetch groups"); } } ngroups = 0; getgrouplist(pw->pw_name, pw->pw_gid, NULL, &ngroups); - groups = malloc(sizeof(gid_t) * ngroups); + groups = xalloc(sizeof(gid_t) * ngroups); getgrouplist(pw->pw_name, pw->pw_gid, groups, &ngroups); for (i = 0; i < ngroups; i++){ @@ -49,7 +48,7 @@ COMMAND(groups) { if(gr == NULL) { free(groups); - error("failed to fetch groups: %s", strerror(errno)); + error("failed to fetch groups"); } printf("%s ",gr->gr_name); -- cgit v1.2.3-freya