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;
}
#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"
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);
#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)
{
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);
}
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);
+}
+
+
+
#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);
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
/* 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,
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;
}
- 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,
}
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);
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;
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,
{
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;
}
}
/* 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);
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;
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;
}
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);
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",
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);
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);
}
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 */
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;
}
/* 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;
}
/* 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)) {
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;
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;
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;
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;
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)) {
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 */
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));
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);
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) {
}
/* 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);
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){
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);
}
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));
}
}
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;
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;
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);
{
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;
}
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);
}
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 */
#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);
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);
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 */
def_prio = priority;
def_arch = nv->name;
}
- l = l->next;
}
return strdup(def_arch);
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 */
#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);
(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);
+ }
+}
#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);
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
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;
}
{
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;
}
/* 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);
+}
+
#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);
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