#include "includes.h"
#include <ctype.h>
+#include <alloca.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
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){
int abstract_pkg_init(abstract_pkg_t *ab_pkg)
{
- memset(ab_pkg, 0, sizeof(abstract_pkg_t));
-
ab_pkg->provided_by = abstract_pkg_vec_alloc();
if (ab_pkg->provided_by==NULL){
return -1;
char **raw =NULL;
char **raw_start=NULL;
- temp_str = (char *) calloc (1, strlen(pkg->dest->info_dir)+strlen(pkg->name)+12);
+ size_t str_size = strlen(pkg->dest->info_dir)+strlen(pkg->name)+12;
+ temp_str = (char *) alloca (str_size);
+ memset(temp_str, 0 , str_size);
+
if (temp_str == NULL ){
opkg_message(conf, OPKG_INFO, "Out of memory in %s\n", __FUNCTION__);
return;
}
free(raw_start);
- free(temp_str);
return ;
}
+#define CHECK_BUFF_SIZE(buff, line, buf_size, page_size) do { \
+ if (strlen(buff) + strlen(line) >= (buf_size)) { \
+ buf_size += page_size; \
+ buff = realloc(buff, buf_size); \
+ } \
+ } while(0)
char * pkg_formatted_info(pkg_t *pkg )
{
char *line;
char * buff;
+ const size_t page_size = 8192;
+ size_t buff_size = page_size;
- buff = calloc(1, 8192);
+ buff = calloc(1, buff_size);
if (buff == NULL) {
fprintf(stderr, "%s: out of memory\n", __FUNCTION__);
return NULL;
}
- buff[0] = '\0';
-
line = pkg_formatted_field(pkg, "Package");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Version");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Depends");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Recommends");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Suggests");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Provides");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Replaces");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Conflicts");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Status");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Section");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Essential"); /* @@@@ should be removed in future release. *//* I do not agree with this Pigi*/
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Architecture");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Maintainer");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "MD5sum");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Size");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Filename");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Conffiles");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Source");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Description");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Installed-Time");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
line = pkg_formatted_field(pkg, "Tags");
+ CHECK_BUFF_SIZE(buff, line, buff_size, page_size);
strncat(buff ,line, strlen(line));
free(line);
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;
}
for (i = 0; i < installed_pkgs->len; i++) {
pkg_t *pkg = installed_pkgs->pkgs[i];
str_list_t *installed_files = pkg_get_installed_files(pkg); /* this causes installed_files to be cached */
- str_list_elt_t *iter;
+ str_list_elt_t *iter, *niter;
if (installed_files == NULL) {
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), niter = str_list_next(installed_files, iter);
+ iter;
+ iter = niter, niter = 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);
}