add num_files() function for maildirs ;)
This commit is contained in:
parent
ad39aa012c
commit
4b4b2ac079
@ -21,6 +21,7 @@ The following information is included:
|
|||||||
- Kernel version
|
- Kernel version
|
||||||
- Keyboard indicators
|
- Keyboard indicators
|
||||||
- Load averages
|
- Load averages
|
||||||
|
- Number of files in a directory (hint: Maildir)
|
||||||
- Memory status (free memory, percentage, total memory and used memory)
|
- Memory status (free memory, percentage, total memory and used memory)
|
||||||
- Swap status (free swap, percentage, total swap and used swap)
|
- Swap status (free swap, percentage, total swap and used swap)
|
||||||
- Temperature
|
- Temperature
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
- kernel_release (uname -r) [argument: NULL]
|
- kernel_release (uname -r) [argument: NULL]
|
||||||
- keyboard_indicators (caps/num lock indicators) [agrument: NULL]
|
- keyboard_indicators (caps/num lock indicators) [agrument: NULL]
|
||||||
- load_avg (load average) [argument: NULL]
|
- load_avg (load average) [argument: NULL]
|
||||||
|
- num_files (number of files in a directory - hint: maildir) [argument: path]
|
||||||
- ram_free (free ram in GB) [argument: NULL]
|
- ram_free (free ram in GB) [argument: NULL]
|
||||||
- ram_perc (ram usage in percent) [argument: NULL]
|
- ram_perc (ram usage in percent) [argument: NULL]
|
||||||
- ram_total (total ram in GB) [argument: NULL]
|
- ram_total (total ram in GB) [argument: NULL]
|
||||||
|
25
slstatus.c
25
slstatus.c
@ -1,5 +1,6 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
|
|
||||||
|
#include <dirent.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
@ -51,6 +52,7 @@ static const char *ip(const char *iface);
|
|||||||
static const char *kernel_release(void);
|
static const char *kernel_release(void);
|
||||||
static const char *keyboard_indicators(void);
|
static const char *keyboard_indicators(void);
|
||||||
static const char *load_avg(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_free(void);
|
||||||
static const char *ram_perc(void);
|
static const char *ram_perc(void);
|
||||||
static const char *ram_used(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]);
|
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 *
|
static const char *
|
||||||
ram_free(void)
|
ram_free(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user