aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
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 fd2ab99a0..09d0cd7e4 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -14,16 +14,8 @@
14 * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html 14 * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
15 */ 15 */
16 16
17#include <fcntl.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <time.h>
22#include <utime.h>
23#include <unistd.h>
24
25#include "unarchive.h"
26#include "busybox.h" 17#include "busybox.h"
18#include "unarchive.h"
27 19
28static void header_verbose_list_ar(const file_header_t *file_header) 20static void header_verbose_list_ar(const file_header_t *file_header)
29{ 21{
@@ -81,7 +73,7 @@ int ar_main(int argc, char **argv)
81 bb_error_msg_and_die(msg_unsupported_err, "insertion"); 73 bb_error_msg_and_die(msg_unsupported_err, "insertion");
82 } 74 }
83 75
84 archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY); 76 archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
85 77
86 while (optind < argc) { 78 while (optind < argc) {
87 archive_handle->filter = filter_accept_list; 79 archive_handle->filter = filter_accept_list;
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index 714dac077..a970aeb20 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -6,12 +6,6 @@
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */ 7 */
8 8
9#include <fcntl.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <unistd.h>
14
15#include "busybox.h" 9#include "busybox.h"
16#include "unarchive.h" 10#include "unarchive.h"
17 11
@@ -30,7 +24,7 @@ int bunzip2_main(int argc, char **argv)
30 filename = argv[optind]; 24 filename = argv[optind];
31 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) { 25 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
32 /* Open input file */ 26 /* Open input file */
33 src_fd = bb_xopen(filename, O_RDONLY); 27 src_fd = xopen(filename, O_RDONLY);
34 } else { 28 } else {
35 src_fd = STDIN_FILENO; 29 src_fd = STDIN_FILENO;
36 filename = 0; 30 filename = 0;
@@ -53,7 +47,7 @@ int bunzip2_main(int argc, char **argv)
53 } 47 }
54 xstat(filename, &stat_buf); 48 xstat(filename, &stat_buf);
55 *extension=0; 49 *extension=0;
56 dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 50 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
57 } else dst_fd = STDOUT_FILENO; 51 } else dst_fd = STDOUT_FILENO;
58 status = uncompressStream(src_fd, dst_fd); 52 status = uncompressStream(src_fd, dst_fd);
59 if(filename) { 53 if(filename) {
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 558e3cd48..0e5772062 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1,44 +1,39 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Mini dpkg implementation for busybox. 3 * mini dpkg implementation for busybox.
4 * This is not meant as a replacement for dpkg 4 * this is not meant as a replacement for dpkg
5 * 5 *
6 * Written By Glenn McGrath with the help of others 6 * written by glenn mcgrath with the help of others
7 * Copyright (C) 2001 by Glenn McGrath 7 * copyright (c) 2001 by glenn mcgrath
8 * 8 *
9 * Started life as a busybox implementation of udpkg 9 * started life as a busybox implementation of udpkg
10 * 10 *
11 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 11 * licensed under gplv2 or later, see file license in this tarball for details.
12 */ 12 */
13 13
14/* 14/*
15 * Known difference between busybox dpkg and the official dpkg that i don't 15 * known difference between busybox dpkg and the official dpkg that i don't
16 * consider important, its worth keeping a note of differences anyway, just to 16 * consider important, its worth keeping a note of differences anyway, just to
17 * make it easier to maintain. 17 * make it easier to maintain.
18 * - The first value for the Confflile: field isnt placed on a new line. 18 * - the first value for the confflile: field isnt placed on a new line.
19 * - When installing a package the Status: field is placed at the end of the 19 * - when installing a package the status: field is placed at the end of the
20 * section, rather than just after the Package: field. 20 * section, rather than just after the package: field.
21 * 21 *
22 * Bugs that need to be fixed 22 * bugs that need to be fixed
23 * - (unknown, please let me know when you find any) 23 * - (unknown, please let me know when you find any)
24 * 24 *
25 */ 25 */
26 26
27#include <fcntl.h>
28#include <getopt.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32#include "unarchive.h"
33#include "busybox.h" 27#include "busybox.h"
28#include "unarchive.h"
34 29
35/* NOTE: If you vary HASH_PRIME sizes be aware, 30/* note: if you vary hash_prime sizes be aware,
36 * 1) Tweaking these will have a big effect on how much memory this program uses. 31 * 1) tweaking these will have a big effect on how much memory this program uses.
37 * 2) For computational efficiency these hash tables should be at least 20% 32 * 2) for computational efficiency these hash tables should be at least 20%
38 * larger than the maximum number of elements stored in it. 33 * larger than the maximum number of elements stored in it.
39 * 3) All _HASH_PRIME's must be a prime number or chaos is assured, if your looking 34 * 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
40 * for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt 35 * for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
41 * 4) If you go bigger than 15 bits you may get into trouble (untested) as its 36 * 4) if you go bigger than 15 bits you may get into trouble (untested) as its
42 * sometimes cast to an unsigned int, if you go to 16 bit you will overlap 37 * sometimes cast to an unsigned int, if you go to 16 bit you will overlap
43 * int's and chaos is assured, 16381 is the max prime for 14 bit field 38 * int's and chaos is assured, 16381 is the max prime for 14 bit field
44 */ 39 */
@@ -163,7 +158,7 @@ static int search_name_hashtable(const char *key)
163 } 158 }
164 } 159 }
165 } 160 }
166 name_hashtable[probe_address] = bb_xstrdup(key); 161 name_hashtable[probe_address] = xstrdup(key);
167 return(probe_address); 162 return(probe_address);
168} 163}
169 164
@@ -204,10 +199,10 @@ static int version_compare_part(const char *version1, const char *version2)
204 int ret; 199 int ret;
205 200
206 if (version1 == NULL) { 201 if (version1 == NULL) {
207 version1 = bb_xstrdup(""); 202 version1 = xstrdup("");
208 } 203 }
209 if (version2 == NULL) { 204 if (version2 == NULL) {
210 version2 = bb_xstrdup(""); 205 version2 = xstrdup("");
211 } 206 }
212 upstream_len1 = strlen(version1); 207 upstream_len1 = strlen(version1);
213 upstream_len2 = strlen(version2); 208 upstream_len2 = strlen(version2);
@@ -215,10 +210,10 @@ static int version_compare_part(const char *version1, const char *version2)
215 while ((len1 < upstream_len1) || (len2 < upstream_len2)) { 210 while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
216 /* Compare non-digit section */ 211 /* Compare non-digit section */
217 tmp_int = strcspn(&version1[len1], "0123456789"); 212 tmp_int = strcspn(&version1[len1], "0123456789");
218 name1_char = bb_xstrndup(&version1[len1], tmp_int); 213 name1_char = xstrndup(&version1[len1], tmp_int);
219 len1 += tmp_int; 214 len1 += tmp_int;
220 tmp_int = strcspn(&version2[len2], "0123456789"); 215 tmp_int = strcspn(&version2[len2], "0123456789");
221 name2_char = bb_xstrndup(&version2[len2], tmp_int); 216 name2_char = xstrndup(&version2[len2], tmp_int);
222 len2 += tmp_int; 217 len2 += tmp_int;
223 tmp_int = strcmp(name1_char, name2_char); 218 tmp_int = strcmp(name1_char, name2_char);
224 free(name1_char); 219 free(name1_char);
@@ -230,10 +225,10 @@ static int version_compare_part(const char *version1, const char *version2)
230 225
231 /* Compare digits */ 226 /* Compare digits */
232 tmp_int = strspn(&version1[len1], "0123456789"); 227 tmp_int = strspn(&version1[len1], "0123456789");
233 name1_char = bb_xstrndup(&version1[len1], tmp_int); 228 name1_char = xstrndup(&version1[len1], tmp_int);
234 len1 += tmp_int; 229 len1 += tmp_int;
235 tmp_int = strspn(&version2[len2], "0123456789"); 230 tmp_int = strspn(&version2[len2], "0123456789");
236 name2_char = bb_xstrndup(&version2[len2], tmp_int); 231 name2_char = xstrndup(&version2[len2], tmp_int);
237 len2 += tmp_int; 232 len2 += tmp_int;
238 ver_num1 = atoi(name1_char); 233 ver_num1 = atoi(name1_char);
239 ver_num2 = atoi(name2_char); 234 ver_num2 = atoi(name2_char);
@@ -292,8 +287,8 @@ static int version_compare(const unsigned int ver1, const unsigned int ver2)
292 } 287 }
293 288
294 /* Compare upstream version */ 289 /* Compare upstream version */
295 upstream_ver1 = bb_xstrdup(ver1_ptr); 290 upstream_ver1 = xstrdup(ver1_ptr);
296 upstream_ver2 = bb_xstrdup(ver2_ptr); 291 upstream_ver2 = xstrdup(ver2_ptr);
297 292
298 /* Chop off debian version, and store for later use */ 293 /* Chop off debian version, and store for later use */
299 deb_ver1 = strrchr(upstream_ver1, '-'); 294 deb_ver1 = strrchr(upstream_ver1, '-');
@@ -429,7 +424,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
429 */ 424 */
430static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type) 425static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
431{ 426{
432 char *line = bb_xstrdup(whole_line); 427 char *line = xstrdup(whole_line);
433 char *line2; 428 char *line2;
434 char *line_ptr1 = NULL; 429 char *line_ptr1 = NULL;
435 char *line_ptr2 = NULL; 430 char *line_ptr2 = NULL;
@@ -444,7 +439,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
444 do { 439 do {
445 /* skip leading spaces */ 440 /* skip leading spaces */
446 field += strspn(field, " "); 441 field += strspn(field, " ");
447 line2 = bb_xstrdup(field); 442 line2 = xstrdup(field);
448 field2 = strtok_r(line2, "|", &line_ptr2); 443 field2 = strtok_r(line2, "|", &line_ptr2);
449 if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) && 444 if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
450 (strcmp(field, field2) != 0)) { 445 (strcmp(field, field2) != 0)) {
@@ -538,6 +533,93 @@ static void free_package(common_node_t *node)
538 } 533 }
539} 534}
540 535
536/*
537 * Gets the next package field from package_buffer, seperated into the field name
538 * and field value, it returns the int offset to the first character of the next field
539 */
540static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
541{
542 int offset_name_start = 0;
543 int offset_name_end = 0;
544 int offset_value_start = 0;
545 int offset_value_end = 0;
546 int offset = 0;
547 int next_offset;
548 int name_length;
549 int value_length;
550 int exit_flag = FALSE;
551
552 if (package_buffer == NULL) {
553 *field_name = NULL;
554 *field_value = NULL;
555 return(-1);
556 }
557 while (1) {
558 next_offset = offset + 1;
559 switch (package_buffer[offset]) {
560 case('\0'):
561 exit_flag = TRUE;
562 break;
563 case(':'):
564 if (offset_name_end == 0) {
565 offset_name_end = offset;
566 offset_value_start = next_offset;
567 }
568 /* TODO: Name might still have trailing spaces if ':' isnt
569 * immediately after name */
570 break;
571 case('\n'):
572 /* TODO: The char next_offset may be out of bounds */
573 if (package_buffer[next_offset] != ' ') {
574 exit_flag = TRUE;
575 break;
576 }
577 case('\t'):
578 case(' '):
579 /* increment the value start point if its a just filler */
580 if (offset_name_start == offset) {
581 offset_name_start++;
582 }
583 if (offset_value_start == offset) {
584 offset_value_start++;
585 }
586 break;
587 }
588 if (exit_flag) {
589 /* Check that the names are valid */
590 offset_value_end = offset;
591 name_length = offset_name_end - offset_name_start;
592 value_length = offset_value_end - offset_value_start;
593 if (name_length == 0) {
594 break;
595 }
596 if ((name_length > 0) && (value_length > 0)) {
597 break;
598 }
599
600 /* If not valid, start fresh with next field */
601 exit_flag = FALSE;
602 offset_name_start = offset + 1;
603 offset_name_end = 0;
604 offset_value_start = offset + 1;
605 offset_value_end = offset + 1;
606 offset++;
607 }
608 offset++;
609 }
610 if (name_length == 0) {
611 *field_name = NULL;
612 } else {
613 *field_name = xstrndup(&package_buffer[offset_name_start], name_length);
614 }
615 if (value_length > 0) {
616 *field_value = xstrndup(&package_buffer[offset_value_start], value_length);
617 } else {
618 *field_value = NULL;
619 }
620 return(next_offset);
621}
622
541static unsigned int fill_package_struct(char *control_buffer) 623static unsigned int fill_package_struct(char *control_buffer)
542{ 624{
543 static const char *const field_names[] = { "Package", "Version", 625 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)
631 status_string += strspn(status_string, " "); 713 status_string += strspn(status_string, " ");
632 } 714 }
633 len = strcspn(status_string, " \n\0"); 715 len = strcspn(status_string, " \n\0");
634 state_sub_string = bb_xstrndup(status_string, len); 716 state_sub_string = xstrndup(status_string, len);
635 state_sub_num = search_name_hashtable(state_sub_string); 717 state_sub_num = search_name_hashtable(state_sub_string);
636 free(state_sub_string); 718 free(state_sub_string);
637 return(state_sub_num); 719 return(state_sub_num);
@@ -666,7 +748,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
666 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen"); 748 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
667 } 749 }
668 750
669 new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]); 751 new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
670 status_hashtable[status_node_num]->status = search_name_hashtable(new_status); 752 status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
671 free(new_status); 753 free(new_status);
672 return; 754 return;
@@ -705,7 +787,7 @@ static void index_status_file(const char *filename)
705 status_node_t *status_node = NULL; 787 status_node_t *status_node = NULL;
706 unsigned int status_num; 788 unsigned int status_num;
707 789
708 status_file = bb_xfopen(filename, "r"); 790 status_file = xfopen(filename, "r");
709 while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) { 791 while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) {
710 const unsigned int package_num = fill_package_struct(control_buffer); 792 const unsigned int package_num = fill_package_struct(control_buffer);
711 if (package_num != -1) { 793 if (package_num != -1) {
@@ -715,7 +797,7 @@ static void index_status_file(const char *filename)
715 if (status_line != NULL) { 797 if (status_line != NULL) {
716 status_line += 7; 798 status_line += 7;
717 status_line += strspn(status_line, " \n\t"); 799 status_line += strspn(status_line, " \n\t");
718 status_line = bb_xstrndup(status_line, strcspn(status_line, "\n\0")); 800 status_line = xstrndup(status_line, strcspn(status_line, "\n\0"));
719 status_node->status = search_name_hashtable(status_line); 801 status_node->status = search_name_hashtable(status_line);
720 free(status_line); 802 free(status_line);
721 } 803 }
@@ -749,8 +831,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
749/* This could do with a cleanup */ 831/* This could do with a cleanup */
750static void write_status_file(deb_file_t **deb_file) 832static void write_status_file(deb_file_t **deb_file)
751{ 833{
752 FILE *old_status_file = bb_xfopen("/var/lib/dpkg/status", "r"); 834 FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
753 FILE *new_status_file = bb_xfopen("/var/lib/dpkg/status.udeb", "w"); 835 FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
754 char *package_name; 836 char *package_name;
755 char *status_from_file; 837 char *status_from_file;
756 char *control_buffer = NULL; 838 char *control_buffer = NULL;
@@ -768,14 +850,14 @@ static void write_status_file(deb_file_t **deb_file)
768 850
769 tmp_string += 8; 851 tmp_string += 8;
770 tmp_string += strspn(tmp_string, " \n\t"); 852 tmp_string += strspn(tmp_string, " \n\t");
771 package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0")); 853 package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
772 write_flag = FALSE; 854 write_flag = FALSE;
773 tmp_string = strstr(control_buffer, "Status:"); 855 tmp_string = strstr(control_buffer, "Status:");
774 if (tmp_string != NULL) { 856 if (tmp_string != NULL) {
775 /* Seperate the status value from the control buffer */ 857 /* Seperate the status value from the control buffer */
776 tmp_string += 7; 858 tmp_string += 7;
777 tmp_string += strspn(tmp_string, " \n\t"); 859 tmp_string += strspn(tmp_string, " \n\t");
778 status_from_file = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n")); 860 status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
779 } else { 861 } else {
780 status_from_file = NULL; 862 status_from_file = NULL;
781 } 863 }
@@ -1181,7 +1263,7 @@ static int run_package_script(const char *package_name, const char *script_type)
1181 char *script_path; 1263 char *script_path;
1182 int result; 1264 int result;
1183 1265
1184 script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type); 1266 script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
1185 1267
1186 /* If the file doesnt exist is isnt a fatal */ 1268 /* If the file doesnt exist is isnt a fatal */
1187 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path); 1269 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)
1200 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1282 /* Create a list of all /var/lib/dpkg/info/<package> files */
1201 remove_files = xzalloc(sizeof(all_control_files)); 1283 remove_files = xzalloc(sizeof(all_control_files));
1202 while (all_control_files[i]) { 1284 while (all_control_files[i]) {
1203 remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]); 1285 remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1204 i++; 1286 i++;
1205 } 1287 }
1206 1288
@@ -1296,8 +1378,8 @@ static void remove_package(const unsigned int package_num, int noisy)
1296 1378
1297 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ 1379 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
1298 exclude_files = xzalloc(sizeof(char*) * 3); 1380 exclude_files = xzalloc(sizeof(char*) * 3);
1299 exclude_files[0] = bb_xstrdup(conffile_name); 1381 exclude_files[0] = xstrdup(conffile_name);
1300 exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name); 1382 exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
1301 1383
1302 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1384 /* Create a list of all /var/lib/dpkg/info/<package> files */
1303 remove_files = all_control_list(package_name); 1385 remove_files = all_control_list(package_name);
@@ -1361,7 +1443,7 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
1361 /* Setup an ar archive handle that refers to the gzip sub archive */ 1443 /* Setup an ar archive handle that refers to the gzip sub archive */
1362 ar_handle = init_handle(); 1444 ar_handle = init_handle();
1363 ar_handle->filter = filter_accept_list_reassign; 1445 ar_handle->filter = filter_accept_list_reassign;
1364 ar_handle->src_fd = bb_xopen(filename, O_RDONLY); 1446 ar_handle->src_fd = xopen(filename, O_RDONLY);
1365 1447
1366 return(ar_handle); 1448 return(ar_handle);
1367} 1449}
@@ -1428,7 +1510,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
1428 1510
1429 name_ptr += strspn(name_ptr, "./"); 1511 name_ptr += strspn(name_ptr, "./");
1430 if (name_ptr[0] != '\0') { 1512 if (name_ptr[0] != '\0') {
1431 archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr); 1513 archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
1432 data_extract_all(archive_handle); 1514 data_extract_all(archive_handle);
1433 } 1515 }
1434 return; 1516 return;
@@ -1457,12 +1539,12 @@ static void unpack_package(deb_file_t *deb_file)
1457 } 1539 }
1458 1540
1459 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ 1541 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
1460 info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name); 1542 info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name);
1461 archive_handle = init_archive_deb_ar(deb_file->filename); 1543 archive_handle = init_archive_deb_ar(deb_file->filename);
1462 init_archive_deb_control(archive_handle); 1544 init_archive_deb_control(archive_handle);
1463 1545
1464 while(all_control_files[i]) { 1546 while(all_control_files[i]) {
1465 char *c = bb_xasprintf("./%s", all_control_files[i]); 1547 char *c = xasprintf("./%s", all_control_files[i]);
1466 llist_add_to(&accept_list, c); 1548 llist_add_to(&accept_list, c);
1467 i++; 1549 i++;
1468 } 1550 }
@@ -1489,7 +1571,7 @@ static void unpack_package(deb_file_t *deb_file)
1489 1571
1490 /* Create the list file */ 1572 /* Create the list file */
1491 strcat(info_prefix, "list"); 1573 strcat(info_prefix, "list");
1492 out_stream = bb_xfopen(info_prefix, "w"); 1574 out_stream = xfopen(info_prefix, "w");
1493 while (archive_handle->sub_archive->passed) { 1575 while (archive_handle->sub_archive->passed) {
1494 /* the leading . has been stripped by data_extract_all_prefix already */ 1576 /* the leading . has been stripped by data_extract_all_prefix already */
1495 fputs(archive_handle->sub_archive->passed->data, out_stream); 1577 fputs(archive_handle->sub_archive->passed->data, out_stream);
@@ -1600,7 +1682,7 @@ int dpkg_main(int argc, char **argv)
1600 if (deb_file[deb_count]->control_file == NULL) { 1682 if (deb_file[deb_count]->control_file == NULL) {
1601 bb_error_msg_and_die("Couldnt extract control file"); 1683 bb_error_msg_and_die("Couldnt extract control file");
1602 } 1684 }
1603 deb_file[deb_count]->filename = bb_xstrdup(argv[optind]); 1685 deb_file[deb_count]->filename = xstrdup(argv[optind]);
1604 package_num = fill_package_struct(deb_file[deb_count]->control_file); 1686 package_num = fill_package_struct(deb_file[deb_count]->control_file);
1605 1687
1606 if (package_num == -1) { 1688 if (package_num == -1) {
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 48a1ac161..ce65e219a 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -4,13 +4,8 @@
4 * 4 *
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */ 6 */
7#include <fcntl.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11
12#include "unarchive.h"
13#include "busybox.h" 7#include "busybox.h"
8#include "unarchive.h"
14 9
15#define DPKG_DEB_OPT_CONTENTS 1 10#define DPKG_DEB_OPT_CONTENTS 1
16#define DPKG_DEB_OPT_CONTROL 2 11#define DPKG_DEB_OPT_CONTROL 2
@@ -81,7 +76,7 @@ int dpkg_deb_main(int argc, char **argv)
81 bb_show_usage(); 76 bb_show_usage();
82 } 77 }
83 78
84 tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY); 79 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
85 80
86 /* Workout where to extract the files */ 81 /* Workout where to extract the files */
87 /* 2nd argument is a dir name */ 82 /* 2nd argument is a dir name */
@@ -90,7 +85,7 @@ int dpkg_deb_main(int argc, char **argv)
90 } 85 }
91 if (extract_dir) { 86 if (extract_dir) {
92 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ 87 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
93 bb_xchdir(extract_dir); 88 xchdir(extract_dir);
94 } 89 }
95 unpack_ar_archive(ar_archive); 90 unpack_ar_archive(ar_archive);
96 91
diff --git a/archival/gunzip.c b/archival/gunzip.c
index bd6047e13..3a1d1cb61 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -27,13 +27,6 @@
27 * See the file algorithm.doc for the compression algorithms and file formats. 27 * See the file algorithm.doc for the compression algorithms and file formats.
28 */ 28 */
29 29
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <fcntl.h>
36
37#include "busybox.h" 30#include "busybox.h"
38#include "unarchive.h" 31#include "unarchive.h"
39 32
@@ -67,7 +60,7 @@ int gunzip_main(int argc, char **argv)
67 src_fd = STDIN_FILENO; 60 src_fd = STDIN_FILENO;
68 opt |= GUNZIP_OPT_STDOUT; 61 opt |= GUNZIP_OPT_STDOUT;
69 } else { 62 } else {
70 src_fd = bb_xopen(old_path, O_RDONLY); 63 src_fd = xopen(old_path, O_RDONLY);
71 64
72 /* Get the time stamp on the input file. */ 65 /* Get the time stamp on the input file. */
73 xstat(old_path, &stat_buf); 66 xstat(old_path, &stat_buf);
@@ -81,13 +74,13 @@ int gunzip_main(int argc, char **argv)
81 74
82 /* Set output filename and number */ 75 /* Set output filename and number */
83 if (opt & GUNZIP_OPT_TEST) { 76 if (opt & GUNZIP_OPT_TEST) {
84 dst_fd = bb_xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */ 77 dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
85 } else if (opt & GUNZIP_OPT_STDOUT) { 78 } else if (opt & GUNZIP_OPT_STDOUT) {
86 dst_fd = STDOUT_FILENO; 79 dst_fd = STDOUT_FILENO;
87 } else { 80 } else {
88 char *extension; 81 char *extension;
89 82
90 new_path = bb_xstrdup(old_path); 83 new_path = xstrdup(old_path);
91 84
92 extension = strrchr(new_path, '.'); 85 extension = strrchr(new_path, '.');
93#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS 86#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
@@ -105,7 +98,7 @@ int gunzip_main(int argc, char **argv)
105 } 98 }
106 99
107 /* Open output file (with correct permissions) */ 100 /* Open output file (with correct permissions) */
108 dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode); 101 dst_fd = xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
109 102
110 /* If unzip succeeds remove the old file */ 103 /* If unzip succeeds remove the old file */
111 delete_path = old_path; 104 delete_path = old_path;
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 6337e0c85..5d1ec302a 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -3,16 +3,6 @@
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */ 4 */
5 5
6#include <sys/types.h>
7
8#include <errno.h>
9#include <fcntl.h>
10#include <stdlib.h>
11#include <string.h>
12#include <utime.h>
13#include <unistd.h>
14#include <stdlib.h>
15
16#include "libbb.h" 6#include "libbb.h"
17#include "unarchive.h" 7#include "unarchive.h"
18 8
@@ -23,7 +13,7 @@ void data_extract_all(archive_handle_t *archive_handle)
23 int res; 13 int res;
24 14
25 if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { 15 if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
26 char *name = bb_xstrdup(file_header->name); 16 char *name = xstrdup(file_header->name);
27 bb_make_directory (dirname(name), -1, FILEUTILS_RECUR); 17 bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
28 free(name); 18 free(name);
29 } 19 }
@@ -68,7 +58,7 @@ void data_extract_all(archive_handle_t *archive_handle)
68 switch(file_header->mode & S_IFMT) { 58 switch(file_header->mode & S_IFMT) {
69 case S_IFREG: { 59 case S_IFREG: {
70 /* Regular file */ 60 /* Regular file */
71 dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); 61 dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
72 bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); 62 bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
73 close(dst_fd); 63 close(dst_fd);
74 break; 64 break;
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index ae96ea375..657d4ab01 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -28,15 +28,7 @@
28 Manuel 28 Manuel
29 */ 29 */
30 30
31#include <setjmp.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <unistd.h>
36#include <limits.h>
37
38#include "libbb.h" 31#include "libbb.h"
39
40#include "unarchive.h" 32#include "unarchive.h"
41 33
42/* Constants for Huffman coding */ 34/* Constants for Huffman coding */
@@ -655,7 +647,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
655 647
656 /* Init the CRC32 table (big endian) */ 648 /* Init the CRC32 table (big endian) */
657 649
658 bd->crc32Table = bb_crc32_filltable(1); 650 bd->crc32Table = crc32_filltable(1);
659 651
660 /* Setup for I/O error handling via longjmp */ 652 /* Setup for I/O error handling via longjmp */
661 653
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 8f33e6e6c..7362da8c2 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -34,8 +34,6 @@
34 */ 34 */
35 35
36#include "libbb.h" 36#include "libbb.h"
37#include <sys/wait.h>
38#include <signal.h>
39#include "unarchive.h" 37#include "unarchive.h"
40 38
41typedef struct huft_s { 39typedef struct huft_s {
@@ -853,7 +851,7 @@ int inflate_unzip(int in, int out)
853 gunzip_bb = 0; 851 gunzip_bb = 0;
854 852
855 /* Create the crc table */ 853 /* Create the crc table */
856 gunzip_crc_table = bb_crc32_filltable(0); 854 gunzip_crc_table = crc32_filltable(0);
857 gunzip_crc = ~0; 855 gunzip_crc = ~0;
858 856
859 /* Allocate space for buffer */ 857 /* Allocate space for buffer */
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 4627695e4..cabb4101b 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -4,12 +4,8 @@
4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
5 */ 5 */
6 6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include "unarchive.h"
12#include "libbb.h" 7#include "libbb.h"
8#include "unarchive.h"
13 9
14char get_header_ar(archive_handle_t *archive_handle) 10char get_header_ar(archive_handle_t *archive_handle)
15{ 11{
@@ -31,7 +27,7 @@ char get_header_ar(archive_handle_t *archive_handle)
31 static unsigned int ar_long_name_size; 27 static unsigned int ar_long_name_size;
32#endif 28#endif
33 29
34 /* dont use bb_xread as we want to handle the error ourself */ 30 /* dont use xread as we want to handle the error ourself */
35 if (read(archive_handle->src_fd, ar.raw, 60) != 60) { 31 if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
36 /* End Of File */ 32 /* End Of File */
37 return(EXIT_FAILURE); 33 return(EXIT_FAILURE);
@@ -85,14 +81,14 @@ char get_header_ar(archive_handle_t *archive_handle)
85 if (long_offset >= ar_long_name_size) { 81 if (long_offset >= ar_long_name_size) {
86 bb_error_msg_and_die("Cant resolve long filename"); 82 bb_error_msg_and_die("Cant resolve long filename");
87 } 83 }
88 typed->name = bb_xstrdup(ar_long_names + long_offset); 84 typed->name = xstrdup(ar_long_names + long_offset);
89 } 85 }
90#else 86#else
91 bb_error_msg_and_die("long filenames not supported"); 87 bb_error_msg_and_die("long filenames not supported");
92#endif 88#endif
93 } else { 89 } else {
94 /* short filenames */ 90 /* short filenames */
95 typed->name = bb_xstrndup(ar.formatted.name, 16); 91 typed->name = xstrndup(ar.formatted.name, 16);
96 } 92 }
97 93
98 typed->name[strcspn(typed->name, " /")] = '\0'; 94 typed->name[strcspn(typed->name, " /")] = '\0';
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 28c743589..d405d0e1b 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -4,13 +4,8 @@
4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
5 */ 5 */
6 6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include <sys/sysmacros.h> /* major() and minor() */
12#include "unarchive.h"
13#include "libbb.h" 7#include "libbb.h"
8#include "unarchive.h"
14 9
15typedef struct hardlinks_s { 10typedef struct hardlinks_s {
16 file_header_t *entry; 11 file_header_t *entry;
@@ -123,7 +118,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
123 pending_hardlinks = 1; 118 pending_hardlinks = 1;
124 while (tmp) { 119 while (tmp) {
125 if (tmp->inode == inode) { 120 if (tmp->inode == inode) {
126 tmp->entry->link_name = bb_xstrdup(file_header->name); 121 tmp->entry->link_name = xstrdup(file_header->name);
127 nlink--; 122 nlink--;
128 } 123 }
129 tmp = tmp->next; 124 tmp = tmp->next;
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index fb7e9ae8f..0c622f44a 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -11,12 +11,8 @@
11 * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html 11 * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
12 */ 12 */
13 13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include <sys/sysmacros.h> /* For makedev */
18#include "unarchive.h"
19#include "libbb.h" 14#include "libbb.h"
15#include "unarchive.h"
20 16
21#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS 17#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
22static char *longname = NULL; 18static char *longname = NULL;
@@ -106,7 +102,7 @@ char get_header_tar(archive_handle_t *archive_handle)
106 } else 102 } else
107#endif 103#endif
108 { 104 {
109 file_header->name = bb_xstrndup(tar.formatted.name,100); 105 file_header->name = xstrndup(tar.formatted.name,100);
110 106
111 if (tar.formatted.prefix[0]) { 107 if (tar.formatted.prefix[0]) {
112 char *temp = file_header->name; 108 char *temp = file_header->name;
@@ -120,7 +116,7 @@ char get_header_tar(archive_handle_t *archive_handle)
120 file_header->size = strtol(tar.formatted.size, NULL, 8); 116 file_header->size = strtol(tar.formatted.size, NULL, 8);
121 file_header->mtime = strtol(tar.formatted.mtime, NULL, 8); 117 file_header->mtime = strtol(tar.formatted.mtime, NULL, 8);
122 file_header->link_name = (tar.formatted.linkname[0] != '\0') ? 118 file_header->link_name = (tar.formatted.linkname[0] != '\0') ?
123 bb_xstrdup(tar.formatted.linkname) : NULL; 119 xstrdup(tar.formatted.linkname) : NULL;
124 file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8), 120 file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8),
125 strtol(tar.formatted.devminor, NULL, 8)); 121 strtol(tar.formatted.devminor, NULL, 8));
126 122
diff --git a/archival/rpm.c b/archival/rpm.c
index 3b70439a7..7b27c0250 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -7,16 +7,6 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <unistd.h>
12#include <signal.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <netinet/in.h> /* For ntohl & htonl function */
16#include <string.h> /* For strncmp */
17#include <sys/mman.h> /* For mmap */
18#include <time.h> /* For ctime */
19
20#include "busybox.h" 10#include "busybox.h"
21#include "unarchive.h" 11#include "unarchive.h"
22 12
@@ -127,7 +117,7 @@ int rpm_main(int argc, char **argv)
127 117
128 if (optind == argc) bb_show_usage(); 118 if (optind == argc) bb_show_usage();
129 while (optind < argc) { 119 while (optind < argc) {
130 rpm_fd = bb_xopen(argv[optind], O_RDONLY); 120 rpm_fd = xopen(argv[optind], O_RDONLY);
131 mytags = rpm_gettags(rpm_fd, (int *) &tagcount); 121 mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
132 offset = lseek(rpm_fd, 0, SEEK_CUR); 122 offset = lseek(rpm_fd, 0, SEEK_CUR);
133 if (!mytags) { printf("Error reading rpm header\n"); exit(-1); } 123 if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
@@ -198,7 +188,7 @@ void extract_cpio_gz(int fd) {
198 bb_error_msg_and_die("Invalid gzip magic"); 188 bb_error_msg_and_die("Invalid gzip magic");
199 } 189 }
200 check_header_gzip(archive_handle->src_fd); 190 check_header_gzip(archive_handle->src_fd);
201 bb_xchdir("/"); // Install RPM's to root 191 xchdir("/"); // Install RPM's to root
202 192
203 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); 193 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
204 archive_handle->offset = 0; 194 archive_handle->offset = 0;
@@ -302,7 +292,7 @@ void fileaction_dobackup(char *filename, int fileref)
302 if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */ 292 if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
303 stat_res = lstat (filename, &oldfile); 293 stat_res = lstat (filename, &oldfile);
304 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */ 294 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
305 newname = bb_xstrdup(filename); 295 newname = xstrdup(filename);
306 newname = strcat(newname, ".rpmorig"); 296 newname = strcat(newname, ".rpmorig");
307 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); 297 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
308 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE); 298 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
@@ -328,7 +318,7 @@ void loop_through_files(int filetag, void (*fileaction)(char *filename, int file
328{ 318{
329 int count = 0; 319 int count = 0;
330 while (rpm_getstring(filetag, count)) { 320 while (rpm_getstring(filetag, count)) {
331 char * filename = bb_xasprintf("%s%s", 321 char * filename = xasprintf("%s%s",
332 rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, 322 rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
333 count)), rpm_getstring(RPMTAG_BASENAMES, count)); 323 count)), rpm_getstring(RPMTAG_BASENAMES, count));
334 fileaction(filename, count++); 324 fileaction(filename, count++);
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 6aae150e2..3ae8458dd 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -6,11 +6,6 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9#include <sys/types.h>
10#include <netinet/in.h> /* For ntohl & htonl function */
11#include <fcntl.h>
12#include <unistd.h>
13#include <string.h>
14#include "busybox.h" 9#include "busybox.h"
15#include "unarchive.h" 10#include "unarchive.h"
16 11
@@ -63,7 +58,7 @@ int rpm2cpio_main(int argc, char **argv)
63 if (argc == 1) { 58 if (argc == 1) {
64 rpm_fd = STDIN_FILENO; 59 rpm_fd = STDIN_FILENO;
65 } else { 60 } else {
66 rpm_fd = bb_xopen(argv[1], O_RDONLY); 61 rpm_fd = xopen(argv[1], O_RDONLY);
67 } 62 }
68 63
69 xread(rpm_fd, &lead, sizeof(struct rpm_lead)); 64 xread(rpm_fd, &lead, sizeof(struct rpm_lead));
diff --git a/archival/uncompress.c b/archival/uncompress.c
index 801293fd9..ca775c787 100644
--- a/archival/uncompress.c
+++ b/archival/uncompress.c
@@ -5,13 +5,6 @@
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */ 6 */
7 7
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <fcntl.h>
14
15#include "busybox.h" 8#include "busybox.h"
16#include "unarchive.h" 9#include "unarchive.h"
17 10
@@ -36,7 +29,7 @@ int uncompress_main(int argc, char **argv)
36 src_fd = STDIN_FILENO; 29 src_fd = STDIN_FILENO;
37 flags |= GUNZIP_TO_STDOUT; 30 flags |= GUNZIP_TO_STDOUT;
38 } else { 31 } else {
39 src_fd = bb_xopen(compressed_file, O_RDONLY); 32 src_fd = xopen(compressed_file, O_RDONLY);
40 } 33 }
41 34
42 /* Check that the input is sane. */ 35 /* Check that the input is sane. */
@@ -52,7 +45,7 @@ int uncompress_main(int argc, char **argv)
52 struct stat stat_buf; 45 struct stat stat_buf;
53 char *extension; 46 char *extension;
54 47
55 uncompressed_file = bb_xstrdup(compressed_file); 48 uncompressed_file = xstrdup(compressed_file);
56 49
57 extension = strrchr(uncompressed_file, '.'); 50 extension = strrchr(uncompressed_file, '.');
58 if (!extension || (strcmp(extension, ".Z") != 0)) { 51 if (!extension || (strcmp(extension, ".Z") != 0)) {
@@ -62,7 +55,7 @@ int uncompress_main(int argc, char **argv)
62 55
63 /* Open output file */ 56 /* Open output file */
64 xstat(compressed_file, &stat_buf); 57 xstat(compressed_file, &stat_buf);
65 dst_fd = bb_xopen3(uncompressed_file, O_WRONLY | O_CREAT, 58 dst_fd = xopen3(uncompressed_file, O_WRONLY | O_CREAT,
66 stat_buf.st_mode); 59 stat_buf.st_mode);
67 60
68 /* If unzip succeeds remove the old file */ 61 /* If unzip succeeds remove the old file */
diff --git a/archival/unlzma.c b/archival/unlzma.c
index bb4b9db6b..fbd207ca1 100644
--- a/archival/unlzma.c
+++ b/archival/unlzma.c
@@ -8,12 +8,6 @@
8 * Licensed under GPL v2, see file LICENSE in this tarball for details. 8 * Licensed under GPL v2, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include <fcntl.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16
17#include "busybox.h" 11#include "busybox.h"
18#include "unarchive.h" 12#include "unarchive.h"
19 13
@@ -31,7 +25,7 @@ int unlzma_main(int argc, char **argv)
31 filename = argv[optind]; 25 filename = argv[optind];
32 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) { 26 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
33 /* Open input file */ 27 /* Open input file */
34 src_fd = bb_xopen(filename, O_RDONLY); 28 src_fd = xopen(filename, O_RDONLY);
35 } else { 29 } else {
36 src_fd = STDIN_FILENO; 30 src_fd = STDIN_FILENO;
37 filename = 0; 31 filename = 0;
@@ -50,7 +44,7 @@ int unlzma_main(int argc, char **argv)
50 } 44 }
51 xstat(filename, &stat_buf); 45 xstat(filename, &stat_buf);
52 *extension = 0; 46 *extension = 0;
53 dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 47 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
54 } else 48 } else
55 dst_fd = STDOUT_FILENO; 49 dst_fd = STDOUT_FILENO;
56 status = unlzma(src_fd, dst_fd); 50 status = unlzma(src_fd, dst_fd);
diff --git a/archival/unzip.c b/archival/unzip.c
index 012f355e2..68083e987 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -24,13 +24,8 @@
24 * - central directory 24 * - central directory
25 */ 25 */
26 26
27#include <fcntl.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31#include <errno.h>
32#include "unarchive.h"
33#include "busybox.h" 27#include "busybox.h"
28#include "unarchive.h"
34 29
35#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50) 30#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
36#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50) 31#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
@@ -68,7 +63,7 @@ static void unzip_skip(int fd, off_t skip)
68static void unzip_create_leading_dirs(char *fn) 63static void unzip_create_leading_dirs(char *fn)
69{ 64{
70 /* Create all leading directories */ 65 /* Create all leading directories */
71 char *name = bb_xstrdup(fn); 66 char *name = xstrdup(fn);
72 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) { 67 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
73 bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */ 68 bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
74 } 69 }
@@ -143,7 +138,7 @@ int unzip_main(int argc, char **argv)
143 break; 138 break;
144 139
145 case 1 : /* The zip file */ 140 case 1 : /* The zip file */
146 src_fn = bb_xstrndup(optarg, strlen(optarg)+4); 141 src_fn = xstrndup(optarg, strlen(optarg)+4);
147 opt_range++; 142 opt_range++;
148 break; 143 break;
149 144
@@ -212,7 +207,7 @@ int unzip_main(int argc, char **argv)
212 207
213 /* Change dir if necessary */ 208 /* Change dir if necessary */
214 if (base_dir) 209 if (base_dir)
215 bb_xchdir(base_dir); 210 xchdir(base_dir);
216 211
217 if (verbosity != v_silent) 212 if (verbosity != v_silent)
218 printf("Archive: %s\n", src_fn); 213 printf("Archive: %s\n", src_fn);
@@ -338,7 +333,7 @@ int unzip_main(int argc, char **argv)
338 overwrite = o_always; 333 overwrite = o_always;
339 case 'y': /* Open file and fall into unzip */ 334 case 'y': /* Open file and fall into unzip */
340 unzip_create_leading_dirs(dst_fn); 335 unzip_create_leading_dirs(dst_fn);
341 dst_fd = bb_xopen(dst_fn, O_WRONLY | O_CREAT); 336 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT);
342 case -1: /* Unzip */ 337 case -1: /* Unzip */
343 if (verbosity == v_normal) { 338 if (verbosity == v_normal) {
344 printf(" inflating: %s\n", dst_fn); 339 printf(" inflating: %s\n", dst_fn);
@@ -366,7 +361,7 @@ int unzip_main(int argc, char **argv)
366 bb_perror_msg_and_die("Cannot read input"); 361 bb_perror_msg_and_die("Cannot read input");
367 } 362 }
368 free(dst_fn); 363 free(dst_fn);
369 dst_fn = bb_xstrdup(key_buf); 364 dst_fn = xstrdup(key_buf);
370 chomp(dst_fn); 365 chomp(dst_fn);
371 goto _check_file; 366 goto _check_file;
372 367