Change llist_add_* to take the address of the list rather than returning the new

head, and change all the callers.
This commit is contained in:
Rob Landley 2006-05-26 23:44:51 +00:00
parent 5edc10275e
commit 8bb50782a5
16 changed files with 42 additions and 57 deletions

View File

@ -97,7 +97,7 @@ int ar_main(int argc, char **argv)
while (optind < argc) {
archive_handle->filter = filter_accept_list;
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind++]);
llist_add_to(&(archive_handle->accept), argv[optind++]);
}
archive_xread_all(archive_handle, magic, 7);

View File

@ -88,7 +88,7 @@ int cpio_main(int argc, char **argv)
while (optind < argc) {
archive_handle->filter = filter_accept_list;
archive_handle->accept = llist_add_to(archive_handle->accept, argv[optind]);
llist_add_to(&(archive_handle->accept), argv[optind]);
optind++;
}

View File

@ -1484,10 +1484,10 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
ar_handle->accept = llist_add_to(NULL, "control.tar.gz");
llist_add_to(&(ar_handle->accept), "control.tar.gz");
#endif
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
ar_handle->accept = llist_add_to(ar_handle->accept, "control.tar.bz2");
llist_add_to(&(ar_handle->accept), "control.tar.bz2");
#endif
/* Assign the tar handle as a subarchive of the ar handle */
@ -1506,10 +1506,10 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
ar_handle->accept = llist_add_to(NULL, "data.tar.gz");
llist_add_to(&(ar_handle->accept), "data.tar.gz");
#endif
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
ar_handle->accept = llist_add_to(ar_handle->accept, "data.tar.bz2");
llist_add_to(&(ar_handle->accept), "data.tar.bz2");
#endif
/* Assign the tar handle as a subarchive of the ar handle */
@ -1575,7 +1575,7 @@ static void unpack_package(deb_file_t *deb_file)
while(all_control_files[i]) {
char *c = (char *) xmalloc(3 + strlen(all_control_files[i]));
sprintf(c, "./%s", all_control_files[i]);
accept_list= llist_add_to(accept_list, c);
llist_add_to(&accept_list, c);
i++;
}
archive_handle->sub_archive->accept = accept_list;
@ -1705,7 +1705,7 @@ int dpkg_main(int argc, char **argv)
llist_t *control_list = NULL;
/* Extract the control file */
control_list = llist_add_to(NULL, "./control");
llist_add_to(&control_list, "./control");
archive_handle = init_archive_deb_ar(argv[optind]);
init_archive_deb_control(archive_handle);
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);

View File

@ -36,13 +36,13 @@ int dpkg_deb_main(int argc, char **argv)
ar_archive->filter = filter_accept_list_reassign;
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
ar_archive->accept = llist_add_to(NULL, "data.tar.gz");
control_tar_llist = llist_add_to(NULL, "control.tar.gz");
llist_add_to(&(ar_archive->accept), "data.tar.gz");
llist_add_to(&control_tar_llist, "control.tar.gz");
#endif
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
ar_archive->accept = llist_add_to(ar_archive->accept, "data.tar.bz2");
control_tar_llist = llist_add_to(control_tar_llist, "control.tar.bz2");
llist_add_to(&(ar_archive->accept), "data.tar.bz2");
llist_add_to(&control_tar_llist, "control.tar.bz2");
#endif
bb_opt_complementally = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
@ -65,7 +65,7 @@ int dpkg_deb_main(int argc, char **argv)
* it should accept a second argument which specifies a
* specific field to print */
ar_archive->accept = control_tar_llist;
tar_archive->accept = llist_add_to(NULL, "./control");
llist_add_to(&(tar_archive->accept), "./control");
tar_archive->filter = filter_accept_list;
tar_archive->action_data = data_extract_to_stdout;
}

View File

@ -206,7 +206,7 @@ char get_header_tar(archive_handle_t *archive_handle)
archive_handle->action_header(archive_handle->file_header);
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle);
archive_handle->passed = llist_add_to(archive_handle->passed, file_header->name);
llist_add_to(&(archive_handle->passed), file_header->name);
} else {
data_skip(archive_handle);
}

View File

@ -24,8 +24,7 @@ archive_handle_t *init_handle(void)
archive_handle_t *archive_handle;
/* Initialise default values */
archive_handle = xmalloc(sizeof(archive_handle_t));
memset(archive_handle, 0, sizeof(archive_handle_t));
archive_handle = xzalloc(sizeof(archive_handle_t));
archive_handle->file_header = xmalloc(sizeof(file_header_t));
archive_handle->action_header = header_skip;
archive_handle->action_data = data_skip;

View File

@ -551,7 +551,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
cur = cur->link;
free(tmp);
while ((line = bb_get_chomped_line_from_file(src_stream)) != NULL)
newlist = llist_add_to(newlist, line);
llist_add_to(&newlist, line);
fclose(src_stream);
}
return newlist;
@ -800,7 +800,7 @@ int tar_main(int argc, char **argv)
if (filename_ptr > argv[optind])
*filename_ptr = '\0';
tar_handle->accept = llist_add_to(tar_handle->accept, argv[optind]);
llist_add_to(&(tar_handle->accept), argv[optind]);
optind++;
}

View File

@ -180,7 +180,7 @@ int unzip_main(int argc, char **argv)
case 1: /* Include files */
if (opt == 1) {
zaccept = llist_add_to(zaccept, optarg);
llist_add_to(&zaccept, optarg);
} else if (opt == 'd') {
base_dir = optarg;
@ -196,7 +196,7 @@ int unzip_main(int argc, char **argv)
case 2 : /* Exclude files */
if (opt == 1) {
zreject = llist_add_to(zreject, optarg);
llist_add_to(&zreject, optarg);
} else if (opt == 'd') { /* Extract to base directory */
base_dir = optarg;

View File

@ -683,7 +683,7 @@ static sed_cmd_t *branch_to(const char *label)
static void append(char *s)
{
bbg.append_head = llist_add_to_end(bbg.append_head, bb_xstrdup(s));
llist_add_to_end(&bbg.append_head, bb_xstrdup(s));
}
static void flush_append(void)

View File

@ -273,7 +273,7 @@ static void load_regexes_from_file(llist_t *fopt)
free(cur);
f = bb_xfopen(ffile, "r");
while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
pattern_head = llist_add_to(pattern_head,
llist_add_to(&pattern_head,
new_grep_list_data(line, PATTERN_MEM_A));
}
}
@ -373,7 +373,7 @@ int grep_main(int argc, char **argv)
else {
char *pattern = new_grep_list_data(*argv++, 0);
pattern_head = llist_add_to(pattern_head, pattern);
llist_add_to(&pattern_head, pattern);
argc--;
}
}

View File

@ -84,8 +84,8 @@ typedef struct llist_s {
char *data;
struct llist_s *link;
} llist_t;
extern llist_t *llist_add_to(llist_t *old_head, void *data);
extern llist_t *llist_add_to_end(llist_t *list_head, void *data);
extern void llist_add_to(llist_t **old_head, void *data);
extern void llist_add_to_end(llist_t **list_head, void *data);
extern void *llist_pop(llist_t **elm);
extern void llist_free(llist_t *elm, void (*freeit)(void *data));

View File

@ -474,8 +474,7 @@ loop_arg_is_opt:
if(on_off->counter)
(*(on_off->counter))++;
if(on_off->list_flg) {
*(llist_t **)(on_off->optarg) =
llist_add_to(*(llist_t **)(on_off->optarg), optarg);
llist_add_to((llist_t **)(on_off->optarg), optarg);
} else if (on_off->optarg) {
*(char **)(on_off->optarg) = optarg;
}

View File

@ -14,37 +14,29 @@
#ifdef L_llist_add_to
/* Add data to the start of the linked list. */
llist_t *llist_add_to(llist_t *old_head, void *data)
void llist_add_to(llist_t **old_head, void *data)
{
llist_t *new_head;
new_head = xmalloc(sizeof(llist_t));
llist_t *new_head = xmalloc(sizeof(llist_t));
new_head->data = data;
new_head->link = old_head;
return (new_head);
new_head->link = *old_head;
*old_head = new_head;
}
#endif
#ifdef L_llist_add_to_end
/* Add data to the end of the linked list. */
llist_t *llist_add_to_end(llist_t *list_head, void *data)
void llist_add_to_end(llist_t **list_head, void *data)
{
llist_t *new_item;
new_item = xmalloc(sizeof(llist_t));
llist_t *new_item = xmalloc(sizeof(llist_t));
new_item->data = data;
new_item->link = NULL;
if (list_head == NULL) {
list_head = new_item;
} else {
llist_t *tail = list_head;
while (tail->link)
tail = tail->link;
if (!*list_head) *list_head = new_item;
else {
llist_t *tail = *list_head;
while (tail->link) tail = tail->link;
tail->link = new_item;
}
return list_head;
}
#endif

View File

@ -739,7 +739,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
}
}
defn->ifaces = llist_add_to_end(defn->ifaces, (char*)currif);
llist_add_to_end(&(defn->ifaces), (char*)currif);
}
debug_noise("iface %s %s %s\n", currif->iface, address_family_name, method_name);
}
@ -753,7 +753,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
}
/* Add the interface to the list */
defn->autointerfaces = llist_add_to_end(defn->autointerfaces, bb_xstrdup(firstword));
llist_add_to_end(&(defn->autointerfaces), bb_xstrdup(firstword));
debug_noise("\nauto %s\n", firstword);
}
currently_processing = NONE;
@ -1202,14 +1202,14 @@ int ifupdown_main(int argc, char **argv)
/* iface_down */
const llist_t *list = state_list;
while (list) {
target_list = llist_add_to_end(target_list, bb_xstrdup(list->data));
llist_add_to_end(&target_list, bb_xstrdup(list->data));
list = list->link;
}
target_list = defn->autointerfaces;
#endif
}
} else {
target_list = llist_add_to_end(target_list, argv[optind]);
llist_add_to_end(&target_list, argv[optind]);
}
@ -1311,7 +1311,7 @@ int ifupdown_main(int argc, char **argv)
char *newiface = xmalloc(strlen(iface) + 1 + strlen(liface) + 1);
sprintf(newiface, "%s=%s", iface, liface);
if (iface_state == NULL) {
state_list = llist_add_to_end(state_list, newiface);
llist_add_to_end(&state_list, newiface);
} else {
free(iface_state->data);
iface_state->data = newiface;

View File

@ -67,12 +67,7 @@ int pidof_main(int argc, char **argv)
if (!strncmp(omits_p->data, "%PPID", 5)) {
llist_pop(&omits_p);
snprintf(getppid_str, sizeof(getppid_str), "%d", getppid());
omits_p = llist_add_to(omits_p, getppid_str);
#if 0
} else {
bb_error_msg_and_die("illegal omit pid value (%s)!\n",
omits_p->data);
#endif
llist_add_to(&omits_p, getppid_str);
}
omits_p = omits_p->link;
}

View File

@ -169,7 +169,7 @@ static llist_t *get_block_backed_filesystems(void)
if(*fs=='#' || *fs=='*') continue;
if(!*fs) continue;
list=llist_add_to_end(list,bb_xstrdup(fs));
llist_add_to_end(&list,bb_xstrdup(fs));
}
if (ENABLE_FEATURE_CLEAN_UP) fclose(f);
}