X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/96f3a8a54eeb3b2294ed953dad8b15349f3e2703..0f9a1a836720c028d89891b85ec8b1dbbd12c485:/components/user.c

diff --git a/components/user.c b/components/user.c
index ffbd945..8ab6db9 100644
--- a/components/user.c
+++ b/components/user.c
@@ -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()))) {
+		fprintf(stderr, "getpwuid '%d': %s\n", geteuid(), strerror(errno));
 		return NULL;
 	}