s/malloc/xmalloc/ s/calloc/xcalloc/ s/realloc/realloc/
[oweals/opkg-lede.git] / libopkg / pkg_dest_list.c
1 /* pkg_dest_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_dest.h"
21 #include "void_list.h"
22 #include "pkg_dest_list.h"
23 #include "libbb/libbb.h"
24
25 int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data)
26 {
27     return void_list_elt_init((void_list_elt_t *) elt, data);
28 }
29
30 void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt)
31 {
32     void_list_elt_deinit((void_list_elt_t *) elt);
33 }
34
35 int pkg_dest_list_init(pkg_dest_list_t *list)
36 {
37     return void_list_init((void_list_t *) list);
38 }
39
40 void pkg_dest_list_deinit(pkg_dest_list_t *list)
41 {
42     pkg_dest_list_elt_t *iter, *n;
43     pkg_dest_t *pkg_dest;
44
45     list_for_each_entry_safe(iter, n,  &list->head, node) {
46         pkg_dest = (pkg_dest_t *)iter->data;
47         pkg_dest_deinit(pkg_dest);
48
49         /* malloced in pkg_dest_list_append */
50         free(pkg_dest);
51         iter->data = NULL;
52     }
53     void_list_deinit((void_list_t *) list);
54 }
55
56 pkg_dest_t *pkg_dest_list_append(pkg_dest_list_t *list, const char *name,
57                                  const char *root_dir,const char *lists_dir)
58 {
59     int err;
60     pkg_dest_t *pkg_dest;
61
62     /* freed in pkg_dest_list_deinit */
63     pkg_dest = xcalloc(1, sizeof(pkg_dest_t));
64
65     pkg_dest_init(pkg_dest, name, root_dir,lists_dir);
66     err = void_list_append((void_list_t *) list, pkg_dest);
67     if (err) {
68         return NULL;
69     }
70
71     return pkg_dest;
72 }
73
74 int pkg_dest_list_push(pkg_dest_list_t *list, pkg_dest_t *data)
75 {
76     return void_list_push((void_list_t *) list, data);
77 }
78
79 pkg_dest_list_elt_t *pkg_dest_list_pop(pkg_dest_list_t *list)
80 {
81     return (pkg_dest_list_elt_t *) void_list_pop((void_list_t *) list);
82 }