Mercurial > pt1.oyama
comparison src/content.c @ 125:e413158cae13
Add ushare project files.
author | naoyan@johnstown.minaminoshima.org |
---|---|
date | Sun, 03 Oct 2010 11:35:19 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
124:9c7bc6c0327e | 125:e413158cae13 |
---|---|
1 /* | |
2 * content.c : GeeXboX uShare content list | |
3 * Originally developped for the GeeXboX project. | |
4 * Copyright (C) 2005-2007 Alexis Saettler <asbin@asbin.org> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU Library General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with this program; if not, write to the Free Software Foundation, | |
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 */ | |
20 | |
21 #include <stdlib.h> | |
22 #include <stdio.h> | |
23 #include <string.h> | |
24 | |
25 #include "content.h" | |
26 | |
27 content_list * | |
28 content_add(content_list *list, const char *item) | |
29 { | |
30 if (!list) | |
31 { | |
32 list = (content_list*) malloc (sizeof(content_list)); | |
33 list->content = NULL; | |
34 list->count = 0; | |
35 } | |
36 if (item) | |
37 { | |
38 list->count++; | |
39 list->content = (char**) realloc (list->content, list->count * sizeof(char*)); | |
40 if (!list->content) | |
41 { | |
42 perror ("error realloc"); | |
43 exit (2); | |
44 } | |
45 list->content[list->count-1] = strdup (item); | |
46 } | |
47 return list; | |
48 } | |
49 | |
50 /* | |
51 * Remove the n'th content (start from 0) | |
52 */ | |
53 content_list * | |
54 content_del(content_list *list, int n) | |
55 { | |
56 int i; | |
57 | |
58 if (!list || n >= list->count) | |
59 return NULL; | |
60 | |
61 if (n >= list->count) | |
62 return list; | |
63 | |
64 if (list->content[n]) | |
65 { | |
66 free (list->content[n]); | |
67 for (i = n ; i < list->count - 1 ; i++) | |
68 list->content[i] = list->content[i+1]; | |
69 list->count--; | |
70 list->content[list->count] = NULL; | |
71 } | |
72 | |
73 return list; | |
74 } | |
75 | |
76 void | |
77 content_free(content_list *list) | |
78 { | |
79 int i; | |
80 if (!list) | |
81 return; | |
82 | |
83 if (list->content) | |
84 { | |
85 for (i=0 ; i < list->count ; i++) | |
86 { | |
87 if (list->content[i]) | |
88 free (list->content[i]); | |
89 } | |
90 free (list->content); | |
91 } | |
92 free (list); | |
93 } |