aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--console-tools/dumpkmap.c9
-rw-r--r--console-tools/loadfont.c14
-rw-r--r--console-tools/loadkmap.c9
-rw-r--r--console-tools/openvt.c2
-rw-r--r--console-tools/setconsole.c9
-rw-r--r--console-tools/setlogcons.c6
-rw-r--r--coreutils/cal.c14
-rw-r--r--coreutils/catv.c4
-rw-r--r--coreutils/chroot.c6
-rw-r--r--coreutils/cksum.c5
-rw-r--r--coreutils/cmp.c11
-rw-r--r--coreutils/comm.c6
-rw-r--r--coreutils/dd.c12
-rw-r--r--coreutils/diff.c41
-rw-r--r--coreutils/dos2unix.c6
-rw-r--r--coreutils/expr.c16
-rw-r--r--coreutils/fold.c9
-rw-r--r--coreutils/head.c7
-rw-r--r--coreutils/ln.c10
-rw-r--r--coreutils/ls.c12
-rw-r--r--coreutils/md5_sha1_sum.c10
-rw-r--r--coreutils/nohup.c7
-rw-r--r--coreutils/sort.c14
-rw-r--r--coreutils/stat.c14
-rw-r--r--coreutils/stty.c36
-rw-r--r--coreutils/tee.c6
-rw-r--r--coreutils/uniq.c7
-rw-r--r--coreutils/uudecode.c9
-rw-r--r--coreutils/uuencode.c11
-rw-r--r--coreutils/watch.c10
-rw-r--r--debianutils/start_stop_daemon.c31
-rw-r--r--e2fsprogs/e2p/feature.c2
-rw-r--r--e2fsprogs/e2p/mntopts.c2
-rw-r--r--e2fsprogs/e2p/ostype.c2
-rw-r--r--e2fsprogs/fsck.c6
-rw-r--r--e2fsprogs/mke2fs.c4
-rw-r--r--e2fsprogs/util.c4
-rw-r--r--editors/awk.c38
-rw-r--r--editors/patch.c12
-rw-r--r--editors/sed.c32
-rw-r--r--editors/vi.c28
-rw-r--r--findutils/find.c17
-rw-r--r--findutils/grep.c9
-rw-r--r--findutils/xargs.c11
-rw-r--r--include/libbb.h52
-rw-r--r--libbb/Makefile.in17
-rw-r--r--libbb/bb_asprintf.c37
-rw-r--r--libbb/bb_xbind.c18
-rw-r--r--libbb/bb_xchdir.c17
-rw-r--r--libbb/bb_xdaemon.c19
-rw-r--r--libbb/bb_xlisten.c17
-rw-r--r--libbb/bb_xsocket.c19
-rw-r--r--libbb/concat_path_file.c3
-rw-r--r--libbb/copy_file.c4
-rw-r--r--libbb/crc32.c5
-rw-r--r--libbb/dump.c5
-rw-r--r--libbb/find_root_device.c7
-rw-r--r--libbb/getopt_ulflags.c7
-rw-r--r--libbb/inet_common.c12
-rw-r--r--libbb/loop.c9
-rw-r--r--libbb/obscure.c7
-rw-r--r--libbb/opendir.c37
-rw-r--r--libbb/print_file.c55
-rw-r--r--libbb/procps.c2
-rw-r--r--libbb/read_package_field.c101
-rw-r--r--libbb/recursive_action.c7
-rw-r--r--libbb/remove_file.c2
-rw-r--r--libbb/run_shell.c4
-rw-r--r--libbb/simplify_path.c3
-rw-r--r--libbb/xconnect.c12
-rw-r--r--libbb/xfuncs.c142
-rw-r--r--loginutils/addgroup.c11
-rw-r--r--loginutils/adduser.c16
-rw-r--r--loginutils/getty.c17
-rw-r--r--loginutils/passwd.c16
-rw-r--r--loginutils/su.c6
-rw-r--r--loginutils/vlock.c14
-rw-r--r--miscutils/crond.c21
-rw-r--r--miscutils/crontab.c36
-rw-r--r--miscutils/devfsd.c8
-rw-r--r--miscutils/hdparm.c16
-rw-r--r--miscutils/last.c10
-rw-r--r--miscutils/less.c54
-rw-r--r--miscutils/makedevs.c13
-rw-r--r--miscutils/mountpoint.c6
-rw-r--r--miscutils/mt.c6
-rw-r--r--miscutils/rx.c16
-rw-r--r--miscutils/watchdog.c9
-rw-r--r--modutils/insmod.c54
-rw-r--r--modutils/modprobe.c35
-rw-r--r--networking/ether-wake.c19
-rw-r--r--networking/fakeidentd.c18
-rw-r--r--networking/ftpgetput.c19
-rw-r--r--networking/hostname.c11
-rw-r--r--networking/ifconfig.c10
-rw-r--r--networking/ifupdown.c48
-rw-r--r--networking/inetd.c27
-rw-r--r--networking/nameif.c14
-rw-r--r--networking/nc.c8
-rw-r--r--networking/route.c30
-rw-r--r--networking/tftp.c16
-rw-r--r--networking/traceroute.c16
-rw-r--r--networking/udhcp/libbb_udhcp.h2
-rw-r--r--networking/udhcp/script.c12
-rw-r--r--networking/vconfig.c12
-rw-r--r--networking/wget.c15
-rw-r--r--procps/sysctl.c17
-rw-r--r--procps/top.c21
-rw-r--r--shell/ash.c4
-rw-r--r--shell/cmdedit.c16
-rw-r--r--shell/hush.c4
-rw-r--r--shell/lash.c12
-rw-r--r--sysklogd/klogd.c9
-rw-r--r--sysklogd/syslogd.c23
-rw-r--r--util-linux/fbset.c13
-rw-r--r--util-linux/fdformat.c24
-rw-r--r--util-linux/freeramdisk.c9
-rw-r--r--util-linux/getopt.c12
-rw-r--r--util-linux/hexdump.c3
-rw-r--r--util-linux/mdev.c10
-rw-r--r--util-linux/mkfs_minix.c20
-rw-r--r--util-linux/mkswap.c2
-rw-r--r--util-linux/more.c23
-rw-r--r--util-linux/mount.c16
-rw-r--r--util-linux/nfsmount.c10
-rw-r--r--util-linux/readprofile.c31
-rw-r--r--util-linux/umount.c4
143 files changed, 710 insertions, 1720 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 @@
* 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 714dac077..a970aeb20 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 558e3cd48..0e5772062 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 48a1ac161..ce65e219a 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 bd6047e13..3a1d1cb61 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 6337e0c85..5d1ec302a 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 ae96ea375..657d4ab01 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 8f33e6e6c..7362da8c2 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 4627695e4..cabb4101b 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 28c743589..d405d0e1b 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 fb7e9ae8f..0c622f44a 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 3b70439a7..7b27c0250 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 6aae150e2..3ae8458dd 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 801293fd9..ca775c787 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 bb4b9db6b..fbd207ca1 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 012f355e2..68083e987 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;
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c
index 62313e77f..7c6633ae8 100644
--- a/console-tools/dumpkmap.c
+++ b/console-tools/dumpkmap.c
@@ -8,13 +8,6 @@
*
*/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/ioctl.h>
#include "busybox.h"
/* From <linux/kd.h> */
@@ -38,7 +31,7 @@ int dumpkmap_main(int argc, char **argv)
if (argc >= 2 && *argv[1] == '-')
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
write(1, magic, 7);
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index 2421cadcf..3d8588565 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -7,18 +7,8 @@
* Loads the console font, and possibly the corresponding screen map(s).
* (Adapted for busybox by Matej Vela.)
*/
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <sys/kd.h>
-#include <endian.h>
#include "busybox.h"
+#include <sys/kd.h>
enum{
PSF_MAGIC1 = 0x36,
@@ -47,7 +37,7 @@ int loadfont_main(int argc, char **argv)
if (argc != 1)
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
loadnewfont(fd);
return EXIT_SUCCESS;
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index 69d33bd95..ec55c3990 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -8,13 +8,6 @@
*
*/
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "busybox.h"
#define BINARY_KEYMAP_MAGIC "bkeymap"
@@ -43,7 +36,7 @@ int loadkmap_main(int argc, char **argv)
if (argc != 1)
bb_show_usage();
- fd = bb_xopen(CURRENT_VC, O_RDWR);
+ fd = xopen(CURRENT_VC, O_RDWR);
xread(0, buff, 7);
if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
diff --git a/console-tools/openvt.c b/console-tools/openvt.c
index 948dba767..0c0cef23c 100644
--- a/console-tools/openvt.c
+++ b/console-tools/openvt.c
@@ -40,7 +40,7 @@ int openvt_main(int argc, char **argv)
close(0); /* so that new vt becomes stdin */
/* and grab new one */
- fd = bb_xopen(vtname, O_RDWR);
+ fd = xopen(vtname, O_RDWR);
/* Reassign stdout and sterr */
dup2(fd, STDOUT_FILENO);
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c
index 79a4313f0..71fe928da 100644
--- a/console-tools/setconsole.c
+++ b/console-tools/setconsole.c
@@ -7,13 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <getopt.h> /* struct option */
-
#include "busybox.h"
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
@@ -47,7 +40,7 @@ int setconsole_main(int argc, char **argv)
device = CONSOLE_DEV;
}
- if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) {
+ if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
bb_perror_msg_and_die("TIOCCONS");
}
return EXIT_SUCCESS;
diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c
index 62a654777..6667eb622 100644
--- a/console-tools/setlogcons.c
+++ b/console-tools/setlogcons.c
@@ -9,10 +9,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
#include "busybox.h"
extern int setlogcons_main(int argc, char **argv)
@@ -28,7 +24,7 @@ extern int setlogcons_main(int argc, char **argv)
if (argc == 2)
arg.subarg = atoi(argv[1]);
- if (ioctl(bb_xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
+ if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
bb_perror_msg_and_die("TIOCLINUX");;
return 0;
diff --git a/coreutils/cal.c b/coreutils/cal.c
index 5d61b6ccf..9628459fe 100644
--- a/coreutils/cal.c
+++ b/coreutils/cal.c
@@ -17,20 +17,8 @@
* Major size reduction... over 50% (>1.5k) on i386.
*/
-#include <sys/types.h>
-#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
#include "busybox.h"
-#ifdef CONFIG_LOCALE_SUPPORT
-#include <locale.h>
-#endif
-
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
@@ -135,7 +123,7 @@ int cal_main(int argc, char **argv)
do {
zero_tm.tm_mon = i;
strftime(buf, sizeof(buf), "%B", &zero_tm);
- month_names[i] = bb_xstrdup(buf);
+ month_names[i] = xstrdup(buf);
if (i < 7) {
zero_tm.tm_wday = i;
diff --git a/coreutils/catv.c b/coreutils/catv.c
index dd4aa44e3..e18203915 100644
--- a/coreutils/catv.c
+++ b/coreutils/catv.c
@@ -11,8 +11,6 @@
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
#include "busybox.h"
-#include <unistd.h>
-#include <fcntl.h>
int catv_main(int argc, char **argv)
{
@@ -28,7 +26,7 @@ int catv_main(int argc, char **argv)
// Read from stdin if there's nothing else to do.
fd = 0;
- if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
+ if (*argv && 0>(fd = xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
else for(;;) {
int i, res;
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 8ad680c02..62cfdc244 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -9,10 +9,6 @@
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
#include "busybox.h"
int chroot_main(int argc, char **argv)
@@ -25,7 +21,7 @@ int chroot_main(int argc, char **argv)
if (chroot(*argv)) {
bb_perror_msg_and_die("cannot change root directory to %s", *argv);
}
- bb_xchdir("/");
+ xchdir("/");
++argv;
if (argc == 2) {
diff --git a/coreutils/cksum.c b/coreutils/cksum.c
index 1396a5d5b..5849ddab2 100644
--- a/coreutils/cksum.c
+++ b/coreutils/cksum.c
@@ -6,14 +6,11 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
-#include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
#include "busybox.h"
int cksum_main(int argc, char **argv) {
- uint32_t *crc32_table = bb_crc32_filltable(1);
+ uint32_t *crc32_table = crc32_filltable(1);
FILE *fp;
uint32_t crc;
diff --git a/coreutils/cmp.c b/coreutils/cmp.c
index 016158bfe..a569eb3fe 100644
--- a/coreutils/cmp.c
+++ b/coreutils/cmp.c
@@ -21,9 +21,6 @@
* in the '-l' case.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
#include "busybox.h"
static FILE *cmp_xfopen_input(const char *filename)
@@ -105,12 +102,12 @@ int cmp_main(int argc, char **argv)
c1 = c2;
}
if (c1 == EOF) {
- bb_xferror(fp1, filename1);
+ xferror(fp1, filename1);
fmt = fmt_eof; /* Well, no error, so it must really be EOF. */
outfile = stderr;
/* There may have been output to stdout (option -l), so
* make sure we fflush before writing to stderr. */
- bb_xfflush_stdout();
+ xfflush_stdout();
}
if (opt_flags != OPT_s) {
if (opt_flags == OPT_l) {
@@ -129,8 +126,8 @@ int cmp_main(int argc, char **argv)
}
} while (c1 != EOF);
- bb_xferror(fp1, filename1);
- bb_xferror(fp2, filename2);
+ xferror(fp1, filename1);
+ xferror(fp2, filename2);
bb_fflush_stdout_and_exit(exit_val);
}
diff --git a/coreutils/comm.c b/coreutils/comm.c
index 8b9380175..7524a7b25 100644
--- a/coreutils/comm.c
+++ b/coreutils/comm.c
@@ -7,10 +7,6 @@
* 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 "busybox.h"
#define COMM_OPT_1 0x01
@@ -57,7 +53,7 @@ static void cmp_files(char **infiles)
int i;
for (i = 0; i < 2; ++i) {
- streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : bb_xfopen(infiles[i], "r"));
+ streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r"));
fgets(thisline[i], LINE_LEN, streams[i]);
}
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 3d6f7cd2d..052cd2902 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -8,14 +8,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h> // For FEATURE_DD_SIGNAL_HANDLING
#include "busybox.h"
static const struct suffix_mult dd_suffixes[] = {
@@ -110,7 +102,7 @@ int dd_main(int argc, char **argv)
else obuf = ibuf;
if (infile != NULL) {
- ifd = bb_xopen(infile, O_RDONLY);
+ ifd = xopen(infile, O_RDONLY);
} else {
ifd = STDIN_FILENO;
infile = bb_msg_standard_input;
@@ -123,7 +115,7 @@ int dd_main(int argc, char **argv)
oflag |= O_TRUNC;
}
- ofd = bb_xopen3(outfile, oflag, 0666);
+ ofd = xopen3(outfile, oflag, 0666);
if (seek && trunc_flag) {
if (ftruncate(ofd, seek * obs) < 0) {
diff --git a/coreutils/diff.c b/coreutils/diff.c
index 368efd383..22c157412 100644
--- a/coreutils/diff.c
+++ b/coreutils/diff.c
@@ -12,23 +12,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <time.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include <stddef.h>
-#include <paths.h>
-#include <dirent.h>
#include "busybox.h"
#define FSIZE_MAX 32768
@@ -917,21 +900,21 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
goto closem;
if (flags & D_EMPTY1)
- f1 = bb_xfopen(bb_dev_null, "r");
+ f1 = xfopen(bb_dev_null, "r");
else {
if (strcmp(file1, "-") == 0)
f1 = stdin;
else
- f1 = bb_xfopen(file1, "r");
+ f1 = xfopen(file1, "r");
}
if (flags & D_EMPTY2)
- f2 = bb_xfopen(bb_dev_null, "r");
+ f2 = xfopen(bb_dev_null, "r");
else {
if (strcmp(file2, "-") == 0)
f2 = stdin;
else
- f2 = bb_xfopen(file2, "r");
+ f2 = xfopen(file2, "r");
}
if ((i = files_differ(f1, f2, flags)) == 0)
@@ -1004,19 +987,19 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
int flags = D_HEADER;
int val;
- char *fullpath1 = bb_xasprintf("%s/%s", dir1, path1);
- char *fullpath2 = bb_xasprintf("%s/%s", dir2, path2);
+ char *fullpath1 = xasprintf("%s/%s", dir1, path1);
+ char *fullpath2 = xasprintf("%s/%s", dir2, path2);
if (stat(fullpath1, &stb1) != 0) {
flags |= D_EMPTY1;
memset(&stb1, 0, sizeof(stb1));
- fullpath1 = bb_xasprintf("%s/%s", dir1, path2);
+ fullpath1 = xasprintf("%s/%s", dir1, path2);
}
if (stat(fullpath2, &stb2) != 0) {
flags |= D_EMPTY2;
memset(&stb2, 0, sizeof(stb2));
stb2.st_mode = stb1.st_mode;
- fullpath2 = bb_xasprintf("%s/%s", dir2, path1);
+ fullpath2 = xasprintf("%s/%s", dir2, path1);
}
if (stb1.st_mode == 0)
@@ -1051,7 +1034,7 @@ static int add_to_dirlist(const char *filename,
{
dl_count++;
dl = xrealloc(dl, dl_count * sizeof(char *));
- dl[dl_count - 1] = bb_xstrdup(filename);
+ dl[dl_count - 1] = xstrdup(filename);
if (cmd_flags & FLAG_r) {
int *pp = (int *) userdata;
int path_len = *pp + 1;
@@ -1077,7 +1060,7 @@ static char **get_dir(char *path)
int path_len = strlen(path);
void *userdata = &path_len;
- /* Reset dl_count - there's no need to free dl as bb_xrealloc does
+ /* Reset dl_count - there's no need to free dl as xrealloc does
* the job nicely. */
dl_count = 0;
@@ -1089,7 +1072,7 @@ static char **get_dir(char *path)
DIR *dp;
struct dirent *ep;
- dp = bb_opendir(path);
+ dp = warn_opendir(path);
while ((ep = readdir(dp))) {
if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
continue;
@@ -1104,7 +1087,7 @@ static char **get_dir(char *path)
/* Copy dl so that we can return it. */
retval = xmalloc(dl_count * sizeof(char *));
for (i = 0; i < dl_count; i++)
- retval[i] = bb_xstrdup(dl[i]);
+ retval[i] = xstrdup(dl[i]);
return retval;
}
diff --git a/coreutils/dos2unix.c b/coreutils/dos2unix.c
index 5bf16e5af..19f1a3257 100644
--- a/coreutils/dos2unix.c
+++ b/coreutils/dos2unix.c
@@ -12,10 +12,6 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <string.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <fcntl.h>
#include "busybox.h"
enum ConvType {
@@ -30,7 +26,7 @@ static int convert(char *fn)
int i;
if (fn != NULL) {
- in = bb_xfopen(fn, "rw");
+ in = xfopen(fn, "rw");
/*
The file is then created with mode read/write and
permissions 0666 for glibc 2.0.6 and earlier or
diff --git a/coreutils/expr.c b/coreutils/expr.c
index 725196039..0a1baa19d 100644
--- a/coreutils/expr.c
+++ b/coreutils/expr.c
@@ -25,14 +25,8 @@
/* no getopt needed */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <regex.h>
-#include <sys/types.h>
-#include <errno.h>
#include "busybox.h"
-
+#include "xregex.h"
/* The kinds of value we can have. */
enum valtype {
@@ -116,9 +110,9 @@ static VALUE *str_value (char *s)
{
VALUE *v;
- v = xmalloc (sizeof(VALUE));
+ v = xmalloc(sizeof(VALUE));
v->type = string;
- v->u.s = bb_xstrdup (s);
+ v->u.s = xstrdup(s);
return v;
}
@@ -148,7 +142,7 @@ static int null (VALUE *v)
static void tostring (VALUE *v)
{
if (v->type == integer) {
- v->u.s = bb_xasprintf ("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
+ v->u.s = xasprintf("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
v->type = string;
}
}
@@ -366,7 +360,7 @@ static VALUE *eval6 (void)
else {
v = xmalloc (sizeof(VALUE));
v->type = string;
- v->u.s = bb_xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
+ v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
}
freev (l);
freev (i1);
diff --git a/coreutils/fold.c b/coreutils/fold.c
index 665b93e6e..aff7bb1d9 100644
--- a/coreutils/fold.c
+++ b/coreutils/fold.c
@@ -10,13 +10,6 @@
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
#include "busybox.h"
static unsigned long flags;
@@ -61,7 +54,7 @@ int fold_main(int argc, char **argv)
if (*a == '-' && !a[1])
break;
if (isdigit(*a)) {
- argv[i] = bb_xasprintf("-w%s", a);
+ argv[i] = xasprintf("-w%s", a);
}
}
}
diff --git a/coreutils/head.c b/coreutils/head.c
index 184e8161c..e961ca6b6 100644
--- a/coreutils/head.c
+++ b/coreutils/head.c
@@ -11,11 +11,6 @@
/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <ctype.h>
-#include <unistd.h>
#include "busybox.h"
static const char head_opts[] =
@@ -137,7 +132,7 @@ int head_main(int argc, char **argv)
bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
retval = EXIT_FAILURE;
}
- bb_xferror_stdout();
+ xferror_stdout();
}
fmt = header_fmt_str;
} while (*++argv);
diff --git a/coreutils/ln.c b/coreutils/ln.c
index 54ced0b89..df183581e 100644
--- a/coreutils/ln.c
+++ b/coreutils/ln.c
@@ -11,10 +11,6 @@
/* BB_AUDIT GNU options missing: -d, -F, -i, and -v. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
#include "busybox.h"
#define LN_SYMLINK 1
@@ -45,7 +41,7 @@ int ln_main(int argc, char **argv)
if (argc == optind + 1) {
*--argv = last;
- last = bb_get_last_path_component(bb_xstrdup(last));
+ last = bb_get_last_path_component(xstrdup(last));
}
do {
@@ -55,7 +51,7 @@ int ln_main(int argc, char **argv)
if (is_directory(src,
(flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
NULL)) {
- src_name = bb_xstrdup(*argv);
+ src_name = xstrdup(*argv);
src = concat_path_file(src, bb_get_last_path_component(src_name));
free(src_name);
src_name = src;
@@ -69,7 +65,7 @@ int ln_main(int argc, char **argv)
if (flag & LN_BACKUP) {
char *backup;
- backup = bb_xasprintf("%s%s", src, suffix);
+ backup = xasprintf("%s%s", src, suffix);
if (rename(src, backup) < 0 && errno != ENOENT) {
bb_perror_msg("%s", src);
status = EXIT_FAILURE;
diff --git a/coreutils/ls.c b/coreutils/ls.c
index de8405dab..6b9fbbfc9 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -37,15 +37,7 @@ enum {
/************************************************************************/
#include "busybox.h"
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <getopt.h> /* struct option */
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h> /* major() and minor() */
-#include <time.h>
+#include <getopt.h>
/* what is the overall style of the listing */
#define STYLE_COLUMNS (1U<<21) /* fill columns */
@@ -535,7 +527,7 @@ static struct dnode **list_dir(const char *path)
dn = NULL;
nfiles = 0;
- dir = bb_opendir(path);
+ dir = warn_opendir(path);
if (dir == NULL) {
status = EXIT_FAILURE;
return (NULL); /* could not open the dir */
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index aea43ff8c..49766a925 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -6,14 +6,6 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <fcntl.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
#include "busybox.h"
typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t;
@@ -129,7 +121,7 @@ static int hash_files(int argc, char **argv, hash_algo_t hash_algo)
if (strcmp(file_ptr, "-") == 0) {
pre_computed_stream = stdin;
} else {
- pre_computed_stream = bb_xfopen(file_ptr, "r");
+ pre_computed_stream = xfopen(file_ptr, "r");
}
while ((line = bb_get_chomped_line_from_file(pre_computed_stream)) != NULL) {
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index 41c4b779c..86d788683 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -9,9 +9,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <signal.h>
-#include <unistd.h>
#include "busybox.h"
int nohup_main(int argc, char *argv[])
@@ -25,7 +22,7 @@ int nohup_main(int argc, char *argv[])
if (argc<2) bb_show_usage();
- nullfd = bb_xopen(bb_dev_null, O_WRONLY|O_APPEND);
+ nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
// If stdin is a tty, detach from it.
if (isatty(0)) dup2(nullfd, 0);
@@ -38,7 +35,7 @@ int nohup_main(int argc, char *argv[])
home = getenv("HOME");
if (home) {
home = concat_path_file(home, nohupout);
- bb_xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
+ xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
}
}
} else dup2(nullfd, 1);
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 3354385a4..195e13d13 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -12,13 +12,6 @@
* http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
*/
-#include <ctype.h>
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
#include "busybox.h"
static int global_flags;
@@ -104,7 +97,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
}
/* Make the copy */
if(end<start) end=start;
- str=bb_xstrndup(str+start,end-start);
+ str=xstrndup(str+start,end-start);
/* Handle -d */
if(flags&FLAG_d) {
for(start=end=0;str[end];end++)
@@ -222,7 +215,6 @@ static int compare_keys(const void *xarg, const void *yarg)
/* Perform fallback sort if necessary */
if(!retval && !(global_flags&FLAG_s))
retval=strcmp(*(char **)xarg, *(char **)yarg);
-//dprintf(2,"reverse=%d\n",flags&FLAG_r);
return ((flags&FLAG_r)?-1:1)*retval;
}
@@ -242,7 +234,7 @@ int sort_main(int argc, char **argv)
#ifdef CONFIG_FEATURE_SORT_BIG
case 'o':
if(outfile) bb_error_msg_and_die("Too many -o.");
- outfile=bb_xfopen(optarg,"w");
+ outfile=xfopen(optarg,"w");
break;
case 't':
if(key_separator || optarg[1])
@@ -289,7 +281,7 @@ int sort_main(int argc, char **argv)
/* Open input files and read data */
for(i=argv[optind] ? optind : optind-1;argv[i];i++) {
if(i<optind || (*argv[i]=='-' && !argv[i][1])) fp=stdin;
- else fp=bb_xfopen(argv[i],"r");
+ else fp=xfopen(argv[i],"r");
for(;;) {
line=GET_LINE(fp);
if(!line) break;
diff --git a/coreutils/stat.c b/coreutils/stat.c
index 7e39d5ecd..8e0121849 100644
--- a/coreutils/stat.c
+++ b/coreutils/stat.c
@@ -12,18 +12,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <pwd.h>
-#include <grp.h>
-#include <sys/vfs.h>
-#include <time.h>
-#include <getopt.h> /* optind */
-#include <sys/stat.h>
-#include <sys/statfs.h>
-#include <sys/statvfs.h>
-#include <string.h>
#include "busybox.h"
/* vars to control behavior */
@@ -321,7 +309,7 @@ static void print_it(char const *masterformat, char const *filename,
char *b;
/* create a working copy of the format string */
- char *format = bb_xstrdup(masterformat);
+ char *format = xstrdup(masterformat);
/* Add 2 to accommodate our conversion of the stat `%s' format string
* to the printf `%llu' one. */
diff --git a/coreutils/stty.c b/coreutils/stty.c
index b78368e7b..073de847b 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -21,31 +21,7 @@
*/
-//#define TEST
-
#include "busybox.h"
-#include <stddef.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-
-#include <sys/param.h>
-#include <unistd.h>
-
-#ifndef STDIN_FILENO
-# define STDIN_FILENO 0
-#endif
-
-#ifndef STDOUT_FILENO
-# define STDOUT_FILENO 1
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <fcntl.h>
#define STREQ(a, b) (strcmp ((a), (b)) == 0)
@@ -469,11 +445,7 @@ static const struct suffix_mult stty_suffixes[] = {
{NULL, 0 }
};
-#ifndef TEST
int stty_main(int argc, char **argv)
-#else
-int main(int argc, char **argv)
-#endif
{
struct termios mode;
void (*output_func)(struct termios *);
@@ -541,7 +513,7 @@ int main(int argc, char **argv)
device_name = file_name;
fclose(stdin);
- bb_xopen(device_name, O_RDONLY | O_NONBLOCK);
+ xopen(device_name, O_RDONLY | O_NONBLOCK);
if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1
|| fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
perror_on_device("%s: couldn't reset non-blocking mode");
@@ -1299,9 +1271,3 @@ static const char *visible(unsigned int ch)
*bpout = '\0';
return (const char *) buf;
}
-
-#ifdef TEST
-
-const char *bb_applet_name = "stty";
-
-#endif
diff --git a/coreutils/tee.c b/coreutils/tee.c
index 30496eefa..4d0e6ff85 100644
--- a/coreutils/tee.c
+++ b/coreutils/tee.c
@@ -10,10 +10,6 @@
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/tee.html */
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <unistd.h>
#include "busybox.h"
int tee_main(int argc, char **argv)
@@ -96,7 +92,7 @@ int tee_main(int argc, char **argv)
do { /* Now check for (input and) output errors. */
/* Checking ferror should be sufficient, but we may want to fclose.
* If we do, remember not to close stdin! */
- bb_xferror(*p, filenames[(int)(p - files)]);
+ xferror(*p, filenames[(int)(p - files)]);
} while (*++p);
bb_fflush_stdout_and_exit(retval);
diff --git a/coreutils/uniq.c b/coreutils/uniq.c
index 956c50796..26afc00f4 100644
--- a/coreutils/uniq.c
+++ b/coreutils/uniq.c
@@ -11,9 +11,6 @@
/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
#include "busybox.h"
-#include <string.h>
-#include <ctype.h>
-#include <unistd.h>
static const char uniq_opts[] = "f:s:" "cdu\0\1\2\4";
@@ -23,7 +20,7 @@ static FILE *xgetoptfile_uniq_s(char **argv, int read0write2)
if ((n = *argv) != NULL) {
if ((*n != '-') || n[1]) {
- return bb_xfopen(n, "r\0w" + read0write2);
+ return xfopen(n, "r\0w" + read0write2);
}
}
return (read0write2) ? stdout : stdin;
@@ -100,7 +97,7 @@ int uniq_main(int argc, char **argv)
}
} while (s1);
- bb_xferror(in, input_filename);
+ xferror(in, input_filename);
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
diff --git a/coreutils/uudecode.c b/coreutils/uudecode.c
index 06b2fc1c1..6050c0af7 100644
--- a/coreutils/uudecode.c
+++ b/coreutils/uudecode.c
@@ -12,11 +12,6 @@
*/
-#include <stdio.h>
-#include <errno.h>
-#include <getopt.h> /* optind */
-#include <string.h>
-#include <stdlib.h>
#include "busybox.h"
static int read_stduu(FILE *src_stream, FILE *dst_stream)
@@ -141,7 +136,7 @@ int uudecode_main(int argc, char **argv)
if (optind == argc) {
src_stream = stdin;
} else if (optind + 1 == argc) {
- src_stream = bb_xfopen(argv[optind], "r");
+ src_stream = xfopen(argv[optind], "r");
} else {
bb_show_usage();
}
@@ -174,7 +169,7 @@ int uudecode_main(int argc, char **argv)
if (strcmp(outname, "-") == 0) {
dst_stream = stdout;
} else {
- dst_stream = bb_xfopen(outname, "w");
+ dst_stream = xfopen(outname, "w");
chmod(outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO));
}
free(line);
diff --git a/coreutils/uuencode.c b/coreutils/uuencode.c
index fee408605..1449d9aeb 100644
--- a/coreutils/uuencode.c
+++ b/coreutils/uuencode.c
@@ -7,12 +7,7 @@
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+
#include "busybox.h"
/* Conversion table. for base 64 */
@@ -92,7 +87,7 @@ int uuencode_main(int argc, char **argv)
switch (argc - optind) {
case 2:
- src_stream = bb_xfopen(argv[optind], "r");
+ src_stream = xfopen(argv[optind], "r");
xstat(argv[optind], &stat_buf);
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
if (src_stream == stdout) {
@@ -128,7 +123,7 @@ int uuencode_main(int argc, char **argv)
}
bb_printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n");
- bb_xferror(src_stream, "source"); /* TODO - Fix this! */
+ xferror(src_stream, "source"); /* TODO - Fix this! */
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
diff --git a/coreutils/watch.c b/coreutils/watch.c
index b783d34de..c8b16b908 100644
--- a/coreutils/watch.c
+++ b/coreutils/watch.c
@@ -16,14 +16,6 @@
* reduced size.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-#include <assert.h>
-#include <unistd.h>
-#include <sys/wait.h>
#include "busybox.h"
int watch_main(int argc, char **argv)
@@ -62,7 +54,7 @@ int watch_main(int argc, char **argv)
printf("\033[H\033[J%s %s\n", header, thyme);
- waitpid(bb_xspawn(watched_argv),0,0);
+ waitpid(xspawn(watched_argv),0,0);
sleep(period);
}
}
diff --git a/debianutils/start_stop_daemon.c b/debianutils/start_stop_daemon.c
index 733fb4112..6f8fb2dc8 100644
--- a/debianutils/start_stop_daemon.c
+++ b/debianutils/start_stop_daemon.c
@@ -3,31 +3,22 @@
* Mini start-stop-daemon implementation(s) for busybox
*
* Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
- * public domain.
* Adapted for busybox David Kimdon <dwhedon@gordian.com>
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <getopt.h> /* struct option */
-#include "pwd_.h"
+#include <getopt.h>
static int signal_nr = 15;
static int user_id = -1;
static int quiet;
-static char *userspec = NULL;
-static char *chuid = NULL;
-static char *cmdname = NULL;
-static char *execname = NULL;
-static char *pidfile = NULL;
+static char *userspec;
+static char *chuid;
+static char *cmdname;
+static char *execname;
+static char *pidfile;
struct pid_list {
struct pid_list *next;
@@ -136,7 +127,7 @@ static void do_procinit(void)
return;
}
- procdir = bb_xopendir("/proc");
+ procdir = xopendir("/proc");
foundany = 0;
while ((entry = readdir(procdir)) != NULL) {
@@ -292,12 +283,12 @@ int start_stop_daemon_main(int argc, char **argv)
}
*--argv = startas;
if (opt & SSD_OPT_BACKGROUND) {
- bb_xdaemon(0, 0);
+ xdaemon(0, 0);
setsid();
}
if (opt & SSD_OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
- FILE *pidf = bb_xfopen(pidfile, "w");
+ FILE *pidf = xfopen(pidfile, "w");
pid_t pidt = getpid();
fprintf(pidf, "%d\n", pidt);
diff --git a/e2fsprogs/e2p/feature.c b/e2fsprogs/e2p/feature.c
index 602c2ff02..b45754f97 100644
--- a/e2fsprogs/e2p/feature.c
+++ b/e2fsprogs/e2p/feature.c
@@ -155,7 +155,7 @@ int e2p_edit_feature(const char *str, __u32 *compat_array, __u32 *ok_array)
unsigned int mask;
int compat_type;
- buf = bb_xstrdup(str);
+ buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;
diff --git a/e2fsprogs/e2p/mntopts.c b/e2fsprogs/e2p/mntopts.c
index 1ec3402f7..17c26c480 100644
--- a/e2fsprogs/e2p/mntopts.c
+++ b/e2fsprogs/e2p/mntopts.c
@@ -100,7 +100,7 @@ int e2p_edit_mntopts(const char *str, __u32 *mntopts, __u32 ok)
int neg;
unsigned int mask;
- buf = bb_xstrdup(str);
+ buf = xstrdup(str);
cp = buf;
while (cp && *cp) {
neg = 0;
diff --git a/e2fsprogs/e2p/ostype.c b/e2fsprogs/e2p/ostype.c
index d55f98bb2..0e111d408 100644
--- a/e2fsprogs/e2p/ostype.c
+++ b/e2fsprogs/e2p/ostype.c
@@ -33,7 +33,7 @@ char *e2p_os2string(int os_type)
else
os = "(unknown os)";
- ret = bb_xstrdup(os);
+ ret = xstrdup(os);
return ret;
}
diff --git a/e2fsprogs/fsck.c b/e2fsprogs/fsck.c
index 3290d00ef..afb6f0c7d 100644
--- a/e2fsprogs/fsck.c
+++ b/e2fsprogs/fsck.c
@@ -129,7 +129,7 @@ static char *base_device(const char *device)
int len;
#endif
- cp = str = bb_xstrdup(device);
+ cp = str = xstrdup(device);
/* Skip over /dev/; if it's not present, give up. */
if (strncmp(cp, "/dev/", 5) != 0)
@@ -544,7 +544,7 @@ static char *find_fsck(char *type)
tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
- s = bb_xasprintf(tpl, s, type);
+ s = xasprintf(tpl, s, type);
if (stat(s, &st) == 0) break;
free(s);
}
@@ -583,7 +583,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
return ENOMEM;
memset(inst, 0, sizeof(struct fsck_instance));
- prog = bb_xasprintf("fsck.%s", type);
+ prog = xasprintf("fsck.%s", type);
argv[0] = prog;
argc = 1;
diff --git a/e2fsprogs/mke2fs.c b/e2fsprogs/mke2fs.c
index f1e40832d..ea6afb92c 100644
--- a/e2fsprogs/mke2fs.c
+++ b/e2fsprogs/mke2fs.c
@@ -226,7 +226,7 @@ static void read_bb_file(ext2_filsys fs, badblocks_list *bb_list,
FILE *f;
errcode_t retval;
- f = bb_xfopen(bad_blocks_file, "r");
+ f = xfopen(bad_blocks_file, "r");
retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
fclose (f);
mke2fs_error_msg_and_die(retval, "read bad blocks from list");
@@ -692,7 +692,7 @@ static void parse_extended_opts(struct ext2_super_block *sb_param,
char *buf, *token, *next, *p, *arg;
int r_usage = 0;
- buf = bb_xstrdup(opts);
+ buf = xstrdup(opts);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
diff --git a/e2fsprogs/util.c b/e2fsprogs/util.c
index 6b72d0e0c..113ef9c8f 100644
--- a/e2fsprogs/util.c
+++ b/e2fsprogs/util.c
@@ -111,7 +111,7 @@ void parse_journal_opts(char **journal_device, int *journal_flags,
{
char *buf, *token, *next, *p, *arg;
int journal_usage = 0;
- buf = bb_xstrdup(opts);
+ buf = xstrdup(opts);
for (token = buf; token && *token; token = next) {
p = strchr(token, ',');
next = 0;
@@ -264,7 +264,7 @@ char *e2fs_set_sbin_path(void)
/* Update our PATH to include /sbin */
#define PATH_SET "/sbin"
if (oldpath)
- oldpath = bb_xasprintf("%s:%s", PATH_SET, oldpath);
+ oldpath = xasprintf("%s:%s", PATH_SET, oldpath);
else
oldpath = PATH_SET;
putenv (oldpath);
diff --git a/editors/awk.c b/editors/awk.c
index 16c871f8c..5d43e1d9e 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -7,19 +7,9 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <strings.h>
-#include <time.h>
-#include <math.h>
-#include <ctype.h>
-#include <getopt.h>
-
-#include "xregex.h"
#include "busybox.h"
+#include "xregex.h"
+#include <math.h>
#define MAXVARFMT 240
@@ -610,7 +600,7 @@ static inline int isalnum_(int c)
static FILE *afopen(const char *path, const char *mode)
{
- return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode);
+ return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
}
/* -------- working with variables (set/get/copy/etc) -------- */
@@ -672,7 +662,7 @@ static var *setvar_p(var *v, char *value)
/* same as setvar_p but make a copy of string */
static var *setvar_s(var *v, const char *value)
{
- return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL);
+ return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
}
/* same as setvar_s but set USER flag */
@@ -709,7 +699,7 @@ static char *getvar_s(var *v)
/* if v is numeric and has no cached string, convert it to string */
if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
- v->string = bb_xstrdup(buf);
+ v->string = xstrdup(buf);
v->type |= VF_CACHED;
}
return (v->string == NULL) ? "" : v->string;
@@ -744,7 +734,7 @@ static var *copyvar(var *dest, const var *src)
dest->type |= (src->type & ~VF_DONTTOUCH);
dest->number = src->number;
if (src->string)
- dest->string = bb_xstrdup(src->string);
+ dest->string = xstrdup(src->string);
}
handle_special(dest);
return dest;
@@ -1144,7 +1134,7 @@ static node *chain_node(uint32_t info)
if (seq->programname != programname) {
seq->programname = programname;
n = chain_node(OC_NEWSOURCE);
- n->l.s = bb_xstrdup(programname);
+ n->l.s = xstrdup(programname);
}
n = seq->last;
@@ -1433,7 +1423,7 @@ static int awk_split(char *s, node *spl, char **slist)
regmatch_t pmatch[2];
/* in worst case, each char would be a separate field */
- *slist = s1 = bb_xstrndup(s, strlen(s) * 2 + 3);
+ *slist = s1 = xstrndup(s, strlen(s) * 2 + 3);
c[0] = c[1] = (char)spl->info;
c[2] = c[3] = '\0';
@@ -1747,7 +1737,7 @@ static char *awk_printf(node *n)
var *v, *arg;
v = nvalloc(1);
- fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v)));
+ fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
i = 0;
while (*f) {
@@ -1941,7 +1931,7 @@ static var *exec_builtin(node *op, var *res)
case B_up:
to_xxx = toupper;
lo_cont:
- s1 = s = bb_xstrdup(as[0]);
+ s1 = s = xstrdup(as[0]);
while (*s1) {
*s1 = (*to_xxx)(*s1);
s1++;
@@ -2118,7 +2108,7 @@ static var *evaluate(node *op, var *res)
bb_perror_msg_and_die("popen");
X.rsm->is_pipe = 1;
} else {
- X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a");
+ X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
}
}
X.F = X.rsm->F;
@@ -2272,7 +2262,7 @@ re_cont:
X.rsm->F = popen(L.s, "r");
X.rsm->is_pipe = TRUE;
} else {
- X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */
+ X.rsm->F = fopen(L.s, "r"); /* not xfopen! */
}
}
} else {
@@ -2564,7 +2554,7 @@ static int is_assignment(const char *expr)
{
char *exprc, *s, *s0, *s1;
- exprc = bb_xstrdup(expr);
+ exprc = xstrdup(expr);
if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
free(exprc);
return FALSE;
@@ -2659,7 +2649,7 @@ int awk_main(int argc, char **argv)
}
for (envp=environ; *envp; envp++) {
- s = bb_xstrdup(*envp);
+ s = xstrdup(*envp);
s1 = strchr(s, '=');
if (!s1) {
goto keep_going;
diff --git a/editors/patch.c b/editors/patch.c
index 337d1bbad..a710d8224 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -67,7 +67,7 @@ static char *extract_filename(char *line, int patch_level)
filename_start_ptr = temp + 1;
}
- return(bb_xstrdup(filename_start_ptr));
+ return(xstrdup(filename_start_ptr));
}
static int file_doesnt_exist(const char *filename)
@@ -89,7 +89,7 @@ int patch_main(int argc, char **argv)
if (ret & 1)
patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX);
if (ret & 2) {
- patch_file = bb_xfopen(i, "r");
+ patch_file = xfopen(i, "r");
} else {
patch_file = stdin;
}
@@ -140,7 +140,7 @@ int patch_main(int argc, char **argv)
bb_make_directory(new_filename, -1, FILEUTILS_RECUR);
*line_ptr = '/';
}
- dst_stream = bb_xfopen(new_filename, "w+");
+ dst_stream = xfopen(new_filename, "w+");
backup_filename = NULL;
} else {
backup_filename = xmalloc(strlen(new_filename) + 6);
@@ -150,16 +150,16 @@ int patch_main(int argc, char **argv)
bb_perror_msg_and_die("Couldnt create file %s",
backup_filename);
}
- dst_stream = bb_xfopen(new_filename, "w");
+ dst_stream = xfopen(new_filename, "w");
}
if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
src_stream = NULL;
} else {
if (strcmp(original_filename, new_filename) == 0) {
- src_stream = bb_xfopen(backup_filename, "r");
+ src_stream = xfopen(backup_filename, "r");
} else {
- src_stream = bb_xfopen(original_filename, "r");
+ src_stream = xfopen(original_filename, "r");
}
}
diff --git a/editors/sed.c b/editors/sed.c
index 89b8dd72c..d5cf3f219 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -132,7 +132,7 @@ void sed_free_and_close_stuff(void)
sed_cmd_t *sed_cmd_next = sed_cmd->next;
if(sed_cmd->file)
- bb_xprint_and_close_file(sed_cmd->file);
+ xprint_and_close_file(sed_cmd->file);
if (sed_cmd->beg_match) {
regfree(sed_cmd->beg_match);
@@ -300,7 +300,7 @@ static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval)
/* If lines glued together, put backslash back. */
if(filecmdstr[idx]=='\n') hack=1;
if(idx==start) bb_error_msg_and_die("Empty filename");
- *retval = bb_xstrndup(filecmdstr+start, idx-start+hack+1);
+ *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
if(hack) *(idx+*retval)='\\';
return idx;
@@ -406,7 +406,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
} else if(isspace(*cmdstr)) cmdstr++;
else break;
}
- sed_cmd->string = bb_xstrdup(cmdstr);
+ sed_cmd->string = xstrdup(cmdstr);
parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0);
cmdstr += strlen(cmdstr);
/* handle file cmds: (r)ead */
@@ -415,7 +415,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
bb_error_msg_and_die("Command only uses one address");
cmdstr += parse_file_cmd(sed_cmd, cmdstr, &sed_cmd->string);
if(sed_cmd->cmd=='w')
- sed_cmd->file=bb_xfopen(sed_cmd->string,"w");
+ sed_cmd->file=xfopen(sed_cmd->string,"w");
/* handle branch commands */
} else if (strchr(":btT", sed_cmd->cmd)) {
int length;
@@ -423,7 +423,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
while(isspace(*cmdstr)) cmdstr++;
length = strcspn(cmdstr, semicolon_whitespace);
if (length) {
- sed_cmd->string = bb_xstrndup(cmdstr, length);
+ sed_cmd->string = xstrndup(cmdstr, length);
cmdstr += length;
}
}
@@ -466,7 +466,7 @@ static void add_cmd(char *cmdstr)
/* Append this line to any unfinished line from last time. */
if (bbg.add_cmd_line) {
- cmdstr = bb_xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
+ cmdstr = xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
free(bbg.add_cmd_line);
bbg.add_cmd_line = cmdstr;
}
@@ -474,7 +474,7 @@ static void add_cmd(char *cmdstr)
/* If this line ends with backslash, request next line. */
temp=strlen(cmdstr);
if(temp && cmdstr[temp-1]=='\\') {
- if (!bbg.add_cmd_line) bbg.add_cmd_line = bb_xstrdup(cmdstr);
+ if (!bbg.add_cmd_line) bbg.add_cmd_line = xstrdup(cmdstr);
bbg.add_cmd_line[temp-1] = 0;
return;
}
@@ -671,7 +671,7 @@ static sed_cmd_t *branch_to(char *label)
static void append(char *s)
{
- llist_add_to_end(&bbg.append_head, bb_xstrdup(s));
+ llist_add_to_end(&bbg.append_head, xstrdup(s));
}
static void flush_append(void)
@@ -852,7 +852,7 @@ restart:
char *tmp = strchr(pattern_space,'\n');
if(tmp) {
- tmp=bb_xstrdup(tmp+1);
+ tmp=xstrdup(tmp+1);
free(pattern_space);
pattern_space=tmp;
goto restart;
@@ -907,7 +907,7 @@ restart:
while ((line = bb_get_chomped_line_from_file(rfile))
!= NULL)
append(line);
- bb_xprint_and_close_file(rfile);
+ xprint_and_close_file(rfile);
}
break;
@@ -996,7 +996,7 @@ restart:
}
case 'g': /* Replace pattern space with hold space */
free(pattern_space);
- pattern_space = bb_xstrdup(bbg.hold_space ? bbg.hold_space : "");
+ pattern_space = xstrdup(bbg.hold_space ? bbg.hold_space : "");
break;
case 'G': /* Append newline and hold space to pattern space */
{
@@ -1019,7 +1019,7 @@ restart:
}
case 'h': /* Replace hold space with pattern space */
free(bbg.hold_space);
- bbg.hold_space = bb_xstrdup(pattern_space);
+ bbg.hold_space = xstrdup(pattern_space);
break;
case 'H': /* Append newline and pattern space to hold space */
{
@@ -1072,7 +1072,7 @@ discard_line:
static void add_cmd_block(char *cmdstr)
{
int go=1;
- char *temp=bb_xstrdup(cmdstr),*temp2=temp;
+ char *temp=xstrdup(cmdstr),*temp2=temp;
while(go) {
int len=strcspn(temp2,"\n");
@@ -1121,14 +1121,14 @@ int sed_main(int argc, char **argv)
FILE *cmdfile;
char *line;
- cmdfile = bb_xfopen(optarg, "r");
+ cmdfile = xfopen(optarg, "r");
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
add_cmd(line);
getpat=0;
free(line);
}
- bb_xprint_and_close_file(cmdfile);
+ xprint_and_close_file(cmdfile);
break;
}
@@ -1172,7 +1172,7 @@ int sed_main(int argc, char **argv)
struct stat statbuf;
int nonstdoutfd;
- bbg.outname=bb_xstrndup(argv[i],strlen(argv[i])+6);
+ bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
strcat(bbg.outname,"XXXXXX");
if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
bb_error_msg_and_die("no temp file");
diff --git a/editors/vi.c b/editors/vi.c
index e0047e49e..593dc8520 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -23,18 +23,6 @@
#include "busybox.h"
-#include <string.h>
-#include <strings.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <time.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <setjmp.h>
-#include <regex.h>
-#include <ctype.h>
-#include <errno.h>
-#define vi_Version BB_VER " " BB_BT
#ifdef CONFIG_LOCALE_SUPPORT
#define Isprint(c) isprint((c))
@@ -349,7 +337,7 @@ int vi_main(int argc, char **argv)
for (; optind < argc; optind++) {
editing = 1; // 0=exit, 1=one file, 2+ =many files
free(cfn);
- cfn = (Byte *) bb_xstrdup(argv[optind]);
+ cfn = (Byte *) xstrdup(argv[optind]);
edit_file(cfn);
}
}
@@ -522,7 +510,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
*q++ = *p;
*q = '\0';
}
- pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern
+ pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
if (*p == '/')
p++;
q = char_search(dot, pat, FORWARD, FULL);
@@ -736,7 +724,7 @@ static void colon(Byte * buf)
// There is a read-able regular file
// make this the current file
- q = (Byte *) bb_xstrdup((char *) fn); // save the cfn
+ q = (Byte *) xstrdup((char *) fn); // save the cfn
free(cfn); // free the old name
cfn = q; // remember new cfn
@@ -788,7 +776,7 @@ static void colon(Byte * buf)
if (strlen((char *) args) > 0) {
// user wants a new filename
free(cfn);
- cfn = (Byte *) bb_xstrdup((char *) args);
+ cfn = (Byte *) xstrdup((char *) args);
} else {
// user wants file status info
last_status_cksum = 0; // force status update
@@ -996,7 +984,7 @@ static void colon(Byte * buf)
}
#endif /* CONFIG_FEATURE_VI_SEARCH */
} else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version
- psb("%s", vi_Version);
+ psb("%s", BB_VER " " BB_BT);
} else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file
|| strncasecmp((char *) cmd, "wq", i) == 0
|| strncasecmp((char *) cmd, "wn", i) == 0
@@ -2313,7 +2301,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
}
refresh(FALSE);
free(obufp);
- obufp = (Byte *) bb_xstrdup((char *) buf);
+ obufp = (Byte *) xstrdup((char *) buf);
return (obufp);
}
@@ -3199,7 +3187,7 @@ key_cmd_mode:
// Stuff the last_modifying_cmd back into stdin
// and let it be re-executed.
if (last_modifying_cmd != 0) {
- ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd);
+ ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
}
break;
#endif /* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3214,7 +3202,7 @@ key_cmd_mode:
if (strlen((char *) q) > 1) { // new pat- save it and find
// there is a new pat
free(last_search_pattern);
- last_search_pattern = (Byte *) bb_xstrdup((char *) q);
+ last_search_pattern = (Byte *) xstrdup((char *) q);
goto dc3; // now find the pattern
}
// user changed mind and erased the "/"- do nothing
diff --git a/findutils/find.c b/findutils/find.c
index 1e15e8899..aa915fa0f 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -11,14 +11,7 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <string.h>
-#include <stdlib.h>
#include <fnmatch.h>
-#include <time.h>
-#include <ctype.h>
static char *pattern;
#ifdef CONFIG_FEATURE_FIND_PRINT0
@@ -138,8 +131,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
int i;
char *cmd_string = "";
for (i = 0; i < num_matches; i++)
- cmd_string = bb_xasprintf("%s%s%s", cmd_string, exec_str[i], fileName);
- cmd_string = bb_xasprintf("%s%s", cmd_string, exec_str[num_matches]);
+ cmd_string = xasprintf("%s%s%s", cmd_string, exec_str[i], fileName);
+ cmd_string = xasprintf("%s%s", cmd_string, exec_str[num_matches]);
system(cmd_string);
goto no_match;
}
@@ -300,7 +293,7 @@ int find_main(int argc, char **argv)
bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
if (*argv[i] == ';')
break;
- cmd_string = bb_xasprintf("%s %s", cmd_string, argv[i]);
+ cmd_string = xasprintf("%s %s", cmd_string, argv[i]);
}
if (*cmd_string == 0)
@@ -311,10 +304,10 @@ int find_main(int argc, char **argv)
while ((b_pos = strstr(cmd_string, "{}") - cmd_string), (b_pos >= 0)) {
num_matches++;
exec_str = xrealloc(exec_str, (num_matches + 1) * sizeof(char *));
- exec_str[num_matches - 1] = bb_xstrndup(cmd_string, b_pos);
+ exec_str[num_matches - 1] = xstrndup(cmd_string, b_pos);
cmd_string += b_pos + 2;
}
- exec_str[num_matches] = bb_xstrdup(cmd_string);
+ exec_str[num_matches] = xstrdup(cmd_string);
exec_opt = 1;
#endif
} else
diff --git a/findutils/grep.c b/findutils/grep.c
index ecb1d0457..b53bf490a 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -17,11 +17,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <string.h>
-#include <errno.h>
#include "xregex.h"
@@ -203,7 +198,7 @@ static int grep_file(FILE *file)
/* Add the line to the circular 'before' buffer */
if(lines_before) {
free(before_buf[curpos]);
- before_buf[curpos] = bb_xstrdup(line);
+ before_buf[curpos] = xstrdup(line);
curpos = (curpos + 1) % lines_before;
}
}
@@ -271,7 +266,7 @@ static void load_regexes_from_file(llist_t *fopt)
fopt = cur->link;
free(cur);
- f = bb_xfopen(ffile, "r");
+ f = xfopen(ffile, "r");
while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
llist_add_to(&pattern_head,
new_grep_list_data(line, PATTERN_MEM_A));
diff --git a/findutils/xargs.c b/findutils/xargs.c
index c3a892695..e46708303 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -18,15 +18,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
/* COMPAT: SYSV version defaults size (and has a max value of) to 470.
We try to make it as large as possible. */
@@ -300,7 +291,7 @@ static int xargs_ask_confirmation(void)
int c, savec;
if (!tty_stream) {
- tty_stream = bb_xfopen(CURRENT_TTY, "r");
+ tty_stream = xfopen(CURRENT_TTY, "r");
/* pranoidal security by vodz */
fcntl(fileno(tty_stream), F_SETFD, FD_CLOEXEC);
}
diff --git a/include/libbb.h b/include/libbb.h
index ddf965fbf..5b2977fce 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -19,7 +19,9 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <malloc.h>
#include <netdb.h>
+#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@ -27,18 +29,26 @@
#include <string.h>
#include <strings.h>
#include <sys/ioctl.h>
+#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/statfs.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
+#include <time.h>
#include <unistd.h>
+#include <utime.h>
#ifdef CONFIG_SELINUX
#include <selinux/selinux.h>
#endif
+#ifdef CONFIG_LOCALE_SUPPORT
+#include <locale.h>
+#endif
+
#include "pwd_.h"
#include "grp_.h"
#include "shadow_.h"
@@ -127,8 +137,8 @@ extern int bb_test(int argc, char** argv);
extern const char *bb_mode_string(int mode);
extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
-extern DIR *bb_opendir(const char *path);
-extern DIR *bb_xopendir(const char *path);
+extern DIR *warn_opendir(const char *path);
+extern DIR *xopendir(const char *path);
extern int remove_file(const char *path, int flags);
extern int copy_file(const char *source, const char *dest, int flags);
@@ -161,26 +171,24 @@ extern char *bb_get_chomped_line_from_file(FILE *file);
extern char *bb_get_chunk_from_file(FILE *file, int *end);
extern int bb_copyfd_size(int fd1, int fd2, const off_t size);
extern int bb_copyfd_eof(int fd1, int fd2);
-extern void bb_xprint_and_close_file(FILE *file);
-extern int bb_xprint_file_by_name(const char *filename);
extern char bb_process_escape_sequence(const char **ptr);
extern char *bb_get_last_path_component(char *path);
extern FILE *bb_wfopen(const char *path, const char *mode);
extern FILE *bb_wfopen_input(const char *filename);
-extern FILE *bb_xfopen(const char *path, const char *mode);
+extern FILE *xfopen(const char *path, const char *mode);
extern int bb_fclose_nonstdin(FILE *f);
extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
extern void xstat(const char *filename, struct stat *buf);
-extern int bb_xsocket(int domain, int type, int protocol);
-extern pid_t bb_spawn(char **argv);
-extern pid_t bb_xspawn(char **argv);
+extern int xsocket(int domain, int type, int protocol);
+extern pid_t spawn(char **argv);
+extern pid_t xspawn(char **argv);
extern int wait4pid(int pid);
-extern void bb_xdaemon(int nochdir, int noclose);
-extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
-extern void bb_xlisten(int s, int backlog);
-extern void bb_xchdir(const char *path);
+extern void xdaemon(int nochdir, int noclose);
+extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
+extern void xlisten(int s, int backlog);
+extern void xchdir(const char *path);
extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
extern char *utoa(unsigned n);
extern void itoa_to_buf(int n, char *buf, unsigned buflen);
@@ -204,9 +212,9 @@ extern int bb_printf(const char * __restrict format, ...)
__attribute__ ((format (printf, 1, 2)));
//#warning rename to xferror_filename?
-extern void bb_xferror(FILE *fp, const char *fn);
-extern void bb_xferror_stdout(void);
-extern void bb_xfflush_stdout(void);
+extern void xferror(FILE *fp, const char *fn);
+extern void xferror_stdout(void);
+extern void xfflush_stdout(void);
extern void bb_warn_ignoring_args(int n);
@@ -224,8 +232,8 @@ extern void *xrealloc(void *old, size_t size);
extern void *xzalloc(size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
-extern char *bb_xstrdup (const char *s);
-extern char *bb_xstrndup (const char *s, int n);
+extern char *xstrdup (const char *s);
+extern char *xstrndup (const char *s, int n);
extern char *safe_strncpy(char *dst, const char *src, size_t size);
extern int safe_strtoi(char *arg, int* value);
extern int safe_strtod(char *arg, double* value);
@@ -321,7 +329,6 @@ char *concat_path_file(const char *path, const char *filename);
char *concat_subpath_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c);
-int read_package_field(const char *package_buffer, char **field_name, char **field_value);
//#warning yuk!
char *fgets_str(FILE *file, const char *terminating_string);
@@ -458,7 +465,8 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
-char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
+void xprint_and_close_file(FILE *file);
#define FAIL_DELAY 3
extern void bb_do_delay(int seconds);
@@ -476,8 +484,8 @@ extern int correct_password ( const struct passwd *pw );
extern char *pw_encrypt(const char *clear, const char *salt);
extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
-extern int bb_xopen(const char *pathname, int flags);
-extern int bb_xopen3(const char *pathname, int flags, int mode);
+extern int xopen(const char *pathname, int flags);
+extern int xopen3(const char *pathname, int flags, int mode);
extern void xread(int fd, void *buf, size_t count);
extern unsigned char xread_char(int fd);
extern void xlseek(int fd, off_t offset, int whence);
@@ -550,7 +558,7 @@ void md5_begin(md5_ctx_t *ctx);
void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
void *md5_end(void *resbuf, md5_ctx_t *ctx);
-extern uint32_t *bb_crc32_filltable (int endian);
+extern uint32_t *crc32_filltable (int endian);
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index cae7f99ed..4f688e77a 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -11,7 +11,7 @@ srcdir=$(top_srcdir)/libbb
LIBBB-n:=
LIBBB-y:= \
- bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \
+ ask_confirmation.c change_identity.c chomp.c \
compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
crc32.c create_icmp_socket.c create_icmp6_socket.c \
device_open.c dump.c error_msg.c error_msg_and_die.c \
@@ -22,15 +22,14 @@ LIBBB-y:= \
kernel_version.c last_char_is.c login.c \
make_directory.c md5.c mode_string.c mtab_file.c \
obscure.c parse_mode.c parse_number.c perror_msg.c \
- perror_msg_and_die.c print_file.c get_console.c \
+ perror_msg_and_die.c get_console.c \
process_escape_sequence.c procps.c qmodule.c \
- read_package_field.c recursive_action.c remove_file.c \
+ recursive_action.c remove_file.c \
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
- bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
@@ -97,18 +96,12 @@ LIBBB_MOBJ6:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ6))
$(LIBBB_MOBJ6):$(LIBBB_MSRC6)
$(compile.c) -DL_$(notdir $*)
-LIBBB_MSRC7:=$(srcdir)/opendir.c
-LIBBB_MOBJ7:=$(call get-file-subparts, ${LIBBB_MSRC7})
-LIBBB_MOBJ7:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ7))
-$(LIBBB_MOBJ7):$(LIBBB_MSRC7)
- $(compile.c) -DL_$(notdir $*)
-
# We need the names of the object files built from MSRC for the L_ defines
LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \
- $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) $(LIBBB_MOBJ7)
+ $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6)
LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \
- $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) $(LIBBB_MSRC7)
+ $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6)
LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC))
diff --git a/libbb/bb_asprintf.c b/libbb/bb_asprintf.c
deleted file mode 100644
index 2bef0b59d..000000000
--- a/libbb/bb_asprintf.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include "libbb.h"
-
-char *bb_xasprintf(const char *format, ...)
-{
- va_list p;
- int r;
- char *string_ptr;
-
-#ifdef HAVE_GNU_EXTENSIONS
- va_start(p, format);
- r = vasprintf(&string_ptr, format, p);
- va_end(p);
-#else
- va_start(p, format);
- r = vsnprintf(NULL, 0, format, p);
- va_end(p);
- string_ptr = xmalloc(r+1);
- va_start(p, format);
- r = vsnprintf(string_ptr, r+1, format, p);
- va_end(p);
-#endif
-
- if (r < 0) {
- bb_perror_msg_and_die("bb_xasprintf");
- }
- return string_ptr;
-}
diff --git a/libbb/bb_xbind.c b/libbb/bb_xbind.c
deleted file mode 100644
index b53f8239a..000000000
--- a/libbb/bb_xbind.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xbind.c - a bind() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
-{
- if (bind(sockfd, my_addr, addrlen))
- bb_perror_msg_and_die("bind");
-}
diff --git a/libbb/bb_xchdir.c b/libbb/bb_xchdir.c
deleted file mode 100644
index 2c2ff27cd..000000000
--- a/libbb/bb_xchdir.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xchdir.c - a chdir() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xchdir(const char *path)
-{
- if (chdir(path))
- bb_perror_msg_and_die("chdir(%s)", path);
-}
-
diff --git a/libbb/bb_xdaemon.c b/libbb/bb_xdaemon.c
deleted file mode 100644
index 218b5247f..000000000
--- a/libbb/bb_xdaemon.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xdaemon.c - a daemon() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <unistd.h>
-#include "libbb.h"
-
-#ifndef BB_NOMMU
-void bb_xdaemon(int nochdir, int noclose)
-{
- if (daemon(nochdir, noclose))
- bb_perror_msg_and_die("daemon");
-}
-#endif
diff --git a/libbb/bb_xlisten.c b/libbb/bb_xlisten.c
deleted file mode 100644
index e135d4836..000000000
--- a/libbb/bb_xlisten.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xlisten.c - a listen() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xlisten(int s, int backlog)
-{
- if (listen(s, backlog))
- bb_perror_msg_and_die("listen");
-}
diff --git a/libbb/bb_xsocket.c b/libbb/bb_xsocket.c
deleted file mode 100644
index c14dd7862..000000000
--- a/libbb/bb_xsocket.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xsocket.c - a socket() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-int bb_xsocket(int domain, int type, int protocol)
-{
- int r = socket(domain, type, protocol);
- if (r < 0)
- bb_perror_msg_and_die("socket");
- return r;
-}
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index 415b6a2fb..ef0d3282d 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -12,7 +12,6 @@
* not addition '/' if path name already have '/'
*/
-#include <string.h>
#include "libbb.h"
char *concat_path_file(const char *path, const char *filename)
@@ -24,5 +23,5 @@ char *concat_path_file(const char *path, const char *filename)
lc = last_char_is(path, '/');
while (*filename == '/')
filename++;
- return bb_xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
+ return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
}
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 38a2cb9c3..d2794e7d6 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -9,8 +9,6 @@
*/
#include "libbb.h"
-#include <utime.h>
-#include <errno.h>
int copy_file(const char *source, const char *dest, int flags)
{
@@ -77,7 +75,7 @@ int copy_file(const char *source, const char *dest, int flags)
}
/* Recursively copy files in SOURCE. */
- if ((dp = bb_opendir(source)) == NULL) {
+ if ((dp = opendir(source)) == NULL) {
status = -1;
goto preserve_status;
}
diff --git a/libbb/crc32.c b/libbb/crc32.c
index 03609952d..538a13622 100644
--- a/libbb/crc32.c
+++ b/libbb/crc32.c
@@ -14,11 +14,10 @@
* endian = 0: little-endian
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "libbb.h"
-uint32_t *bb_crc32_filltable (int endian) {
+uint32_t *crc32_filltable(int endian)
+{
uint32_t *crc_table = xmalloc(256 * sizeof(uint32_t));
uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320;
diff --git a/libbb/dump.c b/libbb/dump.c
index f1d5df2d6..28f745fb6 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -12,9 +12,6 @@
*/
#include "libbb.h"
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h> /* for isdigit() */
#include "dump.h"
enum _vflag bb_dump_vflag = FIRST;
@@ -232,7 +229,7 @@ static void rewrite(FS * fs)
*/
savech = *p2;
p1[1] = '\0';
- pr->fmt = bb_xstrdup(fmtp);
+ pr->fmt = xstrdup(fmtp);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 675f8d2f5..71b79b8d0 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -7,11 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <stdlib.h>
#include "libbb.h"
char *find_block_device(char *path)
@@ -28,7 +23,7 @@ char *find_block_device(char *path)
char devpath[PATH_MAX];
sprintf(devpath,"/dev/%s", entry->d_name);
if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
- retpath = bb_xstrdup(devpath);
+ retpath = xstrdup(devpath);
break;
}
}
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
index a57951305..19c96914d 100644
--- a/libbb/getopt_ulflags.c
+++ b/libbb/getopt_ulflags.c
@@ -7,11 +7,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <getopt.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
#include "libbb.h"
+#include <getopt.h>
/* Documentation
@@ -438,7 +435,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
#if defined(CONFIG_AR) || defined(CONFIG_TAR)
if((spec_flgs & FIRST_ARGV_IS_OPT)) {
if(argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
- argv[1] = bb_xasprintf("-%s", argv[1]);
+ argv[1] = xasprintf("-%s", argv[1]);
if(ENABLE_FEATURE_CLEAN_UP)
spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
}
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index feb0c42f3..75a03fda4 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -11,16 +11,6 @@
#include "libbb.h"
#include "inet_common.h"
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef DEBUG
-# include <resolv.h>
-#endif
-
const char bb_INET_default[] = "default";
@@ -174,7 +164,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
pn->addr = *s_in;
pn->next = INET_nn;
pn->host = host;
- pn->name = bb_xstrdup(name);
+ pn->name = xstrdup(name);
INET_nn = pn;
return (0);
diff --git a/libbb/loop.c b/libbb/loop.c
index 0b05cd75f..da41d1e76 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -8,13 +8,6 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <features.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "libbb.h"
/* For 2.6, use the cleaned up header to get the 64 bit API. */
@@ -59,7 +52,7 @@ char *query_loop(const char *device)
if ((fd = open(device, O_RDONLY)) < 0) return 0;
if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
- dev=bb_xasprintf("%ld %s", (long) loopinfo.lo_offset,
+ dev=xasprintf("%ld %s", (long) loopinfo.lo_offset,
(char *)loopinfo.lo_file_name);
close(fd);
diff --git a/libbb/obscure.c b/libbb/obscure.c
index 3353df949..9ac6bcd82 100644
--- a/libbb/obscure.c
+++ b/libbb/obscure.c
@@ -39,11 +39,6 @@
of crypt do not truncate passwords.
*/
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-#include <strings.h>
-
#include "libbb.h"
static int string_checker_helper(const char *p1, const char *p2) __attribute__ ((__pure__));
@@ -66,7 +61,7 @@ static int string_checker(const char *p1, const char *p2)
/* check string */
int ret = string_checker_helper(p1, p2);
/* Make our own copy */
- char *p = bb_xstrdup(p1);
+ char *p = xstrdup(p1);
/* reverse string */
size = strlen(p);
diff --git a/libbb/opendir.c b/libbb/opendir.c
deleted file mode 100644
index e284db0db..000000000
--- a/libbb/opendir.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * wrapper for opendir()
- *
- * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <dirent.h>
-#include "libbb.h"
-
-#ifdef L_bb_opendir
-DIR *bb_opendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg("unable to open `%s'", path);
- return NULL;
- }
- return dp;
-}
-#endif
-
-#ifdef L_bb_xopendir
-DIR *bb_xopendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg_and_die("unable to open `%s'", path);
- }
- return dp;
-}
-#endif
diff --git a/libbb/print_file.c b/libbb/print_file.c
deleted file mode 100644
index ea5d1d222..000000000
--- a/libbb/print_file.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xprint_and_close_file(FILE *file)
-{
- bb_xfflush_stdout();
- /* Note: Do not use STDOUT_FILENO here, as this is a lib routine
- * and the calling code may have reassigned stdout. */
- if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1) {
- /* bb_copyfd outputs any needed messages, so just die. */
- exit(bb_default_error_retval);
- }
- /* Note: Since we're reading, don't bother checking the return value
- * of fclose(). The only possible failure is EINTR which
- * should already have been taken care of. */
- fclose(file);
-}
-
-/* Returns:
- * 0 if successful
- * -1 if 'filename' does not exist or is a directory
- * exits with default error code if an error occurs
- */
-
-int bb_xprint_file_by_name(const char *filename)
-{
- FILE *f;
-
-#if 0
- /* This check shouldn't be necessary for linux, but is left
- * here disabled just in case. */
- struct stat statBuf;
-
- if(is_directory(filename, TRUE, &statBuf)) {
- bb_error_msg("%s: Is directory", filename);
- } else
-#endif
- if ((f = bb_wfopen(filename, "r")) != NULL) {
- bb_xprint_and_close_file(f);
- return 0;
- }
-
- return -1;
-}
diff --git a/libbb/procps.c b/libbb/procps.c
index 0d4877cb6..8fd5c1f86 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -51,7 +51,7 @@ procps_status_t * procps_scan(int save_user_arg0)
struct stat sb;
if (!dir) {
- dir = bb_xopendir("/proc");
+ dir = xopendir("/proc");
}
for (;;) {
if ((entry = readdir(dir)) == NULL) {
diff --git a/libbb/read_package_field.c b/libbb/read_package_field.c
deleted file mode 100644
index 9e5590347..000000000
--- a/libbb/read_package_field.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) many different people.
- * If you wrote this, please acknowledge your work.
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include "libbb.h"
-
-/*
- * 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
- */
-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 = bb_xstrndup(&package_buffer[offset_name_start], name_length);
- }
- if (value_length > 0) {
- *field_value = bb_xstrndup(&package_buffer[offset_value_start], value_length);
- } else {
- *field_value = NULL;
- }
- return(next_offset);
-}
-
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c
index a30addc4f..d491b781b 100644
--- a/libbb/recursive_action.c
+++ b/libbb/recursive_action.c
@@ -7,11 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <stdlib.h> /* free() */
#include "libbb.h"
#undef DEBUG_RECURS_ACTION
@@ -82,7 +77,7 @@ int recursive_action(const char *fileName,
} else if (status == SKIP)
return TRUE;
}
- dir = bb_opendir(fileName);
+ dir = opendir(fileName);
if (!dir) {
return FALSE;
}
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 2fa6596ee..92534a1c5 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -59,7 +59,7 @@ int remove_file(const char *path, int flags)
return 0;
}
- if ((dp = bb_opendir(path)) == NULL) {
+ if ((dp = opendir(path)) == NULL) {
return -1;
}
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index d5dc37b54..86cb0b056 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -82,10 +82,10 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
- args [0] = bb_get_last_path_component ( bb_xstrdup ( shell ));
+ args [0] = bb_get_last_path_component ( xstrdup ( shell ));
if ( loginshell )
- args [0] = bb_xasprintf ("-%s", args [0]);
+ args [0] = xasprintf ("-%s", args [0]);
if ( command ) {
args [argno++] = "-c";
diff --git a/libbb/simplify_path.c b/libbb/simplify_path.c
index 171798e60..b714c66b6 100644
--- a/libbb/simplify_path.c
+++ b/libbb/simplify_path.c
@@ -7,7 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdlib.h>
#include "libbb.h"
char *bb_simplify_path(const char *path)
@@ -15,7 +14,7 @@ char *bb_simplify_path(const char *path)
char *s, *start, *p;
if (path[0] == '/')
- start = bb_xstrdup(path);
+ start = xstrdup(path);
else {
s = xgetcwd(NULL);
start = concat_path_file(s, path);
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 39052b87b..ce1081d59 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -6,16 +6,6 @@
*
*/
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include "libbb.h"
/* Return network byte ordered port number for a service.
@@ -61,7 +51,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
int xconnect(struct sockaddr_in *s_addr)
{
- int s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ int s = xsocket(AF_INET, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
{
if (ENABLE_FEATURE_CLEAN_UP) close(s);
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 8562a4fcb..699d09c67 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -3,18 +3,12 @@
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2006 Rob Landley
+ * Copyright (C) 2006 Denis Vlasenko
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include "busybox.h"
#ifndef DMALLOC
@@ -59,7 +53,7 @@ void *xcalloc(size_t nmemb, size_t size)
#endif /* DMALLOC */
#ifdef L_xstrdup
-char * bb_xstrdup (const char *s)
+char * xstrdup (const char *s)
{
char *t;
@@ -76,12 +70,12 @@ char * bb_xstrdup (const char *s)
#endif
#ifdef L_xstrndup
-char * bb_xstrndup (const char *s, int n)
+char * xstrndup (const char *s, int n)
{
char *t;
if (ENABLE_DEBUG && s == NULL)
- bb_error_msg_and_die("bb_xstrndup bug");
+ bb_error_msg_and_die("xstrndup bug");
t = xmalloc(++n);
@@ -90,7 +84,7 @@ char * bb_xstrndup (const char *s, int n)
#endif
#ifdef L_xfopen
-FILE *bb_xfopen(const char *path, const char *mode)
+FILE *xfopen(const char *path, const char *mode)
{
FILE *fp;
if ((fp = fopen(path, mode)) == NULL)
@@ -100,14 +94,14 @@ FILE *bb_xfopen(const char *path, const char *mode)
#endif
#ifdef L_xopen
-int bb_xopen(const char *pathname, int flags)
+int xopen(const char *pathname, int flags)
{
- return bb_xopen3(pathname, flags, 0777);
+ return xopen3(pathname, flags, 0777);
}
#endif
#ifdef L_xopen3
-int bb_xopen3(const char *pathname, int flags, int mode)
+int xopen3(const char *pathname, int flags, int mode)
{
int ret;
@@ -175,7 +169,7 @@ unsigned char xread_char(int fd)
#endif
#ifdef L_xferror
-void bb_xferror(FILE *fp, const char *fn)
+void xferror(FILE *fp, const char *fn)
{
if (ferror(fp)) {
bb_error_msg_and_die("%s", fn);
@@ -184,14 +178,14 @@ void bb_xferror(FILE *fp, const char *fn)
#endif
#ifdef L_xferror_stdout
-void bb_xferror_stdout(void)
+void xferror_stdout(void)
{
- bb_xferror(stdout, bb_msg_standard_output);
+ xferror(stdout, bb_msg_standard_output);
}
#endif
#ifdef L_xfflush_stdout
-void bb_xfflush_stdout(void)
+void xfflush_stdout(void)
{
if (fflush(stdout)) {
bb_perror_msg_and_die(bb_msg_standard_output);
@@ -201,7 +195,7 @@ void bb_xfflush_stdout(void)
#ifdef L_spawn
// This does a fork/exec in one call, using vfork().
-pid_t bb_spawn(char **argv)
+pid_t spawn(char **argv)
{
static int failed;
pid_t pid;
@@ -226,9 +220,9 @@ pid_t bb_spawn(char **argv)
#endif
#ifdef L_xspawn
-pid_t bb_xspawn(char **argv)
+pid_t xspawn(char **argv)
{
- pid_t pid = bb_spawn(argv);
+ pid_t pid = spawn(argv);
if (pid < 0) bb_perror_msg_and_die("%s", *argv);
return pid;
}
@@ -347,3 +341,107 @@ off_t fdlength(int fd)
return pos + 1;
}
#endif
+
+#ifdef L_xasprintf
+char *xasprintf(const char *format, ...)
+{
+ va_list p;
+ int r;
+ char *string_ptr;
+
+#if 1
+ // GNU extension
+ va_start(p, format);
+ r = vasprintf(&string_ptr, format, p);
+ va_end(p);
+#else
+ // Bloat for systems that haven't got the GNU extension.
+ va_start(p, format);
+ r = vsnprintf(NULL, 0, format, p);
+ va_end(p);
+ string_ptr = xmalloc(r+1);
+ va_start(p, format);
+ r = vsnprintf(string_ptr, r+1, format, p);
+ va_end(p);
+#endif
+
+ if (r < 0) bb_perror_msg_and_die("xasprintf");
+ return string_ptr;
+}
+#endif
+
+#ifdef L_xprint_and_close_file
+void xprint_and_close_file(FILE *file)
+{
+ // copyfd outputs error messages for us.
+ if (bb_copyfd_eof(fileno(file), 1) == -1) exit(bb_default_error_retval);
+
+ fclose(file);
+}
+#endif
+
+#ifdef L_xchdir
+void xchdir(const char *path)
+{
+ if (chdir(path))
+ bb_perror_msg_and_die("chdir(%s)", path);
+}
+#endif
+
+#ifdef L_warn_opendir
+DIR *warn_opendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL) {
+ bb_perror_msg("unable to open `%s'", path);
+ return NULL;
+ }
+ return dp;
+}
+#endif
+
+#ifdef L_xopendir
+DIR *xopendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL)
+ bb_perror_msg_and_die("unable to open `%s'", path);
+ return dp;
+}
+#endif
+
+#ifdef L_xdaemon
+#ifndef BB_NOMMU
+void xdaemon(int nochdir, int noclose)
+{
+ if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
+}
+#endif
+#endif
+
+#ifdef L_xbind
+void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
+{
+ if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
+}
+#endif
+
+#ifdef L_xsocket
+int xsocket(int domain, int type, int protocol)
+{
+ int r = socket(domain, type, protocol);
+
+ if (r < 0) bb_perror_msg_and_die("socket");
+
+ return r;
+}
+#endif
+
+#ifdef L_xlisten
+void xlisten(int s, int backlog)
+{
+ if (listen(s, backlog)) bb_perror_msg_and_die("listen");
+}
+#endif
diff --git a/loginutils/addgroup.c b/loginutils/addgroup.c
index f4962ffb9..f5a99b796 100644
--- a/loginutils/addgroup.c
+++ b/loginutils/addgroup.c
@@ -9,11 +9,6 @@
*
*/
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <unistd.h>
-
#include "busybox.h"
/* make sure gr_name isn't taken, make sure gid is kosher
@@ -26,7 +21,7 @@ static int group_study(struct group *g)
struct group *grp;
const int max = 65000;
- etc_group = bb_xfopen(bb_path_group_file, "r");
+ etc_group = xfopen(bb_path_group_file, "r");
/* make sure gr_name isn't taken, make sure gid is kosher */
desired = g->gr_gid;
@@ -67,13 +62,13 @@ static int addgroup(char *group, gid_t gid, const char *user)
return 1;
/* add entry to group */
- file = bb_xfopen(bb_path_group_file, "a");
+ file = xfopen(bb_path_group_file, "a");
/* group:passwd:gid:userlist */
fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
fclose(file);
#if ENABLE_FEATURE_SHADOWPASSWDS
- file = bb_xfopen(bb_path_gshadow_file, "a");
+ file = xfopen(bb_path_gshadow_file, "a");
fprintf(file, "%s:!::\n", group);
fclose(file);
#endif
diff --git a/loginutils/adduser.c b/loginutils/adduser.c
index a640ece3b..0133d8288 100644
--- a/loginutils/adduser.c
+++ b/loginutils/adduser.c
@@ -8,14 +8,6 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <stdio.h>
-#include <sys/types.h>
-#include <string.h>
-#include <unistd.h>
-#include <time.h>
-#include <getopt.h>
-#include <sys/stat.h>
-
#include "busybox.h"
#define DONT_SET_PASS (1 << 4)
@@ -32,7 +24,7 @@ static int passwd_study(const char *filename, struct passwd *p)
const int min = 500;
const int max = 65000;
- passwd = bb_xfopen(filename, "r");
+ passwd = xfopen(filename, "r");
/* EDR if uid is out of bounds, set to min */
if ((p->pw_uid > max) || (p->pw_uid < min))
@@ -78,7 +70,7 @@ static void addgroup_wrapper(struct passwd *p)
{
char *cmd;
- cmd = bb_xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name);
+ cmd = xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name);
system(cmd);
free(cmd);
}
@@ -99,7 +91,7 @@ static int adduser(struct passwd *p, unsigned long flags)
int addgroup = !p->pw_gid;
/* make sure everything is kosher and setup uid && gid */
- file = bb_xfopen(bb_path_passwd_file, "a");
+ file = xfopen(bb_path_passwd_file, "a");
fseek(file, 0, SEEK_END);
switch (passwd_study(bb_path_passwd_file, p)) {
@@ -119,7 +111,7 @@ static int adduser(struct passwd *p, unsigned long flags)
#if ENABLE_FEATURE_SHADOWPASSWDS
/* add to shadow if necessary */
- file = bb_xfopen(bb_path_shadow_file, "a");
+ file = xfopen(bb_path_shadow_file, "a");
fseek(file, 0, SEEK_END);
fprintf(file, "%s:!:%ld:%d:%d:%d:::\n",
p->pw_name, /* username */
diff --git a/loginutils/getty.c b/loginutils/getty.c
index 2d05d9a1c..ebb107d4b 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -16,19 +16,6 @@
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <stdarg.h>
-#include <ctype.h>
-#include <getopt.h>
-#include <termios.h>
#include "busybox.h"
#ifdef CONFIG_FEATURE_UTMP
@@ -324,7 +311,7 @@ static void parse_args(int argc, char **argv, struct options *op)
const char *p = op->initstring;
char *q;
- q = op->initstring = bb_xstrdup(op->initstring);
+ q = op->initstring = xstrdup(op->initstring);
/* copy optarg into op->initstring decoding \ddd
octal codes into chars */
while (*p) {
@@ -858,7 +845,7 @@ int getty_main(int argc, char **argv)
};
#ifdef DEBUGGING
- dbf = bb_xfopen(DEBUGTERM, "w");
+ dbf = xfopen(DEBUGTERM, "w");
{
int i;
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index 7745444c0..aa75dd260 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -3,20 +3,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <utime.h>
-#include <syslog.h>
-#include <time.h>
-#include <sys/resource.h>
-#include <errno.h>
-
#include "busybox.h"
+#include <syslog.h>
static char crypt_passwd[128];
@@ -170,7 +158,7 @@ int passwd_main(int argc, char **argv)
bb_show_usage();
}
}
- myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1));
+ myname = (char *) xstrdup(bb_getpwuid(NULL, getuid(), -1));
/* exits on error */
if (optind < argc) {
name = argv[optind];
diff --git a/loginutils/su.c b/loginutils/su.c
index 660ec6f51..6410e748f 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -6,11 +6,7 @@
*/
#include "busybox.h"
-#include <signal.h>
#include <syslog.h>
-#include <sys/resource.h>
-#include <time.h>
-
int su_main ( int argc, char **argv )
{
@@ -43,7 +39,7 @@ int su_main ( int argc, char **argv )
the user, especially if someone su's from a su-shell.
But getlogin can fail -- usually due to lack of utmp entry.
in this case resort to getpwuid. */
- old_user = bb_xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
+ old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
tty = ttyname(2) ? : "none";
openlog(bb_applet_name, 0, LOG_AUTH);
}
diff --git a/loginutils/vlock.c b/loginutils/vlock.c
index a35f9e0ec..b4426ad41 100644
--- a/loginutils/vlock.c
+++ b/loginutils/vlock.c
@@ -16,18 +16,8 @@
/* Fixed by Erik Andersen to do passwords the tinylogin way...
* It now works with md5, sha1, etc passwords. */
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/vt.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <termios.h>
-
#include "busybox.h"
+#include <sys/vt.h>
static struct passwd *pw;
static struct vt_mode ovtm;
@@ -71,7 +61,7 @@ int vlock_main(int argc, char **argv)
bb_error_msg_and_die("Unknown uid %d", getuid());
}
- vfd = bb_xopen(CURRENT_TTY, O_RDWR);
+ vfd = xopen(CURRENT_TTY, O_RDWR);
if (ioctl(vfd, VT_GETMODE, &vtm) < 0) {
bb_perror_msg_and_die("VT_GETMODE");
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 3f60468de..3e12fedc8 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -13,22 +13,7 @@
#define VERSION "2.3.2"
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
+#include <sys/syslog.h>
#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
@@ -193,7 +178,7 @@ int crond_main(int ac, char **av)
* change directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
* version - his died. ;(
*/
@@ -208,7 +193,7 @@ int crond_main(int ac, char **av)
/* reexec for vfork() do continue parent */
vfork_daemon_rexec(1, 0, ac, av, "-f");
#else
- bb_xdaemon(1, 0);
+ xdaemon(1, 0);
#endif
}
diff --git a/miscutils/crontab.c b/miscutils/crontab.c
index 0ed59b0dc..a8e650c60 100644
--- a/miscutils/crontab.c
+++ b/miscutils/crontab.c
@@ -11,22 +11,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <signal.h>
-#include <getopt.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/resource.h>
#ifndef CRONTABS
#define CRONTABS "/var/spool/cron/crontabs"
@@ -47,8 +31,7 @@ static void EditFile(const char *user, const char *file);
static int GetReplaceStream(const char *user, const char *file);
static int ChangeUser(const char *user, short dochdir);
-int
-crontab_main(int ac, char **av)
+int crontab_main(int ac, char **av)
{
enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
const struct passwd *pas;
@@ -147,7 +130,7 @@ crontab_main(int ac, char **av)
* Change directory to our crontab directory
*/
- bb_xchdir(CDir);
+ xchdir(CDir);
/*
* Handle options as appropriate
@@ -177,7 +160,7 @@ crontab_main(int ac, char **av)
char buf[1024];
snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
- fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
+ fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
chown(tmp, getuid(), getgid());
if ((fi = fopen(pas->pw_name, "r"))) {
while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
@@ -244,8 +227,7 @@ crontab_main(int ac, char **av)
return 0;
}
-static int
-GetReplaceStream(const char *user, const char *file)
+static int GetReplaceStream(const char *user, const char *file)
{
int filedes[2];
int pid;
@@ -284,7 +266,7 @@ GetReplaceStream(const char *user, const char *file)
exit(0);
bb_default_error_retval = 0;
- fd = bb_xopen3(file, O_RDONLY, 0);
+ fd = xopen3(file, O_RDONLY, 0);
buf[0] = 0;
write(filedes[1], buf, 1);
while ((n = read(fd, buf, sizeof(buf))) > 0) {
@@ -293,8 +275,7 @@ GetReplaceStream(const char *user, const char *file)
exit(0);
}
-static void
-EditFile(const char *user, const char *file)
+static void EditFile(const char *user, const char *file)
{
int pid;
@@ -324,8 +305,7 @@ EditFile(const char *user, const char *file)
wait4(pid, NULL, 0, NULL);
}
-static int
-ChangeUser(const char *user, short dochdir)
+static int ChangeUser(const char *user, short dochdir)
{
struct passwd *pas;
@@ -349,7 +329,7 @@ ChangeUser(const char *user, short dochdir)
if (dochdir) {
if (chdir(pas->pw_dir) < 0) {
bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
- bb_xchdir(TMPDIR);
+ xchdir(TMPDIR);
}
}
return(pas->pw_uid);
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 39f04780a..0f36970f9 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -475,7 +475,7 @@ int devfsd_main (int argc, char **argv)
if (chdir (mount_point) != 0)
devfsd_perror_msg_and_die(mount_point);
- fd = bb_xopen (".devfsd", O_RDONLY);
+ fd = xopen (".devfsd", O_RDONLY);
if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0)
devfsd_perror_msg_and_die("FD_CLOEXEC");
@@ -704,7 +704,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
num_args -= 3;
for (count = 0; count < num_args; ++count)
- new->u.execute.argv[count] = bb_xstrdup (p[count]);
+ new->u.execute.argv[count] = xstrdup (p[count]);
new->u.execute.argv[num_args] = NULL;
break;
@@ -714,8 +714,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
if (num_args != 2)
goto process_config_line_err; /* missing path and function in line */
- new->u.copy.source = bb_xstrdup (p[0]);
- new->u.copy.destination = bb_xstrdup (p[1]);
+ new->u.copy.source = xstrdup (p[0]);
+ new->u.copy.destination = xstrdup (p[1]);
break;
case 8: /* IGNORE */
/* FALLTROUGH */
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index 925644e1f..aea96d622 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -13,22 +13,8 @@
*/
#include "busybox.h"
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <sys/ioctl.h>
-#include <sys/sysmacros.h>
-#include <sys/times.h>
-#include <sys/mman.h>
-#include <linux/types.h>
#include <linux/hdreg.h>
-#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
-# define __USE_XOPEN
-#endif
-#include <unistd.h>
-
/* device types */
/* ------------ */
#define NO_DEV 0xffff
@@ -1619,7 +1605,7 @@ static void process_dev(char *devname)
unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
const char *fmt = " %s\t= %2ld";
- fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK);
+ fd = xopen(devname, O_RDONLY|O_NONBLOCK);
printf("\n%s:\n", devname);
if (set_readahead)
diff --git a/miscutils/last.c b/miscutils/last.c
index 47c18ffa0..6e35879f3 100644
--- a/miscutils/last.c
+++ b/miscutils/last.c
@@ -8,15 +8,7 @@
*/
#include "busybox.h"
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
#include <utmp.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <time.h>
#ifndef SHUTDOWN_TIME
# define SHUTDOWN_TIME 254
@@ -43,7 +35,7 @@ int last_main(int argc, char **argv)
if (argc > 1) {
bb_show_usage();
}
- file = bb_xopen(bb_path_wtmp_file, O_RDONLY);
+ file = xopen(bb_path_wtmp_file, O_RDONLY);
printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME");
while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) {
diff --git a/miscutils/less.c b/miscutils/less.c
index 596490483..9dd9b9e56 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -31,12 +31,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include <ctype.h>
#ifdef CONFIG_FEATURE_LESS_REGEXP
#include "xregex.h"
@@ -196,7 +190,7 @@ static void add_linenumbers(void)
for (i = 0; i <= num_flines; i++) {
safe_strncpy(current_line, flines[i], 256);
- flines[i] = bb_xasprintf("%5d %s", i + 1, current_line);
+ flines[i] = xasprintf("%5d %s", i + 1, current_line);
}
}
@@ -206,15 +200,15 @@ static void data_readlines(void)
char current_line[256];
FILE *fp;
- fp = (inp_stdin) ? stdin : bb_xfopen(filename, "r");
+ fp = (inp_stdin) ? stdin : xfopen(filename, "r");
flines = NULL;
for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
strcpy(current_line, "");
fgets(current_line, 256, fp);
if (fp != stdin)
- bb_xferror(fp, filename);
+ xferror(fp, filename);
flines = xrealloc(flines, (i+1) * sizeof(char *));
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
num_flines = i - 2;
@@ -226,7 +220,7 @@ static void data_readlines(void)
fclose(fp);
if (inp == NULL)
- inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin;
+ inp = (inp_stdin) ? xfopen(CURRENT_TTY, "r") : stdin;
if (flags & FLAG_N)
add_linenumbers();
@@ -357,12 +351,12 @@ static void buffer_init(void)
/* Fill the buffer until the end of the file or the
end of the buffer is reached */
for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
- buffer[i] = bb_xstrdup(flines[i]);
+ buffer[i] = xstrdup(flines[i]);
}
/* If the buffer still isn't full, fill it with blank lines */
for (; i < (height - 1); i++) {
- buffer[i] = bb_xstrdup("");
+ buffer[i] = xstrdup("");
}
}
@@ -376,7 +370,7 @@ static void buffer_down(int nlines)
line_pos += nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
@@ -386,7 +380,7 @@ static void buffer_down(int nlines)
line_pos += 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
@@ -407,7 +401,7 @@ static void buffer_up(int nlines)
line_pos -= nlines;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
else {
@@ -417,7 +411,7 @@ static void buffer_up(int nlines)
line_pos -= 1;
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
}
}
}
@@ -439,10 +433,10 @@ static void buffer_up(int nlines)
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (i < tilde_line - nlines + 1)
- buffer[i] = bb_xstrdup(flines[line_pos + i]);
+ buffer[i] = xstrdup(flines[line_pos + i]);
else {
if (line_pos >= num_flines - height + 2)
- buffer[i] = bb_xstrdup("~\n");
+ buffer[i] = xstrdup("~\n");
}
}
}
@@ -461,7 +455,7 @@ static void buffer_line(int linenum)
else if (linenum < (num_flines - height - 2)) {
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
}
line_pos = linenum;
buffer_print();
@@ -470,9 +464,9 @@ static void buffer_line(int linenum)
for (i = 0; i < (height - 1); i++) {
free(buffer[i]);
if (linenum + i < num_flines + 2)
- buffer[i] = bb_xstrdup(flines[linenum + i]);
+ buffer[i] = xstrdup(flines[linenum + i]);
else
- buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
+ buffer[i] = xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
}
line_pos = linenum;
/* Set past_eof so buffer_down and buffer_up act differently */
@@ -508,7 +502,7 @@ static void examine_file(void)
newline_offset = strlen(filename) - 1;
filename[newline_offset] = '\0';
- files[num_files] = bb_xstrdup(filename);
+ files[num_files] = xstrdup(filename);
current_file = num_files + 1;
num_files++;
@@ -612,7 +606,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
char *growline = "";
regmatch_t match_structs;
- line2 = bb_xstrdup(line);
+ line2 = xstrdup(line);
match_found = 0;
match_status = regexec(pattern, line2, 1, &match_structs, 0);
@@ -622,17 +616,17 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
match_found = 1;
if (action) {
- growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
+ growline = xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
}
else {
- growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
+ growline = xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
}
line2 += match_structs.rm_eo;
match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
}
- growline = bb_xasprintf("%s%s", growline, line2);
+ growline = xasprintf("%s%s", growline, line2);
return (match_found ? growline : line);
@@ -679,7 +673,7 @@ static void regex_process(void)
/* Get rid of all the highlights we added previously */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &old_pattern, 0);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
}
}
old_pattern = pattern;
@@ -693,7 +687,7 @@ static void regex_process(void)
/* Run the regex on each line of the current file here */
for (i = 0; i <= num_flines; i++) {
current_line = process_regex_on_line(flines[i], &pattern, 1);
- flines[i] = bb_xstrdup(current_line);
+ flines[i] = xstrdup(current_line);
if (match_found) {
match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
match_lines[j] = i;
@@ -864,7 +858,7 @@ static void save_input_to_file(void)
fgets(current_line, 256, inp);
current_line[strlen(current_line) - 1] = '\0';
if (strlen(current_line) > 1) {
- fp = bb_xfopen(current_line, "w");
+ fp = xfopen(current_line, "w");
for (i = 0; i < num_flines; i++)
fprintf(fp, "%s", flines[i]);
fclose(fp);
diff --git a/miscutils/makedevs.c b/miscutils/makedevs.c
index 776bcaa8d..0ebb0538f 100644
--- a/miscutils/makedevs.c
+++ b/miscutils/makedevs.c
@@ -8,15 +8,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <time.h>
-#include <ctype.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/sysmacros.h> /* major() and minor() */
#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
int makedevs_main(int argc, char **argv)
@@ -88,13 +79,13 @@ int makedevs_main(int argc, char **argv)
unsigned long flags;
flags = bb_getopt_ulflags(argc, argv, "d:", &line);
if (line)
- table = bb_xfopen(line, "r");
+ table = xfopen(line, "r");
if (optind >= argc || (rootdir=argv[optind])==NULL) {
bb_error_msg_and_die("root directory not specified");
}
- bb_xchdir(rootdir);
+ xchdir(rootdir);
umask(0);
diff --git a/miscutils/mountpoint.c b/miscutils/mountpoint.c
index 6265a20e1..3e5fb4b46 100644
--- a/miscutils/mountpoint.c
+++ b/miscutils/mountpoint.c
@@ -10,10 +10,6 @@
*/
#include "busybox.h"
-#include <sys/stat.h>
-#include <errno.h> /* errno */
-#include <string.h> /* strerror */
-#include <getopt.h> /* optind */
int mountpoint_main(int argc, char **argv)
{
@@ -46,7 +42,7 @@ int mountpoint_main(int argc, char **argv)
if (S_ISDIR(st.st_mode)) {
dev_t st_dev = st.st_dev;
ino_t st_ino = st.st_ino;
- char *p = bb_xasprintf("%s/..", arg);
+ char *p = xasprintf("%s/..", arg);
if (stat(p, &st) == 0) {
short ret = (st_dev != st.st_dev) ||
diff --git a/miscutils/mt.c b/miscutils/mt.c
index 2720f7eab..f562a91a2 100644
--- a/miscutils/mt.c
+++ b/miscutils/mt.c
@@ -4,11 +4,7 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <sys/mtio.h>
-#include <fcntl.h>
struct mt_opcodes {
char *name;
@@ -105,7 +101,7 @@ int mt_main(int argc, char **argv)
break;
}
- fd = bb_xopen3(file, mode, 0);
+ fd = xopen3(file, mode, 0);
switch (code->value) {
case MTTELL:
diff --git a/miscutils/rx.c b/miscutils/rx.c
index 41673b60e..4cc4913e6 100644
--- a/miscutils/rx.c
+++ b/miscutils/rx.c
@@ -21,18 +21,6 @@
*/
#include "busybox.h"
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <termios.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-
#define SOH 0x01
#define STX 0x02
@@ -274,8 +262,8 @@ int rx_main(int argc, char **argv)
bb_show_usage();
fn = argv[1];
- ttyfd = bb_xopen3(CURRENT_TTY, O_RDWR, 0);
- filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
+ ttyfd = xopen3(CURRENT_TTY, O_RDWR, 0);
+ filefd = xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
if (tcgetattr(ttyfd, &tty) < 0)
bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]);
diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c
index ddd349d9b..ebbab2df3 100644
--- a/miscutils/watchdog.c
+++ b/miscutils/watchdog.c
@@ -9,11 +9,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <signal.h>
#define OPT_FOREGROUND 0x01
#define OPT_TIMER 0x02
@@ -47,13 +42,13 @@ int watchdog_main(int argc, char **argv)
if (!(opts & OPT_FOREGROUND))
vfork_daemon_rexec(0, 1, argc, argv, "-F");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
signal(SIGHUP, watchdog_shutdown);
signal(SIGINT, watchdog_shutdown);
- fd = bb_xopen(argv[argc - 1], O_WRONLY);
+ fd = xopen(argv[argc - 1], O_WRONLY);
while (1) {
/*
diff --git a/modutils/insmod.c b/modutils/insmod.c
index 3113f7446..be41e4449 100644
--- a/modutils/insmod.c
+++ b/modutils/insmod.c
@@ -59,17 +59,6 @@
*/
#include "busybox.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <errno.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <ctype.h>
-#include <assert.h>
-#include <string.h>
-#include <getopt.h>
-#include <fcntl.h>
#include <sys/utsname.h>
#if !defined(CONFIG_FEATURE_2_4_MODULES) && \
@@ -804,12 +793,12 @@ static int check_module_name_match(const char *filename, struct stat *statbuf,
if (fullname[0] == '\0')
return (FALSE);
else {
- char *tmp, *tmp1 = bb_xstrdup(filename);
+ char *tmp, *tmp1 = xstrdup(filename);
tmp = bb_get_last_path_component(tmp1);
if (strcmp(tmp, fullname) == 0) {
free(tmp1);
/* Stop searching if we find a match */
- m_filename = bb_xstrdup(filename);
+ m_filename = xstrdup(filename);
return (FALSE);
}
free(tmp1);
@@ -893,7 +882,6 @@ arch_apply_relocation(struct obj_file *f,
* (which is .got) similar to branch,
* but is full 32 bits relative */
- assert(got != 0);
*loc += got - dot;
break;
@@ -902,7 +890,6 @@ arch_apply_relocation(struct obj_file *f,
goto bb_use_plt;
case R_ARM_GOTOFF: /* address relative to the got */
- assert(got != 0);
*loc += v - got;
break;
@@ -972,7 +959,6 @@ arch_apply_relocation(struct obj_file *f,
break;
case R_386_GOTPC:
- assert(got != 0);
*loc += got - dot;
break;
@@ -980,7 +966,6 @@ arch_apply_relocation(struct obj_file *f,
goto bb_use_got;
case R_386_GOTOFF:
- assert(got != 0);
*loc += v - got;
break;
@@ -1102,7 +1087,6 @@ arch_apply_relocation(struct obj_file *f,
# ifdef R_68K_GOTOFF
case R_68K_GOTOFF:
- assert(got != 0);
*loc += v - got;
break;
# endif
@@ -1157,9 +1141,6 @@ arch_apply_relocation(struct obj_file *f,
struct mips_hi16 *next;
unsigned long insn;
- /* The value for the HI16 had best be the same. */
- assert(v == l->value);
-
/* Do the HI16 relocation. Note that we actually don't
need to know anything about the LO16 itself, except where
to find the low 16 bits of the addend needed by the LO16. */
@@ -1408,9 +1389,7 @@ arch_apply_relocation(struct obj_file *f,
case R_390_PLT32:
case R_390_PLT16DBL:
/* find the plt entry and initialize it. */
- assert(isym != NULL);
pe = (struct arch_single_entry *) &isym->pltent;
- assert(pe->allocated);
if (pe->inited == 0) {
ip = (unsigned long *)(ifile->plt->contents + pe->offset);
ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */
@@ -1440,15 +1419,12 @@ arch_apply_relocation(struct obj_file *f,
break;
case R_390_GOTPC:
- assert(got != 0);
*(unsigned long *) loc += got - dot;
break;
case R_390_GOT12:
case R_390_GOT16:
case R_390_GOT32:
- assert(isym != NULL);
- assert(got != 0);
if (!isym->gotent.inited)
{
isym->gotent.inited = 1;
@@ -1466,7 +1442,6 @@ arch_apply_relocation(struct obj_file *f,
# define R_390_GOTOFF32 R_390_GOTOFF
# endif
case R_390_GOTOFF32:
- assert(got != 0);
*loc += v - got;
break;
@@ -1497,7 +1472,6 @@ arch_apply_relocation(struct obj_file *f,
break;
case R_SH_GOTPC:
- assert(got != 0);
*loc = got - dot + rel->r_addend;
break;
@@ -1505,7 +1479,6 @@ arch_apply_relocation(struct obj_file *f,
goto bb_use_got;
case R_SH_GOTOFF:
- assert(got != 0);
*loc = v - got;
break;
@@ -1627,7 +1600,6 @@ arch_apply_relocation(struct obj_file *f,
case R_X86_64_GOTPCREL:
goto bb_use_got;
# if 0
- assert(isym != NULL);
if (!isym->gotent.reloc_done)
{
isym->gotent.reloc_done = 1;
@@ -1655,12 +1627,10 @@ arch_apply_relocation(struct obj_file *f,
bb_use_plt:
/* find the plt entry and initialize it if necessary */
- assert(isym != NULL);
#if defined(CONFIG_USE_PLT_LIST)
for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;)
pe = pe->next;
- assert(pe != NULL);
#else
pe = &isym->pltent;
#endif
@@ -1734,7 +1704,6 @@ bb_use_plt:
#if defined(CONFIG_USE_GOT_ENTRIES)
bb_use_got:
- assert(isym != NULL);
/* needs an entry in the .got: set it, once */
if (!isym->gotent.inited) {
isym->gotent.inited = 1;
@@ -1814,7 +1783,6 @@ static struct obj_section *arch_xsect_init(struct obj_file *f, char *name,
} else {
myrelsec = obj_create_alloced_section(f, name,
size, offset);
- assert(myrelsec);
}
return myrelsec;
@@ -3778,14 +3746,14 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
};
if (realpath(filename, real)) {
- absolute_filename = bb_xstrdup(real);
+ absolute_filename = xstrdup(real);
}
else {
int save_errno = errno;
bb_error_msg("cannot get realpath for %s", filename);
errno = save_errno;
perror("");
- absolute_filename = bb_xstrdup(filename);
+ absolute_filename = xstrdup(filename);
}
lm_name = strlen(m_name);
@@ -4022,7 +3990,7 @@ int insmod_main( int argc, char **argv)
break;
case 'o': /* name the output module */
free(m_name);
- m_name = bb_xstrdup(optarg);
+ m_name = xstrdup(optarg);
break;
case 'L': /* Stub warning */
/* This is needed for compatibility with modprobe.
@@ -4045,7 +4013,7 @@ int insmod_main( int argc, char **argv)
}
/* Grab the module name */
- tmp1 = bb_xstrdup(argv[optind]);
+ tmp1 = xstrdup(argv[optind]);
tmp = basename(tmp1);
len = strlen(tmp);
@@ -4071,10 +4039,10 @@ int insmod_main( int argc, char **argv)
#if defined(CONFIG_FEATURE_2_6_MODULES)
if (k_version > 4)
- m_fullName = bb_xasprintf("%s.ko", tmp);
+ m_fullName = xasprintf("%s.ko", tmp);
else
#endif
- m_fullName = bb_xasprintf("%s.o", tmp);
+ m_fullName = xasprintf("%s.o", tmp);
if (!m_name) {
m_name = tmp;
@@ -4132,7 +4100,7 @@ int insmod_main( int argc, char **argv)
bb_error_msg_and_die("%s: no module by that name found", m_fullName);
}
} else
- m_filename = bb_xstrdup(argv[optind]);
+ m_filename = xstrdup(argv[optind]);
if (flag_verbose)
printf("Using %s\n", m_filename);
@@ -4334,7 +4302,7 @@ int insmod_ng_main( int argc, char **argv)
struct stat st;
unsigned long len;
void *map;
- char *filename, *options = bb_xstrdup("");
+ char *filename, *options = xstrdup("");
filename = argv[1];
if (!filename) {
@@ -4356,7 +4324,7 @@ int insmod_ng_main( int argc, char **argv)
strcat(options, " ");
}
- fd = bb_xopen3(filename, O_RDONLY, 0);
+ fd = xopen3(filename, O_RDONLY, 0);
fstat(fd, &st);
len = st.st_size;
diff --git a/modutils/modprobe.c b/modutils/modprobe.c
index b11e58d55..5a94c7c92 100644
--- a/modutils/modprobe.c
+++ b/modutils/modprobe.c
@@ -13,15 +13,6 @@
#include "busybox.h"
#include <sys/utsname.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <getopt.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <string.h>
-#include <ctype.h>
-#include <fcntl.h>
#include <fnmatch.h>
struct mod_opt_t { /* one-way list of options to pass to a module */
@@ -148,7 +139,7 @@ static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt )
ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) );
}
- ol-> m_opt_val = bb_xstrdup( opt );
+ ol-> m_opt_val = xstrdup( opt );
ol-> m_next = NULL;
return opt_list;
@@ -160,7 +151,7 @@ static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt )
* dst: pointer to where to store the parsed argument
* return value: the pointer to the first char after the parsed argument,
* NULL if there was no argument parsed (only trailing spaces).
- * Note that memory is allocated with bb_xstrdup when a new argument was
+ * Note that memory is allocated with xstrdup when a new argument was
* parsed. Don't forget to free it!
*/
#define ARG_EMPTY 0x00
@@ -185,7 +176,7 @@ static char *parse_command_string( char *src, char **dst )
/* Reached the start of an argument
* By the way, we duplicate a little too much
* here but what is too much is freed later. */
- *dst = tmp_str = bb_xstrdup( src );
+ *dst = tmp_str = xstrdup( src );
/* Get to the end of that argument */
while( ( *tmp_str != '\0' )
&& ( ( *tmp_str != ' ' )
@@ -309,7 +300,7 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b
(*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
(*current) = (*current)-> m_next;
}
- (*current)-> m_name = bb_xstrdup ( alias );
+ (*current)-> m_name = xstrdup ( alias );
(*current)-> m_isalias = 1;
if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) {
@@ -319,7 +310,7 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b
else {
(*current)-> m_depcnt = 1;
(*current)-> m_deparr = xmalloc ( 1 * sizeof( char * ));
- (*current)-> m_deparr[0] = bb_xstrdup ( mod );
+ (*current)-> m_deparr[0] = xstrdup ( mod );
}
(*current)-> m_next = 0;
}
@@ -388,7 +379,7 @@ static struct dep_t *build_dep ( void )
k_version = un.release[2] - '0';
}
- filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release );
+ filename = xasprintf("/lib/modules/%s/modules.dep", un.release );
fd = open ( filename, O_RDONLY );
if (ENABLE_FEATURE_CLEAN_UP)
free(filename);
@@ -447,7 +438,7 @@ static struct dep_t *build_dep ( void )
if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
dot = col - 2;
- mod = bb_xstrndup ( mods, dot - mods );
+ mod = xstrndup ( mods, dot - mods );
/* enqueue new module */
if ( !current ) {
@@ -458,7 +449,7 @@ static struct dep_t *build_dep ( void )
current = current-> m_next;
}
current-> m_name = mod;
- current-> m_path = bb_xstrdup(modpath);
+ current-> m_path = xstrdup(modpath);
current-> m_options = NULL;
current-> m_isalias = 0;
current-> m_depcnt = 0;
@@ -525,7 +516,7 @@ static struct dep_t *build_dep ( void )
/* Cope with blank lines */
if ((next-deps-ext+1) <= 0)
continue;
- dep = bb_xstrndup ( deps, next - deps - ext + 1 );
+ dep = xstrndup ( deps, next - deps - ext + 1 );
/* Add the new dependable module name */
current-> m_depcnt++;
@@ -562,7 +553,7 @@ static struct dep_t *build_dep ( void )
/* Only 2.6 has a modules.alias file */
if (ENABLE_FEATURE_2_6_MODULES) {
/* Parse kernel-declared aliases */
- filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release);
+ filename = xasprintf("/lib/modules/%s/modules.alias", un.release);
if ((fd = open ( filename, O_RDONLY )) < 0) {
/* Ok, that didn't work. Fall back to looking in /lib/modules */
fd = open ( "/lib/modules/modules.alias", O_RDONLY );
@@ -687,7 +678,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
printf("%s module %s\n", do_insert?"Loading":"Unloading", list-> m_name );
}
if (!show_only) {
- int rc2 = wait4pid(bb_spawn(argv));
+ int rc2 = wait4pid(spawn(argv));
if (do_insert) {
rc = rc2; /* only last module matters */
@@ -724,8 +715,8 @@ static int check_pattern( const char* pat_src, const char* mod_src ) {
char* mod;
char* p;
- pat = bb_xstrdup (pat_src);
- mod = bb_xstrdup (mod_src);
+ pat = xstrdup (pat_src);
+ mod = xstrdup (mod_src);
for (p = pat; (p = strchr(p, '-')); *p++ = '_' );
for (p = mod; (p = strchr(p, '-')); *p++ = '_' );
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
index 1803d2265..75f065cdc 100644
--- a/networking/ether-wake.c
+++ b/networking/ether-wake.c
@@ -65,25 +65,10 @@
*/
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
-
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <features.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
-#include <netdb.h>
#include <netinet/ether.h>
-
-#ifdef __linux__
#include <linux/if.h>
-#endif
#include "busybox.h"
@@ -93,10 +78,10 @@
*/
#ifdef PF_PACKET
# define whereto_t sockaddr_ll
-# define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0)
+# define make_socket() xsocket(PF_PACKET, SOCK_RAW, 0)
#else
# define whereto_t sockaddr
-# define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
+# define make_socket() xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
#endif
#ifdef DEBUG
diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c
index 9cdbc5725..6ee7c328e 100644
--- a/networking/fakeidentd.c
+++ b/networking/fakeidentd.c
@@ -10,19 +10,7 @@
*/
#include "busybox.h"
-
-#include <unistd.h>
-#include <string.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/syslog.h>
-
-#include <pwd.h>
-
#include <sys/syslog.h>
-#include <time.h>
-#include <sys/socket.h>
-#include <errno.h>
#include <sys/uio.h>
@@ -97,7 +85,7 @@ static void inetbind(void)
else
port = se->s_port;
- s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ s = xsocket(AF_INET, SOCK_STREAM, 0);
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
@@ -106,8 +94,8 @@ static void inetbind(void)
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
- bb_xbind(s, (struct sockaddr *)&addr, len);
- bb_xlisten(s, 5);
+ xbind(s, (struct sockaddr *)&addr, len);
+ xlisten(s, 5);
movefd(s, 0);
}
diff --git a/networking/ftpgetput.c b/networking/ftpgetput.c
index 9f3c78976..767ace9fb 100644
--- a/networking/ftpgetput.c
+++ b/networking/ftpgetput.c
@@ -13,19 +13,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/ioctl.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <sys/socket.h>
-
#include "busybox.h"
+#include <getopt.h>
typedef struct ftp_host_info_s {
char *user;
@@ -175,9 +164,9 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
/* only make a local file if we know that one exists on the remote server */
if (fd_local == -1) {
if (do_continue) {
- fd_local = bb_xopen(local_path, O_APPEND | O_WRONLY);
+ fd_local = xopen(local_path, O_APPEND | O_WRONLY);
} else {
- fd_local = bb_xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
+ fd_local = xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
}
}
@@ -223,7 +212,7 @@ static int ftp_send(ftp_host_info_t *server, FILE *control_stream,
if ((local_path[0] == '-') && (local_path[1] == '\0')) {
fd_local = STDIN_FILENO;
} else {
- fd_local = bb_xopen(local_path, O_RDONLY);
+ fd_local = xopen(local_path, O_RDONLY);
fstat(fd_local, &sbuf);
sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size);
diff --git a/networking/hostname.c b/networking/hostname.c
index ec4a0e8d8..03fd88edb 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -13,15 +13,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <errno.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <getopt.h>
#include "busybox.h"
+#include <getopt.h>
extern char *optarg; /* in unistd.h */
extern int optind, opterr, optopt; /* in unistd.h */
@@ -41,7 +34,7 @@ static void do_sethostname(char *s, int isfile)
bb_perror_msg_and_die("sethostname");
}
} else {
- f = bb_xfopen(s, "r");
+ f = xfopen(s, "r");
while (fgets(buf, 255, f) != NULL) {
if (buf[0] =='#') {
continue;
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 7b358c43f..4d346c47f 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -26,14 +26,6 @@
* IPV6 support added by Bart Visscher <magick@linux-fan.com>
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h> /* strcmp and friends */
-#include <ctype.h> /* isdigit and friends */
-#include <stddef.h> /* offsetof */
-#include <unistd.h>
-#include <netdb.h>
-#include <sys/ioctl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
@@ -329,7 +321,7 @@ int ifconfig_main(int argc, char **argv)
}
/* Create a channel to the NET kernel. */
- sockfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
/* get interface name */
safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index 8ee488364..6429c07e5 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -17,22 +17,10 @@
/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */
-#include <sys/stat.h>
+#include "busybox.h"
#include <sys/utsname.h>
-#include <sys/wait.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
#include <fnmatch.h>
#include <getopt.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "busybox.h"
#define MAX_OPT_DEPTH 10
#define EUNBALBRACK 10001
@@ -628,7 +616,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
defn = xzalloc(sizeof(struct interfaces_file_t));
- f = bb_xfopen(filename, "r");
+ f = xfopen(filename, "r");
while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
char *buf_ptr = buf;
@@ -649,7 +637,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches);
}
- currmap->match[currmap->n_matches++] = bb_xstrdup(firstword);
+ currmap->match[currmap->n_matches++] = xstrdup(firstword);
}
currmap->max_mappings = 0;
currmap->n_mappings = 0;
@@ -701,7 +689,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
return NULL;
}
- currif->iface = bb_xstrdup(iface_name);
+ currif->iface = xstrdup(iface_name);
currif->address_family = get_address_family(addr_fams, address_family_name);
if (!currif->address_family) {
@@ -741,7 +729,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
}
/* Add the interface to the list */
- llist_add_to_end(&(defn->autointerfaces), bb_xstrdup(firstword));
+ llist_add_to_end(&(defn->autointerfaces), xstrdup(firstword));
debug_noise("\nauto %s\n", firstword);
}
currently_processing = NONE;
@@ -775,8 +763,8 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options);
currif->option = opt;
}
- currif->option[currif->n_options].name = bb_xstrdup(firstword);
- currif->option[currif->n_options].value = bb_xstrdup(buf_ptr);
+ currif->option[currif->n_options].name = xstrdup(firstword);
+ currif->option[currif->n_options].value = xstrdup(buf_ptr);
if (!currif->option[currif->n_options].name) {
perror(filename);
return NULL;
@@ -796,14 +784,14 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
bb_error_msg("duplicate script in mapping \"%s\"", buf);
return NULL;
} else {
- currmap->script = bb_xstrdup(next_word(&buf_ptr));
+ currmap->script = xstrdup(next_word(&buf_ptr));
}
} else if (strcmp(firstword, "map") == 0) {
if (currmap->max_mappings == currmap->n_mappings) {
currmap->max_mappings = currmap->max_mappings * 2 + 1;
currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings);
}
- currmap->mapping[currmap->n_mappings] = bb_xstrdup(next_word(&buf_ptr));
+ currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr));
currmap->n_mappings++;
} else {
bb_error_msg("misplaced option \"%s\"", buf);
@@ -833,7 +821,7 @@ static char *setlocalenv(char *format, const char *name, const char *value)
char *here;
char *there;
- result = bb_xasprintf(format, name, value);
+ result = xasprintf(format, name, value);
for (here = there = result; *there != '=' && *there; there++) {
if (*there == '-')
@@ -922,7 +910,7 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt)
}
}
- buf = bb_xasprintf("run-parts /etc/network/if-%s.d", opt);
+ buf = xasprintf("run-parts /etc/network/if-%s.d", opt);
if (doit(buf) != 1) {
return 0;
}
@@ -1013,7 +1001,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map)
int i, status;
pid_t pid;
- char *logical = bb_xstrdup(physical);
+ char *logical = xstrdup(physical);
/* Run the mapping script. */
pid = popen2(&in, &out, map->script, physical, NULL);
@@ -1158,7 +1146,7 @@ int ifupdown_main(int argc, char **argv)
/* iface_down */
const llist_t *list = state_list;
while (list) {
- llist_add_to_end(&target_list, bb_xstrdup(list->data));
+ llist_add_to_end(&target_list, xstrdup(list->data));
list = list->link;
}
target_list = defn->autointerfaces;
@@ -1178,15 +1166,15 @@ int ifupdown_main(int argc, char **argv)
int okay = 0;
int cmds_ret;
- iface = bb_xstrdup(target_list->data);
+ iface = xstrdup(target_list->data);
target_list = target_list->link;
pch = strchr(iface, '=');
if (pch) {
*pch = '\0';
- liface = bb_xstrdup(pch + 1);
+ liface = xstrdup(pch + 1);
} else {
- liface = bb_xstrdup(iface);
+ liface = xstrdup(iface);
}
if (!force) {
@@ -1263,7 +1251,7 @@ int ifupdown_main(int argc, char **argv)
llist_t *iface_state = find_iface_state(state_list, iface);
if (cmds == iface_up) {
- char *newiface = bb_xasprintf("%s=%s", iface, liface);
+ char *newiface = xasprintf("%s=%s", iface, liface);
if (iface_state == NULL) {
llist_add_to_end(&state_list, newiface);
} else {
@@ -1281,7 +1269,7 @@ int ifupdown_main(int argc, char **argv)
if (!no_act) {
FILE *state_fp = NULL;
- state_fp = bb_xfopen(statefile, "w");
+ state_fp = xfopen(statefile, "w");
while (state_list) {
if (state_list->data) {
fputs(state_list->data, state_fp);
diff --git a/networking/inetd.c b/networking/inetd.c
index 54294b635..49ca7a36e 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -128,31 +128,8 @@
*
*/
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/file.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-
-
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <errno.h>
-#include <signal.h>
-#include <netdb.h>
-#include <syslog.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <ctype.h>
-#include <time.h>
-
#include "busybox.h"
+#include <syslog.h>
//#define CONFIG_FEATURE_INETD_RPC
//#define CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO
@@ -1314,7 +1291,7 @@ inetd_main (int argc, char *argv[])
/* reexec for vfork() do continue parent */
vfork_daemon_rexec (0, 0, argc, argv, "-f");
#else
- bb_xdaemon (0, 0);
+ xdaemon (0, 0);
#endif
} else {
setsid ();
diff --git a/networking/nameif.c b/networking/nameif.c
index f13ef1b8b..501e244b1 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -10,13 +10,7 @@
*/
#include "busybox.h"
-
-#include <sys/syslog.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-#include <string.h>
-#include <unistd.h>
+#include <syslog.h>
#include <net/if.h>
#include <netinet/ether.h>
@@ -107,7 +101,7 @@ int nameif_main(int argc, char **argv)
if (strlen(*a) > IF_NAMESIZE)
serror("interface name `%s' too long", *a);
ch = xzalloc(sizeof(mactable_t));
- ch->ifname = bb_xstrdup(*a++);
+ ch->ifname = xstrdup(*a++);
ch->mac = cc_macaddr(*a++);
if (clist)
clist->prev = ch;
@@ -115,7 +109,7 @@ int nameif_main(int argc, char **argv)
clist = ch;
}
} else {
- ifh = bb_xfopen(fname, "r");
+ ifh = xfopen(fname, "r");
while ((line = bb_get_line_from_file(ifh)) != NULL) {
char *line_ptr;
@@ -128,7 +122,7 @@ int nameif_main(int argc, char **argv)
}
name_length = strcspn(line_ptr, " \t");
ch = xzalloc(sizeof(mactable_t));
- ch->ifname = bb_xstrndup(line_ptr, name_length);
+ ch->ifname = xstrndup(line_ptr, name_length);
if (name_length > IF_NAMESIZE)
serror("interface name `%s' too long", ch->ifname);
line_ptr += name_length;
diff --git a/networking/nc.c b/networking/nc.c
index 117bbe20e..3f4149e14 100644
--- a/networking/nc.c
+++ b/networking/nc.c
@@ -54,10 +54,10 @@ int nc_main(int argc, char **argv)
alarm(wsecs);
}
- if (infile) cfd = bb_xopen(infile, O_RDWR);
+ if (infile) cfd = xopen(infile, O_RDWR);
else {
opt = 1;
- sfd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ sfd = xsocket(AF_INET, SOCK_STREAM, 0);
fcntl(sfd, F_SETFD, FD_CLOEXEC);
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt));
address.sin_family = AF_INET;
@@ -67,13 +67,13 @@ int nc_main(int argc, char **argv)
if (lport != 0) {
address.sin_port = lport;
- bb_xbind(sfd, (struct sockaddr *) &address, sizeof(address));
+ xbind(sfd, (struct sockaddr *) &address, sizeof(address));
}
if (do_listen) {
socklen_t addrlen = sizeof(address);
- bb_xlisten(sfd, do_listen);
+ xlisten(sfd, do_listen);
// If we didn't specify a port number, query and print it to stderr.
diff --git a/networking/route.c b/networking/route.c
index d90578615..5fd888617 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -26,20 +26,12 @@
* remove ridiculous amounts of bloat.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <unistd.h>
-#include <fcntl.h>
+#include "busybox.h"
+#include "inet_common.h"
#include <getopt.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
#include <net/route.h>
#include <net/if.h>
-#include "busybox.h"
-#include "inet_common.h"
+
#ifndef RTF_UP
/* Keep this in sync with /usr/src/linux/include/linux/route.h */
@@ -166,8 +158,6 @@ static void INET_setroute(int action, char **args)
const char *netmask = NULL;
int skfd, isnet, xflag;
- assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
-
/* Grab the -net or -host options. Remember they were transformed. */
xflag = kw_lookup(tbl_hash_net_host, &args);
@@ -335,7 +325,7 @@ static void INET_setroute(int action, char **args)
}
/* Create a socket to the INET kernel. */
- skfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
@@ -353,9 +343,6 @@ static void INET6_setroute(int action, char **args)
int prefix_len, skfd;
const char *devname;
- assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
-
- {
/* We know args isn't NULL from the check in route_main. */
const char *target = *args++;
@@ -374,7 +361,6 @@ static void INET6_setroute(int action, char **args)
bb_error_msg_and_die("resolving %s", target);
}
}
- }
/* Clean out the RTREQ structure. */
memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
@@ -429,7 +415,7 @@ static void INET6_setroute(int action, char **args)
}
/* Create a socket to the INET6 kernel. */
- skfd = bb_xsocket(AF_INET6, SOCK_DGRAM, 0);
+ skfd = xsocket(AF_INET6, SOCK_DGRAM, 0);
rt.rtmsg_ifindex = 0;
@@ -503,7 +489,7 @@ void displayroutes(int noresolve, int netstatfmt)
struct sockaddr_in s_addr;
struct in_addr mask;
- FILE *fp = bb_xfopen("/proc/net/route", "r");
+ FILE *fp = xfopen("/proc/net/route", "r");
bb_printf("Kernel IP routing table\n"
"Destination Gateway Genmask"
@@ -573,7 +559,7 @@ static void INET6_displayroutes(int noresolve)
int iflags, metric, refcnt, use, prefix_len, slen;
struct sockaddr_in6 snaddr6;
- FILE *fp = bb_xfopen("/proc/net/ipv6_route", "r");
+ FILE *fp = xfopen("/proc/net/ipv6_route", "r");
bb_printf("Kernel IPv6 routing table\n%-44s%-40s"
"Flags Metric Ref Use Iface\n",
@@ -699,7 +685,7 @@ int route_main(int argc, char **argv)
#endif
displayroutes(noresolve, opt & ROUTE_OPT_e);
- bb_xferror_stdout();
+ xferror_stdout();
bb_fflush_stdout_and_exit(EXIT_SUCCESS);
}
diff --git a/networking/tftp.c b/networking/tftp.c
index dfa599ab5..42fd9d2ca 100644
--- a/networking/tftp.c
+++ b/networking/tftp.c
@@ -19,18 +19,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* ------------------------------------------------------------------------- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <fcntl.h>
-
#include "busybox.h"
@@ -159,7 +147,7 @@ static int tftp(const int cmd, const struct hostent *host,
char *buf=xmalloc(tftp_bufsize += 4);
if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- /* need to unlink the localfile, so don't use bb_xsocket here. */
+ /* need to unlink the localfile, so don't use xsocket here. */
bb_perror_msg("socket");
return EXIT_FAILURE;
}
@@ -167,7 +155,7 @@ static int tftp(const int cmd, const struct hostent *host,
len = sizeof(sa);
memset(&sa, 0, len);
- bb_xbind(socketfd, (struct sockaddr *)&sa, len);
+ xbind(socketfd, (struct sockaddr *)&sa, len);
sa.sin_family = host->h_addrtype;
sa.sin_port = port;
diff --git a/networking/traceroute.c b/networking/traceroute.c
index c2084fc1e..446490303 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -357,7 +357,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
struct IFADDRLIST *st_ifaddrlist;
- fd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ fd = xsocket(AF_INET, SOCK_DGRAM, 0);
ifc.ifc_len = sizeof(ibuf);
ifc.ifc_buf = (caddr_t)ibuf;
@@ -457,7 +457,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
struct IFADDRLIST *al;
char buf[256], tdevice[256], device[256];
- f = bb_xfopen(route, "r");
+ f = xfopen(route, "r");
/* Find the appropriate interface */
n = 0;
@@ -875,7 +875,7 @@ gethostinfo(const char *host)
hi = xcalloc(1, sizeof(*hi));
addr = inet_addr(host);
if ((int32_t)addr != -1) {
- hi->name = bb_xstrdup(host);
+ hi->name = xstrdup(host);
hi->n = 1;
hi->addrs = xcalloc(1, sizeof(hi->addrs[0]));
hi->addrs[0] = addr;
@@ -885,7 +885,7 @@ gethostinfo(const char *host)
hp = xgethostbyname(host);
if (hp->h_addrtype != AF_INET || hp->h_length != 4)
bb_perror_msg_and_die("bad host %s", host);
- hi->name = bb_xstrdup(hp->h_name);
+ hi->name = xstrdup(hp->h_name);
for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p)
continue;
hi->n = n;
@@ -1081,11 +1081,11 @@ traceroute_main(int argc, char *argv[])
bb_perror_msg_and_die("unknown protocol %s", cp);
/* Insure the socket fds won't be 0, 1 or 2 */
- do n = bb_xopen(bb_dev_null, O_RDONLY); while (n < 2);
+ do n = xopen(bb_dev_null, O_RDONLY); while (n < 2);
if (n > 2)
close(n);
- s = bb_xsocket(AF_INET, SOCK_RAW, pe->p_proto);
+ s = xsocket(AF_INET, SOCK_RAW, pe->p_proto);
#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG)
@@ -1096,7 +1096,7 @@ traceroute_main(int argc, char *argv[])
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
sizeof(on));
- sndsock = bb_xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
+ sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
#if defined(IP_OPTIONS)
@@ -1248,7 +1248,7 @@ traceroute_main(int argc, char *argv[])
outip->ip_src = from->sin_addr;
#ifndef IP_HDRINCL
- bb_xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
+ xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
#endif
fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr));
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h
index 3cf2d1401..c21d3baab 100644
--- a/networking/udhcp/libbb_udhcp.h
+++ b/networking/udhcp/libbb_udhcp.h
@@ -20,8 +20,6 @@
#define COMBINED_BINARY
-#define xfopen bb_xfopen
-
void udhcp_background(const char *pidfile);
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
void udhcp_logging(int level, const char *fmt, ...);
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 8c4933455..5a4b33a53 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -149,10 +149,10 @@ static char **fill_envp(struct dhcpMessage *packet)
envp = xzalloc(sizeof(char *) * (num_options + 5));
j = 0;
- envp[j++] = bb_xasprintf("interface=%s", client_config.interface);
- envp[j++] = bb_xasprintf("PATH=%s",
+ envp[j++] = xasprintf("interface=%s", client_config.interface);
+ envp[j++] = xasprintf("PATH=%s",
getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin");
- envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/");
+ envp[j++] = xasprintf("HOME=%s", getenv("HOME") ? : "/");
if (packet == NULL) return envp;
@@ -170,7 +170,7 @@ static char **fill_envp(struct dhcpMessage *packet)
/* Fill in a subnet bits option for things like /24 */
if (dhcp_options[i].code == DHCP_SUBNET) {
memcpy(&subnet, temp, 4);
- envp[j++] = bb_xasprintf("mask=%d", mton(&subnet));
+ envp[j++] = xasprintf("mask=%d", mton(&subnet));
}
}
if (packet->siaddr) {
@@ -180,12 +180,12 @@ static char **fill_envp(struct dhcpMessage *packet)
if (!(over & FILE_FIELD) && packet->file[0]) {
/* watch out for invalid packets */
packet->file[sizeof(packet->file) - 1] = '\0';
- envp[j++] = bb_xasprintf("boot_file=%s", packet->file);
+ envp[j++] = xasprintf("boot_file=%s", packet->file);
}
if (!(over & SNAME_FIELD) && packet->sname[0]) {
/* watch out for invalid packets */
packet->sname[sizeof(packet->sname) - 1] = '\0';
- envp[j++] = bb_xasprintf("sname=%s", packet->sname);
+ envp[j++] = xasprintf("sname=%s", packet->sname);
}
return envp;
}
diff --git a/networking/vconfig.c b/networking/vconfig.c
index 6cbbb54ca..b90f41085 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -9,14 +9,8 @@
/* BB_AUDIT SUSv3 N/A */
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <string.h>
-#include <limits.h>
#include "busybox.h"
+#include <net/if.h>
/* Stuff from linux/if_vlan.h, kernel version 2.4.23 */
enum vlan_ioctl_cmds {
@@ -124,7 +118,7 @@ int vconfig_main(int argc, char **argv)
/* Don't bother closing the filedes. It will be closed on cleanup. */
/* Will die if 802.1q is not present */
- bb_xopen3(conf_file_name, O_RDONLY, 0);
+ xopen3(conf_file_name, O_RDONLY, 0);
memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
@@ -159,7 +153,7 @@ int vconfig_main(int argc, char **argv)
}
}
- fd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ fd = xsocket(AF_INET, SOCK_STREAM, 0);
if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) {
bb_perror_msg_and_die("ioctl error for %s", *argv);
}
diff --git a/networking/wget.c b/networking/wget.c
index 6565bb1f3..1b7555abc 100644
--- a/networking/wget.c
+++ b/networking/wget.c
@@ -7,9 +7,6 @@
*/
#include "busybox.h"
-#include <errno.h>
-#include <signal.h>
-#include <sys/ioctl.h>
#include <getopt.h>
@@ -221,7 +218,7 @@ int wget_main(int argc, char **argv)
if (use_proxy) {
proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
if (proxy && *proxy) {
- parse_url(bb_xstrdup(proxy), &server);
+ parse_url(xstrdup(proxy), &server);
} else {
use_proxy = 0;
}
@@ -263,7 +260,7 @@ int wget_main(int argc, char **argv)
output = stdout;
quiet_flag = TRUE;
} else {
- output = bb_xfopen(fname_out, (do_continue ? "a" : "w"));
+ output = xfopen(fname_out, (do_continue ? "a" : "w"));
}
/*
@@ -396,9 +393,9 @@ read_response:
}
if (strcasecmp(buf, "location") == 0) {
if (s[0] == '/')
- target.path = bb_xstrdup(s+1);
+ target.path = xstrdup(s+1);
else {
- parse_url(bb_xstrdup(s), &target);
+ parse_url(xstrdup(s), &target);
if (use_proxy == 0) {
server.host = target.host;
server.port = target.port;
@@ -419,7 +416,7 @@ read_response:
* FTP session
*/
if (! target.user)
- target.user = bb_xstrdup("anonymous:busybox@");
+ target.user = xstrdup("anonymous:busybox@");
sfp = open_socket(&s_in);
if (ftpcmd(NULL, NULL, sfp, buf) != 220)
@@ -556,7 +553,7 @@ void parse_url(char *url, struct host_info *h)
*sp++ = '\0';
h->path = sp;
} else
- h->path = bb_xstrdup("");
+ h->path = xstrdup("");
up = strrchr(h->host, '@');
if (up != NULL) {
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 5673d293f..03a03889e 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -15,15 +15,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <dirent.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
/*
* Function Prototypes
@@ -202,8 +193,8 @@ int sysctl_write_setting(const char *setting, int output)
return -2;
}
- tmpname = bb_xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);
- outname = bb_xstrdup(tmpname + strlen(PROC_PATH));
+ tmpname = xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);
+ outname = xstrdup(tmpname + strlen(PROC_PATH));
while ((cptr = strchr(tmpname, '.')) != NULL)
*cptr = '/';
@@ -258,7 +249,7 @@ int sysctl_read_setting(const char *setting, int output)
bb_error_msg(ERR_INVALID_KEY, setting);
tmpname = concat_path_file(PROC_PATH, name);
- outname = bb_xstrdup(tmpname + strlen(PROC_PATH));
+ outname = xstrdup(tmpname + strlen(PROC_PATH));
while ((cptr = strchr(tmpname, '.')) != NULL)
*cptr = '/';
@@ -309,7 +300,7 @@ int sysctl_display_all(const char *path, int output, int show_table)
char *tmpdir;
struct stat ts;
- if (!(dp = bb_opendir(path))) {
+ if (!(dp = opendir(path))) {
retval = -1;
} else {
while ((de = readdir(dp)) != NULL) {
diff --git a/procps/top.c b/procps/top.c
index bf30c23f6..1b6f7072f 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -29,22 +29,9 @@
*/
#include "busybox.h"
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ioctl.h>
//#define CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */
-#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
-#include <time.h>
-#include <fcntl.h>
-#include <netinet/in.h> /* htons */
-#endif
-
-
typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q);
static procps_status_t *top; /* Hehe */
@@ -116,7 +103,7 @@ static struct jiffy_counts jif, prev_jif;
static void get_jiffy_counts(void)
{
- FILE* fp = bb_xfopen("stat", "r");
+ FILE* fp = xfopen("stat", "r");
prev_jif = jif;
if (fscanf(fp, "cpu %lld %lld %lld %lld %lld %lld %lld %lld",
&jif.usr,&jif.nic,&jif.sys,&jif.idle,
@@ -196,7 +183,7 @@ static unsigned long display_generic(int scr_width)
unsigned int needs_conversion = 1;
/* read memory info */
- fp = bb_xfopen("meminfo", "r");
+ fp = xfopen("meminfo", "r");
/*
* Old kernels (such as 2.4.x) had a nice summary of memory info that
@@ -238,7 +225,7 @@ static unsigned long display_generic(int scr_width)
fclose(fp);
/* read load average as a string */
- fp = bb_xfopen("loadavg", "r");
+ fp = xfopen("loadavg", "r");
buf[0] = '\0';
fgets(buf, sizeof(buf), fp);
end = strchr(buf, ' ');
@@ -414,7 +401,7 @@ int top_main(int argc, char **argv)
}
/* change to /proc */
- bb_xchdir("/proc");
+ xchdir("/proc");
#ifdef CONFIG_FEATURE_USE_TERMIOS
tcgetattr(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
diff --git a/shell/ash.c b/shell/ash.c
index 5031ae153..c1b2b0ed6 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6011,7 +6011,7 @@ static inline void putprompt(const char *s)
{
#ifdef CONFIG_ASH_EXPAND_PRMT
free(cmdedit_prompt);
- cmdedit_prompt = bb_xstrdup(s);
+ cmdedit_prompt = xstrdup(s);
#else
cmdedit_prompt = s;
#endif
@@ -8105,7 +8105,7 @@ static int dotcmd(int argc, char **argv)
int status = 0;
for (sp = cmdenviron; sp; sp = sp->next)
- setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
+ setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
if (argc >= 2) { /* That's what SVR2 does */
char *fullname;
diff --git a/shell/cmdedit.c b/shell/cmdedit.c
index 59226aff5..0af1a2ad0 100644
--- a/shell/cmdedit.c
+++ b/shell/cmdedit.c
@@ -216,7 +216,7 @@ static void cmdedit_set_out_char(int next_char)
printf("\033[7m%c\033[0m", c);
} else
#endif
- putchar(c);
+ if (initial_settings.c_lflag & ECHO) putchar(c);
if (++cmdedit_x >= cmdedit_termw) {
/* terminal is scrolled down */
cmdedit_y++;
@@ -546,8 +546,8 @@ static void cmdedit_init(void)
my_euid = geteuid();
entry = getpwuid(my_euid);
if (entry) {
- user_buf = bb_xstrdup(entry->pw_name);
- home_pwd_buf = bb_xstrdup(entry->pw_dir);
+ user_buf = xstrdup(entry->pw_name);
+ home_pwd_buf = xstrdup(entry->pw_dir);
}
#endif
@@ -634,7 +634,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
while ((entry = getpwent()) != NULL) {
/* Null usernames should result in all users as possible completions. */
if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) {
- add_match(bb_xasprintf("~%s", entry->pw_name), '/');
+ add_match(xasprintf("~%s", entry->pw_name), '/');
}
}
@@ -684,7 +684,7 @@ static int path_parse(char ***p, int flags)
*p = xmalloc(npth * sizeof(char *));
tmp = pth;
- (*p)[0] = bb_xstrdup(tmp);
+ (*p)[0] = xstrdup(tmp);
npth = 1; /* count words is + 1 count ':' */
for (;;) {
@@ -1114,7 +1114,7 @@ static void input_tab(int *lastWasTab)
if (!matches)
return; /* not found */
/* find minimal match */
- tmp1 = bb_xstrdup(matches[0]);
+ tmp1 = xstrdup(matches[0]);
for (tmp = tmp1; *tmp; tmp++)
for (len_found = 1; len_found < num_matches; len_found++)
if (matches[len_found][(tmp - tmp1)] != *tmp) {
@@ -1175,7 +1175,7 @@ static void get_previous_history(void)
{
if(command_ps[0] != 0 || history[cur_history] == 0) {
free(history[cur_history]);
- history[cur_history] = bb_xstrdup(command_ps);
+ history[cur_history] = xstrdup(command_ps);
}
cur_history--;
}
@@ -1856,7 +1856,7 @@ rewrite_line:
for(i = 0; i < (MAX_HISTORY-1); i++)
history[i] = history[i+1];
}
- history[i++] = bb_xstrdup(command);
+ history[i++] = xstrdup(command);
cur_history = i;
n_history = i;
#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT)
diff --git a/shell/hush.c b/shell/hush.c
index 8c432942e..8df91a1e8 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1320,7 +1320,7 @@ static int run_pipe_real(struct pipe *pi)
* variable. */
int export_me=0;
char *name, *value;
- name = bb_xstrdup(child->argv[i]);
+ name = xstrdup(child->argv[i]);
debug_printf("Local environment set: %s\n", name);
value = strchr(name, '=');
if (value)
@@ -2753,7 +2753,7 @@ int hush_main(int argc, char **argv)
debug_printf("\nrunning script '%s'\n", argv[optind]);
global_argv = argv+optind;
global_argc = argc-optind;
- input = bb_xfopen(argv[optind], "r");
+ input = xfopen(argv[optind], "r");
opt = parse_file_outer(input);
#ifdef CONFIG_FEATURE_CLEAN_UP
diff --git a/shell/lash.c b/shell/lash.c
index 92c24d1c2..eae949e18 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -710,7 +710,7 @@ static char * strsep_space( char *string, int * ix)
return NULL;
}
- token = bb_xstrndup(string, *ix);
+ token = xstrndup(string, *ix);
return token;
}
@@ -751,7 +751,7 @@ static int expand_arguments(char *command)
/* We need a clean copy, so strsep can mess up the copy while
* we write stuff into the original (in a minute) */
- cmd = cmd_copy = bb_xstrdup(command);
+ cmd = cmd_copy = xstrdup(command);
*command = '\0';
for (ix = 0, tmpcmd = cmd;
(tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) {
@@ -1123,10 +1123,10 @@ static int parse_command(char **command_ptr, struct job *job, int *inbg)
prog->argv[argc_l] = NULL;
if (!return_command) {
- job->text = bb_xstrdup(*command_ptr);
+ job->text = xstrdup(*command_ptr);
} else {
/* This leaves any trailing spaces, which is a bit sloppy */
- job->text = bb_xstrndup(*command_ptr, return_command - *command_ptr);
+ job->text = xstrndup(*command_ptr, return_command - *command_ptr);
}
*command_ptr = return_command;
@@ -1543,7 +1543,7 @@ int lash_main(int argc_l, char **argv_l)
input = NULL;
if (local_pending_command != 0)
bb_error_msg_and_die("multiple -c arguments");
- local_pending_command = bb_xstrdup(argv[optind]);
+ local_pending_command = xstrdup(argv[optind]);
optind++;
argv = argv+optind;
break;
@@ -1575,7 +1575,7 @@ int lash_main(int argc_l, char **argv_l)
}
} else if (!local_pending_command && argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
- input = bb_xfopen(argv[optind], "r");
+ input = xfopen(argv[optind], "r");
/* be lazy, never mark this closed */
llist_add_to(&close_me_list, (void *)(long)fileno(input));
}
diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c
index 92590d209..677c9e607 100644
--- a/sysklogd/klogd.c
+++ b/sysklogd/klogd.c
@@ -18,13 +18,6 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h> /* for our signal() handlers */
-#include <string.h> /* strncpy() */
-#include <errno.h> /* errno and friends */
-#include <unistd.h>
-#include <ctype.h>
#include <sys/syslog.h>
#include <sys/klog.h>
@@ -66,7 +59,7 @@ int klogd_main(int argc, char **argv)
#ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
}
}
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index dfff75728..87313af43 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -14,24 +14,9 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <netdb.h>
#include <paths.h>
-#include <signal.h>
-#include <stdarg.h>
#include <stdbool.h>
-#include <time.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <sys/types.h>
#include <sys/un.h>
-#include <sys/param.h>
/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
#define SYSLOG_NAMES
@@ -368,7 +353,7 @@ static void message(char *fmt, ...)
static void init_RemoteLog(void)
{
memset(&remoteaddr, 0, sizeof(remoteaddr));
- remotefd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
+ remotefd = xsocket(AF_INET, SOCK_DGRAM, 0);
remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list;
remoteaddr.sin_port = htons(RemotePort);
@@ -537,7 +522,7 @@ static void doSyslogd(void)
memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
- sock_fd = bb_xsocket(AF_UNIX, SOCK_DGRAM, 0);
+ sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);
@@ -623,7 +608,7 @@ int syslogd_main(int argc, char **argv)
#endif
#ifdef CONFIG_FEATURE_REMOTE_LOG
case 'R':
- RemoteHost = bb_xstrdup(optarg);
+ RemoteHost = xstrdup(optarg);
if ((p = strchr(RemoteHost, ':'))) {
RemotePort = atoi(p + 1);
*p = '\0';
@@ -672,7 +657,7 @@ int syslogd_main(int argc, char **argv)
#ifdef BB_NOMMU
vfork_daemon_rexec(0, 1, argc, argv, "-n");
#else
- bb_xdaemon(0, 1);
+ xdaemon(0, 1);
#endif
}
doSyslogd();
diff --git a/util-linux/fbset.c b/util-linux/fbset.c
index 7d3cae251..9a207b6e3 100644
--- a/util-linux/fbset.c
+++ b/util-linux/fbset.c
@@ -12,15 +12,6 @@
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <ctype.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/ioctl.h>
#include "busybox.h"
#define DEFAULTFBDEV FB_0
@@ -186,7 +177,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
char buf[256];
char *p = buf;
- f = bb_xfopen(fn, "r");
+ f = xfopen(fn, "r");
while (!feof(f)) {
fgets(buf, sizeof(buf), f);
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
@@ -396,7 +387,7 @@ int fbset_main(int argc, char **argv)
}
}
- fh = bb_xopen(fbdev, O_RDONLY);
+ fh = xopen(fbdev, O_RDONLY);
if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
bb_perror_msg_and_die("fbset(ioctl)");
if (g_options & OPT_READMODE) {
diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c
index f94d455c9..63ec2204d 100644
--- a/util-linux/fdformat.c
+++ b/util-linux/fdformat.c
@@ -9,14 +9,6 @@
* 5 July 2003 -- modified for Busybox by Erik Andersen
*/
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
#include "busybox.h"
@@ -60,10 +52,10 @@ static void print_and_flush(const char * __restrict format, ...)
va_start(arg, format);
bb_vfprintf(stdout, format, arg);
va_end(arg);
- bb_xfflush_stdout();
+ xfflush_stdout();
}
-static void bb_xioctl(int fd, int request, void *argp, const char *string)
+static void xioctl(int fd, int request, void *argp, const char *string)
{
if (ioctl (fd, request, argp) < 0) {
bb_perror_msg_and_die(string);
@@ -95,9 +87,9 @@ int fdformat_main(int argc,char **argv)
/* O_RDWR for formatting and verifying */
- fd = bb_xopen(*argv,O_RDWR );
+ fd = xopen(*argv,O_RDWR );
- bb_xioctl(fd, FDGETPRM, &param, "FDGETPRM");/*original message was: "Could not determine current format type" */
+ xioctl(fd, FDGETPRM, &param, "FDGETPRM");/*original message was: "Could not determine current format type" */
print_and_flush("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n",
(param.head == 2) ? "Double" : "Single",
@@ -105,22 +97,22 @@ int fdformat_main(int argc,char **argv)
/* FORMAT */
print_and_flush("Formatting ... ", NULL);
- bb_xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
+ xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
/* n == track */
for (n = 0; n < param.track; n++)
{
descr.head = 0;
descr.track = n;
- bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+ xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
print_and_flush("%3d\b\b\b", n);
if (param.head == 2) {
descr.head = 1;
- bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+ xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
}
}
- bb_xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
+ xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
print_and_flush("done\n", NULL);
/* VERIFY */
diff --git a/util-linux/freeramdisk.c b/util-linux/freeramdisk.c
index c959158c9..9e1c453e4 100644
--- a/util-linux/freeramdisk.c
+++ b/util-linux/freeramdisk.c
@@ -9,13 +9,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/ioctl.h>
-#include <stdlib.h>
-#include <unistd.h>
#include "busybox.h"
/* From <linux/fd.h> */
@@ -28,7 +21,7 @@ int freeramdisk_main(int argc, char **argv)
if (argc != 2) bb_show_usage();
- fd = bb_xopen(argv[1], O_RDWR);
+ fd = xopen(argv[1], O_RDWR);
// Act like freeramdisk, fdflush, or both depending on configuration.
result = ioctl(fd, (ENABLE_FREERAMDISK && bb_applet_name[1]=='r')
diff --git a/util-linux/getopt.c b/util-linux/getopt.c
index fab8f8398..bf05f9164 100644
--- a/util-linux/getopt.c
+++ b/util-linux/getopt.c
@@ -31,14 +31,8 @@
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <getopt.h>
-
#include "busybox.h"
+#include <getopt.h>
/* NON_OPT is the code that is returned when a non-option is found in '+'
mode */
@@ -86,7 +80,7 @@ const char *normalize(const char *arg)
free(BUFFER);
if (!quote) { /* Just copy arg */
- BUFFER=bb_xstrdup(arg);
+ BUFFER=xstrdup(arg);
return BUFFER;
}
@@ -215,7 +209,7 @@ void add_longopt(const char *name,int has_arg)
long_options[long_options_nr-1].has_arg=has_arg;
long_options[long_options_nr-1].flag=NULL;
long_options[long_options_nr-1].val=LONG_OPT;
- long_options[long_options_nr-1].name=bb_xstrdup(name);
+ long_options[long_options_nr-1].name=xstrdup(name);
}
long_options_nr++;
}
diff --git a/util-linux/hexdump.c b/util-linux/hexdump.c
index 12f540a53..136243122 100644
--- a/util-linux/hexdump.c
+++ b/util-linux/hexdump.c
@@ -11,7 +11,6 @@
#include "busybox.h"
#include <getopt.h>
-#include <string.h>
#include "dump.h"
static void bb_dump_addfile(char *name)
@@ -20,7 +19,7 @@ static void bb_dump_addfile(char *name)
FILE *fp;
char *buf;
- fp = bb_xfopen(name, "r");
+ fp = xfopen(name, "r");
while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
p = skip_whitespace(buf);
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index c77c122b5..7c1223dcb 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -10,10 +10,6 @@
*/
#include "busybox.h"
-#include <ctype.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/sysmacros.h>
#include "xregex.h"
#define DEV_PATH "/dev"
@@ -146,7 +142,7 @@ static void make_device(char *path, int delete)
break;
}
if ((s2-s+1) & (1<<delete))
- command = bb_xstrndup(pos, end-pos);
+ command = xstrndup(pos, end-pos);
}
pos = end2;
@@ -180,7 +176,7 @@ static void make_device(char *path, int delete)
int rc;
char *s;
- s=bb_xasprintf("MDEV=%s",device_name);
+ s=xasprintf("MDEV=%s",device_name);
putenv(s);
rc = system(command);
s[4]=0;
@@ -232,7 +228,7 @@ int mdev_main(int argc, char *argv[])
char *env_path;
RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
- bb_xchdir(DEV_PATH);
+ xchdir(DEV_PATH);
/* Scan */
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 7f52b563e..a8737a6c9 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -62,20 +62,8 @@
* removed getopt based parser and added a hand rolled one.
*/
-#include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include <string.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <sys/param.h>
-#include <mntent.h>
#include "busybox.h"
+#include <mntent.h>
#define MINIX_ROOT_INO 1
#define MINIX_LINK_MAX 250
@@ -304,7 +292,7 @@ static inline int get_size(const char *file)
int fd;
long size;
- fd = bb_xopen3(file, O_RDWR, 0);
+ fd = xopen3(file, O_RDWR, 0);
if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd);
return (size * 512);
@@ -678,7 +666,7 @@ static void get_list_blocks(char *filename)
FILE *listfile;
unsigned long blockno;
- listfile = bb_xfopen(filename, "r");
+ listfile = xfopen(filename, "r");
while (!feof(listfile)) {
fscanf(listfile, "%ld\n", &blockno);
mark_zone(blockno);
@@ -817,7 +805,7 @@ goodbye:
tmp += dirsize;
*(short *) tmp = 2;
strcpy(tmp + 2, ".badblocks");
- DEV = bb_xopen3(device_name, O_RDWR, 0);
+ DEV = xopen3(device_name, O_RDWR, 0);
if (fstat(DEV, &statbuf) < 0)
bb_error_msg_and_die("unable to stat %s", device_name);
if (!S_ISBLK(statbuf.st_mode))
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 9b1e2b5c3..b109f5ce1 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -20,7 +20,7 @@ int mkswap_main(int argc, char *argv[])
// Figure out how big the device is and announce our intentions.
- fd = bb_xopen(argv[1],O_RDWR);
+ fd = xopen(argv[1],O_RDWR);
len = fdlength(fd);
pagesize = getpagesize();
printf("Setting up swapspace version 1, size = %ld bytes\n", (long)(len-pagesize));
diff --git a/util-linux/more.c b/util-linux/more.c
index 2ad1e797c..f68292e80 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -11,28 +11,9 @@
*
* Termios corrects by Vladimir Oleynik <dzo@simtreas.ru>
*
- * 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
- * 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>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "busybox.h"
@@ -76,7 +57,7 @@ int more_main(int argc, char **argv)
if(isatty(STDOUT_FILENO)) {
cin = fopen(CURRENT_TTY, "r");
if (!cin)
- cin = bb_xfopen(CONSOLE_DEV, "r");
+ cin = xfopen(CONSOLE_DEV, "r");
please_display_more_prompt = 2;
#ifdef CONFIG_FEATURE_USE_TERMIOS
cin_fileno = fileno(cin);
diff --git a/util-linux/mount.c b/util-linux/mount.c
index c64c3f438..f665a0875 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -23,13 +23,7 @@
*/
#include "busybox.h"
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
#include <mntent.h>
-#include <ctype.h>
-#include <fcntl.h> // for CONFIG_FEATURE_MOUNT_LOOP
-#include <sys/ioctl.h> // for CONFIG_FEATURE_MOUNT_LOOP
// These two aren't always defined in old headers
#ifndef MS_BIND
@@ -89,12 +83,12 @@ struct {
static void append_mount_options(char **oldopts, char *newopts)
{
if(*oldopts && **oldopts) {
- char *temp=bb_xasprintf("%s,%s",*oldopts,newopts);
+ char *temp=xasprintf("%s,%s",*oldopts,newopts);
free(*oldopts);
*oldopts=temp;
} else {
if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts);
- *oldopts = bb_xstrdup(newopts);
+ *oldopts = xstrdup(newopts);
}
}
@@ -165,7 +159,7 @@ static llist_t *get_block_backed_filesystems(void)
if(*fs=='#' || *fs=='*') continue;
if(!*fs) continue;
- llist_add_to_end(&list,bb_xstrdup(fs));
+ llist_add_to_end(&list,xstrdup(fs));
}
if (ENABLE_FEATURE_CLEAN_UP) fclose(f);
}
@@ -367,7 +361,7 @@ report_error:
int mount_main(int argc, char **argv)
{
- char *cmdopts = bb_xstrdup(""), *fstabname, *fstype=0, *storage_path=0;
+ char *cmdopts = xstrdup(""), *fstabname, *fstype=0, *storage_path=0;
FILE *fstab;
int i, opt, all = FALSE, rc = 0;
struct mntent mtpair[2], *mtcur = mtpair;
@@ -493,7 +487,7 @@ int mount_main(int argc, char **argv)
// Mount the last thing we found.
mtcur = mtnext;
- mtcur->mnt_opts=bb_xstrdup(mtcur->mnt_opts);
+ mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
append_mount_options(&(mtcur->mnt_opts),cmdopts);
rc = singlemount(mtcur, 0);
free(mtcur->mnt_opts);
diff --git a/util-linux/nfsmount.c b/util-linux/nfsmount.c
index 705975d29..e7d194f0f 100644
--- a/util-linux/nfsmount.c
+++ b/util-linux/nfsmount.c
@@ -26,10 +26,6 @@
*/
#include "busybox.h"
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <time.h>
#include <sys/utsname.h>
#undef TRUE
#undef FALSE
@@ -391,7 +387,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
}
sprintf(new_opts, "%s%saddr=%s",
old_opts, *old_opts ? "," : "", s);
- *mount_opts = bb_xstrdup(new_opts);
+ *mount_opts = xstrdup(new_opts);
/* Set default options.
* rsize/wsize (and bsize, for ver >= 3) are left 0 in order to
@@ -459,7 +455,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
else if (!strcmp(opt, "mountport"))
mountport = val;
else if (!strcmp(opt, "mounthost"))
- mounthost=bb_xstrndup(opteq+1,
+ mounthost=xstrndup(opteq+1,
strcspn(opteq+1," \t\n\r,"));
else if (!strcmp(opt, "mountprog"))
mountprog = val;
@@ -729,7 +725,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
if (!bg)
goto fail;
if (!running_bg) {
- prev_bg_host = bb_xstrdup(hostname);
+ prev_bg_host = xstrdup(hostname);
if (retry > 0)
retval = EX_BG;
goto fail;
diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c
index 8fe8787ba..aaa419a3c 100644
--- a/util-linux/readprofile.c
+++ b/util-linux/readprofile.c
@@ -4,19 +4,7 @@
*
* Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it)
*
- * 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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
/*
@@ -44,17 +32,8 @@
* Paul Mundt <lethal@linux-sh.org>.
*/
-#include <errno.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/utsname.h>
-
#include "busybox.h"
+#include <sys/utsname.h>
#define S_LEN 128
@@ -138,7 +117,7 @@ int readprofile_main(int argc, char **argv)
to_write = 1; /* sth different from sizeof(int) */
}
- fd = bb_xopen(defaultpro,O_WRONLY);
+ fd = xopen(defaultpro,O_WRONLY);
if (write(fd, &multiplier, to_write) != to_write)
bb_perror_msg_and_die("error writing %s", defaultpro);
@@ -151,7 +130,7 @@ int readprofile_main(int argc, char **argv)
* Use an fd for the profiling buffer, to skip stdio overhead
*/
- proFd = bb_xopen(proFile,O_RDONLY);
+ proFd = xopen(proFile,O_RDONLY);
if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
|| (lseek(proFd,0,SEEK_SET) < 0))
@@ -198,7 +177,7 @@ int readprofile_main(int argc, char **argv)
total = 0;
- map = bb_xfopen(mapFile, "r");
+ map = xfopen(mapFile, "r");
while (fgets(mapline,S_LEN,map)) {
if (sscanf(mapline,"%llx %s %s",&fn_add,mode,fn_name) != 3)
diff --git a/util-linux/umount.c b/util-linux/umount.c
index b5696f78b..b74b11027 100644
--- a/util-linux/umount.c
+++ b/util-linux/umount.c
@@ -66,8 +66,8 @@ int umount_main(int argc, char **argv)
} else while (getmntent_r(fp,&me,path,sizeof(path))) {
m = xmalloc(sizeof(struct mtab_list));
m->next = mtl;
- m->device = bb_xstrdup(me.mnt_fsname);
- m->dir = bb_xstrdup(me.mnt_dir);
+ m->device = xstrdup(me.mnt_fsname);
+ m->dir = xstrdup(me.mnt_dir);
mtl = m;
}
endmntent(fp);