]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/getgrouplist.3
getgrouplist.3: EXAMPLES: Fix error handling for getpwnam(3)
[thirdparty/man-pages.git] / man3 / getgrouplist.3
index 5e11b426b2afea72f42ce03642ff9b53819e5bf6..61d3b7a9bbaf497104ec0ea4fe4476b0783bcaa6 100644 (file)
@@ -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. */