summaryrefslogtreecommitdiffstats
path: root/src/tag.c
blob: 2415dec804b849550372518b34ff68f3280d699a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "tag.h"
#include "link.h"
#include "ref.h"

#include <string.h>

struct tag *
tag_init(const char *path, const char *fname)
{
	struct tag *tag;
	int len;

	tag = malloc(sizeof(struct tag));
	ASSERT(tag != NULL);

	tag->fname = strdup(fname);
	ASSERT(tag->fname != NULL);

	tag->new_fname = NULL;

	tag->fpath = aprintf("%s/%s", path, fname);
	ASSERT(tag->fpath != NULL);

	len = mbstowcs(NULL, tag->fname, 0);
	ASSERT(len > 0);
	tag->name = calloc(len + 1, sizeof(wchar_t));
	ASSERT(tag->name != NULL);
	mbstowcs(tag->name, tag->fname, len + 1);

	tag->link = LINK_EMPTY;

	list_init(&tag->tracks);

	return tag;
}

void
tag_free(struct tag *tag)
{
	free(tag->fname);
	free(tag->fpath);
	free(tag->name);

	refs_free(&tag->tracks);

	free(tag);
}