aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-08 10:48:49 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:47 -0700
commit7b5c84829768b8ee2ac0ad131045736afc586643 (patch)
tree4168ad6056896895c1e1f98d9db7bee900c18d9e
parent6f43d71628db3c9acb9e0693216885685566b7d3 (diff)
downloadmpd-7b5c84829768b8ee2ac0ad131045736afc586643.tar.gz
mpd-7b5c84829768b8ee2ac0ad131045736afc586643.tar.xz
mpd-7b5c84829768b8ee2ac0ad131045736afc586643.zip
directory: added directory_is_empty()
directory_is_empty() is a tiny inline function which determine if a directory has any child objects (sub directories or songs).
-rw-r--r--src/directory.c2
-rw-r--r--src/directory.h5
2 files changed, 6 insertions, 1 deletions
diff --git a/src/directory.c b/src/directory.c
index f6bb50913..38f32c271 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -86,7 +86,7 @@ static void deleteEmptyDirectoriesInDirectory(Directory * directory)
for (i = dv->nr; --i >= 0; ) {
deleteEmptyDirectoriesInDirectory(dv->base[i]);
- if (!dv->base[i]->children.nr && !dv->base[i]->songs.nr)
+ if (directory_is_empty(dv->base[i]))
dirvec_delete(dv, dv->base[i]);
}
if (!dv->nr)
diff --git a/src/directory.h b/src/directory.h
index c43f8f3c5..552bbe28e 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -49,6 +49,11 @@ Directory * newDirectory(const char *dirname, Directory * parent);
void freeDirectory(Directory * directory);
+static inline int directory_is_empty(Directory *directory)
+{
+ return directory->children.nr == 0 && directory->songs.nr == 0;
+}
+
Directory * getDirectory(const char *name);
void sortDirectory(Directory * directory);