Get rid of err.h as it is not portable
Replace warn() and warnx() with fprintf() and add <stdio.h> where necessary.
This commit is contained in:
		@@ -1,5 +1,4 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
@@ -29,12 +28,12 @@ battery_perc(const char *bat)
 | 
			
		||||
 | 
			
		||||
	fd = open("/dev/apm", O_RDONLY);
 | 
			
		||||
	if (fd < 0) {
 | 
			
		||||
		warn("Failed to open file /dev/apm");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /dev/apm");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ioctl(fd, APM_IOC_GETPOWER, &apm_info) < 0) {
 | 
			
		||||
		warn("Failed to get battery info");
 | 
			
		||||
		fprintf(stderr, "Failed to get battery info");
 | 
			
		||||
		close(fd);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <sys/statvfs.h>
 | 
			
		||||
 | 
			
		||||
@@ -11,7 +10,7 @@ disk_free(const char *mnt)
 | 
			
		||||
	struct statvfs fs;
 | 
			
		||||
 | 
			
		||||
	if (statvfs(mnt, &fs) < 0) {
 | 
			
		||||
		warn("Failed to get filesystem info");
 | 
			
		||||
		fprintf(stderr, "Failed to get filesystem info");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -25,7 +24,7 @@ disk_perc(const char *mnt)
 | 
			
		||||
	struct statvfs fs;
 | 
			
		||||
 | 
			
		||||
	if (statvfs(mnt, &fs) < 0) {
 | 
			
		||||
		warn("Failed to get filesystem info");
 | 
			
		||||
		fprintf(stderr, "Failed to get filesystem info");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -40,7 +39,7 @@ disk_total(const char *mnt)
 | 
			
		||||
	struct statvfs fs;
 | 
			
		||||
 | 
			
		||||
	if (statvfs(mnt, &fs) < 0) {
 | 
			
		||||
		warn("Failed to get filesystem info");
 | 
			
		||||
		fprintf(stderr, "Failed to get filesystem info");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -53,7 +52,7 @@ disk_used(const char *mnt)
 | 
			
		||||
	struct statvfs fs;
 | 
			
		||||
 | 
			
		||||
	if (statvfs(mnt, &fs) < 0) {
 | 
			
		||||
		warn("Failed to get filesystem info");
 | 
			
		||||
		fprintf(stderr, "Failed to get filesystem info");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#include "../util.h"
 | 
			
		||||
@@ -8,7 +8,7 @@ const char *
 | 
			
		||||
hostname(void)
 | 
			
		||||
{
 | 
			
		||||
	if (gethostname(buf, sizeof(buf)) == -1) {
 | 
			
		||||
		warn("hostname");
 | 
			
		||||
		fprintf(stderr, "gethostbyname failed");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <ifaddrs.h>
 | 
			
		||||
#include <netdb.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
@@ -16,7 +15,7 @@ ipv4(const char *iface)
 | 
			
		||||
	char host[NI_MAXHOST];
 | 
			
		||||
 | 
			
		||||
	if (getifaddrs(&ifaddr) == -1) {
 | 
			
		||||
		warn("Failed to get IPv4 address for interface %s", iface);
 | 
			
		||||
		fprintf(stderr, "Failed to get IPv4 address for interface %s", iface);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -27,7 +26,7 @@ ipv4(const char *iface)
 | 
			
		||||
		s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
 | 
			
		||||
		if ((strcmp(ifa->ifa_name, iface) == 0) && (ifa->ifa_addr->sa_family == AF_INET)) {
 | 
			
		||||
			if (s != 0) {
 | 
			
		||||
				warnx("Failed to get IPv4 address for interface %s", iface);
 | 
			
		||||
				fprintf(stderr, "Failed to get IPv4 address for interface %s", iface);
 | 
			
		||||
				return NULL;
 | 
			
		||||
			}
 | 
			
		||||
			return bprintf("%s", host);
 | 
			
		||||
@@ -47,7 +46,7 @@ ipv6(const char *iface)
 | 
			
		||||
	char host[NI_MAXHOST];
 | 
			
		||||
 | 
			
		||||
	if (getifaddrs(&ifaddr) == -1) {
 | 
			
		||||
		warn("Failed to get IPv6 address for interface %s", iface);
 | 
			
		||||
		fprintf(stderr, "Failed to get IPv6 address for interface %s", iface);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -58,7 +57,7 @@ ipv6(const char *iface)
 | 
			
		||||
		s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
 | 
			
		||||
		if ((strcmp(ifa->ifa_name, iface) == 0) && (ifa->ifa_addr->sa_family == AF_INET6)) {
 | 
			
		||||
			if (s != 0) {
 | 
			
		||||
				warnx("Failed to get IPv6 address for interface %s", iface);
 | 
			
		||||
				fprintf(stderr, "Failed to get IPv6 address for interface %s", iface);
 | 
			
		||||
				return NULL;
 | 
			
		||||
			}
 | 
			
		||||
			return bprintf("%s", host);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <X11/Xlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../util.h"
 | 
			
		||||
@@ -11,7 +11,7 @@ keyboard_indicators(void)
 | 
			
		||||
	XKeyboardState state;
 | 
			
		||||
 | 
			
		||||
	if (dpy == NULL) {
 | 
			
		||||
		warnx("XOpenDisplay failed");
 | 
			
		||||
		fprintf(stderr, "Cannot open display");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	XGetKeyboardControl(dpy, &state);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "../util.h"
 | 
			
		||||
@@ -10,7 +10,7 @@ load_avg(const char *fmt)
 | 
			
		||||
	double avgs[3];
 | 
			
		||||
 | 
			
		||||
	if (getloadavg(avgs, 3) < 0) {
 | 
			
		||||
		warnx("Failed to get the load avg");
 | 
			
		||||
		fprintf(stderr, "Failed to get the load avg");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <dirent.h>
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
@@ -14,7 +13,7 @@ num_files(const char *dir)
 | 
			
		||||
	int num = 0;
 | 
			
		||||
 | 
			
		||||
	if ((fd = opendir(dir)) == NULL) {
 | 
			
		||||
		warn("Failed to get number of files in directory %s", dir);
 | 
			
		||||
		fprintf(stderr, "Failed to get number of files in directory %s", dir);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
@@ -13,7 +12,7 @@ run_command(const char *cmd)
 | 
			
		||||
 | 
			
		||||
	fp = popen(cmd, "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to get command output for %s", cmd);
 | 
			
		||||
		fprintf(stderr, "Failed to get command output for %s", cmd);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	p = fgets(buf, sizeof(buf) - 1, fp);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
@@ -16,12 +15,12 @@ swap_free(void)
 | 
			
		||||
 | 
			
		||||
	fp = fopen("/proc/meminfo", "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to open file /proc/meminfo");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /proc/meminfo");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
 | 
			
		||||
		warn("swap_free: read error");
 | 
			
		||||
		fprintf(stderr, "swap_free: read error");
 | 
			
		||||
		fclose(fp);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
@@ -48,12 +47,12 @@ swap_perc(void)
 | 
			
		||||
 | 
			
		||||
	fp = fopen("/proc/meminfo", "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to open file /proc/meminfo");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /proc/meminfo");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
 | 
			
		||||
		warn("swap_perc: read error");
 | 
			
		||||
		fprintf(stderr, "swap_perc: read error");
 | 
			
		||||
		fclose(fp);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
@@ -84,11 +83,11 @@ swap_total(void)
 | 
			
		||||
 | 
			
		||||
	fp = fopen("/proc/meminfo", "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to open file /proc/meminfo");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /proc/meminfo");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
 | 
			
		||||
		warn("swap_total: read error");
 | 
			
		||||
		fprintf(stderr, "swap_total: read error");
 | 
			
		||||
		fclose(fp);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
@@ -111,11 +110,11 @@ swap_used(void)
 | 
			
		||||
 | 
			
		||||
	fp = fopen("/proc/meminfo", "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to open file /proc/meminfo");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /proc/meminfo");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	if ((bytes_read = fread(buf, sizeof(char), sizeof(buf) - 1, fp)) == 0) {
 | 
			
		||||
		warn("swap_used: read error");
 | 
			
		||||
		fprintf(stderr, "swap_used: read error");
 | 
			
		||||
		fclose(fp);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <pwd.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
@@ -18,7 +18,7 @@ username(void)
 | 
			
		||||
	struct passwd *pw = getpwuid(geteuid());
 | 
			
		||||
 | 
			
		||||
	if (pw == NULL) {
 | 
			
		||||
		warn("Failed to get username");
 | 
			
		||||
		fprintf(stderr, "Failed to get username");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <sys/soundcard.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
@@ -19,19 +18,19 @@ vol_perc(const char *card)
 | 
			
		||||
 | 
			
		||||
	afd = open(card, O_RDONLY | O_NONBLOCK);
 | 
			
		||||
	if (afd == -1) {
 | 
			
		||||
		warn("Cannot open %s", card);
 | 
			
		||||
		fprintf(stderr, "Cannot open %s", card);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ioctl(afd, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) {
 | 
			
		||||
		warn("Cannot get volume for %s", card);
 | 
			
		||||
		fprintf(stderr, "Cannot get volume for %s", card);
 | 
			
		||||
		close(afd);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	for (i = 0; i < LEN(vnames); i++) {
 | 
			
		||||
		if (devmask & (1 << i) && !strcmp("vol", vnames[i])) {
 | 
			
		||||
			if (ioctl(afd, MIXER_READ(i), &v) == -1) {
 | 
			
		||||
				warn("vol_perc: ioctl");
 | 
			
		||||
				fprintf(stderr, "vol_perc: ioctl");
 | 
			
		||||
				close(afd);
 | 
			
		||||
				return NULL;
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,5 @@
 | 
			
		||||
/* See LICENSE file for copyright and license details. */
 | 
			
		||||
#if defined(__linux__)
 | 
			
		||||
#include <err.h>
 | 
			
		||||
#include <ifaddrs.h>
 | 
			
		||||
#include <linux/wireless.h>
 | 
			
		||||
#include <sys/socket.h>
 | 
			
		||||
@@ -26,7 +25,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) {
 | 
			
		||||
		warn("Failed to open file %s", path);
 | 
			
		||||
		fprintf(stderr, "Failed to open file %s", path);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	p = fgets(status, 5, fp);
 | 
			
		||||
@@ -37,7 +36,7 @@ wifi_perc(const char *iface)
 | 
			
		||||
 | 
			
		||||
	fp = fopen("/proc/net/wireless", "r");
 | 
			
		||||
	if (fp == NULL) {
 | 
			
		||||
		warn("Failed to open file /proc/net/wireless");
 | 
			
		||||
		fprintf(stderr, "Failed to open file /proc/net/wireless");
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -72,12 +71,12 @@ wifi_essid(const char *iface)
 | 
			
		||||
	snprintf(wreq.ifr_name, sizeof(wreq.ifr_name), "%s", iface);
 | 
			
		||||
 | 
			
		||||
	if (sockfd == -1) {
 | 
			
		||||
		warn("Failed to get ESSID for interface %s", iface);
 | 
			
		||||
		fprintf(stderr, "Failed to get ESSID for interface %s", iface);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
	wreq.u.essid.pointer = id;
 | 
			
		||||
	if (ioctl(sockfd,SIOCGIWESSID, &wreq) == -1) {
 | 
			
		||||
		warn("Failed to get ESSID for interface %s", iface);
 | 
			
		||||
		fprintf(stderr, "Failed to get ESSID for interface %s", iface);
 | 
			
		||||
		close(sockfd);
 | 
			
		||||
		return NULL;
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user