diff options
author | Mike Frysinger <vapier@gentoo.org> | 2006-12-16 19:12:19 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2006-12-16 19:12:19 +0000 |
commit | 832255d18adb277bb06c74a8b50c4862e5a7f914 (patch) | |
tree | b6adb89fd364284b49ee1c6e1253a549bc8cf747 /test/pwd_grp/getgroups.c | |
parent | 9db10d18c0f4e25830f782acea9be6b971d48f3c (diff) |
clean up
Diffstat (limited to 'test/pwd_grp/getgroups.c')
-rw-r--r-- | test/pwd_grp/getgroups.c | 137 |
1 files changed, 64 insertions, 73 deletions
diff --git a/test/pwd_grp/getgroups.c b/test/pwd_grp/getgroups.c index ea31b5829..0c093081a 100644 --- a/test/pwd_grp/getgroups.c +++ b/test/pwd_grp/getgroups.c @@ -1,9 +1,9 @@ /* This test was ripped out of GNU 'id' from coreutils-5.0 - * by Erik Andersen. + * by Erik Andersen. * * * id is Copyright (C) 1989-2003 Free Software Foundation, Inc. - * and licensed under the GPL v2 or later, and was written by + * and licensed under the GPL v2 or later, and was written by * Arnold Robbins, with a major rewrite by David MacKenzie, */ @@ -19,90 +19,81 @@ static int problems = 0; /* Print the name or value of group ID GID. */ -static void -print_group (gid_t gid) +static void print_group(gid_t gid) { - struct group *grp = NULL; + struct group *grp = NULL; - grp = getgrgid (gid); - if (grp == NULL) - { - warn("cannot find name for group ID %u", gid); - problems++; - } + grp = getgrgid(gid); + if (grp == NULL) { + warn("cannot find name for group ID %u", gid); + problems++; + } - if (grp == NULL) - printf ("%u", (unsigned) gid); - else - printf ("%s", grp->gr_name); + if (grp == NULL) + printf("%u", (unsigned)gid); + else + printf("%s", grp->gr_name); } -static int -xgetgroups (gid_t gid, int *n_groups, gid_t **groups) +static int xgetgroups(gid_t gid, int *n_groups, gid_t ** groups) { - int max_n_groups; - int ng; - gid_t *g; - int fail = 0; - - max_n_groups = getgroups (0, NULL); - - /* Add 1 just in case max_n_groups is zero. */ - g = (gid_t *) malloc (max_n_groups * sizeof (gid_t) + 1); - if (g==NULL) - err(EXIT_FAILURE, "out of memory"); - ng = getgroups (max_n_groups, g); - - if (ng < 0) - { - warn("cannot get supplemental group list"); - ++fail; - free (groups); - } - if (!fail) - { - *n_groups = ng; - *groups = g; - } - return fail; + int max_n_groups; + int ng; + gid_t *g; + int fail = 0; + + max_n_groups = getgroups(0, NULL); + + /* Add 1 just in case max_n_groups is zero. */ + g = (gid_t *) malloc(max_n_groups * sizeof(gid_t) + 1); + if (g == NULL) + err(EXIT_FAILURE, "out of memory"); + ng = getgroups(max_n_groups, g); + + if (ng < 0) { + warn("cannot get supplemental group list"); + ++fail; + free(groups); + } + if (!fail) { + *n_groups = ng; + *groups = g; + } + return fail; } /* Print all of the distinct groups the user is in. */ -int main (int argc, char **argv) +int main(int argc, char *argv[]) { - struct passwd *pwd; - - pwd = getpwuid (getuid()); - if (pwd == NULL) - problems++; + struct passwd *pwd; - print_group (getgid()); - if (getegid() != getgid()) - { - putchar (' '); - print_group (getegid()); - } + pwd = getpwuid(getuid()); + if (pwd == NULL) + problems++; - { - int n_groups; - gid_t *groups; - register int i; + print_group(getgid()); + if (getegid() != getgid()) { + putchar(' '); + print_group(getegid()); + } - if (xgetgroups ((pwd ? pwd->pw_gid : (gid_t) -1), - &n_groups, &groups)) { - return ++problems; + int n_groups = 0; + gid_t *groups; + register int i; + + if (xgetgroups((pwd ? pwd->pw_gid : (gid_t) - 1), + &n_groups, &groups)) { + return ++problems; + } + + for (i = 0; i < n_groups; i++) + if (groups[i] != getgid() && groups[i] != getegid()) { + putchar(' '); + print_group(groups[i]); + } + free(groups); } - - for (i = 0; i < n_groups; i++) - if (groups[i] != getgid() && groups[i] != getegid()) - { - putchar (' '); - print_group (groups[i]); - } - free (groups); - } - putchar('\n'); - return (problems != 0); + putchar('\n'); + return (problems != 0); } - |