diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index a8ea4a97ab..7664df59d0 100644 --- a/src/util.c +++ b/src/util.c @@ -2092,6 +2092,35 @@ bool is_device_path(const char *path) { path_startswith(path, "/sys/"); } +int dir_is_empty(const char *path) { + DIR *d; + int r; + struct dirent buf, *de; + + if (!(d = opendir(path))) + return -errno; + + for (;;) { + if ((r = readdir_r(d, &buf, &de)) > 0) { + r = -r; + break; + } + + if (!de) { + r = 1; + break; + } + + if (!ignore_file(de->d_name)) { + r = 0; + break; + } + } + + closedir(d); + return r; +} + static const char *const ioprio_class_table[] = { [IOPRIO_CLASS_NONE] = "none", [IOPRIO_CLASS_RT] = "realtime", |