summaryrefslogtreecommitdiff
path: root/components/wifi.c
diff options
context:
space:
mode:
authorAaron Marcher <me@drkhsh.at>2018-03-28 19:46:27 +0200
committerAaron Marcher <me@drkhsh.at>2018-03-28 19:46:27 +0200
commitfaa52bdcc0221de2d8fae950e409a8ac5e05bfcd (patch)
tree7e1641219e1d65d82f8e5467a1a599d11fd6164c /components/wifi.c
parent2289798b6d3565d96cc81d5208c50afa2010e296 (diff)
Format error messages properly
Make use of strerror(errno) and format all errors equally: function ['parameters']: error message
Diffstat (limited to 'components/wifi.c')
-rw-r--r--components/wifi.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/components/wifi.c b/components/wifi.c
index 500332e..388a30d 100644
--- a/components/wifi.c
+++ b/components/wifi.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#if defined(__linux__)
+#include <errno.h>
#include <ifaddrs.h>
#include <linux/wireless.h>
#include <sys/socket.h>
@@ -25,7 +26,7 @@ wifi_perc(const char *iface)
snprintf(path, sizeof(path), "%s%s%s", "/sys/class/net/", iface, "/operstate");
fp = fopen(path, "r");
if (fp == NULL) {
- fprintf(stderr, "Failed to open file %s", path);
+ fprintf(stderr, "fopen '%s': %s\n", path, strerror(errno));
return NULL;
}
p = fgets(status, 5, fp);
@@ -36,7 +37,7 @@ wifi_perc(const char *iface)
fp = fopen("/proc/net/wireless", "r");
if (fp == NULL) {
- fprintf(stderr, "Failed to open file /proc/net/wireless");
+ fprintf(stderr, "fopen '/proc/net/wireless': %s\n", strerror(errno));
return NULL;
}
@@ -71,12 +72,12 @@ wifi_essid(const char *iface)
snprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", iface);
if (sockfd == -1) {
- fprintf(stderr, "Failed to get ESSID for interface %s", iface);
+ fprintf(stderr, "socket 'AF_INET': %s\n", strerror(errno));
return NULL;
}
wreq.u.essid.pointer = id;
if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) {
- fprintf(stderr, "Failed to get ESSID for interface %s", iface);
+ fprintf(stderr, "ioctl 'SIOCGIWESSID': %s\n", strerror(errno));
close(sockfd);
return NULL;
}