Xinqi Bao's Git

Refactor entropy.c
[slstatus.git] / components / user.c
index ffbd945..cd503f6 100644 (file)
@@ -1,6 +1,8 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -15,10 +17,10 @@ gid(void)
 const char *
 username(void)
 {
-       struct passwd *pw = getpwuid(geteuid());
+       struct passwd *pw;
 
-       if (pw == NULL) {
-               fprintf(stderr, "Failed to get username");
+       if (!(pw = getpwuid(geteuid()))) {
+               warn("getpwuid '%d':", geteuid());
                return NULL;
        }