aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-08 11:08:16 +0200
committerMax Kellermann <max@duempel.org>2008-10-08 11:08:16 +0200
commit0bfe7802d251286db03c7d9dfd1b3cd325060863 (patch)
tree8f71eda8f6243b2e0b71fb3458beff3ddd244e7e
parent3b6efa99daf466f95407560b294fce5e5170ef63 (diff)
downloadmpd-0bfe7802d251286db03c7d9dfd1b3cd325060863.tar.gz
mpd-0bfe7802d251286db03c7d9dfd1b3cd325060863.tar.xz
mpd-0bfe7802d251286db03c7d9dfd1b3cd325060863.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.c4
-rw-r--r--src/directory.c14
-rw-r--r--src/directory.h2
3 files changed, 9 insertions, 11 deletions
diff --git a/src/database.c b/src/database.c
index 46d5a6352..d2c0ce3a4 100644
--- a/src/database.c
+++ b/src/database.c
@@ -39,7 +39,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);
@@ -240,7 +240,7 @@ 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 af278664c..3bafacf7c 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -32,10 +32,11 @@ 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;
@@ -46,8 +47,7 @@ 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); */
@@ -131,7 +131,7 @@ directory_save(FILE *fp, struct directory *directory)
size_t i;
int retv;
- if (directory->path) {
+ if (!isRootDirectory(directory->path)) {
retv = fprintf(fp, "%s%s\n", DIRECTORY_BEGIN,
directory_get_path(directory));
if (retv < 0)
@@ -151,7 +151,7 @@ directory_save(FILE *fp, struct directory *directory)
songvec_save(fp, &directory->songs);
- if (directory->path &&
+ if (!isRootDirectory(directory->path) &&
fprintf(fp, DIRECTORY_END "%s\n",
directory_get_path(directory)) < 0)
return -1;
diff --git a/src/directory.h b/src/directory.h
index d8a8ea2af..ad24ca56f 100644
--- a/src/directory.h
+++ b/src/directory.h
@@ -73,8 +73,6 @@ directory_is_empty(struct directory *directory)
static inline const char *
directory_get_path(struct directory *directory)
{
- if (directory->path == NULL)
- return "";
return directory->path;
}