diff options
-rw-r--r-- | src/utils.c | 19 |
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 |