X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/96f3a8a54eeb3b2294ed953dad8b15349f3e2703..ceb13206a4d9f410ab49c3824c487658c341d8c8:/components/hostname.c

diff --git a/components/hostname.c b/components/hostname.c
index 45dbb5b..dc3bbf1 100644
--- a/components/hostname.c
+++ b/components/hostname.c
@@ -1,5 +1,7 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 
 #include "../util.h"
@@ -7,8 +9,8 @@
 const char *
 hostname(void)
 {
-	if (gethostname(buf, sizeof(buf)) == -1) {
-		fprintf(stderr, "gethostbyname failed");
+	if (gethostname(buf, sizeof(buf)) < 0) {
+		warn("gethostbyname:");
 		return NULL;
 	}