aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-09 19:44:10 +0200
committerMax Kellermann <max@duempel.org>2012-08-09 21:04:07 +0200
commita0478f98af3fb53168bdffa666894dde87cfe597 (patch)
treebbc01c320ab292ca32bc8a661ba2d00a52fd4db5
parent5e2c62db2fd8ddc165b358f23c19b4e8b873b4ec (diff)
downloadmpd-a0478f98af3fb53168bdffa666894dde87cfe597.tar.gz
mpd-a0478f98af3fb53168bdffa666894dde87cfe597.tar.xz
mpd-a0478f98af3fb53168bdffa666894dde87cfe597.zip
Directory: move code to directory_allocate()
-rw-r--r--src/Directory.cxx26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/Directory.cxx b/src/Directory.cxx
index 326fa24e9..eab526b38 100644
--- a/src/Directory.cxx
+++ b/src/Directory.cxx
@@ -37,24 +37,34 @@ extern "C" {
#include <string.h>
#include <stdlib.h>
-struct directory *
-directory_new(const char *path, struct directory *parent)
+static directory *
+directory_allocate(const char *path)
{
- size_t pathlen = strlen(path);
-
assert(path != NULL);
- assert((*path == 0) == (parent == NULL));
- struct directory *directory =
+ const size_t path_size = strlen(path) + 1;
+ directory *directory =
(struct directory *)g_malloc0(sizeof(*directory)
- sizeof(directory->path)
- + pathlen + 1);
+ + path_size);
INIT_LIST_HEAD(&directory->children);
INIT_LIST_HEAD(&directory->songs);
INIT_LIST_HEAD(&directory->playlists);
+ memcpy(directory->path, path, path_size);
+
+ return directory;
+}
+
+struct directory *
+directory_new(const char *path, struct directory *parent)
+{
+ assert(path != NULL);
+ assert((*path == 0) == (parent == NULL));
+
+ directory *directory = directory_allocate(path);
+
directory->parent = parent;
- memcpy(directory->path, path, pathlen + 1);
return directory;
}