num_files.c - slstatus - status monitor | |
git clone git://git.suckless.org/slstatus | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
num_files.c (534B) | |
--- | |
1 /* See LICENSE file for copyright and license details. */ | |
2 #include <dirent.h> | |
3 #include <stdio.h> | |
4 #include <string.h> | |
5 | |
6 #include "../slstatus.h" | |
7 #include "../util.h" | |
8 | |
9 const char * | |
10 num_files(const char *path) | |
11 { | |
12 struct dirent *dp; | |
13 DIR *dir; | |
14 int num; | |
15 | |
16 if (!(dir = opendir(path))) { | |
17 warn("opendir '%s':", path); | |
18 return NULL; | |
19 } | |
20 | |
21 num = 0; | |
22 while ((dp = readdir(dir))) { | |
23 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."… | |
24 continue; /* skip self and parent */ | |
25 | |
26 num++; | |
27 } | |
28 | |
29 closedir(dir); | |
30 | |
31 return bprintf("%d", num); | |
32 } |