summaryrefslogtreecommitdiffstats
path: root/libopkg
diff options
context:
space:
mode:
Diffstat (limited to 'libopkg')
-rw-r--r--libopkg/conffile_list.c3
-rw-r--r--libopkg/conffile_list.h4
-rw-r--r--libopkg/nv_pair.c1
-rw-r--r--libopkg/nv_pair_list.c45
-rw-r--r--libopkg/nv_pair_list.h28
-rw-r--r--libopkg/opkg.c22
-rw-r--r--libopkg/opkg_cmd.c20
-rw-r--r--libopkg/opkg_conf.c22
-rw-r--r--libopkg/opkg_install.c49
-rw-r--r--libopkg/opkg_remove.c19
-rw-r--r--libopkg/pkg.c54
-rw-r--r--libopkg/pkg_dest_list.c6
-rw-r--r--libopkg/pkg_dest_list.h17
-rw-r--r--libopkg/pkg_extract.c4
-rw-r--r--libopkg/pkg_hash.c7
-rw-r--r--libopkg/pkg_src_list.c6
-rw-r--r--libopkg/pkg_src_list.h21
-rw-r--r--libopkg/str_list.c30
-rw-r--r--libopkg/str_list.h24
-rw-r--r--libopkg/void_list.c215
-rw-r--r--libopkg/void_list.h21
21 files changed, 296 insertions, 322 deletions
diff --git a/libopkg/conffile_list.c b/libopkg/conffile_list.c
index 965c3d0..401c6b4 100644
--- a/libopkg/conffile_list.c
+++ b/libopkg/conffile_list.c
@@ -42,6 +42,7 @@ int conffile_list_push(conffile_list_t *list, conffile_t *data)
conffile_list_elt_t *conffile_list_pop(conffile_list_t *list)
{
- return nv_pair_list_pop(list);
+ conffile_list_elt_t *pos = nv_pair_list_pop(list);
+ return pos;
}
diff --git a/libopkg/conffile_list.h b/libopkg/conffile_list.h
index 87e093f..b044d63 100644
--- a/libopkg/conffile_list.h
+++ b/libopkg/conffile_list.h
@@ -20,8 +20,8 @@
#include "nv_pair_list.h"
-typedef struct nv_pair_list_elt conffile_list_elt_t;
-typedef struct nv_pair_list conffile_list_t;
+typedef nv_pair_list_elt_t conffile_list_elt_t;
+typedef nv_pair_list_t conffile_list_t;
#include "conffile.h"
diff --git a/libopkg/nv_pair.c b/libopkg/nv_pair.c
index dcbd40f..8cfb06a 100644
--- a/libopkg/nv_pair.c
+++ b/libopkg/nv_pair.c
@@ -22,6 +22,7 @@
int nv_pair_init(nv_pair_t *nv_pair, const char *name, const char *value)
{
+
nv_pair->name = str_dup_safe(name);
nv_pair->value = str_dup_safe(value);
diff --git a/libopkg/nv_pair_list.c b/libopkg/nv_pair_list.c
index 544d1e0..fc4cd0f 100644
--- a/libopkg/nv_pair_list.c
+++ b/libopkg/nv_pair_list.c
@@ -21,15 +21,6 @@
#include "void_list.h"
#include "nv_pair_list.h"
-int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data)
-{
- return void_list_elt_init((void_list_elt_t *) elt, data);
-}
-
-void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt)
-{
- void_list_elt_deinit((void_list_elt_t *) elt);
-}
int nv_pair_list_init(nv_pair_list_t *list)
{
@@ -38,16 +29,19 @@ int nv_pair_list_init(nv_pair_list_t *list)
void nv_pair_list_deinit(nv_pair_list_t *list)
{
- nv_pair_list_elt_t *iter;
+ nv_pair_list_elt_t *pos;
nv_pair_t *nv_pair;
- for (iter = list->head; iter; iter = iter->next) {
- nv_pair = iter->data;
+ while(!void_list_empty(list)) {
+ pos = nv_pair_list_pop(list);
+ if (!pos)
+ break;
+ nv_pair = (nv_pair_t *) pos->data;
nv_pair_deinit(nv_pair);
-
/* malloced in nv_pair_list_append */
free(nv_pair);
- iter->data = NULL;
+ pos->data = NULL;
+ //free(pos);
}
void_list_deinit((void_list_t *) list);
}
@@ -88,11 +82,30 @@ char *nv_pair_list_find(nv_pair_list_t *list, char *name)
nv_pair_list_elt_t *iter;
nv_pair_t *nv_pair;
- for (iter = list->head; iter; iter = iter->next) {
- nv_pair = iter->data;
+ list_for_each_entry(iter, &list->head, node) {
+ nv_pair = (nv_pair_t *)iter->data;
if (strcmp(nv_pair->name, name) == 0) {
return nv_pair->value;
}
}
return NULL;
}
+
+nv_pair_list_elt_t *nv_pair_list_first(nv_pair_list_t *list) {
+ return (nv_pair_list_elt_t * )void_list_first((void_list_t *) list);
+}
+
+nv_pair_list_elt_t *nv_pair_list_prev(nv_pair_list_t *list, nv_pair_list_elt_t *node) {
+ return (nv_pair_list_elt_t * )void_list_prev((void_list_t *) list, (void_list_elt_t *)node);
+}
+
+nv_pair_list_elt_t *nv_pair_list_next(nv_pair_list_t *list, nv_pair_list_elt_t *node) {
+ return (nv_pair_list_elt_t * )void_list_next((void_list_t *) list, (void_list_elt_t *)node);
+}
+
+nv_pair_list_elt_t *nv_pair_list_last(nv_pair_list_t *list) {
+ return (nv_pair_list_elt_t * )void_list_last((void_list_t *) list);
+}
+
+
+
diff --git a/libopkg/nv_pair_list.h b/libopkg/nv_pair_list.h
index 0040d71..fc9d9e2 100644
--- a/libopkg/nv_pair_list.h
+++ b/libopkg/nv_pair_list.h
@@ -21,32 +21,15 @@
#include "nv_pair.h"
#include "void_list.h"
-typedef struct nv_pair_list_elt nv_pair_list_elt_t;
-struct nv_pair_list_elt
-{
- nv_pair_list_elt_t *next;
- nv_pair_t *data;
-};
+typedef struct void_list_elt nv_pair_list_elt_t;
-typedef struct nv_pair_list nv_pair_list_t;
-struct nv_pair_list
-{
- nv_pair_list_elt_t pre_head;
- nv_pair_list_elt_t *head;
- nv_pair_list_elt_t *tail;
-};
+typedef struct void_list nv_pair_list_t;
static inline int nv_pair_list_empty(nv_pair_list_t *list)
{
- if (list->head == NULL)
- return 1;
- else
- return 0;
+ return void_list_empty ((void_list_t *)list);
}
-int nv_pair_list_elt_init(nv_pair_list_elt_t *elt, nv_pair_t *data);
-void nv_pair_list_elt_deinit(nv_pair_list_elt_t *elt);
-
int nv_pair_list_init(nv_pair_list_t *list);
void nv_pair_list_deinit(nv_pair_list_t *list);
@@ -56,5 +39,10 @@ int nv_pair_list_push(nv_pair_list_t *list, nv_pair_t *data);
nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t *list);
char *nv_pair_list_find(nv_pair_list_t *list, char *name);
+nv_pair_list_elt_t *nv_pair_list_first(nv_pair_list_t *list);
+nv_pair_list_elt_t *nv_pair_list_prev(nv_pair_list_t *list, nv_pair_list_elt_t *node);
+nv_pair_list_elt_t *nv_pair_list_next(nv_pair_list_t *list, nv_pair_list_elt_t *node);
+nv_pair_list_elt_t *nv_pair_list_last(nv_pair_list_t *list);
+
#endif
diff --git a/libopkg/opkg.c b/libopkg/opkg.c
index 0dff32b..521072d 100644
--- a/libopkg/opkg.c
+++ b/libopkg/opkg.c
@@ -785,18 +785,16 @@ opkg_update_package_lists (opkg_t *opkg, opkg_progress_callback_t progress_callb
/* count the number of sources so we can give some progress updates */
sources_list_count = 0;
sources_done = 0;
- iter = opkg->conf->pkg_src_list.head;
- while (iter)
+ list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
{
sources_list_count++;
- iter = iter->next;
}
- for (iter = opkg->conf->pkg_src_list.head; iter; iter = iter->next)
+ list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
{
char *url, *list_file_name = NULL;
- src = iter->data;
+ src = (pkg_src_t *)iter->data;
if (src->extra_data) /* debian style? */
sprintf_alloc (&url, "%s/%s/%s", src->value, src->extra_data,
@@ -1040,17 +1038,17 @@ int opkg_repository_accessibility_check(opkg_t *opkg)
src = str_list_alloc();
- for (iter = opkg->conf->pkg_src_list.head; iter; iter = iter->next)
+ list_for_each_entry(iter, &opkg->conf->pkg_src_list.head, node)
{
- if (strstr(iter->data->value, "://") &&
- index(strstr(iter->data->value, "://") + 3, '/'))
- stmp = strndup(iter->data->value,
- (index(strstr(iter->data->value, "://") + 3, '/') - iter->data->value)*sizeof(char));
+ if (strstr(((pkg_src_t *)iter->data)->value, "://") &&
+ index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/'))
+ stmp = strndup(((pkg_src_t *)iter->data)->value,
+ (index(strstr(((pkg_src_t *)iter->data)->value, "://") + 3, '/') - ((pkg_src_t *)iter->data)->value)*sizeof(char));
else
- stmp = strdup(iter->data->value);
+ stmp = strdup(((pkg_src_t *)iter->data)->value);
- for (iter1 = src->head; iter1; iter1 = iter1->next)
+ for (iter1 = str_list_first(src); iter1; iter1 = str_list_next(src, iter1))
{
if (strstr(iter1->data, stmp))
break;
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index fae3085..518493e 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -217,10 +217,10 @@ static int opkg_update_cmd(opkg_conf_t *conf, int argc, char **argv)
}
- for (iter = conf->pkg_src_list.head; iter; iter = iter->next) {
+ for (iter = void_list_first(&conf->pkg_src_list); iter; iter = void_list_next(&conf->pkg_src_list, iter)) {
char *url, *list_file_name;
- src = iter->data;
+ src = (pkg_src_t *)iter->data;
if (src->extra_data) /* debian style? */
sprintf_alloc(&url, "%s/%s/%s", src->value, src->extra_data,
@@ -849,8 +849,8 @@ static int opkg_info_status_cmd(opkg_conf_t *conf, int argc, char **argv, int in
}
if (conf->verbosity > 1) {
conffile_list_elt_t *iter;
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
- conffile_t *cf = iter->data;
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ conffile_t *cf = (conffile_t *)iter->data;
int modified = conffile_has_been_modified(conf, cf);
opkg_message(conf, OPKG_NOTICE, "conffile=%s md5sum=%s modified=%d\n",
cf->name, cf->value, modified);
@@ -1140,7 +1140,7 @@ static int opkg_files_cmd(opkg_conf_t *conf, int argc, char **argv)
buff = realloc (buff, buff_len);
goto try_again;
}
- for (iter = installed_files->head; iter; iter = iter->next) {
+ for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
used_len += strlen (iter->data) + 1;
while (buff_len <= used_len) {
buff_len *= 2;
@@ -1447,8 +1447,8 @@ static int opkg_search_cmd(opkg_conf_t *conf, int argc, char **argv)
installed_files = pkg_get_installed_files(pkg);
- for (iter = installed_files->head; iter; iter = iter->next) {
- installed_file = iter->data;
+ for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
+ installed_file = (char *)iter->data;
if (fnmatch(argv[0], installed_file, 0)==0) {
if (opkg_cb_list) opkg_cb_list(pkg->name,
installed_file,
@@ -1491,11 +1491,9 @@ static int opkg_print_architecture_cmd(opkg_conf_t *conf, int argc, char **argv)
{
nv_pair_list_elt_t *l;
- l = conf->arch_list.head;
- while (l) {
- nv_pair_t *nv = l->data;
+ list_for_each_entry(l, &conf->arch_list.head, node) {
+ nv_pair_t *nv = (nv_pair_t *)l->data;
printf("arch %s %s\n", nv->name, nv->value);
- l = l->next;
}
return 0;
}
diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c
index c29e4c2..d722a0d 100644
--- a/libopkg/opkg_conf.c
+++ b/libopkg/opkg_conf.c
@@ -215,7 +215,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args)
}
/* Even if there is no conf file, we'll need at least one dest. */
- if (tmp_dest_nv_pair_list.head == NULL) {
+ if (nv_pair_list_empty(&tmp_dest_nv_pair_list)) {
nv_pair_list_append(&tmp_dest_nv_pair_list,
OPKG_CONF_DEFAULT_DEST_NAME,
OPKG_CONF_DEFAULT_DEST_ROOT_DIR);
@@ -383,8 +383,8 @@ static int opkg_conf_set_default_dest(opkg_conf_t *conf,
pkg_dest_list_elt_t *iter;
pkg_dest_t *dest;
- for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
- dest = iter->data;
+ for (iter = void_list_first(&conf->pkg_dest_list); iter; iter = void_list_next(&conf->pkg_dest_list, iter)) {
+ dest = (pkg_dest_t *)iter->data;
if (strcmp(dest->name, default_dest_name) == 0) {
conf->default_dest = dest;
conf->restrict_to_default_dest = 1;
@@ -403,8 +403,8 @@ static int set_and_load_pkg_src_list(opkg_conf_t *conf, pkg_src_list_t *pkg_src_
pkg_src_t *src;
char *list_file;
- for (iter = pkg_src_list->head; iter; iter = iter->next) {
- src = iter->data;
+ for (iter = void_list_first(pkg_src_list); iter; iter = void_list_next(pkg_src_list, iter)) {
+ src = (pkg_src_t *)iter->data;
if (src == NULL) {
continue;
}
@@ -429,8 +429,8 @@ static int set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair
pkg_dest_t *dest;
char *root_dir;
- for (iter = nv_pair_list->head; iter; iter = iter->next) {
- nv_pair = iter->data;
+ for (iter = nv_pair_list_first(nv_pair_list); iter; iter = nv_pair_list_next(nv_pair_list, iter)) {
+ nv_pair = (nv_pair_t *)iter->data;
if (conf->offline_root) {
sprintf_alloc(&root_dir, "%s%s", conf->offline_root, nv_pair->value);
@@ -655,8 +655,8 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
if (conf->noaction)
return 0;
- for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
- dest = iter->data;
+ for (iter = void_list_first(&conf->pkg_dest_list); iter; iter = void_list_next(&conf->pkg_dest_list, iter)) {
+ dest = (pkg_dest_t *)iter->data;
dest->status_file = fopen(dest->status_file_tmp_name, "w");
if (dest->status_file == NULL) {
fprintf(stderr, "%s: Can't open status file: %s for writing: %s\n",
@@ -692,8 +692,8 @@ int opkg_conf_write_status_files(opkg_conf_t *conf)
pkg_vec_free(all);
- for (iter = conf->pkg_dest_list.head; iter; iter = iter->next) {
- dest = iter->data;
+ for (iter = void_list_first(&conf->pkg_dest_list); iter; iter = void_list_next(&conf->pkg_dest_list, iter)) {
+ dest = (pkg_dest_t *)iter->data;
if (dest->status_file) {
err = ferror(dest->status_file);
fclose(dest->status_file);
diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c
index 3a1d69d..8625f62 100644
--- a/libopkg/opkg_install.c
+++ b/libopkg/opkg_install.c
@@ -434,8 +434,8 @@ static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_p
str_list_t *new_list = pkg_get_installed_files(new_pkg);
str_list_elt_t *iter;
- for (iter = new_list->head; iter; iter = iter->next) {
- char *new_file = iter->data;
+ for (iter = str_list_first(new_list); iter; iter = str_list_next(new_list, iter)) {
+ char *new_file = (char *)iter->data;
pkg_t *owner = file_hash_get_file_owner(conf, new_file);
if (!new_file)
opkg_message(conf, OPKG_ERROR, "Null new_file for new_pkg=%s\n", new_pkg->name);
@@ -444,8 +444,8 @@ static int update_file_ownership(opkg_conf_t *conf, pkg_t *new_pkg, pkg_t *old_p
}
if (old_pkg) {
str_list_t *old_list = pkg_get_installed_files(old_pkg);
- for (iter = old_list->head; iter; iter = iter->next) {
- char *old_file = iter->data;
+ for (iter = str_list_first(old_list); iter; iter = str_list_next(old_list, iter)) {
+ char *old_file = (char *)iter->data;
pkg_t *owner = file_hash_get_file_owner(conf, old_file);
if (owner == old_pkg) {
/* obsolete */
@@ -517,7 +517,7 @@ static int unpack_pkg_control_files(opkg_conf_t *conf, pkg_t *pkg)
move all of unpack_pkg_control_files to that function. */
/* Don't need to re-read conffiles if we already have it */
- if (pkg->conffiles.head) {
+ if (!nv_pair_list_empty(&pkg->conffiles)) {
return 0;
}
@@ -1144,7 +1144,7 @@ static int backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_p
/* Backup all modified conffiles */
if (old_pkg) {
- for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
+ for (iter = nv_pair_list_first(&old_pkg->conffiles); iter; iter = nv_pair_list_next(&old_pkg->conffiles, iter)) {
char *cf_name;
cf = iter->data;
@@ -1162,9 +1162,9 @@ static int backup_modified_conffiles(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_p
}
/* Backup all conffiles that were not conffiles in old_pkg */
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
char *cf_name;
- cf = iter->data;
+ cf = (conffile_t *)iter->data;
cf_name = root_filename_alloc(conf, cf->name);
/* Ignore if this was a conffile in old_pkg as well */
if (pkg_get_conffile(old_pkg, cf->name)) {
@@ -1188,13 +1188,13 @@ static int backup_modified_conffiles_unwind(opkg_conf_t *conf, pkg_t *pkg, pkg_t
conffile_list_elt_t *iter;
if (old_pkg) {
- for (iter = old_pkg->conffiles.head; iter; iter = iter->next) {
- backup_remove(iter->data->name);
+ for (iter = nv_pair_list_first(&old_pkg->conffiles); iter; iter = nv_pair_list_next(&old_pkg->conffiles, iter)) {
+ backup_remove(((nv_pair_t *)iter->data)->name);
}
}
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
- backup_remove(iter->data->name);
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ backup_remove(((nv_pair_t *)iter->data)->name);
}
return 0;
@@ -1222,9 +1222,9 @@ static int check_data_file_clashes(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
int clashes = 0;
files_list = pkg_get_installed_files(pkg);
- for (iter = files_list->head; iter; iter = iter->next) {
+ for (iter = str_list_first(files_list); iter; iter = str_list_next(files_list, iter)) {
char *root_filename;
- char *filename = iter->data;
+ char *filename = (char *) iter->data;
root_filename = root_filename_alloc(conf, filename);
if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
pkg_t *owner;
@@ -1309,9 +1309,9 @@ static int check_data_file_clashes_change(opkg_conf_t *conf, pkg_t *pkg, pkg_t *
int clashes = 0;
files_list = pkg_get_installed_files(pkg);
- for (iter = files_list->head; iter; iter = iter->next) {
+ for (iter = str_list_first(files_list); iter; iter = str_list_next(files_list, iter)) {
char *root_filename;
- char *filename = iter->data;
+ char *filename = (char *) iter->data;
root_filename = root_filename_alloc(conf, filename);
if (file_exists(root_filename) && (! file_is_dir(root_filename))) {
pkg_t *owner;
@@ -1377,6 +1377,7 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
str_list_elt_t *of;
str_list_t *new_files;
str_list_elt_t *nf;
+ str_list_elt_t **niter;
if (old_pkg == NULL) {
return 0;
@@ -1385,14 +1386,18 @@ static int remove_obsolesced_files(opkg_conf_t *conf, pkg_t *pkg, pkg_t *old_pkg
old_files = pkg_get_installed_files(old_pkg);
new_files = pkg_get_installed_files(pkg);
- for (of = old_files->head; of; of = of->next) {
+ for (of = str_list_first(old_files); of; of = str_list_next(old_files, of)) {
pkg_t *owner;
char *old, *new;
- old = of->data;
- for (nf = new_files->head; nf; nf = nf->next) {
+ old = (char *)of->data;
+ for (nf = str_list_first(new_files); nf; nf = str_list_next(new_files, nf)) {
new = nf->data;
if (strcmp(old, new) == 0) {
- goto NOT_OBSOLETE;
+ niter = &nf;
+ nf=str_list_next(new_files, nf);
+ str_list_remove(new_files, niter);
+ free(new);
+ goto NOT_OBSOLETE;
}
}
if (file_is_dir(old)) {
@@ -1549,9 +1554,9 @@ static int resolve_conffiles(opkg_conf_t *conf, pkg_t *pkg)
if (conf->noaction) return 0;
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
char *root_filename;
- cf = iter->data;
+ cf = (conffile_t *)iter->data;
root_filename = root_filename_alloc(conf, cf->name);
/* Might need to initialize the md5sum for each conffile */
diff --git a/libopkg/opkg_remove.c b/libopkg/opkg_remove.c
index 3edb6de..0b913fd 100644
--- a/libopkg/opkg_remove.c
+++ b/libopkg/opkg_remove.c
@@ -346,8 +346,8 @@ int remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
str_list_init(&installed_dirs);
installed_files = pkg_get_installed_files(pkg);
- for (iter = installed_files->head; iter; iter = iter->next) {
- file_name = iter->data;
+ for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
+ file_name = (char *)iter->data;
if (file_is_dir(file_name)) {
str_list_append(&installed_dirs, strdup(file_name));
@@ -377,8 +377,8 @@ int remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
if (!conf->noaction) {
do {
removed_a_dir = 0;
- for (iter = installed_dirs.head; iter; iter = iter->next) {
- file_name = iter->data;
+ for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) {
+ file_name = (char *)iter->data;
if (rmdir(file_name) == 0) {
opkg_message(conf, OPKG_INFO, " deleting %s\n", file_name);
@@ -395,8 +395,8 @@ int remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
pkg_remove_installed_files_list(conf, pkg);
/* Don't print warning for dirs that are provided by other packages */
- for (iter = installed_dirs.head; iter; iter = iter->next) {
- file_name = iter->data;
+ for (iter = str_list_first(&installed_dirs); iter; iter = str_list_next(&installed_dirs, iter)) {
+ file_name = (char *)iter->data;
owner = file_hash_get_file_owner(conf, file_name);
if (owner) {
@@ -407,9 +407,10 @@ int remove_data_files_and_list(opkg_conf_t *conf, pkg_t *pkg)
}
/* cleanup */
- for (iter = installed_dirs.head; iter; iter = iter->next) {
- free(iter->data);
- iter->data = NULL;
+ while (!void_list_empty(&installed_dirs)) {
+ iter = str_list_pop(&installed_dirs);
+ free(iter->data);
+ free(iter);
}
str_list_deinit(&installed_dirs);
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index 309af55..cc33e70 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -412,8 +412,8 @@ int pkg_merge(pkg_t *oldpkg, pkg_t *newpkg, int set_status)
oldpkg->priority = str_dup_safe(newpkg->priority);
if (!oldpkg->source)
oldpkg->source = str_dup_safe(newpkg->source);
- if (oldpkg->conffiles.head == NULL){
- oldpkg->conffiles = newpkg->conffiles;
+ if (nv_pair_list_empty(&oldpkg->conffiles)){
+ list_splice_init(&newpkg->conffiles.head, &oldpkg->conffiles.head);
conffile_list_init(&newpkg->conffiles);
}
if (!oldpkg->installed_files){
@@ -643,14 +643,14 @@ char * pkg_formatted_field(pkg_t *pkg, const char *field )
conffile_list_elt_t *iter;
char confstr[LINE_LEN];
- if (pkg->conffiles.head == NULL) {
+ if (nv_pair_list_empty(&pkg->conffiles)) {
return temp;
}
len = 14 ;
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
- if (iter->data->name && iter->data->value) {
- len = len + (strlen(iter->data->name)+strlen(iter->data->value)+5);
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ if (((conffile_t *)iter->data)->name && ((conffile_t *)iter->data)->value) {
+ len = len + (strlen(((conffile_t *)iter->data)->name)+strlen(((conffile_t *)iter->data)->value)+5);
}
}
temp = (char *)realloc(temp,len);
@@ -660,9 +660,11 @@ char * pkg_formatted_field(pkg_t *pkg, const char *field )
}
temp[0]='\0';
strncpy(temp, "Conffiles:\n", 12);
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
- if (iter->data->name && iter->data->value) {
- snprintf(confstr, LINE_LEN, "%s %s\n", iter->data->name, iter->data->value);
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ if (((conffile_t *)iter->data)->name && ((conffile_t *)iter->data)->value) {
+ snprintf(confstr, LINE_LEN, "%s %s\n",
+ ((conffile_t *)iter->data)->name,
+ ((conffile_t *)iter->data)->value);
strncat(temp, confstr, strlen(confstr));
}
}
@@ -1395,23 +1397,13 @@ str_list_t *pkg_get_installed_files(pkg_t *pkg)
work. */
int pkg_free_installed_files(pkg_t *pkg)
{
- str_list_elt_t *iter;
-
pkg->installed_files_ref_cnt--;
if (pkg->installed_files_ref_cnt > 0)
return 0;
if (pkg->installed_files) {
-
- for (iter = pkg->installed_files->head; iter; iter = iter->next) {
- /* malloced in pkg_get_installed_files */
- free (iter->data);
- iter->data = NULL;
- }
-
- str_list_deinit(pkg->installed_files);
- free (pkg->installed_files);
+ str_list_deinit(pkg->installed_files);
}
pkg->installed_files = NULL;
@@ -1449,8 +1441,8 @@ conffile_t *pkg_get_conffile(pkg_t *pkg, const char *file_name)
return NULL;
}
- for (iter = pkg->conffiles.head; iter; iter = iter->next) {
- conffile = iter->data;
+ for (iter = nv_pair_list_first(&pkg->conffiles); iter; iter = nv_pair_list_next(&pkg->conffiles, iter)) {
+ conffile = (conffile_t *)iter->data;
if (strcmp(conffile->name, file_name) == 0) {
return conffile;
@@ -1671,15 +1663,12 @@ int pkg_arch_supported(opkg_conf_t *conf, pkg_t *pkg)
if (!pkg->architecture)
return 1;
- l = conf->arch_list.head;
-
- while (l) {
- nv_pair_t *nv = l->data;
+ list_for_each_entry(l , &conf->arch_list.head, node) {
+ nv_pair_t *nv = (nv_pair_t *)l->data;
if (strcmp(nv->name, pkg->architecture) == 0) {
opkg_message(conf, OPKG_DEBUG, "arch %s (priority %s) supported for pkg %s\n", nv->name, nv->value, pkg->name);
return 1;
}
- l = l->next;
}
opkg_message(conf, OPKG_DEBUG, "arch %s unsupported for pkg %s\n", pkg->architecture, pkg->name);
@@ -1690,15 +1679,12 @@ int pkg_get_arch_priority(opkg_conf_t *conf, const char *archname)
{
nv_pair_list_elt_t *l;
- l = conf->arch_list.head;
-
- while (l) {
- nv_pair_t *nv = l->data;
+ list_for_each_entry(l , &conf->arch_list.head, node) {
+ nv_pair_t *nv = (nv_pair_t *)l->data;
if (strcmp(nv->name, archname) == 0) {
int priority = strtol(nv->value, NULL, 0);
return priority;
}
- l = l->next;
}
return 0;
}
@@ -1750,8 +1736,8 @@ int pkg_info_preinstall_check(opkg_conf_t *conf)
opkg_message(conf, OPKG_ERROR, "No installed files for pkg %s\n", pkg->name);
break;
}
- for (iter = installed_files->head; iter; iter = iter->next) {
- char *installed_file = iter->data;
+ for (iter = str_list_first(installed_files); iter; iter = str_list_next(installed_files, iter)) {
+ char *installed_file = (char *) iter->data;
// opkg_message(conf, OPKG_DEBUG2, "pkg %s: file=%s\n", pkg->name, installed_file);
file_hash_set_file_owner(conf, installed_file, pkg);
}
diff --git a/libopkg/pkg_dest_list.c b/libopkg/pkg_dest_list.c
index 48ca07f..2c03e73 100644
--- a/libopkg/pkg_dest_list.c
+++ b/libopkg/pkg_dest_list.c
@@ -38,11 +38,11 @@ int pkg_dest_list_init(pkg_dest_list_t *list)
void pkg_dest_list_deinit(pkg_dest_list_t *list)
{
- pkg_dest_list_elt_t *iter;
+ pkg_dest_list_elt_t *iter, *n;
pkg_dest_t *pkg_dest;
- for (iter = list->head; iter; iter = iter->next) {
- pkg_dest = iter->data;
+ list_for_each_entry_safe(iter, n, &list->head, node) {
+ pkg_dest = (pkg_dest_t *)iter->data;
pkg_dest_deinit(pkg_dest);
/* malloced in pkg_dest_list_append */
diff --git a/libopkg/pkg_dest_list.h b/libopkg/pkg_dest_list.h
index 76258d3..3e976bc 100644
--- a/libopkg/pkg_dest_list.h
+++ b/libopkg/pkg_dest_list.h
@@ -20,20 +20,9 @@
#include "pkg_dest.h"
-typedef struct pkg_dest_list_elt pkg_dest_list_elt_t;
-struct pkg_dest_list_elt
-{
- pkg_dest_list_elt_t *next;
- pkg_dest_t *data;
-};
-
-typedef struct pkg_dest_list pkg_dest_list_t;
-struct pkg_dest_list
-{
- pkg_dest_list_elt_t pre_head;
- pkg_dest_list_elt_t *head;
- pkg_dest_list_elt_t *tail;
-};
+typedef struct void_list_elt pkg_dest_list_elt_t;
+
+typedef struct void_list pkg_dest_list_t;
int pkg_dest_list_elt_init(pkg_dest_list_elt_t *elt, pkg_dest_t *data);
void pkg_dest_list_elt_deinit(pkg_dest_list_elt_t *elt);
diff --git a/libopkg/pkg_extract.c b/libopkg/pkg_extract.c
index f972182..eae7746 100644
--- a/libopkg/pkg_extract.c
+++ b/libopkg/pkg_extract.c
@@ -102,8 +102,8 @@ int pkg_extract_data_file_names_to_file(pkg_t *pkg, const char *file_name)
tmp = tmpfile();
if (pkg->installed_files) {
str_list_elt_t *elt;
- for (elt = pkg->installed_files->head; elt; elt = elt->next) {
- fprintf(file, "%s\n", elt->data);
+ for (elt = str_list_first(pkg->installed_files); elt; elt = str_list_next(pkg->installed_files, elt)) {
+ fprintf(file, "%s\n", (char *)elt->data);
}
} else {
err = pkg_extract_data_file_names_to_stream(pkg, tmp);
diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c
index 35f65a3..8718e20 100644
--- a/libopkg/pkg_hash.c
+++ b/libopkg/pkg_hash.c
@@ -93,10 +93,8 @@ static char *pkg_get_default_arch(opkg_conf_t *conf)
char *def_arch = HOST_CPU_STR; /* Default arch */
int def_prio = 0; /* Other archs override this */
- l = conf->arch_list.head;
-
- while (l) {
- nv_pair_t *nv = l->data;
+ list_for_each_entry(l , &conf->arch_list.head, node) {
+ nv_pair_t *nv = (nv_pair_t *)l->data;
int priority = strtol(nv->value, NULL, 0);
/* Check if this arch has higher priority, and is valid */
@@ -106,7 +104,6 @@ static char *pkg_get_default_arch(opkg_conf_t *conf)
def_prio = priority;
def_arch = nv->name;
}
- l = l->next;
}
return strdup(def_arch);
diff --git a/libopkg/pkg_src_list.c b/libopkg/pkg_src_list.c
index c9f02f1..9a2a90f 100644
--- a/libopkg/pkg_src_list.c
+++ b/libopkg/pkg_src_list.c
@@ -27,11 +27,11 @@ int pkg_src_list_init(pkg_src_list_t *list)
void pkg_src_list_deinit(pkg_src_list_t *list)
{
- pkg_src_list_elt_t *iter;
+ pkg_src_list_elt_t *iter, *n;
pkg_src_t *pkg_src;
- for (iter = list->head; iter; iter = iter->next) {
- pkg_src = iter->data;
+ list_for_each_entry_safe(iter, n, &list->head, node) {
+ pkg_src = (pkg_src_t *)iter->data;
pkg_src_deinit(pkg_src);
/* malloced in pkg_src_list_append */
diff --git a/libopkg/pkg_src_list.h b/libopkg/pkg_src_list.h
index 6afd0a1..ce95eb4 100644
--- a/libopkg/pkg_src_list.h
+++ b/libopkg/pkg_src_list.h
@@ -19,28 +19,15 @@
#define PKG_SRC_LIST_H
#include "pkg_src.h"
+#include "void_list.h"
-typedef struct pkg_src_list_elt pkg_src_list_elt_t;
-struct pkg_src_list_elt
-{
- pkg_src_list_elt_t *next;
- pkg_src_t *data;
-};
+typedef struct void_list_elt pkg_src_list_elt_t;
-typedef struct pkg_src_list pkg_src_list_t;
-struct pkg_src_list
-{
- pkg_src_list_elt_t pre_head;
- pkg_src_list_elt_t *head;
- pkg_src_list_elt_t *tail;
-};
+typedef struct void_list pkg_src_list_t;
static inline int pkg_src_list_empty(pkg_src_list_t *list)
{
- if (list->head == NULL)
- return 1;
- else
- return 0;
+ return void_list_empty((void_list_t *)list);
}
int pkg_src_list_elt_init(pkg_src_list_elt_t *elt, nv_pair_t *data);
diff --git a/libopkg/str_list.c b/libopkg/str_list.c
index 1d21746..b354c9e 100644
--- a/libopkg/str_list.c
+++ b/libopkg/str_list.c
@@ -74,3 +74,33 @@ char *str_list_remove_elt(str_list_t *list, const char *target_str)
(void *)target_str,
(void_list_cmp_t)strcmp);
}
+
+str_list_elt_t *str_list_first(str_list_t *list) {
+ return (str_list_elt_t * )void_list_first((void_list_t *) list);
+}
+
+str_list_elt_t *str_list_prev(str_list_t *list, str_list_elt_t *node) {
+ return (str_list_elt_t * )void_list_prev((void_list_t *) list, (void_list_elt_t *)node);
+}
+
+str_list_elt_t *str_list_next(str_list_t *list, str_list_elt_t *node) {
+ return (str_list_elt_t * )void_list_next((void_list_t *) list, (void_list_elt_t *)node);
+}
+
+str_list_elt_t *str_list_last(str_list_t *list) {
+ return (str_list_elt_t * )void_list_last((void_list_t *) list);
+}
+
+
+void str_list_purge(str_list_t *list) {
+ str_list_elt_t *elt;
+ while (!void_list_empty(list)) {
+ elt = str_list_first(list);
+ if (!elt)
+ return;
+ list_del_init(&elt->node);
+ free(elt->data);
+ elt->data=NULL;
+ free(elt);
+ }
+}
diff --git a/libopkg/str_list.h b/libopkg/str_list.h
index a05d60d..b187a06 100644
--- a/libopkg/str_list.h
+++ b/libopkg/str_list.h
@@ -20,20 +20,9 @@
#include "void_list.h"
-typedef struct str_list_elt str_list_elt_t;
-struct str_list_elt
-{
- str_list_elt_t *next;
- char *data;
-};
-
-typedef struct xstr_list str_list_t;
-struct xstr_list
-{
- str_list_elt_t pre_head;
- str_list_elt_t *head;
- str_list_elt_t *tail;
-};
+typedef struct void_list_elt str_list_elt_t;
+
+typedef struct void_list str_list_t;
int str_list_elt_init(str_list_elt_t *elt, char *data);
void str_list_elt_deinit(str_list_elt_t *elt);
@@ -48,4 +37,11 @@ str_list_elt_t *str_list_pop(str_list_t *list);
str_list_elt_t *str_list_remove(str_list_t *list, str_list_elt_t **iter);
char *str_list_remove_elt(str_list_t *list, const char *target_str);
+str_list_elt_t *str_list_first(str_list_t *list);
+str_list_elt_t *str_list_prev(str_list_t *list, str_list_elt_t *node);
+str_list_elt_t *str_list_next(str_list_t *list, str_list_elt_t *node);
+str_list_elt_t *str_list_last(str_list_t *list);
+
+void str_list_purge(str_list_t *list);
+
#endif
diff --git a/libopkg/void_list.c b/libopkg/void_list.c
index 3d9d611..676e3b1 100644
--- a/libopkg/void_list.c
+++ b/libopkg/void_list.c
@@ -22,24 +22,33 @@
int void_list_elt_init(void_list_elt_t *elt, void *data)
{
- elt->next = NULL;
+ INIT_LIST_HEAD(&elt->node);
elt->data = data;
return 0;
}
+void_list_elt_t * void_list_elt_new (void *data) {
+ void_list_elt_t *elt;
+ /* freed in void_list_deinit */
+ elt = calloc(1, sizeof(void_list_elt_t));
+ if (elt == NULL) {
+ fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
+ return NULL;
+ }
+ void_list_elt_init(elt, data);
+ return elt;
+}
+
void void_list_elt_deinit(void_list_elt_t *elt)
{
+ list_del_init(&elt->node);
void_list_elt_init(elt, NULL);
}
int void_list_init(void_list_t *list)
{
- void_list_elt_init(&list->pre_head, NULL);
- list->head = NULL;
- list->pre_head.next = list->head;
- list->tail = NULL;
-
+ INIT_LIST_HEAD(&list->head);
return 0;
}
@@ -47,108 +56,67 @@ void void_list_deinit(void_list_t *list)
{
void_list_elt_t *elt;
- while (list->head) {
+ while (!void_list_empty(list)) {
elt = void_list_pop(list);
void_list_elt_deinit(elt);
/* malloced in void_list_append */
free(elt);
}
+ INIT_LIST_HEAD(&list->head);
}
int void_list_append(void_list_t *list, void *data)
{
- void_list_elt_t *elt;
-
- /* freed in void_list_deinit */
- elt = calloc(1, sizeof(void_list_elt_t));
- if (elt == NULL) {
- fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
- return ENOMEM;
- }
-
- void_list_elt_init(elt, data);
-
- if (list->tail) {
- list->tail->next = elt;
- list->tail = elt;
- } else {
- list->head = elt;
- list->pre_head.next = list->head;
- list->tail = elt;
- }
+ void_list_elt_t *elt = void_list_elt_new(data);
+
+ list_add_tail(&elt->node, &list->head);
return 0;
}
int void_list_push(void_list_t *list, void *data)
{
- void_list_elt_t *elt;
-
- elt = calloc(1, sizeof(void_list_elt_t));
- if (elt == NULL) {
- fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
- return ENOMEM;
- }
+ void_list_elt_t *elt = void_list_elt_new(data);
- void_list_elt_init(elt, data);
-
- elt->next = list->head;
- list->head->next = elt;
- if (list->tail == NULL) {
- list->tail = list->head;
- }
+ list_add(&elt->node, &list->head);
return 0;
}
void_list_elt_t *void_list_pop(void_list_t *list)
{
- void_list_elt_t *elt;
-
- elt = list->head;
+ struct list_head *node;
- if (list->head) {
- list->head = list->head->next;
- list->pre_head.next = list->head;
- if (list->head == NULL) {
- list->tail = NULL;
- }
- }
-
- return elt;
+ if (void_list_empty(list))
+ return NULL;
+ node = list->head.next;
+ list_del_init(node);
+ return list_entry(node, void_list_elt_t, node);
}
void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
{
- void_list_elt_t *prior;
+ void_list_elt_t *pos, *n;
void_list_elt_t *old_elt;
- void *old_data;
+ void *old_data = NULL;
old_elt = *iter;
+ if (!old_elt)
+ return old_data;
old_data = old_elt->data;
- if (old_elt == list->head) {
- prior = &list->pre_head;
- void_list_pop(list);
- } else {
- for (prior = list->head; prior; prior = prior->next) {
- if (prior->next == old_elt) {
- break;
- }
- }
- if (prior == NULL || prior->next != old_elt) {
- fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
- return NULL;
- }
- prior->next = old_elt->next;
-
- if (old_elt == list->tail) {
- list->tail = prior;
- }
+ list_for_each_entry_safe(pos, n, &list->head, node) {
+ if (pos == old_elt)
+ break;
+ }
+ if ( pos != old_elt) {
+ fprintf(stderr, "%s: ERROR: element not found in list\n", __FUNCTION__);
+ return NULL;
}
- void_list_elt_deinit(old_elt);
- *iter = prior;
+ *iter = list_entry(pos->node.prev, void_list_elt_t, node);
+ void_list_elt_deinit(pos);
+ free(pos);
return old_data;
}
@@ -156,48 +124,59 @@ void *void_list_remove(void_list_t *list, void_list_elt_t **iter)
/* remove element containing elt data, using cmp(elt->data, target_data) == 0. */
void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp)
{
- void_list_elt_t *prior;
- void_list_elt_t *old_elt = NULL;
- void *old_data = NULL;
-
- if (!list) {
- fprintf(stderr, "Error: void_list_remove_elt list is NULL\n");
- return NULL;
- }
- if (!target_data) {
- fprintf(stderr, "Error: void_list_remove_elt target_data is NULL\n");
- return NULL;
- }
-
- /* first element */
- if (list->head && list->head->data && (cmp(list->head->data, target_data) == 0)) {
- old_elt = list->head;
- old_data = list->head->data;
- void_list_pop(list);
- } else {
- int found = 0;
- for (prior = list->head; prior && prior->next; prior = prior->next) {
- if (prior->next->data && (cmp(prior->next->data, target_data) == 0)) {
- old_elt = prior->next;
- old_data = old_elt->data;
- found = 1;
- break;
- }
- }
- if (!found) {
- return NULL;
- }
- prior->next = old_elt->next;
-
- if (old_elt == list->tail) {
- list->tail = prior;
- }
- }
- if (old_elt)
- void_list_elt_deinit(old_elt);
-
- if (old_data)
- return old_data;
- else
- return NULL;
+ void_list_elt_t *pos, *n;
+ void *old_data = NULL;
+ list_for_each_entry_safe(pos, n, &list->head, node) {
+ if ( pos->data && cmp(pos->data, target_data)==0 ){
+ old_data = pos->data;
+ void_list_elt_deinit(pos);
+ break;
+ }
+ }
+ return old_data;
}
+
+void_list_elt_t *void_list_first(void_list_t *list) {
+ struct list_head *elt;
+ if (!list)
+ return NULL;
+ elt = list->head.next;
+ if (elt == &list->head ) {
+ return NULL;
+ }
+ return list_entry(elt, void_list_elt_t, node);
+}
+
+void_list_elt_t *void_list_prev(void_list_t *list, void_list_elt_t *node) {
+ struct list_head *elt;
+ if (!list || !node)
+ return NULL;
+ elt = node->node.prev;
+ if (elt == &list->head ) {
+ return NULL;
+ }
+ return list_entry(elt, void_list_elt_t, node);
+}
+
+void_list_elt_t *void_list_next(void_list_t *list, void_list_elt_t *node) {
+ struct list_head *elt;
+ if (!list || !node)
+ return NULL;
+ elt = node->node.next;
+ if (elt == &list->head ) {
+ return NULL;
+ }
+ return list_entry(elt, void_list_elt_t, node);
+}
+
+void_list_elt_t *void_list_last(void_list_t *list) {
+ struct list_head *elt;
+ if (!list)
+ return NULL;
+ elt = list->head.prev;
+ if (elt == &list->head ) {
+ return NULL;
+ }
+ return list_entry(elt, void_list_elt_t, node);
+}
+
diff --git a/libopkg/void_list.h b/libopkg/void_list.h
index b2a0f2c..ca380b8 100644
--- a/libopkg/void_list.h
+++ b/libopkg/void_list.h
@@ -18,27 +18,24 @@
#ifndef VOID_LIST_H
#define VOID_LIST_H
+#include "list.h"
+
typedef struct void_list_elt void_list_elt_t;
struct void_list_elt
{
- void_list_elt_t *next;
+ struct list_head node;
void *data;
};
typedef struct void_list void_list_t;
struct void_list
{
- void_list_elt_t pre_head;
- void_list_elt_t *head;
- void_list_elt_t *tail;
+ struct list_head head;
};
static inline int void_list_empty(void_list_t *list)
{
- if (list->head == NULL)
- return 1;
- else
- return 0;
+ return list_empty(&list->head);
}
int void_list_elt_init(void_list_elt_t *elt, void *data);
@@ -56,4 +53,12 @@ void *void_list_remove(void_list_t *list, void_list_elt_t **iter);
typedef int (*void_list_cmp_t)(const void *, const void *);
void *void_list_remove_elt(void_list_t *list, const void *target_data, void_list_cmp_t cmp);
+void_list_elt_t *void_list_first(void_list_t *list);
+void_list_elt_t *void_list_prev(void_list_t *list, void_list_elt_t *node);
+void_list_elt_t *void_list_next(void_list_t *list, void_list_elt_t *node);
+void_list_elt_t *void_list_last(void_list_t *list);
+
+void void_list_purge(void_list_t *list);
+
+
#endif