tcount.c - spoon - [fork] customized build of spoon, the dwm status utility
(HTM) git clone git://src.adamsgaard.dk/spoon
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
tcount.c (523B)
---
1 #include <dirent.h>
2 #include <err.h>
3 #include <stdio.h>
4 #include <string.h>
5
6 int
7 countread(void *arg, char *buf, size_t len)
8 {
9 char *path = arg;
10 unsigned long count = 0;
11 struct dirent *e;
12 DIR *d;
13
14 if ((d = opendir(path)) == NULL) {
15 warn("open %s", path);
16 return -1;
17 }
18
19 while ((e = readdir(d)) != NULL) {
20 if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, ".."))
21 continue;
22 ++count;
23 }
24 closedir(d);
25
26 if (count > 0)
27 snprintf(buf, len, " m: %lu |", count);
28 else
29 snprintf(buf, len, "");
30
31
32 return 0;
33 }