aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-05-29 07:42:02 +0000
committerRob Landley <rob@landley.net>2006-05-29 07:42:02 +0000
commit1ec5b2905484b7904aabb01f56c70265fb538c82 (patch)
tree87292bfd7e99ce26b226518e244f4a96914397f9 /archival
parenta6e131dab39ee67522687a56b39ed815b9ae15ec (diff)
downloadbusybox-1ec5b2905484b7904aabb01f56c70265fb538c82.tar.gz
More size shrinkage.
Diffstat (limited to 'archival')
-rw-r--r--archival/dpkg.c134
-rw-r--r--archival/gzip.c12
-rw-r--r--archival/libunarchive/data_extract_to_buffer.c17
-rw-r--r--archival/libunarchive/decompress_bunzip2.c3
-rw-r--r--archival/libunarchive/get_header_ar.c15
-rw-r--r--archival/libunarchive/get_header_cpio.c21
-rw-r--r--archival/libunarchive/get_header_tar.c6
-rw-r--r--archival/libunarchive/rangecoder.h4
-rw-r--r--archival/rpm.c11
-rw-r--r--archival/unzip.c3
10 files changed, 35 insertions, 191 deletions
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2895f4f38..c911333e0 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -7,19 +7,7 @@
*
* Started life as a busybox implementation of udpkg
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/*
@@ -556,7 +544,7 @@ static unsigned int fill_package_struct(char *control_buffer)
"Conflicts", "Suggests", "Recommends", "Enhances", 0
};
- common_node_t *new_node = (common_node_t *) xcalloc(1, sizeof(common_node_t));
+ common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
char *field_name;
char *field_value;
int field_start = 0;
@@ -677,8 +665,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
}
- new_status = (char *) xmalloc(want_len + flag_len + status_len + 3);
- sprintf(new_status, "%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
+ new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
free(new_status);
return;
@@ -741,79 +728,6 @@ static void index_status_file(const char *filename)
return;
}
-#if 0 /* this code is no longer used */
-char *get_depends_field(common_node_t *package, const int depends_type)
-{
- char *depends = NULL;
- char *old_sep = (char *)xcalloc(1, 3);
- char *new_sep = (char *)xcalloc(1, 3);
- int line_size = 0;
- int depends_size;
-
- int i;
-
- for (i = 0; i < package->num_of_edges; i++) {
- if ((package->edge[i]->type == EDGE_OR_PRE_DEPENDS) ||
- (package->edge[i]->type == EDGE_OR_DEPENDS)) {
- }
-
- if ((package->edge[i]->type == depends_type) ||
- (package->edge[i]->type == depends_type + 1)) {
- /* Check if its the first time through */
-
- depends_size = 8 + strlen(name_hashtable[package->edge[i]->name])
- + strlen(name_hashtable[package->edge[i]->version]);
- line_size += depends_size;
- depends = (char *) xrealloc(depends, line_size + 1);
-
- /* Check to see if this dependency is the type we are looking for
- * +1 to check for 'extra' types, e.g. ored dependecies */
- strcpy(old_sep, new_sep);
- if (package->edge[i]->type == depends_type) {
- strcpy(new_sep, ", ");
- }
- else if (package->edge[i]->type == depends_type + 1) {
- strcpy(new_sep, "| ");
- }
-
- if (depends_size == line_size) {
- strcpy(depends, "");
- } else {
- if ((strcmp(old_sep, "| ") == 0) && (strcmp(new_sep, "| ") == 0)) {
- strcat(depends, " | ");
- } else {
- strcat(depends, ", ");
- }
- }
-
- strcat(depends, name_hashtable[package->edge[i]->name]);
- if (strcmp(name_hashtable[package->edge[i]->version], "NULL") != 0) {
- if (package->edge[i]->operator == VER_EQUAL) {
- strcat(depends, " (= ");
- }
- else if (package->edge[i]->operator == VER_LESS) {
- strcat(depends, " (<< ");
- }
- else if (package->edge[i]->operator == VER_LESS_EQUAL) {
- strcat(depends, " (<= ");
- }
- else if (package->edge[i]->operator == VER_MORE) {
- strcat(depends, " (>> ");
- }
- else if (package->edge[i]->operator == VER_MORE_EQUAL) {
- strcat(depends, " (>= ");
- } else {
- strcat(depends, " (");
- }
- strcat(depends, name_hashtable[package->edge[i]->version]);
- strcat(depends, ")");
- }
- }
- }
- return(depends);
-}
-#endif
-
static void write_buffer_no_status(FILE *new_status_file, const char *control_buffer)
{
char *name;
@@ -1027,11 +941,9 @@ static int check_deps(deb_file_t **deb_file, int deb_start, int dep_max_count)
package_hashtable[package_num]->edge[j]->operator);
if (package_hashtable[conflicts_package_num] == NULL) {
/* create a new package */
- common_node_t *new_node = (common_node_t *) xmalloc(sizeof(common_node_t));
+ common_node_t *new_node = (common_node_t *) xzalloc(sizeof(common_node_t));
new_node->name = package_hashtable[package_num]->edge[j]->name;
new_node->version = package_hashtable[package_num]->edge[j]->version;
- new_node->num_of_edges = 0;
- new_node->edge = NULL;
package_hashtable[conflicts_package_num] = new_node;
}
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
@@ -1279,15 +1191,10 @@ static int run_package_script(const char *package_name, const char *script_type)
char *script_path;
int result;
- script_path = xmalloc(strlen(package_name) + strlen(script_type) + 21);
- sprintf(script_path, "/var/lib/dpkg/info/%s.%s", package_name, script_type);
+ script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesnt exist is isnt a fatal */
- if (lstat(script_path, &path_stat) < 0) {
- result = EXIT_SUCCESS;
- } else {
- result = system(script_path);
- }
+ result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
free(script_path);
return(result);
}
@@ -1301,13 +1208,11 @@ static char **all_control_list(const char *package_name)
char **remove_files;
/* Create a list of all /var/lib/dpkg/info/<package> files */
- remove_files = xmalloc(sizeof(all_control_files));
+ remove_files = xzalloc(sizeof(all_control_files));
while (all_control_files[i]) {
- remove_files[i] = xmalloc(strlen(package_name) + strlen(all_control_files[i]) + 21);
- sprintf(remove_files[i], "/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
+ remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
i++;
}
- remove_files[sizeof(all_control_files)/sizeof(char*) - 1] = NULL;
return(remove_files);
}
@@ -1400,11 +1305,9 @@ static void remove_package(const unsigned int package_num, int noisy)
free_array(remove_files);
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
- exclude_files = xmalloc(sizeof(char*) * 3);
+ exclude_files = xzalloc(sizeof(char*) * 3);
exclude_files[0] = bb_xstrdup(conffile_name);
- exclude_files[1] = xmalloc(package_name_length + 27);
- sprintf(exclude_files[1], "/var/lib/dpkg/info/%s.postrm", package_name);
- exclude_files[2] = NULL;
+ exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = all_control_list(package_name);
@@ -1440,8 +1343,7 @@ static void purge_package(const unsigned int package_num)
sprintf(list_name, "/var/lib/dpkg/info/%s.list", package_name);
remove_files = create_list(list_name);
- exclude_files = xmalloc(sizeof(char*));
- exclude_files[0] = NULL;
+ exclude_files = xzalloc(sizeof(char*));
/* Some directories cant be removed straight away, so do multiple passes */
while (remove_file_array(remove_files, exclude_files));
@@ -1536,9 +1438,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
name_ptr += strspn(name_ptr, "./");
if (name_ptr[0] != '\0') {
- archive_handle->file_header->name = xmalloc(strlen(archive_handle->buffer) + 2 + strlen(name_ptr));
- strcpy(archive_handle->file_header->name, archive_handle->buffer);
- strcat(archive_handle->file_header->name, name_ptr);
+ archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr);
data_extract_all(archive_handle);
}
return;
@@ -1567,14 +1467,12 @@ static void unpack_package(deb_file_t *deb_file)
}
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
- info_prefix = (char *) xmalloc(strlen(package_name) + 20 + 4 + 2);
- sprintf(info_prefix, "/var/lib/dpkg/info/%s.", package_name);
+ info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name);
archive_handle = init_archive_deb_ar(deb_file->filename);
init_archive_deb_control(archive_handle);
while(all_control_files[i]) {
- char *c = (char *) xmalloc(3 + strlen(all_control_files[i]));
- sprintf(c, "./%s", all_control_files[i]);
+ char *c = bb_xasprintf("./%s", all_control_files[i]);
llist_add_to(&accept_list, c);
i++;
}
@@ -1699,7 +1597,7 @@ int dpkg_main(int argc, char **argv)
while (optind < argc) {
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
deb_file = xrealloc(deb_file, sizeof(deb_file_t *) * (deb_count + 2));
- deb_file[deb_count] = (deb_file_t *) xmalloc(sizeof(deb_file_t));
+ deb_file[deb_count] = (deb_file_t *) xzalloc(sizeof(deb_file_t));
if (dpkg_opt & dpkg_opt_filename) {
archive_handle_t *archive_handle;
llist_t *control_list = NULL;
@@ -1742,8 +1640,6 @@ int dpkg_main(int argc, char **argv)
}
}
else if (dpkg_opt & dpkg_opt_package_name) {
- deb_file[deb_count]->filename = NULL;
- deb_file[deb_count]->control_file = NULL;
deb_file[deb_count]->package = search_package_hashtable(
search_name_hashtable(argv[optind]),
search_name_hashtable("ANY"), VER_ANY);
diff --git a/archival/gzip.c b/archival/gzip.c
index c31706af3..4f60c6b24 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -16,11 +16,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-/* These defines are very important for BusyBox. Without these,
- * huge chunks of ram are pre-allocated making the BusyBox bss
- * size Freaking Huge(tm), which is a bad thing.*/
#define SMALL_MEM
-#define DYN_ALLOC
#include <stdlib.h>
#include <stdio.h>
@@ -87,17 +83,11 @@ typedef unsigned long ulg;
# endif
#endif
-#ifdef DYN_ALLOC
# define DECLARE(type, array, size) static type * array
# define ALLOC(type, array, size) { \
- array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
+ array = (type*)xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)); \
}
# define FREE(array) {free(array), array=NULL;}
-#else
-# define DECLARE(type, array, size) static type array[size]
-# define ALLOC(type, array, size)
-# define FREE(array)
-#endif
#define tab_suffix window
#define tab_prefix prev /* hash link (see deflate.c) */
diff --git a/archival/libunarchive/data_extract_to_buffer.c b/archival/libunarchive/data_extract_to_buffer.c
index 1255fe1da..3eaca98b3 100644
--- a/archival/libunarchive/data_extract_to_buffer.c
+++ b/archival/libunarchive/data_extract_to_buffer.c
@@ -1,17 +1,7 @@
/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * Copyright 2002 Glenn McGrath
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
@@ -21,8 +11,7 @@ void data_extract_to_buffer(archive_handle_t *archive_handle)
{
const unsigned int size = archive_handle->file_header->size;
- archive_handle->buffer = xmalloc(size + 1);
+ archive_handle->buffer = xzalloc(size + 1);
archive_xread_all(archive_handle, archive_handle->buffer, size);
- archive_handle->buffer[size] = '\0';
}
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index 5e26ffd9f..ae96ea375 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -644,8 +644,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
/* Allocate bunzip_data. Most fields initialize to zero. */
- bd=*bdp=xmalloc(i);
- memset(bd,0,sizeof(bunzip_data));
+ bd=*bdp=xzalloc(i);
/* Setup input buffer */
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 385f33dbf..69c4bf2b2 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -1,17 +1,6 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+/* Copyright 2001 Glenn McGrath.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <stdio.h>
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 2bbcd8e5d..f54b5af69 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -1,17 +1,6 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+/* Copyright 2002 Laurence Anderson
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include <stdio.h>
@@ -85,9 +74,8 @@ char get_header_cpio(archive_handle_t *archive_handle)
file_header->size = tmpsize;
}
- file_header->name = (char *) xmalloc(namesize + 1);
+ file_header->name = (char *) xzalloc(namesize + 1);
archive_xread_all(archive_handle, file_header->name, namesize); /* Read in filename */
- file_header->name[namesize] = '\0';
archive_handle->offset += namesize;
/* Update offset amount and skip padding before file contents */
@@ -113,9 +101,8 @@ char get_header_cpio(archive_handle_t *archive_handle)
}
if (S_ISLNK(file_header->mode)) {
- file_header->link_name = (char *) xmalloc(file_header->size + 1);
+ file_header->link_name = (char *) xzalloc(file_header->size + 1);
archive_xread_all(archive_handle, file_header->link_name, file_header->size);
- file_header->link_name[file_header->size] = '\0';
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */
} else {
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index c9308f906..f3f04b582 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -168,17 +168,15 @@ char get_header_tar(archive_handle_t *archive_handle)
break;
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
case 'L': {
- longname = xmalloc(file_header->size + 1);
+ longname = xzalloc(file_header->size + 1);
archive_xread_all(archive_handle, longname, file_header->size);
- longname[file_header->size] = '\0';
archive_handle->offset += file_header->size;
return(get_header_tar(archive_handle));
}
case 'K': {
- linkname = xmalloc(file_header->size + 1);
+ linkname = xzalloc(file_header->size + 1);
archive_xread_all(archive_handle, linkname, file_header->size);
- linkname[file_header->size] = '\0';
archive_handle->offset += file_header->size;
file_header->name = linkname;
diff --git a/archival/libunarchive/rangecoder.h b/archival/libunarchive/rangecoder.h
index e43ec3908..b806eebf6 100644
--- a/archival/libunarchive/rangecoder.h
+++ b/archival/libunarchive/rangecoder.h
@@ -36,12 +36,12 @@ static void rc_read(rc_t * rc)
}
/* Called once */
-static ATTRIBUTE_ALWAYS_INLINE void rc_init(rc_t * rc, int fd, int buffer_size)
+static void rc_init(rc_t * rc, int fd, int buffer_size)
{
int i;
rc->fd = fd;
- rc->buffer = malloc(buffer_size);
+ rc->buffer = xmalloc(buffer_size);
rc->buffer_size = buffer_size;
rc->buffer_end = rc->buffer + rc->buffer_size;
rc->ptr = rc->buffer_end;
diff --git a/archival/rpm.c b/archival/rpm.c
index 7f69f0510..9bbc4a856 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -208,7 +208,7 @@ void extract_cpio_gz(int fd) {
rpm_index **rpm_gettags(int fd, int *num_tags)
{
- rpm_index **tags = calloc(200, sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
+ rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
int pass, tagindex = 0;
lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
@@ -327,13 +327,10 @@ void fileaction_list(char *filename, int ATTRIBUTE_UNUSED fileref)
void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
{
int count = 0;
- char *filename, *tmp_dirname, *tmp_basename;
while (rpm_getstring(filetag, count)) {
- tmp_dirname = rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, count)); /* 1st put on the directory */
- tmp_basename = rpm_getstring(RPMTAG_BASENAMES, count);
- filename = xmalloc(strlen(tmp_basename) + strlen(tmp_dirname) + 1);
- strcpy(filename, tmp_dirname); /* First the directory name */
- strcat(filename, tmp_basename); /* then the filename */
+ char * filename = bb_xasprintf("%s%s",
+ rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
+ count)), rpm_getstring(RPMTAG_BASENAMES, count));
fileaction(filename, count++);
free(filename);
}
diff --git a/archival/unzip.c b/archival/unzip.c
index 0b1e6f997..c6ef9a183 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -275,9 +275,8 @@ int unzip_main(int argc, char **argv)
/* Read filename */
free(dst_fn);
- dst_fn = xmalloc(zip_header.formated.filename_len + 1);
+ dst_fn = xzalloc(zip_header.formated.filename_len + 1);
unzip_read(src_fd, dst_fn, zip_header.formated.filename_len);
- dst_fn[zip_header.formated.filename_len] = 0;
/* Skip extra header bytes */
unzip_skip(src_fd, zip_header.formated.extra_len);