1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-07 18:27:04 +03:00

util: improve dir_is_empty() call

Simplify the call, and add dir_is_populated() as inverse call, in order
to make some checks easier to read.
This commit is contained in:
Lennart Poettering 2015-10-19 23:58:17 +02:00
parent 2dcc3c69a1
commit ac7edd9167
2 changed files with 12 additions and 13 deletions

View File

@ -2381,25 +2381,16 @@ bool is_device_path(const char *path) {
int dir_is_empty(const char *path) {
_cleanup_closedir_ DIR *d;
struct dirent *de;
d = opendir(path);
if (!d)
return -errno;
for (;;) {
struct dirent *de;
FOREACH_DIRENT(de, d, return -errno)
return 0;
errno = 0;
de = readdir(d);
if (!de && errno != 0)
return -errno;
if (!de)
return 1;
if (!hidden_file(de->d_name))
return 0;
}
return 1;
}
char* dirname_malloc(const char *path) {

View File

@ -358,6 +358,14 @@ bool is_device_path(const char *path);
int dir_is_empty(const char *path);
char* dirname_malloc(const char *path);
static inline int dir_is_populated(const char *path) {
int r;
r = dir_is_empty(path);
if (r < 0)
return r;
return !r;
}
char* lookup_uid(uid_t uid);
char* getlogname_malloc(void);
char* getusername_malloc(void);