diff options
author | Max Kellermann <max@duempel.org> | 2008-10-08 11:08:16 +0200 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-11 19:21:48 -0700 |
commit | 313e8e3ecc15e65700e64252207227612d6d9195 (patch) | |
tree | 3d6a0ee583b8f415f6937fdfa11d7b5b5046c77b | |
parent | d32498dfec5f97275e6d769080a2a39c16f214c8 (diff) | |
download | mpd-313e8e3ecc15e65700e64252207227612d6d9195.tar.gz mpd-313e8e3ecc15e65700e64252207227612d6d9195.tar.xz mpd-313e8e3ecc15e65700e64252207227612d6d9195.zip |
directory: path must not be NULL
For the root directory, let's set path to an empty string. This saves
a few checks.
-rw-r--r-- | src/database.c | 4 | ||||
-rw-r--r-- | src/directory.c | 14 | ||||
-rw-r--r-- | src/directory.h | 2 |
3 files changed, 10 insertions, 10 deletions
diff --git a/src/database.c b/src/database.c index 98e50ad87..bd278a635 100644 --- a/src/database.c +++ b/src/database.c @@ -37,7 +37,7 @@ static time_t directory_dbModTime; void db_init(void) { - music_root = directory_new(NULL, NULL); + music_root = directory_new("", NULL); updateDirectory(music_root); stats.numberOfSongs = countSongsIn(NULL); stats.dbPlayTime = sumSongTimesIn(NULL); @@ -233,7 +233,7 @@ int db_load(void) struct stat st; if (!music_root) - music_root = directory_new(NULL, NULL); + music_root = directory_new("", NULL); while (!(fp = fopen(dbFile, "r")) && errno == EINTR) ; if (fp == NULL) { ERROR("unable to open db file \"%s\": %s\n", diff --git a/src/directory.c b/src/directory.c index f79cc2dbc..295fdd09a 100644 --- a/src/directory.c +++ b/src/directory.c @@ -30,10 +30,11 @@ struct directory * directory_new(const char *dirname, struct directory * parent) { struct directory *directory; - directory = xcalloc(1, sizeof(*directory)); + assert(dirname != NULL); + assert((*dirname == 0) == (parent == NULL)); - if (dirname && strlen(dirname)) - directory->path = xstrdup(dirname); + directory = xcalloc(1, sizeof(*directory)); + directory->path = xstrdup(dirname); directory->parent = parent; return directory; @@ -43,8 +44,7 @@ void directory_free(struct directory * directory) { dirvec_destroy(&directory->children); songvec_destroy(&directory->songs); - if (directory->path) - free(directory->path); + free(directory->path); free(directory); /* this resets last dir returned */ /*directory_get_path(NULL); */ @@ -140,7 +140,7 @@ int directory_save(int fd, struct directory * directory) struct dirvec *children = &directory->children; size_t i; - if (directory->path && + if (!isRootDirectory(directory->path) && fdprintf(fd, DIRECTORY_BEGIN "%s\n", directory_get_path(directory)) < 0) return -1; @@ -165,7 +165,7 @@ int directory_save(int fd, struct directory * directory) if (fdprintf(fd, SONG_END "\n") < 0) return -1; - if (directory->path && + if (!isRootDirectory(directory->path) && fdprintf(fd, DIRECTORY_END "%s\n", directory_get_path(directory)) < 0) return -1; diff --git a/src/directory.h b/src/directory.h index 5609e4ea4..17c218bfb 100644 --- a/src/directory.h +++ b/src/directory.h @@ -63,7 +63,7 @@ static inline int directory_is_empty(struct directory *directory) static inline const char * directory_get_path(struct directory *dir) { - return dir->path ? dir->path : ""; + return dir->path; } void directory_prune_empty(struct directory *directory); |