summaryrefslogtreecommitdiffstats
path: root/src/track.c
blob: e6f35cf4d20ab7a69ad8032d9abccaa62a5124af (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 "ref.h"
#include "track.h"

#include <wchar.h>
#include <string.h>
#include <sys/stat.h>


struct track *
track_init(const char *dir, const char *fname)
{
	struct track *track;
	struct stat info;

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

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

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

	track->name = calloc(strlen(track->fname) + 1, sizeof(wchar_t));
	ASSERT(track->name != NULL);
	mbstowcs(track->name, track->fname, strlen(track->fname) + 1);

	track->fid = -1;
	if (!stat(track->fpath, &info))
		track->fid = info.st_ino;

	track->tags = LIST_HEAD;

	return track;
}

void
track_free(struct track *t)
{
	free(t->fname);
	free(t->fpath);
	free(t->name);

	refs_free(&t->tags);

	free(t);
}