From 4b4b2ac0790a51ea624397f829f29ed92e82fd53 Mon Sep 17 00:00:00 2001 From: aaron marcher Date: Sun, 6 Aug 2017 15:02:16 +0200 Subject: add num_files() function for maildirs ;) --- slstatus.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'slstatus.c') diff --git a/slstatus.c b/slstatus.c index af26fe7..5564771 100644 --- a/slstatus.c +++ b/slstatus.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ +#include #include #include #include @@ -51,6 +52,7 @@ static const char *ip(const char *iface); static const char *kernel_release(void); static const char *keyboard_indicators(void); static const char *load_avg(void); +static const char *num_files(const char *dir); static const char *ram_free(void); static const char *ram_perc(void); static const char *ram_used(void); @@ -402,6 +404,29 @@ load_avg(void) return bprintf("%.2f %.2f %.2f", avgs[0], avgs[1], avgs[2]); } +static const char * +num_files(const char *dir) +{ + struct dirent *dp; + DIR *fd; + int num = 0; + + if ((fd = opendir(dir)) == NULL) { + warn("Failed to get number of files in directory %s", dir); + return UNKNOWN_STR; + } + + while ((dp = readdir(fd)) != NULL) { + if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) + continue; /* skip self and parent */ + num++; + } + + closedir(fd); + + return bprintf("%d", num); +} + static const char * ram_free(void) { -- cgit v1.2.3