-
Notifications
You must be signed in to change notification settings - Fork 0
/
Playlist.c
49 lines (45 loc) · 1.1 KB
/
Playlist.c
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
48
49
/*
* Playlist.c
*
* Created on: 2013-03-06
* Author: danny
*/
#include "Playlist.h"
struct Playlist* initPlaylist(char* listname) {
struct Playlist* this = (struct Playlist*)malloc(sizeof(struct Playlist));
if(this == NULL) {
printf("playlist cannot malloc\n");
return NULL;
}
setListName(this, listname);
//this->songs = initQueue();
this->num_of_songs = 0;
this->id = 0;
//this->next = this->prev = NULL;
return this;
}
void setListId(struct Playlist* this, int id) {
this->id = id;
}
void setListName(struct Playlist* this, char* name) {
if(this == NULL || name == NULL) return;
int size = strlen(name);
if(size > LISTNAME_LENGTH-1) {
strncpy(this->list_name, name, LISTNAME_LENGTH-1);
this->list_name[LISTNAME_LENGTH-1] = '\0';
} else
strcpy(this->list_name, name);
}
void killPlaylist(struct Playlist** this) {
if(this == NULL || *this == NULL) return;
free(*this);
*this = NULL;
}
void generateListNameForSD(char* str, int list_index_in_db){
char index[2];
index[0] = list_index_in_db + '0';
index[1] = '\0';
strcpy(str, "LIST");
strcat(str, index);
strcat(str, ".TXT");
}