opkg: add autoremove command line option
[oweals/opkg-lede.git] / libopkg / pkg_src_list.c
1 /* pkg_src_list.c - the itsy 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 "opkg.h"
19
20 #include "pkg_src_list.h"
21 #include "void_list.h"
22
23 int pkg_src_list_init(pkg_src_list_t *list)
24 {
25     return void_list_init((void_list_t *) list);
26 }
27
28 void pkg_src_list_deinit(pkg_src_list_t *list)
29 {
30     pkg_src_list_elt_t *iter;
31     pkg_src_t *pkg_src;
32
33     for (iter = list->head; iter; iter = iter->next) {
34       pkg_src = iter->data;
35       pkg_src_deinit(pkg_src);
36
37       /* malloced in pkg_src_list_append */
38       free(pkg_src);
39       iter->data = NULL;
40     }
41     void_list_deinit((void_list_t *) list);
42 }
43
44 pkg_src_t *pkg_src_list_append(pkg_src_list_t *list,
45                                const char *name, const char *base_url, const char *extra_data,
46                                int gzip)
47 {
48     int err;
49
50     /* freed in pkg_src_list_deinit */
51     pkg_src_t *pkg_src = malloc(sizeof(pkg_src_t));
52
53     if (pkg_src == NULL) {
54         fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
55         return NULL;
56     }
57     pkg_src_init(pkg_src, name, base_url, extra_data, gzip);
58
59     err = void_list_append((void_list_t *) list, pkg_src);
60     if (err) {
61         return NULL;
62     }
63
64     return pkg_src;
65 }
66
67 int pkg_src_list_push(pkg_src_list_t *list, pkg_src_t *data)
68 {
69     return void_list_push((void_list_t *) list, data);
70 }
71
72 pkg_src_list_elt_t *pkg_src_list_pop(pkg_src_list_t *list)
73 {
74     return (pkg_src_list_elt_t *) void_list_pop((void_list_t *) list);
75 }