From 80fc20d1d69b14f36ad9bb64d8af38481cbf1ff5 Mon Sep 17 00:00:00 2001
From: Laslo Hunhold <dev@frign.de>
Date: Fri, 18 May 2018 10:59:05 +0200
Subject: Add warn() and die()

Given slstatus is a tool that runs in the background, most likely run
from .xinitrc, it's important to prepend the name of the tool to error
messages so it becomes clear where the error is coming from.

To make this much more consistent, this commit adds warn() and die()
utility functions consistent with other suckless projects and adapts all
calls to fprintf(stderr, *) to the warn() and die() functions, greatly
increasing the readability of the code.
---
 components/ip.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'components/ip.c')

diff --git a/components/ip.c b/components/ip.c
index 85ac15e..fce2b66 100644
--- a/components/ip.c
+++ b/components/ip.c
@@ -19,7 +19,7 @@ ipv4(const char *iface)
 	char host[NI_MAXHOST];
 
 	if (getifaddrs(&ifaddr) < 0) {
-		fprintf(stderr, "getifaddrs: %s\n", strerror(errno));
+		warn("getifaddrs:");
 		return NULL;
 	}
 
@@ -32,7 +32,7 @@ ipv4(const char *iface)
 		if (!strcmp(ifa->ifa_name, iface) &&
 		    (ifa->ifa_addr->sa_family == AF_INET)) {
 			if (s != 0) {
-				fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
+				warn("getnameinfo: %s", gai_strerror(s));
 				return NULL;
 			}
 			return bprintf("%s", host);
@@ -52,7 +52,7 @@ ipv6(const char *iface)
 	char host[NI_MAXHOST];
 
 	if (getifaddrs(&ifaddr) < 0) {
-		fprintf(stderr, "getifaddrs: %s\n", strerror(errno));
+		warn("getifaddrs:");
 		return NULL;
 	}
 
@@ -65,7 +65,7 @@ ipv6(const char *iface)
 		if (!strcmp(ifa->ifa_name, iface) &&
 		    (ifa->ifa_addr->sa_family == AF_INET6)) {
 			if (s != 0) {
-				fprintf(stderr, "getnameinfo: %s\n", gai_strerror(s));
+				warn("getnameinfo: %s", gai_strerror(s));
 				return NULL;
 			}
 			return bprintf("%s", host);
-- 
cgit v1.2.3