X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/0aefd57f9f469aba25ffbe9bdda04e894b9d739a..d3a212da7e09f11753aafd76f16dccb1ade822e1:/slstatus.c

diff --git a/slstatus.c b/slstatus.c
index 163b44e..a3b6b6a 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -1,12 +1,10 @@
 /* See LICENSE file for copyright and license details. */
 
 #include <alsa/asoundlib.h>
-#include <arpa/inet.h>
 #include <fcntl.h>
 #include <ifaddrs.h>
 #include <limits.h>
 #include <linux/wireless.h>
-#include <locale.h>
 #include <netdb.h>
 #include <pwd.h>
 #include <stdarg.h>
@@ -29,9 +27,8 @@
 #include "strlcat.h"
 #include "strlcpy.h"
 
-typedef char *(*op_fun)();
 struct arg {
-	op_fun func;
+	char *(*func)();
 	const char *format;
 	const char *args;
 };
@@ -105,7 +102,7 @@ battery_perc(const char *battery)
 	int now, full, perc;
 	char batterynowfile[64];
 	char batteryfullfile[64];
-	FILE *fp = fopen(batterynowfile, "r");
+	FILE *fp;
 
 	strlcpy(batterynowfile, BATTERY_PATH, sizeof(batterynowfile));
 	strlcat(batterynowfile, battery, sizeof(batterynowfile));
@@ -117,6 +114,7 @@ battery_perc(const char *battery)
 	strlcat(batteryfullfile, "/", sizeof(batteryfullfile));
 	strlcat(batteryfullfile, BATTERY_FULL, sizeof(batteryfullfile));
 
+	fp = fopen(batterynowfile, "r");
 	if (fp == NULL ) {
 		fprintf(stderr, "Error opening battery file: %s: %s\n",
 						batterynowfile,
@@ -251,7 +249,8 @@ entropy(void)
 	FILE *fp = fopen("/proc/sys/kernel/random/entropy_avail", "r");
 
 	if (fp == NULL) {
-		fprintf(stderr, "Could not open entropy file.\n");
+		fprintf(stderr, "Could not open entropy file: %s\n",
+						strerror(errno));
 		return smprintf(UNKNOWN_STR);
 	}
 
@@ -263,8 +262,7 @@ entropy(void)
 static char *
 gid(void)
 {
-	gid_t gid = getgid();
-	return smprintf("%d", gid);
+	return smprintf("%d", getgid());
 }
 
 static char *
@@ -475,45 +473,31 @@ uptime(void)
 static char *
 username(void)
 {
-	register struct passwd *pw;
-	register uid_t uid;
-
-	uid = geteuid();
-	pw = getpwuid(uid);
+	uid_t uid = geteuid();
+	struct passwd *pw = getpwuid(uid);
 
-	if (pw)
+	if (pw == NULL)
 		return smprintf("%s", pw->pw_name);
-	else {
-		fprintf(stderr, "Could not get username: %s\n",
-					strerror(errno));
-		return smprintf(UNKNOWN_STR);
-	}
 
+	fprintf(stderr, "Could not get username: %s\n",
+					strerror(errno));
 	return smprintf(UNKNOWN_STR);
 }
 
 static char *
 uid(void)
 {
-	/* FIXME: WHY USE register modifier? */
-	register uid_t uid;
-
-	uid = geteuid();
-
-	if (uid)
-		return smprintf("%d", uid);
-	else {
-		fprintf(stderr, "Could not get uid.\n");
-		return smprintf(UNKNOWN_STR);
-	}
-
-	return smprintf(UNKNOWN_STR);
+	return smprintf("%d", geteuid());
 }
 
 
 static char *
 vol_perc(const char *soundcard)
 {
+	/*
+	 * TODO: FIXME: 
+	 * https://github.com/drkh5h/slstatus/issues/12
+	 */
 	int mute = 0;
 	long vol = 0, max = 0, min = 0;
 	snd_mixer_t *handle;
@@ -562,12 +546,14 @@ wifi_perc(const char *wificard)
 	char path[64];
 	char status[5];
 	char needle[strlen(wificard)+2];
-	FILE *fp = fopen(path, "r");
+	FILE *fp;
 
 	strlcpy(path, "/sys/class/net/", sizeof(path));
 	strlcat(path, wificard, sizeof(path));
 	strlcat(path, "/operstate", sizeof(path));
 
+	fp = fopen(path, "r");
+
 	if(fp == NULL) {
 		fprintf(stderr, "Error opening wifi operstate file: %s\n",
 							strerror(errno));