aboutsummaryrefslogtreecommitdiffstats
path: root/src/list.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-11 02:59:16 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-11 02:59:16 +0000
commitd6a87f538d2347cd4610962a0004052c0c6ba8de (patch)
tree3bc0d5b0f93eb14d520f37607eec51fe456aafd0 /src/list.c
parent4ec3df033954d01663087011efecfca37749f965 (diff)
downloadmpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.tar.gz
mpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.tar.xz
mpd-d6a87f538d2347cd4610962a0004052c0c6ba8de.zip
ok, now song->url is only the filename, not the full path to the song
git-svn-id: https://svn.musicpd.org/mpd/trunk@2602 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/list.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/list.c b/src/list.c
index 48f1e1c62..f0d30d802 100644
--- a/src/list.c
+++ b/src/list.c
@@ -42,7 +42,7 @@ void freeListNodesArray(List * list) {
list->nodesArray = NULL;
}
-List * makeList(ListFreeDataFunc * freeDataFunc) {
+List * makeList(ListFreeDataFunc * freeDataFunc, int strdupKeys) {
List * list = malloc(sizeof(List));
assert(list!=NULL);
@@ -52,6 +52,7 @@ List * makeList(ListFreeDataFunc * freeDataFunc) {
list->freeDataFunc = freeDataFunc;
list->numberOfNodes = 0;
list->nodesArray = NULL;
+ list->strdupKeys = strdupKeys;
return list;
}
@@ -93,10 +94,12 @@ int insertInListBeforeNode(List * list, ListNode * beforeNode, char * key,
}
beforeNode->prevNode = node;
}
-
- node->key = malloc((strlen(key)+1)*sizeof(char));
+
+ if(list->strdupKeys) node->key = strdup(key);
+ else node->key = key;
+
assert(node->key!=NULL);
- strcpy(node->key,key);
+
node->data = data;
list->numberOfNodes++;
@@ -104,7 +107,7 @@ int insertInListBeforeNode(List * list, ListNode * beforeNode, char * key,
return 1;
}
-ListNode * insertInList(List * list,char * key,void * data) {
+ListNode * insertInList(List * list, char * key, void * data) {
ListNode * node;
assert(list!=NULL);
@@ -125,10 +128,10 @@ ListNode * insertInList(List * list,char * key,void * data) {
assert(list->lastNode->nextNode==NULL);
list->lastNode->nextNode = node;
}
-
- node->key = malloc((strlen(key)+1)*sizeof(char));
- assert(node->key!=NULL);
- strcpy(node->key,key);
+
+ if(list->strdupKeys) node->key = strdup(key);
+ else node->key = key;
+
node->data = data;
node->nextNode = NULL;
node->prevNode = list->lastNode;
@@ -267,7 +270,8 @@ void deleteNodeFromList(List * list,ListNode * node) {
if(list->freeDataFunc) {
list->freeDataFunc(node->data);
}
- free(node->key);
+
+ if(list->strdupKeys) free(node->key);
free(node);
list->numberOfNodes--;
@@ -290,7 +294,7 @@ void freeList(void * list) {
while(tmpNode!=NULL) {
tmpNode2 = tmpNode->nextNode;
- free(tmpNode->key);
+ if(((List *)list)->strdupKeys) free(tmpNode->key);
if(((List *)list)->freeDataFunc) {
((List *)list)->freeDataFunc(tmpNode->data);
}
@@ -311,7 +315,7 @@ void clearList(List * list) {
while(tmpNode!=NULL) {
tmpNode2 = tmpNode->nextNode;
- free(tmpNode->key);
+ if(list->strdupKeys) free(tmpNode->key);
if(((List *)list)->freeDataFunc) {
((List *)list)->freeDataFunc(tmpNode->data);
}
@@ -400,8 +404,8 @@ void quickSort(ListNode ** nodesArray, long start, long end) {
ListNode * pivotNode;
char * pivotKey;
- List * startList = makeList(free);
- List * endList = makeList(free);
+ List * startList = makeList(free, 0);
+ List * endList = makeList(free, 0);
long * startPtr = malloc(sizeof(long));
long * endPtr = malloc(sizeof(long));
*startPtr = start;