diff options
Diffstat (limited to 'upstream/archlinux/man3/getgrouplist.3')
-rw-r--r-- | upstream/archlinux/man3/getgrouplist.3 | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/upstream/archlinux/man3/getgrouplist.3 b/upstream/archlinux/man3/getgrouplist.3 index 2852a9e2..8b86cbec 100644 --- a/upstream/archlinux/man3/getgrouplist.3 +++ b/upstream/archlinux/man3/getgrouplist.3 @@ -7,7 +7,7 @@ .\" .\" SPDX-License-Identifier: Linux-man-pages-copyleft .\" -.TH getgrouplist 3 2023-10-31 "Linux man-pages 6.06" +.TH getgrouplist 3 2024-05-02 "Linux man-pages 6.8" .SH NAME getgrouplist \- get list of groups to which a user belongs .SH LIBRARY @@ -134,6 +134,7 @@ ngroups = 3 \& .\" SRC BEGIN (getgrouplist.c) .EX +#include <errno.h> #include <grp.h> #include <pwd.h> #include <stdio.h> @@ -142,10 +143,10 @@ ngroups = 3 int main(int argc, char *argv[]) { - int ngroups; - struct passwd *pw; - struct group *gr; - gid_t *groups; + int ngroups; + gid_t *groups; + struct group *gr; + struct passwd *pw; \& if (argc != 3) { fprintf(stderr, "Usage: %s <user> <ngroups>\en", argv[0]); @@ -162,10 +163,14 @@ main(int argc, char *argv[]) \& /* Fetch passwd structure (contains first group ID for user). */ \& + errno = 0; pw = getpwnam(argv[1]); if (pw == NULL) { - perror("getpwnam"); - exit(EXIT_SUCCESS); + if (errno) + perror("getpwnam"); + else + fprintf(stderr, "no such user\en"); + exit(EXIT_FAILURE); } \& /* Retrieve group list. */ @@ -179,7 +184,7 @@ main(int argc, char *argv[]) /* Display list of retrieved groups, along with group names. */ \& fprintf(stderr, "ngroups = %d\en", ngroups); - for (size_t j = 0; j < ngroups; j++) { + for (int j = 0; j < ngroups; j++) { printf("%d", groups[j]); gr = getgrgid(groups[j]); if (gr != NULL) |