summaryrefslogtreecommitdiff
path: root/slstatus/components/num_files.c
diff options
context:
space:
mode:
authorcoasteen <coasteen@proton.me>2026-07-09 10:42:28 +0330
committercoasteen <coasteen@proton.me>2026-07-09 10:42:28 +0330
commit8cbadb61604667b407b53ee1258433994fa4765a (patch)
tree97765fb29418fd6278fcb4cbb9760893afaf7a58 /slstatus/components/num_files.c
Diffstat (limited to 'slstatus/components/num_files.c')
-rwxr-xr-xslstatus/components/num_files.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/slstatus/components/num_files.c b/slstatus/components/num_files.c
new file mode 100755
index 0000000..df0acd1
--- /dev/null
+++ b/slstatus/components/num_files.c
@@ -0,0 +1,32 @@
+/* See LICENSE file for copyright and license details. */
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../slstatus.h"
+#include "../util.h"
+
+const char *
+num_files(const char *path)
+{
+ struct dirent *dp;
+ DIR *dir;
+ int num;
+
+ if (!(dir = opendir(path))) {
+ warn("opendir '%s':", path);
+ return NULL;
+ }
+
+ num = 0;
+ while ((dp = readdir(dir))) {
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+ continue; /* skip self and parent */
+
+ num++;
+ }
+
+ closedir(dir);
+
+ return bprintf("%d", num);
+}