From f8e2879c37b9ee5953e71456ba777363f7dc30fc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:06:44 +0200 Subject: directory: converted isRootDirectory() to an inline function The function isRootDirectory() is tiny and can be converted to an inline function. Don't allow name==NULL. --- src/directory.c | 10 +++++----- src/directory.h | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/directory.c b/src/directory.c index f76dd9c95..25a6bcec8 100644 --- a/src/directory.c +++ b/src/directory.c @@ -105,11 +105,6 @@ struct directory * directory_get_root(void) return music_root; } -int isRootDirectory(const char *name) -{ - return (!name || name[0] == '\0' || !strcmp(name, "/")); -} - static struct directory * getSubDirectory(struct directory * directory, const char *name) { @@ -118,6 +113,8 @@ getSubDirectory(struct directory * directory, const char *name) char *duplicated; char *locate; + assert(name != NULL); + if (isRootDirectory(name)) return directory; @@ -143,6 +140,9 @@ getSubDirectory(struct directory * directory, const char *name) struct directory * getDirectory(const char *name) { + if (name == NULL) + return music_root; + return getSubDirectory(music_root, name); } diff --git a/src/directory.h b/src/directory.h index 72de511e7..127da678c 100644 --- a/src/directory.h +++ b/src/directory.h @@ -41,7 +41,11 @@ void directory_init(void); void directory_finish(void); -int isRootDirectory(const char *name); +static inline int isRootDirectory(const char *name) +{ + /* TODO: verify and remove !name check */ + return (!name || *name == '\0' || !strcmp(name, "/")); +} struct directory * directory_get_root(void); -- cgit v1.2.3