directory: use mpd_sizeof_str_flex_array for path, too
This way we avoid unnecessary heap allocations.
This commit is contained in:
parent
8867bd554c
commit
8d907fb9fa
@ -23,16 +23,18 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
struct directory *
|
struct directory *
|
||||||
directory_new(const char *dirname, struct directory *parent)
|
directory_new(const char *path, struct directory *parent)
|
||||||
{
|
{
|
||||||
struct directory *directory;
|
struct directory *directory;
|
||||||
|
size_t pathlen = strlen(path);
|
||||||
|
|
||||||
assert(dirname != NULL);
|
assert(path != NULL);
|
||||||
assert((*dirname == 0) == (parent == NULL));
|
assert((*path == 0) == (parent == NULL));
|
||||||
|
|
||||||
directory = xcalloc(1, sizeof(*directory));
|
directory = xcalloc(1, sizeof(*directory) -
|
||||||
directory->path = xstrdup(dirname);
|
sizeof(directory->path) + pathlen + 1);
|
||||||
directory->parent = parent;
|
directory->parent = parent;
|
||||||
|
memcpy(directory->path, path, pathlen + 1);
|
||||||
|
|
||||||
return directory;
|
return directory;
|
||||||
}
|
}
|
||||||
@ -42,7 +44,6 @@ directory_free(struct directory *directory)
|
|||||||
{
|
{
|
||||||
dirvec_destroy(&directory->children);
|
dirvec_destroy(&directory->children);
|
||||||
songvec_destroy(&directory->songs);
|
songvec_destroy(&directory->songs);
|
||||||
free(directory->path);
|
|
||||||
free(directory);
|
free(directory);
|
||||||
/* this resets last dir returned */
|
/* this resets last dir returned */
|
||||||
/*directory_get_path(NULL); */
|
/*directory_get_path(NULL); */
|
||||||
|
@ -35,13 +35,13 @@
|
|||||||
#define DIRECTORY_FS_CHARSET "fs_charset: "
|
#define DIRECTORY_FS_CHARSET "fs_charset: "
|
||||||
|
|
||||||
struct directory {
|
struct directory {
|
||||||
char *path;
|
|
||||||
struct dirvec children;
|
struct dirvec children;
|
||||||
struct songvec songs;
|
struct songvec songs;
|
||||||
struct directory *parent;
|
struct directory *parent;
|
||||||
ino_t inode;
|
ino_t inode;
|
||||||
dev_t device;
|
dev_t device;
|
||||||
unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
|
unsigned stat; /* not needed if ino_t == dev_t == 0 is impossible */
|
||||||
|
char path[sizeof(long)];
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
|
Loading…
Reference in New Issue
Block a user