From 313e8e3ecc15e65700e64252207227612d6d9195 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Oct 2008 11:08:16 +0200 Subject: directory: path must not be NULL For the root directory, let's set path to an empty string. This saves a few checks. --- src/directory.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/directory.c') 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; -- cgit v1.2.3