aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2023-12-10 01:07:15 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2023-12-10 01:07:15 -0500
commit0910bee606b629c9110ab18d286f13273ba9876d (patch)
tree7be91886a8a6d5b76d4efcd82eb6931a596b012f
parent58df72e651e6b45ba60b0ab3cc29538976cd9697 (diff)
downloadstasis-0910bee606b629c9110ab18d286f13273ba9876d.tar.gz
Add isempty_dir() function
-rw-r--r--src/utils.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 7fe98b8..6aa9ffb 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -465,4 +465,23 @@ char *xmkstemp(FILE **fp) {
}
char *path = strdup(t_name);
return path;
+}
+
+int isempty_dir(const char *path) {
+ DIR *dp;
+ struct dirent *rec;
+ size_t count = 0;
+
+ dp = opendir(path);
+ if (!dp) {
+ return -1;
+ }
+ while ((rec = readdir(dp)) != NULL) {
+ if (!strcmp(rec->d_name, ".") || !strcmp(rec->d_name, "..")) {
+ continue;
+ }
+ count++;
+ }
+
+ return count == 0;
} \ No newline at end of file