diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-11 20:41:55 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-12 05:27:32 -0700 |
commit | e28fb29349a811f0f306e9ac4bedf6013417d043 (patch) | |
tree | c28a33e1361a4a507dc2c401f4cce26eda7cd9aa /src/directory.c | |
parent | c6ee14dca5d7336dad20a6057aa2a8006d4447b8 (diff) | |
download | mpd-e28fb29349a811f0f306e9ac4bedf6013417d043.tar.gz mpd-e28fb29349a811f0f306e9ac4bedf6013417d043.tar.xz mpd-e28fb29349a811f0f306e9ac4bedf6013417d043.zip |
directory: make music_root global and avoid runtime initialization
mpd can't function without music_root; so don't bother
allocating it on the heap nor checking to see if it's
initialized.
Don't allow directory_new() to create a directory w/o a parent
or with an empty path, either: root is root and there can
be only one</highlander>.
Diffstat (limited to 'src/directory.c')
-rw-r--r-- | src/directory.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/directory.c b/src/directory.c index 699b6fbc1..846f2510a 100644 --- a/src/directory.c +++ b/src/directory.c @@ -23,14 +23,18 @@ #include "myfprintf.h" #include "dirvec.h" +struct directory music_root; + struct directory * directory_new(const char *path, struct directory * parent) { struct directory *dir; - size_t pathlen = strlen(path); + size_t pathlen; - assert(path != NULL); - assert((*path == 0) == (parent == NULL)); + assert(path); + assert(*path); + assert(parent); + pathlen = strlen(path); dir = xcalloc(1, sizeof(*dir) - sizeof(dir->path) + pathlen + 1); memcpy(dir->path, path, pathlen + 1); dir->parent = parent; @@ -42,9 +46,8 @@ void directory_free(struct directory *dir) { dirvec_destroy(&dir->children); songvec_destroy(&dir->songs); - free(dir); - /* this resets last dir returned */ - /*directory_get_path(NULL); */ + if (dir != &music_root) + free(dir); } void directory_prune_empty(struct directory *dir) |