summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorRob Landley2006-08-03 15:41:12 +0000
committerRob Landley2006-08-03 15:41:12 +0000
commitd921b2ecc0d294ad4bf8c7458fc52a60c28727d2 (patch)
treee4a2769349867c441cf2983d83097bb66701a733 /archival
parent6dce0b6fa79f2d4bb7e9d90e1fbc0f6beb25f855 (diff)
downloadbusybox-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.zip
busybox-d921b2ecc0d294ad4bf8c7458fc52a60c28727d2.tar.gz
Remove bb_ prefixes from xfuncs.c (and a few other places), consolidate
things like xasprintf() into xfuncs.c, remove xprint_file_by_name() (it only had one user), clean up lots of #includes... General cleanup pass. What I've been doing for the last couple days. And it conflicts! I've removed httpd.c from this checkin due to somebody else touching that file. It builds for me. I have to catch a bus. (Now you know why I'm looking forward to Mercurial.)
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c12
-rw-r--r--archival/bunzip2.c10
-rw-r--r--archival/dpkg.c184
-rw-r--r--archival/dpkg_deb.c11
-rw-r--r--archival/gunzip.c15
-rw-r--r--archival/libunarchive/data_extract_all.c14
-rw-r--r--archival/libunarchive/decompress_bunzip2.c10
-rw-r--r--archival/libunarchive/decompress_unzip.c4
-rw-r--r--archival/libunarchive/get_header_ar.c12
-rw-r--r--archival/libunarchive/get_header_cpio.c9
-rw-r--r--archival/libunarchive/get_header_tar.c10
-rw-r--r--archival/rpm.c18
-rw-r--r--archival/rpm2cpio.c7
-rw-r--r--archival/uncompress.c13
-rw-r--r--archival/unlzma.c10
-rw-r--r--archival/unzip.c17
16 files changed, 173 insertions, 183 deletions
diff --git a/archival/ar.c b/archival/ar.c
index fd2ab99..09d0cd7 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -14,16 +14,8 @@
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <utime.h>
-#include <unistd.h>
-
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
static void header_verbose_list_ar(const file_header_t *file_header)
{
@@ -81,7 +73,7 @@ int ar_main(int argc, char **argv)
bb_error_msg_and_die(msg_unsupported_err, "insertion");
}
- archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY);
+ archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
while (optind < argc) {
archive_handle->filter = filter_accept_list;
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index 714dac0..a970aeb 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -6,12 +6,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
#include "unarchive.h"
@@ -30,7 +24,7 @@ int bunzip2_main(int argc, char **argv)
filename = argv[optind];
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
- src_fd = bb_xopen(filename, O_RDONLY);
+ src_fd = xopen(filename, O_RDONLY);
} else {
src_fd = STDIN_FILENO;
filename = 0;
@@ -53,7 +47,7 @@ int bunzip2_main(int argc, char **argv)
}
xstat(filename, &stat_buf);
*extension=0;
- dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
} else dst_fd = STDOUT_FILENO;
status = uncompressStream(src_fd, dst_fd);
if(filename) {
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 558e3cd..0e57720 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1,44 +1,39 @@
/* vi: set sw=4 ts=4: */
/*
- * Mini dpkg implementation for busybox.
- * This is not meant as a replacement for dpkg
+ * mini dpkg implementation for busybox.
+ * this is not meant as a replacement for dpkg
*
- * Written By Glenn McGrath with the help of others
- * Copyright (C) 2001 by Glenn McGrath
+ * written by glenn mcgrath with the help of others
+ * copyright (c) 2001 by glenn mcgrath
*
- * Started life as a busybox implementation of udpkg
+ * started life as a busybox implementation of udpkg
*
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ * licensed under gplv2 or later, see file license in this tarball for details.
*/
/*
- * Known difference between busybox dpkg and the official dpkg that i don't
+ * known difference between busybox dpkg and the official dpkg that i don't
* consider important, its worth keeping a note of differences anyway, just to
* make it easier to maintain.
- * - The first value for the Confflile: field isnt placed on a new line.
- * - When installing a package the Status: field is placed at the end of the
- * section, rather than just after the Package: field.
+ * - the first value for the confflile: field isnt placed on a new line.
+ * - when installing a package the status: field is placed at the end of the
+ * section, rather than just after the package: field.
*
- * Bugs that need to be fixed
+ * bugs that need to be fixed
* - (unknown, please let me know when you find any)
*
*/
-#include <fcntl.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
-/* NOTE: If you vary HASH_PRIME sizes be aware,
- * 1) Tweaking these will have a big effect on how much memory this program uses.
- * 2) For computational efficiency these hash tables should be at least 20%
+/* note: if you vary hash_prime sizes be aware,
+ * 1) tweaking these will have a big effect on how much memory this program uses.
+ * 2) for computational efficiency these hash tables should be at least 20%
* larger than the maximum number of elements stored in it.
- * 3) All _HASH_PRIME's must be a prime number or chaos is assured, if your looking
+ * 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
* for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
- * 4) If you go bigger than 15 bits you may get into trouble (untested) as its
+ * 4) if you go bigger than 15 bits you may get into trouble (untested) as its
* sometimes cast to an unsigned int, if you go to 16 bit you will overlap
* int's and chaos is assured, 16381 is the max prime for 14 bit field
*/
@@ -163,7 +158,7 @@ static int search_name_hashtable(const char *key)
}
}
}
- name_hashtable[probe_address] = bb_xstrdup(key);
+ name_hashtable[probe_address] = xstrdup(key);
return(probe_address);
}
@@ -204,10 +199,10 @@ static int version_compare_part(const char *version1, const char *version2)
int ret;
if (version1 == NULL) {
- version1 = bb_xstrdup("");
+ version1 = xstrdup("");
}
if (version2 == NULL) {
- version2 = bb_xstrdup("");
+ version2 = xstrdup("");
}
upstream_len1 = strlen(version1);
upstream_len2 = strlen(version2);
@@ -215,10 +210,10 @@ static int version_compare_part(const char *version1, const char *version2)
while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
/* Compare non-digit section */
tmp_int = strcspn(&version1[len1], "0123456789");
- name1_char = bb_xstrndup(&version1[len1], tmp_int);
+ name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strcspn(&version2[len2], "0123456789");
- name2_char = bb_xstrndup(&version2[len2], tmp_int);
+ name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
tmp_int = strcmp(name1_char, name2_char);
free(name1_char);
@@ -230,10 +225,10 @@ static int version_compare_part(const char *version1, const char *version2)
/* Compare digits */
tmp_int = strspn(&version1[len1], "0123456789");
- name1_char = bb_xstrndup(&version1[len1], tmp_int);
+ name1_char = xstrndup(&version1[len1], tmp_int);
len1 += tmp_int;
tmp_int = strspn(&version2[len2], "0123456789");
- name2_char = bb_xstrndup(&version2[len2], tmp_int);
+ name2_char = xstrndup(&version2[len2], tmp_int);
len2 += tmp_int;
ver_num1 = atoi(name1_char);
ver_num2 = atoi(name2_char);
@@ -292,8 +287,8 @@ static int version_compare(const unsigned int ver1, const unsigned int ver2)
}
/* Compare upstream version */
- upstream_ver1 = bb_xstrdup(ver1_ptr);
- upstream_ver2 = bb_xstrdup(ver2_ptr);
+ upstream_ver1 = xstrdup(ver1_ptr);
+ upstream_ver2 = xstrdup(ver2_ptr);
/* Chop off debian version, and store for later use */
deb_ver1 = strrchr(upstream_ver1, '-');
@@ -429,7 +424,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
*/
static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
{
- char *line = bb_xstrdup(whole_line);
+ char *line = xstrdup(whole_line);
char *line2;
char *line_ptr1 = NULL;
char *line_ptr2 = NULL;
@@ -444,7 +439,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
do {
/* skip leading spaces */
field += strspn(field, " ");
- line2 = bb_xstrdup(field);
+ line2 = xstrdup(field);
field2 = strtok_r(line2, "|", &line_ptr2);
if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
(strcmp(field, field2) != 0)) {
@@ -538,6 +533,93 @@ static void free_package(common_node_t *node)
}
}
+/*
+ * Gets the next package field from package_buffer, seperated into the field name
+ * and field value, it returns the int offset to the first character of the next field
+ */
+static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
+{
+ int offset_name_start = 0;
+ int offset_name_end = 0;
+ int offset_value_start = 0;
+ int offset_value_end = 0;
+ int offset = 0;
+ int next_offset;
+ int name_length;
+ int value_length;
+ int exit_flag = FALSE;
+
+ if (package_buffer == NULL) {
+ *field_name = NULL;
+ *field_value = NULL;
+ return(-1);
+ }
+ while (1) {
+ next_offset = offset + 1;
+ switch (package_buffer[offset]) {
+ case('\0'):
+ exit_flag = TRUE;
+ break;
+ case(':'):
+ if (offset_name_end == 0) {
+ offset_name_end = offset;
+ offset_value_start = next_offset;
+ }
+ /* TODO: Name might still have trailing spaces if ':' isnt
+ * immediately after name */
+ break;
+ case('\n'):
+ /* TODO: The char next_offset may be out of bounds */
+ if (package_buffer[next_offset] != ' ') {
+ exit_flag = TRUE;
+ break;
+ }
+ case('\t'):
+ case(' '):
+ /* increment the value start point if its a just filler */
+ if (offset_name_start == offset) {
+ offset_name_start++;
+ }
+ if (offset_value_start == offset) {
+ offset_value_start++;
+ }
+ break;
+ }
+ if (exit_flag) {
+ /* Check that the names are valid */
+ offset_value_end = offset;
+ name_length = offset_name_end - offset_name_start;
+ value_length = offset_value_end - offset_value_start;
+ if (name_length == 0) {
+ break;
+ }
+ if ((name_length > 0) && (value_length > 0)) {
+ break;
+ }
+
+ /* If not valid, start fresh with next field */
+ exit_flag = FALSE;
+ offset_name_start = offset + 1;
+ offset_name_end = 0;
+ offset_value_start = offset + 1;
+ offset_value_end = offset + 1;
+ offset++;
+ }
+ offset++;
+ }
+ if (name_length == 0) {
+ *field_name = NULL;
+ } else {
+ *field_name = xstrndup(&package_buffer[offset_name_start], name_length);
+ }
+ if (value_length > 0) {
+ *field_value = xstrndup(&package_buffer[offset_value_start], value_length);
+ } else {
+ *field_value = NULL;
+ }
+ return(next_offset);
+}
+
static unsigned int fill_package_struct(char *control_buffer)
{
static const char *const field_names[] = { "Package", "Version",
@@ -631,7 +713,7 @@ static unsigned int get_status(const unsigned int status_node, const int num)
status_string += strspn(status_string, " ");
}
len = strcspn(status_string, " \n\0");
- state_sub_string = bb_xstrndup(status_string, len);
+ state_sub_string = xstrndup(status_string, len);
state_sub_num = search_name_hashtable(state_sub_string);
free(state_sub_string);
return(state_sub_num);
@@ -666,7 +748,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 = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
+ new_status = 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;
@@ -705,7 +787,7 @@ static void index_status_file(const char *filename)
status_node_t *status_node = NULL;
unsigned int status_num;
- status_file = bb_xfopen(filename, "r");
+ status_file = xfopen(filename, "r");
while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) {
const unsigned int package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
@@ -715,7 +797,7 @@ static void index_status_file(const char *filename)
if (status_line != NULL) {
status_line += 7;
status_line += strspn(status_line, " \n\t");
- status_line = bb_xstrndup(status_line, strcspn(status_line, "\n\0"));
+ status_line = xstrndup(status_line, strcspn(status_line, "\n\0"));
status_node->status = search_name_hashtable(status_line);
free(status_line);
}
@@ -749,8 +831,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
/* This could do with a cleanup */
static void write_status_file(deb_file_t **deb_file)
{
- FILE *old_status_file = bb_xfopen("/var/lib/dpkg/status", "r");
- FILE *new_status_file = bb_xfopen("/var/lib/dpkg/status.udeb", "w");
+ FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
+ FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
char *package_name;
char *status_from_file;
char *control_buffer = NULL;
@@ -768,14 +850,14 @@ static void write_status_file(deb_file_t **deb_file)
tmp_string += 8;
tmp_string += strspn(tmp_string, " \n\t");
- package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
+ package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
write_flag = FALSE;
tmp_string = strstr(control_buffer, "Status:");
if (tmp_string != NULL) {
/* Seperate the status value from the control buffer */
tmp_string += 7;
tmp_string += strspn(tmp_string, " \n\t");
- status_from_file = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n"));
+ status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
} else {
status_from_file = NULL;
}
@@ -1181,7 +1263,7 @@ static int run_package_script(const char *package_name, const char *script_type)
char *script_path;
int result;
- script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
+ script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesnt exist is isnt a fatal */
result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
@@ -1200,7 +1282,7 @@ static char **all_control_list(const char *package_name)
/* Create a list of all /var/lib/dpkg/info/<package> files */
remove_files = xzalloc(sizeof(all_control_files));
while (all_control_files[i]) {
- remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
+ remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
i++;
}
@@ -1296,8 +1378,8 @@ static void remove_package(const unsigned int package_num, int noisy)
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
exclude_files = xzalloc(sizeof(char*) * 3);
- exclude_files[0] = bb_xstrdup(conffile_name);
- exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
+ exclude_files[0] = xstrdup(conffile_name);
+ exclude_files[1] = 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);
@@ -1361,7 +1443,7 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
/* Setup an ar archive handle that refers to the gzip sub archive */
ar_handle = init_handle();
ar_handle->filter = filter_accept_list_reassign;
- ar_handle->src_fd = bb_xopen(filename, O_RDONLY);
+ ar_handle->src_fd = xopen(filename, O_RDONLY);
return(ar_handle);
}
@@ -1428,7 +1510,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 = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr);
+ archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
data_extract_all(archive_handle);
}
return;
@@ -1457,12 +1539,12 @@ static void unpack_package(deb_file_t *deb_file)
}
/* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
- info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name);
+ info_prefix = 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 = bb_xasprintf("./%s", all_control_files[i]);
+ char *c = xasprintf("./%s", all_control_files[i]);
llist_add_to(&accept_list, c);
i++;
}
@@ -1489,7 +1571,7 @@ static void unpack_package(deb_file_t *deb_file)
/* Create the list file */
strcat(info_prefix, "list");
- out_stream = bb_xfopen(info_prefix, "w");
+ out_stream = xfopen(info_prefix, "w");
while (archive_handle->sub_archive->passed) {
/* the leading . has been stripped by data_extract_all_prefix already */
fputs(archive_handle->sub_archive->passed->data, out_stream);
@@ -1600,7 +1682,7 @@ int dpkg_main(int argc, char **argv)
if (deb_file[deb_count]->control_file == NULL) {
bb_error_msg_and_die("Couldnt extract control file");
}
- deb_file[deb_count]->filename = bb_xstrdup(argv[optind]);
+ deb_file[deb_count]->filename = xstrdup(argv[optind]);
package_num = fill_package_struct(deb_file[deb_count]->control_file);
if (package_num == -1) {
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 48a1ac1..ce65e21 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -4,13 +4,8 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
#define DPKG_DEB_OPT_CONTENTS 1
#define DPKG_DEB_OPT_CONTROL 2
@@ -81,7 +76,7 @@ int dpkg_deb_main(int argc, char **argv)
bb_show_usage();
}
- tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY);
+ tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
/* Workout where to extract the files */
/* 2nd argument is a dir name */
@@ -90,7 +85,7 @@ int dpkg_deb_main(int argc, char **argv)
}
if (extract_dir) {
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
- bb_xchdir(extract_dir);
+ xchdir(extract_dir);
}
unpack_ar_archive(ar_archive);
diff --git a/archival/gunzip.c b/archival/gunzip.c
index bd6047e..3a1d1cb 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -27,13 +27,6 @@
* See the file algorithm.doc for the compression algorithms and file formats.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
#include "busybox.h"
#include "unarchive.h"
@@ -67,7 +60,7 @@ int gunzip_main(int argc, char **argv)
src_fd = STDIN_FILENO;
opt |= GUNZIP_OPT_STDOUT;
} else {
- src_fd = bb_xopen(old_path, O_RDONLY);
+ src_fd = xopen(old_path, O_RDONLY);
/* Get the time stamp on the input file. */
xstat(old_path, &stat_buf);
@@ -81,13 +74,13 @@ int gunzip_main(int argc, char **argv)
/* Set output filename and number */
if (opt & GUNZIP_OPT_TEST) {
- dst_fd = bb_xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
+ dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
} else if (opt & GUNZIP_OPT_STDOUT) {
dst_fd = STDOUT_FILENO;
} else {
char *extension;
- new_path = bb_xstrdup(old_path);
+ new_path = xstrdup(old_path);
extension = strrchr(new_path, '.');
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
@@ -105,7 +98,7 @@ int gunzip_main(int argc, char **argv)
}
/* Open output file (with correct permissions) */
- dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
/* If unzip succeeds remove the old file */
delete_path = old_path;
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 6337e0c..5d1ec30 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -3,16 +3,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <utime.h>
-#include <unistd.h>
-#include <stdlib.h>
-
#include "libbb.h"
#include "unarchive.h"
@@ -23,7 +13,7 @@ void data_extract_all(archive_handle_t *archive_handle)
int res;
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
- char *name = bb_xstrdup(file_header->name);
+ char *name = xstrdup(file_header->name);
bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
free(name);
}
@@ -68,7 +58,7 @@ void data_extract_all(archive_handle_t *archive_handle)
switch(file_header->mode & S_IFMT) {
case S_IFREG: {
/* Regular file */
- dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
+ dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
close(dst_fd);
break;
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index ae96ea3..657d4ab 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -28,15 +28,7 @@
Manuel
*/
-#include <setjmp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-
#include "libbb.h"
-
#include "unarchive.h"
/* Constants for Huffman coding */
@@ -655,7 +647,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
/* Init the CRC32 table (big endian) */
- bd->crc32Table = bb_crc32_filltable(1);
+ bd->crc32Table = crc32_filltable(1);
/* Setup for I/O error handling via longjmp */
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 8f33e6e..7362da8 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -34,8 +34,6 @@
*/
#include "libbb.h"
-#include <sys/wait.h>
-#include <signal.h>
#include "unarchive.h"
typedef struct huft_s {
@@ -853,7 +851,7 @@ int inflate_unzip(int in, int out)
gunzip_bb = 0;
/* Create the crc table */
- gunzip_crc_table = bb_crc32_filltable(0);
+ gunzip_crc_table = crc32_filltable(0);
gunzip_crc = ~0;
/* Allocate space for buffer */
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 4627695..cabb410 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -4,12 +4,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
char get_header_ar(archive_handle_t *archive_handle)
{
@@ -31,7 +27,7 @@ char get_header_ar(archive_handle_t *archive_handle)
static unsigned int ar_long_name_size;
#endif
- /* dont use bb_xread as we want to handle the error ourself */
+ /* dont use xread as we want to handle the error ourself */
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
/* End Of File */
return(EXIT_FAILURE);
@@ -85,14 +81,14 @@ char get_header_ar(archive_handle_t *archive_handle)
if (long_offset >= ar_long_name_size) {
bb_error_msg_and_die("Cant resolve long filename");
}
- typed->name = bb_xstrdup(ar_long_names + long_offset);
+ typed->name = xstrdup(ar_long_names + long_offset);
}
#else
bb_error_msg_and_die("long filenames not supported");
#endif
} else {
/* short filenames */
- typed->name = bb_xstrndup(ar.formatted.name, 16);
+ typed->name = xstrndup(ar.formatted.name, 16);
}
typed->name[strcspn(typed->name, " /")] = '\0';
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 28c7435..d405d0e 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -4,13 +4,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/sysmacros.h> /* major() and minor() */
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
typedef struct hardlinks_s {
file_header_t *entry;
@@ -123,7 +118,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
pending_hardlinks = 1;
while (tmp) {
if (tmp->inode == inode) {
- tmp->entry->link_name = bb_xstrdup(file_header->name);
+ tmp->entry->link_name = xstrdup(file_header->name);
nlink--;
}
tmp = tmp->next;
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index fb7e9ae..0c622f4 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -11,12 +11,8 @@
* http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/sysmacros.h> /* For makedev */
-#include "unarchive.h"
#include "libbb.h"
+#include "unarchive.h"
#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
static char *longname = NULL;
@@ -106,7 +102,7 @@ char get_header_tar(archive_handle_t *archive_handle)
} else
#endif
{
- file_header->name = bb_xstrndup(tar.formatted.name,100);
+ file_header->name = xstrndup(tar.formatted.name,100);
if (tar.formatted.prefix[0]) {
char *temp = file_header->name;
@@ -120,7 +116,7 @@ char get_header_tar(archive_handle_t *archive_handle)
file_header->size = strtol(tar.formatted.size, NULL, 8);
file_header->mtime = strtol(tar.formatted.mtime, NULL, 8);
file_header->link_name = (tar.formatted.linkname[0] != '\0') ?
- bb_xstrdup(tar.formatted.linkname) : NULL;
+ xstrdup(tar.formatted.linkname) : NULL;
file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8),
strtol(tar.formatted.devminor, NULL, 8));
diff --git a/archival/rpm.c b/archival/rpm.c
index 3b70439..7b27c02 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -7,16 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <netinet/in.h> /* For ntohl & htonl function */
-#include <string.h> /* For strncmp */
-#include <sys/mman.h> /* For mmap */
-#include <time.h> /* For ctime */
-
#include "busybox.h"
#include "unarchive.h"
@@ -127,7 +117,7 @@ int rpm_main(int argc, char **argv)
if (optind == argc) bb_show_usage();
while (optind < argc) {
- rpm_fd = bb_xopen(argv[optind], O_RDONLY);
+ rpm_fd = xopen(argv[optind], O_RDONLY);
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
offset = lseek(rpm_fd, 0, SEEK_CUR);
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
@@ -198,7 +188,7 @@ void extract_cpio_gz(int fd) {
bb_error_msg_and_die("Invalid gzip magic");
}
check_header_gzip(archive_handle->src_fd);
- bb_xchdir("/"); // Install RPM's to root
+ xchdir("/"); // Install RPM's to root
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
archive_handle->offset = 0;
@@ -302,7 +292,7 @@ void fileaction_dobackup(char *filename, int fileref)
if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
stat_res = lstat (filename, &oldfile);
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
- newname = bb_xstrdup(filename);
+ newname = xstrdup(filename);
newname = strcat(newname, ".rpmorig");
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
@@ -328,7 +318,7 @@ void loop_through_files(int filetag, void (*fileaction)(char *filename, int file
{
int count = 0;
while (rpm_getstring(filetag, count)) {
- char * filename = bb_xasprintf("%s%s",
+ char * filename = xasprintf("%s%s",
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
count)), rpm_getstring(RPMTAG_BASENAMES, count));
fileaction(filename, count++);
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 6aae150..3ae8458 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -6,11 +6,6 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <netinet/in.h> /* For ntohl & htonl function */
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
#include "busybox.h"
#include "unarchive.h"
@@ -63,7 +58,7 @@ int rpm2cpio_main(int argc, char **argv)
if (argc == 1) {
rpm_fd = STDIN_FILENO;
} else {
- rpm_fd = bb_xopen(argv[1], O_RDONLY);
+ rpm_fd = xopen(argv[1], O_RDONLY);
}
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
diff --git a/archival/uncompress.c b/archival/uncompress.c
index 801293f..ca775c7 100644
--- a/archival/uncompress.c
+++ b/archival/uncompress.c
@@ -5,13 +5,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
#include "busybox.h"
#include "unarchive.h"
@@ -36,7 +29,7 @@ int uncompress_main(int argc, char **argv)
src_fd = STDIN_FILENO;
flags |= GUNZIP_TO_STDOUT;
} else {
- src_fd = bb_xopen(compressed_file, O_RDONLY);
+ src_fd = xopen(compressed_file, O_RDONLY);
}
/* Check that the input is sane. */
@@ -52,7 +45,7 @@ int uncompress_main(int argc, char **argv)
struct stat stat_buf;
char *extension;
- uncompressed_file = bb_xstrdup(compressed_file);
+ uncompressed_file = xstrdup(compressed_file);
extension = strrchr(uncompressed_file, '.');
if (!extension || (strcmp(extension, ".Z") != 0)) {
@@ -62,7 +55,7 @@ int uncompress_main(int argc, char **argv)
/* Open output file */
xstat(compressed_file, &stat_buf);
- dst_fd = bb_xopen3(uncompressed_file, O_WRONLY | O_CREAT,
+ dst_fd = xopen3(uncompressed_file, O_WRONLY | O_CREAT,
stat_buf.st_mode);
/* If unzip succeeds remove the old file */
diff --git a/archival/unlzma.c b/archival/unlzma.c
index bb4b9db..fbd207c 100644
--- a/archival/unlzma.c
+++ b/archival/unlzma.c
@@ -8,12 +8,6 @@
* Licensed under GPL v2, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
#include "unarchive.h"
@@ -31,7 +25,7 @@ int unlzma_main(int argc, char **argv)
filename = argv[optind];
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
/* Open input file */
- src_fd = bb_xopen(filename, O_RDONLY);
+ src_fd = xopen(filename, O_RDONLY);
} else {
src_fd = STDIN_FILENO;
filename = 0;
@@ -50,7 +44,7 @@ int unlzma_main(int argc, char **argv)
}
xstat(filename, &stat_buf);
*extension = 0;
- dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
+ dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
} else
dst_fd = STDOUT_FILENO;
status = unlzma(src_fd, dst_fd);
diff --git a/archival/unzip.c b/archival/unzip.c
index 012f355..68083e9 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -24,13 +24,8 @@
* - central directory
*/
-#include <fcntl.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include "unarchive.h"
#include "busybox.h"
+#include "unarchive.h"
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
@@ -68,7 +63,7 @@ static void unzip_skip(int fd, off_t skip)
static void unzip_create_leading_dirs(char *fn)
{
/* Create all leading directories */
- char *name = bb_xstrdup(fn);
+ char *name = xstrdup(fn);
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
}
@@ -143,7 +138,7 @@ int unzip_main(int argc, char **argv)
break;
case 1 : /* The zip file */
- src_fn = bb_xstrndup(optarg, strlen(optarg)+4);
+ src_fn = xstrndup(optarg, strlen(optarg)+4);
opt_range++;
break;
@@ -212,7 +207,7 @@ int unzip_main(int argc, char **argv)
/* Change dir if necessary */
if (base_dir)
- bb_xchdir(base_dir);
+ xchdir(base_dir);
if (verbosity != v_silent)
printf("Archive: %s\n", src_fn);
@@ -338,7 +333,7 @@ int unzip_main(int argc, char **argv)
overwrite = o_always;
case 'y': /* Open file and fall into unzip */
unzip_create_leading_dirs(dst_fn);
- dst_fd = bb_xopen(dst_fn, O_WRONLY | O_CREAT);
+ dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT);
case -1: /* Unzip */
if (verbosity == v_normal) {
printf(" inflating: %s\n", dst_fn);
@@ -366,7 +361,7 @@ int unzip_main(int argc, char **argv)
bb_perror_msg_and_die("Cannot read input");
}
free(dst_fn);
- dst_fn = bb_xstrdup(key_buf);
+ dst_fn = xstrdup(key_buf);
chomp(dst_fn);
goto _check_file;