diff options
author | Fedor Lapshin <fe.lap.prog@gmail.com> | 2024-03-29 03:21:11 +0300 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2024-03-30 23:55:59 +0100 |
commit | 570c98b78b8d3afcc30486cac35a8bd18e36c097 (patch) | |
tree | f8759aaf90fa3dfbafa333e1649c120e0c3a087b | |
parent | f49a7e49c579a46513161e42051c344c622833c3 (diff) |
getgrouplist.3: EXAMPLES: Fix error handling for getpwnam(3)
Signed-off-by: Fedor Lapshin <fe.lap.prog@gmail.com>
Co-developed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | man3/getgrouplist.3 | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3 index 5e11b426b..61d3b7a9b 100644 --- a/man3/getgrouplist.3 +++ b/man3/getgrouplist.3 @@ -134,6 +134,7 @@ ngroups = 3 \& .\" SRC BEGIN (getgrouplist.c) .EX +#include <errno.h> #include <grp.h> #include <pwd.h> #include <stdio.h> @@ -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. */ |