summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/main.c b/main.c
index 54f93df..39927f1 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,7 @@
#define _GNU_SOURCE
#include <sys/sysinfo.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
@@ -46,6 +48,13 @@ static char *readline(char *dir, char *file)
return line;
}
+static int isdir(const char *path)
+{
+ struct stat st;
+
+ return ! stat(path, &st) && S_ISDIR(st.st_mode);
+}
+
static void print_battery_status(void)
{
#define PRINT(...) str += snprintf(str, sizeof(status) - (str - status), __VA_ARGS__)
@@ -54,6 +63,9 @@ static void print_battery_status(void)
char *str = status;
+ if (! isdir(SYSPATH))
+ return;
+
if (! strcasecmp("charging", readline(SYSPATH, "status")))
PRINT("%s ", charging);