s/malloc/xmalloc/ s/calloc/xcalloc/ s/realloc/realloc/
[oweals/opkg-lede.git] / libopkg / pkg_src_list.c
1 /* pkg_src_list.c - the opkg package management system
2
3    Carl D. Worth
4
5    Copyright (C) 2001 University of Southern California
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2, or (at
10    your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16 */
17
18 #include "includes.h"
19
20 #include "pkg_src_list.h"
21 #include "void_list.h"
22 #include "libbb/libbb.h"
23
24 int pkg_src_list_init(pkg_src_list_t *list)
25 {
26     return void_list_init((void_list_t *) list);
27 }
28
29 void pkg_src_list_deinit(pkg_src_list_t *list)
30 {
31     pkg_src_list_elt_t *iter, *n;
32     pkg_src_t *pkg_src;
33
34     list_for_each_entry_safe(iter, n, &list->head, node) {
35       pkg_src = (pkg_src_t *)iter->data;
36       pkg_src_deinit(pkg_src);
37
38       /* malloced in pkg_src_list_append */
39       free(pkg_src);
40       iter->data = NULL;
41     }
42     void_list_deinit((void_list_t *) list);
43 }
44
45 pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
46                                const char *name, const char *base_url, const char *extra_data,
47                                int gzip)
48 {
49     int err;
50
51     /* freed in pkg_src_list_deinit */
52     pkg_src_t *pkg_src = xcalloc(1, sizeof(pkg_src_t));
53     pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
54
55     err = void_list_append((void_list_t *) list, pkg_src);
56     if (err) {
57         return NULL;
58     }
59
60     return pkg_src;
61 }
62
63 int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
64 {
65     return void_list_push((void_list_t *) list, data);
66 }
67
68 pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
69 {
70     return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
71 }