aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-08 11:08:16 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:48 -0700
commit313e8e3ecc15e65700e64252207227612d6d9195 (patch)
tree3d6a0ee583b8f415f6937fdfa11d7b5b5046c77b /src/directory.c
parentd32498dfec5f97275e6d769080a2a39c16f214c8 (diff)
downloadmpd-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.
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c14
1 files changed, 7 insertions, 7 deletions
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;