From ba5c9b0375b84456553b9b57cb68cb204c1d9418 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 af00b90f3..b8e6fa1f0 100644 --- a/src/directory.c +++ b/src/directory.c @@ -101,11 +101,6 @@ void directory_finish(void) freeDirectory(music_root); } -int isRootDirectory(const char *name) -{ - return (!name || name[0] == '\0' || !strcmp(name, "/")); -} - struct directory * directory_get_root(void) { @@ -122,6 +117,8 @@ getSubDirectory(struct directory * directory, const char *name) char *duplicated; char *locate; + assert(name != NULL); + if (isRootDirectory(name)) return directory; @@ -148,6 +145,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 c1ff1828b..554b77513 100644 --- a/src/directory.h +++ b/src/directory.h @@ -46,7 +46,11 @@ void directory_init(void); void directory_finish(void); -int isRootDirectory(const char *name); +static inline bool +isRootDirectory(const char *name) +{ + return name[0] == 0 || (name[0] == '/' && name[1] == 0); +} struct directory * directory_get_root(void); -- cgit v1.2.3