aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-03 15:41:12 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-08-03 15:41:12 +0000
commit5e2a5391f9142bca773aab4c829615895b69a6b7 (patch)
treee4a2769349867c441cf2983d83097bb66701a733
parente883e03918a0e26e390ea23996abdb8fc1925f88 (diff)
downloadbusybox-w32-5e2a5391f9142bca773aab4c829615895b69a6b7.tar.gz
busybox-w32-5e2a5391f9142bca773aab4c829615895b69a6b7.tar.bz2
busybox-w32-5e2a5391f9142bca773aab4c829615895b69a6b7.zip
Remove bb_ prefixes from xfuncs.c (and a few other places), consolidate
things like xasprintf() into xfuncs.c, remove xprint_file_by_name() (it only had one user), clean up lots of #includes... General cleanup pass. What I've been doing for the last couple days. And it conflicts! I've removed httpd.c from this checkin due to somebody else touching that file. It builds for me. I have to catch a bus. (Now you know why I'm looking forward to Mercurial.) git-svn-id: svn://busybox.net/trunk/busybox@15767 69ca8d6d-28ef-0310-b511-8ec308f3f277
-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 @@
14 * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html 14 * http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
15 */ 15 */
16 16
17#include <fcntl.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <time.h>
22#include <utime.h>
23#include <unistd.h>
24
25#include "unarchive.h"
26#include "busybox.h" 17#include "busybox.h"
18#include "unarchive.h"
27 19
28static void header_verbose_list_ar(const file_header_t *file_header) 20static void header_verbose_list_ar(const file_header_t *file_header)
29{ 21{
@@ -81,7 +73,7 @@ int ar_main(int argc, char **argv)
81 bb_error_msg_and_die(msg_unsupported_err, "insertion"); 73 bb_error_msg_and_die(msg_unsupported_err, "insertion");
82 } 74 }
83 75
84 archive_handle->src_fd = bb_xopen(argv[optind++], O_RDONLY); 76 archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
85 77
86 while (optind < argc) { 78 while (optind < argc) {
87 archive_handle->filter = filter_accept_list; 79 archive_handle->filter = filter_accept_list;
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index 714dac077..a970aeb20 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -6,12 +6,6 @@
6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 6 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
7 */ 7 */
8 8
9#include <fcntl.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <unistd.h>
14
15#include "busybox.h" 9#include "busybox.h"
16#include "unarchive.h" 10#include "unarchive.h"
17 11
@@ -30,7 +24,7 @@ int bunzip2_main(int argc, char **argv)
30 filename = argv[optind]; 24 filename = argv[optind];
31 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) { 25 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
32 /* Open input file */ 26 /* Open input file */
33 src_fd = bb_xopen(filename, O_RDONLY); 27 src_fd = xopen(filename, O_RDONLY);
34 } else { 28 } else {
35 src_fd = STDIN_FILENO; 29 src_fd = STDIN_FILENO;
36 filename = 0; 30 filename = 0;
@@ -53,7 +47,7 @@ int bunzip2_main(int argc, char **argv)
53 } 47 }
54 xstat(filename, &stat_buf); 48 xstat(filename, &stat_buf);
55 *extension=0; 49 *extension=0;
56 dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 50 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
57 } else dst_fd = STDOUT_FILENO; 51 } else dst_fd = STDOUT_FILENO;
58 status = uncompressStream(src_fd, dst_fd); 52 status = uncompressStream(src_fd, dst_fd);
59 if(filename) { 53 if(filename) {
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 558e3cd48..0e5772062 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1,44 +1,39 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2/* 2/*
3 * Mini dpkg implementation for busybox. 3 * mini dpkg implementation for busybox.
4 * This is not meant as a replacement for dpkg 4 * this is not meant as a replacement for dpkg
5 * 5 *
6 * Written By Glenn McGrath with the help of others 6 * written by glenn mcgrath with the help of others
7 * Copyright (C) 2001 by Glenn McGrath 7 * copyright (c) 2001 by glenn mcgrath
8 * 8 *
9 * Started life as a busybox implementation of udpkg 9 * started life as a busybox implementation of udpkg
10 * 10 *
11 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 11 * licensed under gplv2 or later, see file license in this tarball for details.
12 */ 12 */
13 13
14/* 14/*
15 * Known difference between busybox dpkg and the official dpkg that i don't 15 * known difference between busybox dpkg and the official dpkg that i don't
16 * consider important, its worth keeping a note of differences anyway, just to 16 * consider important, its worth keeping a note of differences anyway, just to
17 * make it easier to maintain. 17 * make it easier to maintain.
18 * - The first value for the Confflile: field isnt placed on a new line. 18 * - the first value for the confflile: field isnt placed on a new line.
19 * - When installing a package the Status: field is placed at the end of the 19 * - when installing a package the status: field is placed at the end of the
20 * section, rather than just after the Package: field. 20 * section, rather than just after the package: field.
21 * 21 *
22 * Bugs that need to be fixed 22 * bugs that need to be fixed
23 * - (unknown, please let me know when you find any) 23 * - (unknown, please let me know when you find any)
24 * 24 *
25 */ 25 */
26 26
27#include <fcntl.h>
28#include <getopt.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32#include "unarchive.h"
33#include "busybox.h" 27#include "busybox.h"
28#include "unarchive.h"
34 29
35/* NOTE: If you vary HASH_PRIME sizes be aware, 30/* note: if you vary hash_prime sizes be aware,
36 * 1) Tweaking these will have a big effect on how much memory this program uses. 31 * 1) tweaking these will have a big effect on how much memory this program uses.
37 * 2) For computational efficiency these hash tables should be at least 20% 32 * 2) for computational efficiency these hash tables should be at least 20%
38 * larger than the maximum number of elements stored in it. 33 * larger than the maximum number of elements stored in it.
39 * 3) All _HASH_PRIME's must be a prime number or chaos is assured, if your looking 34 * 3) all _hash_prime's must be a prime number or chaos is assured, if your looking
40 * for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt 35 * for a prime, try http://www.utm.edu/research/primes/lists/small/10000.txt
41 * 4) If you go bigger than 15 bits you may get into trouble (untested) as its 36 * 4) if you go bigger than 15 bits you may get into trouble (untested) as its
42 * sometimes cast to an unsigned int, if you go to 16 bit you will overlap 37 * sometimes cast to an unsigned int, if you go to 16 bit you will overlap
43 * int's and chaos is assured, 16381 is the max prime for 14 bit field 38 * int's and chaos is assured, 16381 is the max prime for 14 bit field
44 */ 39 */
@@ -163,7 +158,7 @@ static int search_name_hashtable(const char *key)
163 } 158 }
164 } 159 }
165 } 160 }
166 name_hashtable[probe_address] = bb_xstrdup(key); 161 name_hashtable[probe_address] = xstrdup(key);
167 return(probe_address); 162 return(probe_address);
168} 163}
169 164
@@ -204,10 +199,10 @@ static int version_compare_part(const char *version1, const char *version2)
204 int ret; 199 int ret;
205 200
206 if (version1 == NULL) { 201 if (version1 == NULL) {
207 version1 = bb_xstrdup(""); 202 version1 = xstrdup("");
208 } 203 }
209 if (version2 == NULL) { 204 if (version2 == NULL) {
210 version2 = bb_xstrdup(""); 205 version2 = xstrdup("");
211 } 206 }
212 upstream_len1 = strlen(version1); 207 upstream_len1 = strlen(version1);
213 upstream_len2 = strlen(version2); 208 upstream_len2 = strlen(version2);
@@ -215,10 +210,10 @@ static int version_compare_part(const char *version1, const char *version2)
215 while ((len1 < upstream_len1) || (len2 < upstream_len2)) { 210 while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
216 /* Compare non-digit section */ 211 /* Compare non-digit section */
217 tmp_int = strcspn(&version1[len1], "0123456789"); 212 tmp_int = strcspn(&version1[len1], "0123456789");
218 name1_char = bb_xstrndup(&version1[len1], tmp_int); 213 name1_char = xstrndup(&version1[len1], tmp_int);
219 len1 += tmp_int; 214 len1 += tmp_int;
220 tmp_int = strcspn(&version2[len2], "0123456789"); 215 tmp_int = strcspn(&version2[len2], "0123456789");
221 name2_char = bb_xstrndup(&version2[len2], tmp_int); 216 name2_char = xstrndup(&version2[len2], tmp_int);
222 len2 += tmp_int; 217 len2 += tmp_int;
223 tmp_int = strcmp(name1_char, name2_char); 218 tmp_int = strcmp(name1_char, name2_char);
224 free(name1_char); 219 free(name1_char);
@@ -230,10 +225,10 @@ static int version_compare_part(const char *version1, const char *version2)
230 225
231 /* Compare digits */ 226 /* Compare digits */
232 tmp_int = strspn(&version1[len1], "0123456789"); 227 tmp_int = strspn(&version1[len1], "0123456789");
233 name1_char = bb_xstrndup(&version1[len1], tmp_int); 228 name1_char = xstrndup(&version1[len1], tmp_int);
234 len1 += tmp_int; 229 len1 += tmp_int;
235 tmp_int = strspn(&version2[len2], "0123456789"); 230 tmp_int = strspn(&version2[len2], "0123456789");
236 name2_char = bb_xstrndup(&version2[len2], tmp_int); 231 name2_char = xstrndup(&version2[len2], tmp_int);
237 len2 += tmp_int; 232 len2 += tmp_int;
238 ver_num1 = atoi(name1_char); 233 ver_num1 = atoi(name1_char);
239 ver_num2 = atoi(name2_char); 234 ver_num2 = atoi(name2_char);
@@ -292,8 +287,8 @@ static int version_compare(const unsigned int ver1, const unsigned int ver2)
292 } 287 }
293 288
294 /* Compare upstream version */ 289 /* Compare upstream version */
295 upstream_ver1 = bb_xstrdup(ver1_ptr); 290 upstream_ver1 = xstrdup(ver1_ptr);
296 upstream_ver2 = bb_xstrdup(ver2_ptr); 291 upstream_ver2 = xstrdup(ver2_ptr);
297 292
298 /* Chop off debian version, and store for later use */ 293 /* Chop off debian version, and store for later use */
299 deb_ver1 = strrchr(upstream_ver1, '-'); 294 deb_ver1 = strrchr(upstream_ver1, '-');
@@ -429,7 +424,7 @@ static void add_edge_to_node(common_node_t *node, edge_t *edge)
429 */ 424 */
430static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type) 425static void add_split_dependencies(common_node_t *parent_node, const char *whole_line, unsigned int edge_type)
431{ 426{
432 char *line = bb_xstrdup(whole_line); 427 char *line = xstrdup(whole_line);
433 char *line2; 428 char *line2;
434 char *line_ptr1 = NULL; 429 char *line_ptr1 = NULL;
435 char *line_ptr2 = NULL; 430 char *line_ptr2 = NULL;
@@ -444,7 +439,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
444 do { 439 do {
445 /* skip leading spaces */ 440 /* skip leading spaces */
446 field += strspn(field, " "); 441 field += strspn(field, " ");
447 line2 = bb_xstrdup(field); 442 line2 = xstrdup(field);
448 field2 = strtok_r(line2, "|", &line_ptr2); 443 field2 = strtok_r(line2, "|", &line_ptr2);
449 if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) && 444 if ( (edge_type == EDGE_DEPENDS || edge_type == EDGE_PRE_DEPENDS) &&
450 (strcmp(field, field2) != 0)) { 445 (strcmp(field, field2) != 0)) {
@@ -538,6 +533,93 @@ static void free_package(common_node_t *node)
538 } 533 }
539} 534}
540 535
536/*
537 * Gets the next package field from package_buffer, seperated into the field name
538 * and field value, it returns the int offset to the first character of the next field
539 */
540static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
541{
542 int offset_name_start = 0;
543 int offset_name_end = 0;
544 int offset_value_start = 0;
545 int offset_value_end = 0;
546 int offset = 0;
547 int next_offset;
548 int name_length;
549 int value_length;
550 int exit_flag = FALSE;
551
552 if (package_buffer == NULL) {
553 *field_name = NULL;
554 *field_value = NULL;
555 return(-1);
556 }
557 while (1) {
558 next_offset = offset + 1;
559 switch (package_buffer[offset]) {
560 case('\0'):
561 exit_flag = TRUE;
562 break;
563 case(':'):
564 if (offset_name_end == 0) {
565 offset_name_end = offset;
566 offset_value_start = next_offset;
567 }
568 /* TODO: Name might still have trailing spaces if ':' isnt
569 * immediately after name */
570 break;
571 case('\n'):
572 /* TODO: The char next_offset may be out of bounds */
573 if (package_buffer[next_offset] != ' ') {
574 exit_flag = TRUE;
575 break;
576 }
577 case('\t'):
578 case(' '):
579 /* increment the value start point if its a just filler */
580 if (offset_name_start == offset) {
581 offset_name_start++;
582 }
583 if (offset_value_start == offset) {
584 offset_value_start++;
585 }
586 break;
587 }
588 if (exit_flag) {
589 /* Check that the names are valid */
590 offset_value_end = offset;
591 name_length = offset_name_end - offset_name_start;
592 value_length = offset_value_end - offset_value_start;
593 if (name_length == 0) {
594 break;
595 }
596 if ((name_length > 0) && (value_length > 0)) {
597 break;
598 }
599
600 /* If not valid, start fresh with next field */
601 exit_flag = FALSE;
602 offset_name_start = offset + 1;
603 offset_name_end = 0;
604 offset_value_start = offset + 1;
605 offset_value_end = offset + 1;
606 offset++;
607 }
608 offset++;
609 }
610 if (name_length == 0) {
611 *field_name = NULL;
612 } else {
613 *field_name = xstrndup(&package_buffer[offset_name_start], name_length);
614 }
615 if (value_length > 0) {
616 *field_value = xstrndup(&package_buffer[offset_value_start], value_length);
617 } else {
618 *field_value = NULL;
619 }
620 return(next_offset);
621}
622
541static unsigned int fill_package_struct(char *control_buffer) 623static unsigned int fill_package_struct(char *control_buffer)
542{ 624{
543 static const char *const field_names[] = { "Package", "Version", 625 static const char *const field_names[] = { "Package", "Version",
@@ -631,7 +713,7 @@ static unsigned int get_status(const unsigned int status_node, const int num)
631 status_string += strspn(status_string, " "); 713 status_string += strspn(status_string, " ");
632 } 714 }
633 len = strcspn(status_string, " \n\0"); 715 len = strcspn(status_string, " \n\0");
634 state_sub_string = bb_xstrndup(status_string, len); 716 state_sub_string = xstrndup(status_string, len);
635 state_sub_num = search_name_hashtable(state_sub_string); 717 state_sub_num = search_name_hashtable(state_sub_string);
636 free(state_sub_string); 718 free(state_sub_string);
637 return(state_sub_num); 719 return(state_sub_num);
@@ -666,7 +748,7 @@ static void set_status(const unsigned int status_node_num, const char *new_value
666 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen"); 748 bb_error_msg_and_die("DEBUG ONLY: this shouldnt happen");
667 } 749 }
668 750
669 new_status = bb_xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]); 751 new_status = xasprintf("%s %s %s", name_hashtable[want], name_hashtable[flag], name_hashtable[status]);
670 status_hashtable[status_node_num]->status = search_name_hashtable(new_status); 752 status_hashtable[status_node_num]->status = search_name_hashtable(new_status);
671 free(new_status); 753 free(new_status);
672 return; 754 return;
@@ -705,7 +787,7 @@ static void index_status_file(const char *filename)
705 status_node_t *status_node = NULL; 787 status_node_t *status_node = NULL;
706 unsigned int status_num; 788 unsigned int status_num;
707 789
708 status_file = bb_xfopen(filename, "r"); 790 status_file = xfopen(filename, "r");
709 while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) { 791 while ((control_buffer = fgets_str(status_file, "\n\n")) != NULL) {
710 const unsigned int package_num = fill_package_struct(control_buffer); 792 const unsigned int package_num = fill_package_struct(control_buffer);
711 if (package_num != -1) { 793 if (package_num != -1) {
@@ -715,7 +797,7 @@ static void index_status_file(const char *filename)
715 if (status_line != NULL) { 797 if (status_line != NULL) {
716 status_line += 7; 798 status_line += 7;
717 status_line += strspn(status_line, " \n\t"); 799 status_line += strspn(status_line, " \n\t");
718 status_line = bb_xstrndup(status_line, strcspn(status_line, "\n\0")); 800 status_line = xstrndup(status_line, strcspn(status_line, "\n\0"));
719 status_node->status = search_name_hashtable(status_line); 801 status_node->status = search_name_hashtable(status_line);
720 free(status_line); 802 free(status_line);
721 } 803 }
@@ -749,8 +831,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
749/* This could do with a cleanup */ 831/* This could do with a cleanup */
750static void write_status_file(deb_file_t **deb_file) 832static void write_status_file(deb_file_t **deb_file)
751{ 833{
752 FILE *old_status_file = bb_xfopen("/var/lib/dpkg/status", "r"); 834 FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
753 FILE *new_status_file = bb_xfopen("/var/lib/dpkg/status.udeb", "w"); 835 FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
754 char *package_name; 836 char *package_name;
755 char *status_from_file; 837 char *status_from_file;
756 char *control_buffer = NULL; 838 char *control_buffer = NULL;
@@ -768,14 +850,14 @@ static void write_status_file(deb_file_t **deb_file)
768 850
769 tmp_string += 8; 851 tmp_string += 8;
770 tmp_string += strspn(tmp_string, " \n\t"); 852 tmp_string += strspn(tmp_string, " \n\t");
771 package_name = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n\0")); 853 package_name = xstrndup(tmp_string, strcspn(tmp_string, "\n\0"));
772 write_flag = FALSE; 854 write_flag = FALSE;
773 tmp_string = strstr(control_buffer, "Status:"); 855 tmp_string = strstr(control_buffer, "Status:");
774 if (tmp_string != NULL) { 856 if (tmp_string != NULL) {
775 /* Seperate the status value from the control buffer */ 857 /* Seperate the status value from the control buffer */
776 tmp_string += 7; 858 tmp_string += 7;
777 tmp_string += strspn(tmp_string, " \n\t"); 859 tmp_string += strspn(tmp_string, " \n\t");
778 status_from_file = bb_xstrndup(tmp_string, strcspn(tmp_string, "\n")); 860 status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
779 } else { 861 } else {
780 status_from_file = NULL; 862 status_from_file = NULL;
781 } 863 }
@@ -1181,7 +1263,7 @@ static int run_package_script(const char *package_name, const char *script_type)
1181 char *script_path; 1263 char *script_path;
1182 int result; 1264 int result;
1183 1265
1184 script_path = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type); 1266 script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
1185 1267
1186 /* If the file doesnt exist is isnt a fatal */ 1268 /* If the file doesnt exist is isnt a fatal */
1187 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path); 1269 result = lstat(script_path, &path_stat) < 0 ? EXIT_SUCCESS : system(script_path);
@@ -1200,7 +1282,7 @@ static char **all_control_list(const char *package_name)
1200 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1282 /* Create a list of all /var/lib/dpkg/info/<package> files */
1201 remove_files = xzalloc(sizeof(all_control_files)); 1283 remove_files = xzalloc(sizeof(all_control_files));
1202 while (all_control_files[i]) { 1284 while (all_control_files[i]) {
1203 remove_files[i] = bb_xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]); 1285 remove_files[i] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, all_control_files[i]);
1204 i++; 1286 i++;
1205 } 1287 }
1206 1288
@@ -1296,8 +1378,8 @@ static void remove_package(const unsigned int package_num, int noisy)
1296 1378
1297 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */ 1379 /* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
1298 exclude_files = xzalloc(sizeof(char*) * 3); 1380 exclude_files = xzalloc(sizeof(char*) * 3);
1299 exclude_files[0] = bb_xstrdup(conffile_name); 1381 exclude_files[0] = xstrdup(conffile_name);
1300 exclude_files[1] = bb_xasprintf("/var/lib/dpkg/info/%s.postrm", package_name); 1382 exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.postrm", package_name);
1301 1383
1302 /* Create a list of all /var/lib/dpkg/info/<package> files */ 1384 /* Create a list of all /var/lib/dpkg/info/<package> files */
1303 remove_files = all_control_list(package_name); 1385 remove_files = all_control_list(package_name);
@@ -1361,7 +1443,7 @@ static archive_handle_t *init_archive_deb_ar(const char *filename)
1361 /* Setup an ar archive handle that refers to the gzip sub archive */ 1443 /* Setup an ar archive handle that refers to the gzip sub archive */
1362 ar_handle = init_handle(); 1444 ar_handle = init_handle();
1363 ar_handle->filter = filter_accept_list_reassign; 1445 ar_handle->filter = filter_accept_list_reassign;
1364 ar_handle->src_fd = bb_xopen(filename, O_RDONLY); 1446 ar_handle->src_fd = xopen(filename, O_RDONLY);
1365 1447
1366 return(ar_handle); 1448 return(ar_handle);
1367} 1449}
@@ -1428,7 +1510,7 @@ static void data_extract_all_prefix(archive_handle_t *archive_handle)
1428 1510
1429 name_ptr += strspn(name_ptr, "./"); 1511 name_ptr += strspn(name_ptr, "./");
1430 if (name_ptr[0] != '\0') { 1512 if (name_ptr[0] != '\0') {
1431 archive_handle->file_header->name = bb_xasprintf("%s%s", archive_handle->buffer, name_ptr); 1513 archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
1432 data_extract_all(archive_handle); 1514 data_extract_all(archive_handle);
1433 } 1515 }
1434 return; 1516 return;
@@ -1457,12 +1539,12 @@ static void unpack_package(deb_file_t *deb_file)
1457 } 1539 }
1458 1540
1459 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */ 1541 /* Extract control.tar.gz to /var/lib/dpkg/info/<package>.filename */
1460 info_prefix = bb_xasprintf("/var/lib/dpkg/info/%s.", package_name); 1542 info_prefix = xasprintf("/var/lib/dpkg/info/%s.", package_name);
1461 archive_handle = init_archive_deb_ar(deb_file->filename); 1543 archive_handle = init_archive_deb_ar(deb_file->filename);
1462 init_archive_deb_control(archive_handle); 1544 init_archive_deb_control(archive_handle);
1463 1545
1464 while(all_control_files[i]) { 1546 while(all_control_files[i]) {
1465 char *c = bb_xasprintf("./%s", all_control_files[i]); 1547 char *c = xasprintf("./%s", all_control_files[i]);
1466 llist_add_to(&accept_list, c); 1548 llist_add_to(&accept_list, c);
1467 i++; 1549 i++;
1468 } 1550 }
@@ -1489,7 +1571,7 @@ static void unpack_package(deb_file_t *deb_file)
1489 1571
1490 /* Create the list file */ 1572 /* Create the list file */
1491 strcat(info_prefix, "list"); 1573 strcat(info_prefix, "list");
1492 out_stream = bb_xfopen(info_prefix, "w"); 1574 out_stream = xfopen(info_prefix, "w");
1493 while (archive_handle->sub_archive->passed) { 1575 while (archive_handle->sub_archive->passed) {
1494 /* the leading . has been stripped by data_extract_all_prefix already */ 1576 /* the leading . has been stripped by data_extract_all_prefix already */
1495 fputs(archive_handle->sub_archive->passed->data, out_stream); 1577 fputs(archive_handle->sub_archive->passed->data, out_stream);
@@ -1600,7 +1682,7 @@ int dpkg_main(int argc, char **argv)
1600 if (deb_file[deb_count]->control_file == NULL) { 1682 if (deb_file[deb_count]->control_file == NULL) {
1601 bb_error_msg_and_die("Couldnt extract control file"); 1683 bb_error_msg_and_die("Couldnt extract control file");
1602 } 1684 }
1603 deb_file[deb_count]->filename = bb_xstrdup(argv[optind]); 1685 deb_file[deb_count]->filename = xstrdup(argv[optind]);
1604 package_num = fill_package_struct(deb_file[deb_count]->control_file); 1686 package_num = fill_package_struct(deb_file[deb_count]->control_file);
1605 1687
1606 if (package_num == -1) { 1688 if (package_num == -1) {
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 48a1ac161..ce65e219a 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -4,13 +4,8 @@
4 * 4 *
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */ 6 */
7#include <fcntl.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11
12#include "unarchive.h"
13#include "busybox.h" 7#include "busybox.h"
8#include "unarchive.h"
14 9
15#define DPKG_DEB_OPT_CONTENTS 1 10#define DPKG_DEB_OPT_CONTENTS 1
16#define DPKG_DEB_OPT_CONTROL 2 11#define DPKG_DEB_OPT_CONTROL 2
@@ -81,7 +76,7 @@ int dpkg_deb_main(int argc, char **argv)
81 bb_show_usage(); 76 bb_show_usage();
82 } 77 }
83 78
84 tar_archive->src_fd = ar_archive->src_fd = bb_xopen(argv[optind++], O_RDONLY); 79 tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
85 80
86 /* Workout where to extract the files */ 81 /* Workout where to extract the files */
87 /* 2nd argument is a dir name */ 82 /* 2nd argument is a dir name */
@@ -90,7 +85,7 @@ int dpkg_deb_main(int argc, char **argv)
90 } 85 }
91 if (extract_dir) { 86 if (extract_dir) {
92 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ 87 mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
93 bb_xchdir(extract_dir); 88 xchdir(extract_dir);
94 } 89 }
95 unpack_ar_archive(ar_archive); 90 unpack_ar_archive(ar_archive);
96 91
diff --git a/archival/gunzip.c b/archival/gunzip.c
index bd6047e13..3a1d1cb61 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -27,13 +27,6 @@
27 * See the file algorithm.doc for the compression algorithms and file formats. 27 * See the file algorithm.doc for the compression algorithms and file formats.
28 */ 28 */
29 29
30#include <stdlib.h>
31#include <string.h>
32#include <unistd.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <fcntl.h>
36
37#include "busybox.h" 30#include "busybox.h"
38#include "unarchive.h" 31#include "unarchive.h"
39 32
@@ -67,7 +60,7 @@ int gunzip_main(int argc, char **argv)
67 src_fd = STDIN_FILENO; 60 src_fd = STDIN_FILENO;
68 opt |= GUNZIP_OPT_STDOUT; 61 opt |= GUNZIP_OPT_STDOUT;
69 } else { 62 } else {
70 src_fd = bb_xopen(old_path, O_RDONLY); 63 src_fd = xopen(old_path, O_RDONLY);
71 64
72 /* Get the time stamp on the input file. */ 65 /* Get the time stamp on the input file. */
73 xstat(old_path, &stat_buf); 66 xstat(old_path, &stat_buf);
@@ -81,13 +74,13 @@ int gunzip_main(int argc, char **argv)
81 74
82 /* Set output filename and number */ 75 /* Set output filename and number */
83 if (opt & GUNZIP_OPT_TEST) { 76 if (opt & GUNZIP_OPT_TEST) {
84 dst_fd = bb_xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */ 77 dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
85 } else if (opt & GUNZIP_OPT_STDOUT) { 78 } else if (opt & GUNZIP_OPT_STDOUT) {
86 dst_fd = STDOUT_FILENO; 79 dst_fd = STDOUT_FILENO;
87 } else { 80 } else {
88 char *extension; 81 char *extension;
89 82
90 new_path = bb_xstrdup(old_path); 83 new_path = xstrdup(old_path);
91 84
92 extension = strrchr(new_path, '.'); 85 extension = strrchr(new_path, '.');
93#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS 86#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
@@ -105,7 +98,7 @@ int gunzip_main(int argc, char **argv)
105 } 98 }
106 99
107 /* Open output file (with correct permissions) */ 100 /* Open output file (with correct permissions) */
108 dst_fd = bb_xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode); 101 dst_fd = xopen3(new_path, O_WRONLY | O_CREAT, stat_buf.st_mode);
109 102
110 /* If unzip succeeds remove the old file */ 103 /* If unzip succeeds remove the old file */
111 delete_path = old_path; 104 delete_path = old_path;
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c
index 6337e0c85..5d1ec302a 100644
--- a/archival/libunarchive/data_extract_all.c
+++ b/archival/libunarchive/data_extract_all.c
@@ -3,16 +3,6 @@
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */ 4 */
5 5
6#include <sys/types.h>
7
8#include <errno.h>
9#include <fcntl.h>
10#include <stdlib.h>
11#include <string.h>
12#include <utime.h>
13#include <unistd.h>
14#include <stdlib.h>
15
16#include "libbb.h" 6#include "libbb.h"
17#include "unarchive.h" 7#include "unarchive.h"
18 8
@@ -23,7 +13,7 @@ void data_extract_all(archive_handle_t *archive_handle)
23 int res; 13 int res;
24 14
25 if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) { 15 if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
26 char *name = bb_xstrdup(file_header->name); 16 char *name = xstrdup(file_header->name);
27 bb_make_directory (dirname(name), -1, FILEUTILS_RECUR); 17 bb_make_directory (dirname(name), -1, FILEUTILS_RECUR);
28 free(name); 18 free(name);
29 } 19 }
@@ -68,7 +58,7 @@ void data_extract_all(archive_handle_t *archive_handle)
68 switch(file_header->mode & S_IFMT) { 58 switch(file_header->mode & S_IFMT) {
69 case S_IFREG: { 59 case S_IFREG: {
70 /* Regular file */ 60 /* Regular file */
71 dst_fd = bb_xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL); 61 dst_fd = xopen(file_header->name, O_WRONLY | O_CREAT | O_EXCL);
72 bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size); 62 bb_copyfd_size(archive_handle->src_fd, dst_fd, file_header->size);
73 close(dst_fd); 63 close(dst_fd);
74 break; 64 break;
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index ae96ea375..657d4ab01 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -28,15 +28,7 @@
28 Manuel 28 Manuel
29 */ 29 */
30 30
31#include <setjmp.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
35#include <unistd.h>
36#include <limits.h>
37
38#include "libbb.h" 31#include "libbb.h"
39
40#include "unarchive.h" 32#include "unarchive.h"
41 33
42/* Constants for Huffman coding */ 34/* Constants for Huffman coding */
@@ -655,7 +647,7 @@ static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
655 647
656 /* Init the CRC32 table (big endian) */ 648 /* Init the CRC32 table (big endian) */
657 649
658 bd->crc32Table = bb_crc32_filltable(1); 650 bd->crc32Table = crc32_filltable(1);
659 651
660 /* Setup for I/O error handling via longjmp */ 652 /* Setup for I/O error handling via longjmp */
661 653
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 8f33e6e6c..7362da8c2 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -34,8 +34,6 @@
34 */ 34 */
35 35
36#include "libbb.h" 36#include "libbb.h"
37#include <sys/wait.h>
38#include <signal.h>
39#include "unarchive.h" 37#include "unarchive.h"
40 38
41typedef struct huft_s { 39typedef struct huft_s {
@@ -853,7 +851,7 @@ int inflate_unzip(int in, int out)
853 gunzip_bb = 0; 851 gunzip_bb = 0;
854 852
855 /* Create the crc table */ 853 /* Create the crc table */
856 gunzip_crc_table = bb_crc32_filltable(0); 854 gunzip_crc_table = crc32_filltable(0);
857 gunzip_crc = ~0; 855 gunzip_crc = ~0;
858 856
859 /* Allocate space for buffer */ 857 /* Allocate space for buffer */
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index 4627695e4..cabb4101b 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -4,12 +4,8 @@
4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
5 */ 5 */
6 6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include "unarchive.h"
12#include "libbb.h" 7#include "libbb.h"
8#include "unarchive.h"
13 9
14char get_header_ar(archive_handle_t *archive_handle) 10char get_header_ar(archive_handle_t *archive_handle)
15{ 11{
@@ -31,7 +27,7 @@ char get_header_ar(archive_handle_t *archive_handle)
31 static unsigned int ar_long_name_size; 27 static unsigned int ar_long_name_size;
32#endif 28#endif
33 29
34 /* dont use bb_xread as we want to handle the error ourself */ 30 /* dont use xread as we want to handle the error ourself */
35 if (read(archive_handle->src_fd, ar.raw, 60) != 60) { 31 if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
36 /* End Of File */ 32 /* End Of File */
37 return(EXIT_FAILURE); 33 return(EXIT_FAILURE);
@@ -85,14 +81,14 @@ char get_header_ar(archive_handle_t *archive_handle)
85 if (long_offset >= ar_long_name_size) { 81 if (long_offset >= ar_long_name_size) {
86 bb_error_msg_and_die("Cant resolve long filename"); 82 bb_error_msg_and_die("Cant resolve long filename");
87 } 83 }
88 typed->name = bb_xstrdup(ar_long_names + long_offset); 84 typed->name = xstrdup(ar_long_names + long_offset);
89 } 85 }
90#else 86#else
91 bb_error_msg_and_die("long filenames not supported"); 87 bb_error_msg_and_die("long filenames not supported");
92#endif 88#endif
93 } else { 89 } else {
94 /* short filenames */ 90 /* short filenames */
95 typed->name = bb_xstrndup(ar.formatted.name, 16); 91 typed->name = xstrndup(ar.formatted.name, 16);
96 } 92 }
97 93
98 typed->name[strcspn(typed->name, " /")] = '\0'; 94 typed->name[strcspn(typed->name, " /")] = '\0';
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c
index 28c743589..d405d0e1b 100644
--- a/archival/libunarchive/get_header_cpio.c
+++ b/archival/libunarchive/get_header_cpio.c
@@ -4,13 +4,8 @@
4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 4 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
5 */ 5 */
6 6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include <sys/sysmacros.h> /* major() and minor() */
12#include "unarchive.h"
13#include "libbb.h" 7#include "libbb.h"
8#include "unarchive.h"
14 9
15typedef struct hardlinks_s { 10typedef struct hardlinks_s {
16 file_header_t *entry; 11 file_header_t *entry;
@@ -123,7 +118,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
123 pending_hardlinks = 1; 118 pending_hardlinks = 1;
124 while (tmp) { 119 while (tmp) {
125 if (tmp->inode == inode) { 120 if (tmp->inode == inode) {
126 tmp->entry->link_name = bb_xstrdup(file_header->name); 121 tmp->entry->link_name = xstrdup(file_header->name);
127 nlink--; 122 nlink--;
128 } 123 }
129 tmp = tmp->next; 124 tmp = tmp->next;
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index fb7e9ae8f..0c622f44a 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -11,12 +11,8 @@
11 * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html 11 * http://www.opengroup.org/onlinepubs/007904975/utilities/pax.html
12 */ 12 */
13 13
14#include <stdio.h>
15#include <stdlib.h>
16#include <string.h>
17#include <sys/sysmacros.h> /* For makedev */
18#include "unarchive.h"
19#include "libbb.h" 14#include "libbb.h"
15#include "unarchive.h"
20 16
21#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS 17#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
22static char *longname = NULL; 18static char *longname = NULL;
@@ -106,7 +102,7 @@ char get_header_tar(archive_handle_t *archive_handle)
106 } else 102 } else
107#endif 103#endif
108 { 104 {
109 file_header->name = bb_xstrndup(tar.formatted.name,100); 105 file_header->name = xstrndup(tar.formatted.name,100);
110 106
111 if (tar.formatted.prefix[0]) { 107 if (tar.formatted.prefix[0]) {
112 char *temp = file_header->name; 108 char *temp = file_header->name;
@@ -120,7 +116,7 @@ char get_header_tar(archive_handle_t *archive_handle)
120 file_header->size = strtol(tar.formatted.size, NULL, 8); 116 file_header->size = strtol(tar.formatted.size, NULL, 8);
121 file_header->mtime = strtol(tar.formatted.mtime, NULL, 8); 117 file_header->mtime = strtol(tar.formatted.mtime, NULL, 8);
122 file_header->link_name = (tar.formatted.linkname[0] != '\0') ? 118 file_header->link_name = (tar.formatted.linkname[0] != '\0') ?
123 bb_xstrdup(tar.formatted.linkname) : NULL; 119 xstrdup(tar.formatted.linkname) : NULL;
124 file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8), 120 file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8),
125 strtol(tar.formatted.devminor, NULL, 8)); 121 strtol(tar.formatted.devminor, NULL, 8));
126 122
diff --git a/archival/rpm.c b/archival/rpm.c
index 3b70439a7..7b27c0250 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -7,16 +7,6 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <unistd.h>
12#include <signal.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <netinet/in.h> /* For ntohl & htonl function */
16#include <string.h> /* For strncmp */
17#include <sys/mman.h> /* For mmap */
18#include <time.h> /* For ctime */
19
20#include "busybox.h" 10#include "busybox.h"
21#include "unarchive.h" 11#include "unarchive.h"
22 12
@@ -127,7 +117,7 @@ int rpm_main(int argc, char **argv)
127 117
128 if (optind == argc) bb_show_usage(); 118 if (optind == argc) bb_show_usage();
129 while (optind < argc) { 119 while (optind < argc) {
130 rpm_fd = bb_xopen(argv[optind], O_RDONLY); 120 rpm_fd = xopen(argv[optind], O_RDONLY);
131 mytags = rpm_gettags(rpm_fd, (int *) &tagcount); 121 mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
132 offset = lseek(rpm_fd, 0, SEEK_CUR); 122 offset = lseek(rpm_fd, 0, SEEK_CUR);
133 if (!mytags) { printf("Error reading rpm header\n"); exit(-1); } 123 if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
@@ -198,7 +188,7 @@ void extract_cpio_gz(int fd) {
198 bb_error_msg_and_die("Invalid gzip magic"); 188 bb_error_msg_and_die("Invalid gzip magic");
199 } 189 }
200 check_header_gzip(archive_handle->src_fd); 190 check_header_gzip(archive_handle->src_fd);
201 bb_xchdir("/"); // Install RPM's to root 191 xchdir("/"); // Install RPM's to root
202 192
203 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); 193 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
204 archive_handle->offset = 0; 194 archive_handle->offset = 0;
@@ -302,7 +292,7 @@ void fileaction_dobackup(char *filename, int fileref)
302 if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */ 292 if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
303 stat_res = lstat (filename, &oldfile); 293 stat_res = lstat (filename, &oldfile);
304 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */ 294 if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
305 newname = bb_xstrdup(filename); 295 newname = xstrdup(filename);
306 newname = strcat(newname, ".rpmorig"); 296 newname = strcat(newname, ".rpmorig");
307 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); 297 copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
308 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE); 298 remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
@@ -328,7 +318,7 @@ void loop_through_files(int filetag, void (*fileaction)(char *filename, int file
328{ 318{
329 int count = 0; 319 int count = 0;
330 while (rpm_getstring(filetag, count)) { 320 while (rpm_getstring(filetag, count)) {
331 char * filename = bb_xasprintf("%s%s", 321 char * filename = xasprintf("%s%s",
332 rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, 322 rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
333 count)), rpm_getstring(RPMTAG_BASENAMES, count)); 323 count)), rpm_getstring(RPMTAG_BASENAMES, count));
334 fileaction(filename, count++); 324 fileaction(filename, count++);
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 6aae150e2..3ae8458dd 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -6,11 +6,6 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9#include <sys/types.h>
10#include <netinet/in.h> /* For ntohl & htonl function */
11#include <fcntl.h>
12#include <unistd.h>
13#include <string.h>
14#include "busybox.h" 9#include "busybox.h"
15#include "unarchive.h" 10#include "unarchive.h"
16 11
@@ -63,7 +58,7 @@ int rpm2cpio_main(int argc, char **argv)
63 if (argc == 1) { 58 if (argc == 1) {
64 rpm_fd = STDIN_FILENO; 59 rpm_fd = STDIN_FILENO;
65 } else { 60 } else {
66 rpm_fd = bb_xopen(argv[1], O_RDONLY); 61 rpm_fd = xopen(argv[1], O_RDONLY);
67 } 62 }
68 63
69 xread(rpm_fd, &lead, sizeof(struct rpm_lead)); 64 xread(rpm_fd, &lead, sizeof(struct rpm_lead));
diff --git a/archival/uncompress.c b/archival/uncompress.c
index 801293fd9..ca775c787 100644
--- a/archival/uncompress.c
+++ b/archival/uncompress.c
@@ -5,13 +5,6 @@
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */ 6 */
7 7
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <fcntl.h>
14
15#include "busybox.h" 8#include "busybox.h"
16#include "unarchive.h" 9#include "unarchive.h"
17 10
@@ -36,7 +29,7 @@ int uncompress_main(int argc, char **argv)
36 src_fd = STDIN_FILENO; 29 src_fd = STDIN_FILENO;
37 flags |= GUNZIP_TO_STDOUT; 30 flags |= GUNZIP_TO_STDOUT;
38 } else { 31 } else {
39 src_fd = bb_xopen(compressed_file, O_RDONLY); 32 src_fd = xopen(compressed_file, O_RDONLY);
40 } 33 }
41 34
42 /* Check that the input is sane. */ 35 /* Check that the input is sane. */
@@ -52,7 +45,7 @@ int uncompress_main(int argc, char **argv)
52 struct stat stat_buf; 45 struct stat stat_buf;
53 char *extension; 46 char *extension;
54 47
55 uncompressed_file = bb_xstrdup(compressed_file); 48 uncompressed_file = xstrdup(compressed_file);
56 49
57 extension = strrchr(uncompressed_file, '.'); 50 extension = strrchr(uncompressed_file, '.');
58 if (!extension || (strcmp(extension, ".Z") != 0)) { 51 if (!extension || (strcmp(extension, ".Z") != 0)) {
@@ -62,7 +55,7 @@ int uncompress_main(int argc, char **argv)
62 55
63 /* Open output file */ 56 /* Open output file */
64 xstat(compressed_file, &stat_buf); 57 xstat(compressed_file, &stat_buf);
65 dst_fd = bb_xopen3(uncompressed_file, O_WRONLY | O_CREAT, 58 dst_fd = xopen3(uncompressed_file, O_WRONLY | O_CREAT,
66 stat_buf.st_mode); 59 stat_buf.st_mode);
67 60
68 /* If unzip succeeds remove the old file */ 61 /* If unzip succeeds remove the old file */
diff --git a/archival/unlzma.c b/archival/unlzma.c
index bb4b9db6b..fbd207ca1 100644
--- a/archival/unlzma.c
+++ b/archival/unlzma.c
@@ -8,12 +8,6 @@
8 * Licensed under GPL v2, see file LICENSE in this tarball for details. 8 * Licensed under GPL v2, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include <fcntl.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16
17#include "busybox.h" 11#include "busybox.h"
18#include "unarchive.h" 12#include "unarchive.h"
19 13
@@ -31,7 +25,7 @@ int unlzma_main(int argc, char **argv)
31 filename = argv[optind]; 25 filename = argv[optind];
32 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) { 26 if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
33 /* Open input file */ 27 /* Open input file */
34 src_fd = bb_xopen(filename, O_RDONLY); 28 src_fd = xopen(filename, O_RDONLY);
35 } else { 29 } else {
36 src_fd = STDIN_FILENO; 30 src_fd = STDIN_FILENO;
37 filename = 0; 31 filename = 0;
@@ -50,7 +44,7 @@ int unlzma_main(int argc, char **argv)
50 } 44 }
51 xstat(filename, &stat_buf); 45 xstat(filename, &stat_buf);
52 *extension = 0; 46 *extension = 0;
53 dst_fd = bb_xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode); 47 dst_fd = xopen3(filename, O_WRONLY | O_CREAT, stat_buf.st_mode);
54 } else 48 } else
55 dst_fd = STDOUT_FILENO; 49 dst_fd = STDOUT_FILENO;
56 status = unlzma(src_fd, dst_fd); 50 status = unlzma(src_fd, dst_fd);
diff --git a/archival/unzip.c b/archival/unzip.c
index 012f355e2..68083e987 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -24,13 +24,8 @@
24 * - central directory 24 * - central directory
25 */ 25 */
26 26
27#include <fcntl.h>
28#include <stdlib.h>
29#include <string.h>
30#include <unistd.h>
31#include <errno.h>
32#include "unarchive.h"
33#include "busybox.h" 27#include "busybox.h"
28#include "unarchive.h"
34 29
35#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50) 30#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
36#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50) 31#define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50)
@@ -68,7 +63,7 @@ static void unzip_skip(int fd, off_t skip)
68static void unzip_create_leading_dirs(char *fn) 63static void unzip_create_leading_dirs(char *fn)
69{ 64{
70 /* Create all leading directories */ 65 /* Create all leading directories */
71 char *name = bb_xstrdup(fn); 66 char *name = xstrdup(fn);
72 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) { 67 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
73 bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */ 68 bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */
74 } 69 }
@@ -143,7 +138,7 @@ int unzip_main(int argc, char **argv)
143 break; 138 break;
144 139
145 case 1 : /* The zip file */ 140 case 1 : /* The zip file */
146 src_fn = bb_xstrndup(optarg, strlen(optarg)+4); 141 src_fn = xstrndup(optarg, strlen(optarg)+4);
147 opt_range++; 142 opt_range++;
148 break; 143 break;
149 144
@@ -212,7 +207,7 @@ int unzip_main(int argc, char **argv)
212 207
213 /* Change dir if necessary */ 208 /* Change dir if necessary */
214 if (base_dir) 209 if (base_dir)
215 bb_xchdir(base_dir); 210 xchdir(base_dir);
216 211
217 if (verbosity != v_silent) 212 if (verbosity != v_silent)
218 printf("Archive: %s\n", src_fn); 213 printf("Archive: %s\n", src_fn);
@@ -338,7 +333,7 @@ int unzip_main(int argc, char **argv)
338 overwrite = o_always; 333 overwrite = o_always;
339 case 'y': /* Open file and fall into unzip */ 334 case 'y': /* Open file and fall into unzip */
340 unzip_create_leading_dirs(dst_fn); 335 unzip_create_leading_dirs(dst_fn);
341 dst_fd = bb_xopen(dst_fn, O_WRONLY | O_CREAT); 336 dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT);
342 case -1: /* Unzip */ 337 case -1: /* Unzip */
343 if (verbosity == v_normal) { 338 if (verbosity == v_normal) {
344 printf(" inflating: %s\n", dst_fn); 339 printf(" inflating: %s\n", dst_fn);
@@ -366,7 +361,7 @@ int unzip_main(int argc, char **argv)
366 bb_perror_msg_and_die("Cannot read input"); 361 bb_perror_msg_and_die("Cannot read input");
367 } 362 }
368 free(dst_fn); 363 free(dst_fn);
369 dst_fn = bb_xstrdup(key_buf); 364 dst_fn = xstrdup(key_buf);
370 chomp(dst_fn); 365 chomp(dst_fn);
371 goto _check_file; 366 goto _check_file;
372 367
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 @@
8 * 8 *
9 */ 9 */
10 10
11#include <errno.h>
12#include <fcntl.h>
13#include <stdio.h>
14#include <unistd.h>
15#include <string.h>
16#include <stdlib.h>
17#include <sys/ioctl.h>
18#include "busybox.h" 11#include "busybox.h"
19 12
20/* From <linux/kd.h> */ 13/* From <linux/kd.h> */
@@ -38,7 +31,7 @@ int dumpkmap_main(int argc, char **argv)
38 if (argc >= 2 && *argv[1] == '-') 31 if (argc >= 2 && *argv[1] == '-')
39 bb_show_usage(); 32 bb_show_usage();
40 33
41 fd = bb_xopen(CURRENT_VC, O_RDWR); 34 fd = xopen(CURRENT_VC, O_RDWR);
42 35
43 write(1, magic, 7); 36 write(1, magic, 7);
44 37
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 @@
7 * Loads the console font, and possibly the corresponding screen map(s). 7 * Loads the console font, and possibly the corresponding screen map(s).
8 * (Adapted for busybox by Matej Vela.) 8 * (Adapted for busybox by Matej Vela.)
9 */ 9 */
10#include <stdio.h>
11#include <string.h>
12#include <fcntl.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <sys/types.h>
16#include <dirent.h>
17#include <errno.h>
18#include <sys/ioctl.h>
19#include <sys/kd.h>
20#include <endian.h>
21#include "busybox.h" 10#include "busybox.h"
11#include <sys/kd.h>
22 12
23enum{ 13enum{
24 PSF_MAGIC1 = 0x36, 14 PSF_MAGIC1 = 0x36,
@@ -47,7 +37,7 @@ int loadfont_main(int argc, char **argv)
47 if (argc != 1) 37 if (argc != 1)
48 bb_show_usage(); 38 bb_show_usage();
49 39
50 fd = bb_xopen(CURRENT_VC, O_RDWR); 40 fd = xopen(CURRENT_VC, O_RDWR);
51 loadnewfont(fd); 41 loadnewfont(fd);
52 42
53 return EXIT_SUCCESS; 43 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 @@
8 * 8 *
9 */ 9 */
10 10
11#include <errno.h>
12#include <fcntl.h>
13#include <stdio.h>
14#include <string.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <sys/ioctl.h>
18#include "busybox.h" 11#include "busybox.h"
19 12
20#define BINARY_KEYMAP_MAGIC "bkeymap" 13#define BINARY_KEYMAP_MAGIC "bkeymap"
@@ -43,7 +36,7 @@ int loadkmap_main(int argc, char **argv)
43 if (argc != 1) 36 if (argc != 1)
44 bb_show_usage(); 37 bb_show_usage();
45 38
46 fd = bb_xopen(CURRENT_VC, O_RDWR); 39 fd = xopen(CURRENT_VC, O_RDWR);
47 40
48 xread(0, buff, 7); 41 xread(0, buff, 7);
49 if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) 42 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)
40 close(0); /* so that new vt becomes stdin */ 40 close(0); /* so that new vt becomes stdin */
41 41
42 /* and grab new one */ 42 /* and grab new one */
43 fd = bb_xopen(vtname, O_RDWR); 43 fd = xopen(vtname, O_RDWR);
44 44
45 /* Reassign stdout and sterr */ 45 /* Reassign stdout and sterr */
46 dup2(fd, STDOUT_FILENO); 46 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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <sys/ioctl.h>
11#include <sys/stat.h>
12#include <sys/types.h>
13#include <fcntl.h>
14#include <stdio.h>
15#include <getopt.h> /* struct option */
16
17#include "busybox.h" 10#include "busybox.h"
18 11
19#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS 12#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
@@ -47,7 +40,7 @@ int setconsole_main(int argc, char **argv)
47 device = CONSOLE_DEV; 40 device = CONSOLE_DEV;
48 } 41 }
49 42
50 if (-1 == ioctl(bb_xopen(device, O_RDONLY), TIOCCONS)) { 43 if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
51 bb_perror_msg_and_die("TIOCCONS"); 44 bb_perror_msg_and_die("TIOCCONS");
52 } 45 }
53 return EXIT_SUCCESS; 46 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 @@
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 */ 10 */
11 11
12#include <stdio.h>
13#include <stdlib.h>
14#include <fcntl.h>
15#include <sys/ioctl.h>
16#include "busybox.h" 12#include "busybox.h"
17 13
18extern int setlogcons_main(int argc, char **argv) 14extern int setlogcons_main(int argc, char **argv)
@@ -28,7 +24,7 @@ extern int setlogcons_main(int argc, char **argv)
28 if (argc == 2) 24 if (argc == 2)
29 arg.subarg = atoi(argv[1]); 25 arg.subarg = atoi(argv[1]);
30 26
31 if (ioctl(bb_xopen(VC_1, O_RDONLY), TIOCLINUX, &arg)) 27 if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
32 bb_perror_msg_and_die("TIOCLINUX");; 28 bb_perror_msg_and_die("TIOCLINUX");;
33 29
34 return 0; 30 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 @@
17 * Major size reduction... over 50% (>1.5k) on i386. 17 * Major size reduction... over 50% (>1.5k) on i386.
18 */ 18 */
19 19
20#include <sys/types.h>
21#include <ctype.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <time.h>
26#include <unistd.h>
27
28#include "busybox.h" 20#include "busybox.h"
29 21
30#ifdef CONFIG_LOCALE_SUPPORT
31#include <locale.h>
32#endif
33
34#define THURSDAY 4 /* for reformation */ 22#define THURSDAY 4 /* for reformation */
35#define SATURDAY 6 /* 1 Jan 1 was a Saturday */ 23#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
36 24
@@ -135,7 +123,7 @@ int cal_main(int argc, char **argv)
135 do { 123 do {
136 zero_tm.tm_mon = i; 124 zero_tm.tm_mon = i;
137 strftime(buf, sizeof(buf), "%B", &zero_tm); 125 strftime(buf, sizeof(buf), "%B", &zero_tm);
138 month_names[i] = bb_xstrdup(buf); 126 month_names[i] = xstrdup(buf);
139 127
140 if (i < 7) { 128 if (i < 7) {
141 zero_tm.tm_wday = i; 129 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 @@
11 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */ 11 * http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
12 12
13#include "busybox.h" 13#include "busybox.h"
14#include <unistd.h>
15#include <fcntl.h>
16 14
17int catv_main(int argc, char **argv) 15int catv_main(int argc, char **argv)
18{ 16{
@@ -28,7 +26,7 @@ int catv_main(int argc, char **argv)
28 // Read from stdin if there's nothing else to do. 26 // Read from stdin if there's nothing else to do.
29 27
30 fd = 0; 28 fd = 0;
31 if (*argv && 0>(fd = bb_xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE; 29 if (*argv && 0>(fd = xopen(*argv, O_RDONLY))) retval = EXIT_FAILURE;
32 else for(;;) { 30 else for(;;) {
33 int i, res; 31 int i, res;
34 32
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 @@
9 9
10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */ 10/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
11 11
12#include <stdlib.h>
13#include <stdio.h>
14#include <unistd.h>
15#include <errno.h>
16#include "busybox.h" 12#include "busybox.h"
17 13
18int chroot_main(int argc, char **argv) 14int chroot_main(int argc, char **argv)
@@ -25,7 +21,7 @@ int chroot_main(int argc, char **argv)
25 if (chroot(*argv)) { 21 if (chroot(*argv)) {
26 bb_perror_msg_and_die("cannot change root directory to %s", *argv); 22 bb_perror_msg_and_die("cannot change root directory to %s", *argv);
27 } 23 }
28 bb_xchdir("/"); 24 xchdir("/");
29 25
30 ++argv; 26 ++argv;
31 if (argc == 2) { 27 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 @@
6 * 6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
8 8
9#include <stdio.h>
10#include <unistd.h>
11#include <fcntl.h>
12#include "busybox.h" 9#include "busybox.h"
13 10
14int cksum_main(int argc, char **argv) { 11int cksum_main(int argc, char **argv) {
15 12
16 uint32_t *crc32_table = bb_crc32_filltable(1); 13 uint32_t *crc32_table = crc32_filltable(1);
17 14
18 FILE *fp; 15 FILE *fp;
19 uint32_t crc; 16 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 @@
21 * in the '-l' case. 21 * in the '-l' case.
22 */ 22 */
23 23
24#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include "busybox.h" 24#include "busybox.h"
28 25
29static FILE *cmp_xfopen_input(const char *filename) 26static FILE *cmp_xfopen_input(const char *filename)
@@ -105,12 +102,12 @@ int cmp_main(int argc, char **argv)
105 c1 = c2; 102 c1 = c2;
106 } 103 }
107 if (c1 == EOF) { 104 if (c1 == EOF) {
108 bb_xferror(fp1, filename1); 105 xferror(fp1, filename1);
109 fmt = fmt_eof; /* Well, no error, so it must really be EOF. */ 106 fmt = fmt_eof; /* Well, no error, so it must really be EOF. */
110 outfile = stderr; 107 outfile = stderr;
111 /* There may have been output to stdout (option -l), so 108 /* There may have been output to stdout (option -l), so
112 * make sure we fflush before writing to stderr. */ 109 * make sure we fflush before writing to stderr. */
113 bb_xfflush_stdout(); 110 xfflush_stdout();
114 } 111 }
115 if (opt_flags != OPT_s) { 112 if (opt_flags != OPT_s) {
116 if (opt_flags == OPT_l) { 113 if (opt_flags == OPT_l) {
@@ -129,8 +126,8 @@ int cmp_main(int argc, char **argv)
129 } 126 }
130 } while (c1 != EOF); 127 } while (c1 != EOF);
131 128
132 bb_xferror(fp1, filename1); 129 xferror(fp1, filename1);
133 bb_xferror(fp2, filename2); 130 xferror(fp2, filename2);
134 131
135 bb_fflush_stdout_and_exit(exit_val); 132 bb_fflush_stdout_and_exit(exit_val);
136} 133}
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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <unistd.h>
14#include "busybox.h" 10#include "busybox.h"
15 11
16#define COMM_OPT_1 0x01 12#define COMM_OPT_1 0x01
@@ -57,7 +53,7 @@ static void cmp_files(char **infiles)
57 int i; 53 int i;
58 54
59 for (i = 0; i < 2; ++i) { 55 for (i = 0; i < 2; ++i) {
60 streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : bb_xfopen(infiles[i], "r")); 56 streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r"));
61 fgets(thisline[i], LINE_LEN, streams[i]); 57 fgets(thisline[i], LINE_LEN, streams[i]);
62 } 58 }
63 59
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 @@
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <stdlib.h>
14#include <stdio.h>
15#include <unistd.h>
16#include <string.h>
17#include <fcntl.h>
18#include <signal.h> // For FEATURE_DD_SIGNAL_HANDLING
19#include "busybox.h" 11#include "busybox.h"
20 12
21static const struct suffix_mult dd_suffixes[] = { 13static const struct suffix_mult dd_suffixes[] = {
@@ -110,7 +102,7 @@ int dd_main(int argc, char **argv)
110 else obuf = ibuf; 102 else obuf = ibuf;
111 103
112 if (infile != NULL) { 104 if (infile != NULL) {
113 ifd = bb_xopen(infile, O_RDONLY); 105 ifd = xopen(infile, O_RDONLY);
114 } else { 106 } else {
115 ifd = STDIN_FILENO; 107 ifd = STDIN_FILENO;
116 infile = bb_msg_standard_input; 108 infile = bb_msg_standard_input;
@@ -123,7 +115,7 @@ int dd_main(int argc, char **argv)
123 oflag |= O_TRUNC; 115 oflag |= O_TRUNC;
124 } 116 }
125 117
126 ofd = bb_xopen3(outfile, oflag, 0666); 118 ofd = xopen3(outfile, oflag, 0666);
127 119
128 if (seek && trunc_flag) { 120 if (seek && trunc_flag) {
129 if (ftruncate(ofd, seek * obs) < 0) { 121 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 @@
12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 */ 13 */
14 14
15#include <time.h>
16#include <sys/types.h>
17#include <sys/param.h>
18#include <sys/stat.h>
19#include <ctype.h>
20#include <errno.h>
21#include <signal.h>
22#include <stdlib.h>
23#include <stdio.h>
24#include <stdarg.h>
25#include <string.h>
26#include <unistd.h>
27#include <sys/wait.h>
28#include <fcntl.h>
29#include <stddef.h>
30#include <paths.h>
31#include <dirent.h>
32#include "busybox.h" 15#include "busybox.h"
33 16
34#define FSIZE_MAX 32768 17#define FSIZE_MAX 32768
@@ -917,21 +900,21 @@ static int diffreg(char *ofile1, char *ofile2, int flags)
917 goto closem; 900 goto closem;
918 901
919 if (flags & D_EMPTY1) 902 if (flags & D_EMPTY1)
920 f1 = bb_xfopen(bb_dev_null, "r"); 903 f1 = xfopen(bb_dev_null, "r");
921 else { 904 else {
922 if (strcmp(file1, "-") == 0) 905 if (strcmp(file1, "-") == 0)
923 f1 = stdin; 906 f1 = stdin;
924 else 907 else
925 f1 = bb_xfopen(file1, "r"); 908 f1 = xfopen(file1, "r");
926 } 909 }
927 910
928 if (flags & D_EMPTY2) 911 if (flags & D_EMPTY2)
929 f2 = bb_xfopen(bb_dev_null, "r"); 912 f2 = xfopen(bb_dev_null, "r");
930 else { 913 else {
931 if (strcmp(file2, "-") == 0) 914 if (strcmp(file2, "-") == 0)
932 f2 = stdin; 915 f2 = stdin;
933 else 916 else
934 f2 = bb_xfopen(file2, "r"); 917 f2 = xfopen(file2, "r");
935 } 918 }
936 919
937 if ((i = files_differ(f1, f2, flags)) == 0) 920 if ((i = files_differ(f1, f2, flags)) == 0)
@@ -1004,19 +987,19 @@ static void do_diff(char *dir1, char *path1, char *dir2, char *path2)
1004 int flags = D_HEADER; 987 int flags = D_HEADER;
1005 int val; 988 int val;
1006 989
1007 char *fullpath1 = bb_xasprintf("%s/%s", dir1, path1); 990 char *fullpath1 = xasprintf("%s/%s", dir1, path1);
1008 char *fullpath2 = bb_xasprintf("%s/%s", dir2, path2); 991 char *fullpath2 = xasprintf("%s/%s", dir2, path2);
1009 992
1010 if (stat(fullpath1, &stb1) != 0) { 993 if (stat(fullpath1, &stb1) != 0) {
1011 flags |= D_EMPTY1; 994 flags |= D_EMPTY1;
1012 memset(&stb1, 0, sizeof(stb1)); 995 memset(&stb1, 0, sizeof(stb1));
1013 fullpath1 = bb_xasprintf("%s/%s", dir1, path2); 996 fullpath1 = xasprintf("%s/%s", dir1, path2);
1014 } 997 }
1015 if (stat(fullpath2, &stb2) != 0) { 998 if (stat(fullpath2, &stb2) != 0) {
1016 flags |= D_EMPTY2; 999 flags |= D_EMPTY2;
1017 memset(&stb2, 0, sizeof(stb2)); 1000 memset(&stb2, 0, sizeof(stb2));
1018 stb2.st_mode = stb1.st_mode; 1001 stb2.st_mode = stb1.st_mode;
1019 fullpath2 = bb_xasprintf("%s/%s", dir2, path1); 1002 fullpath2 = xasprintf("%s/%s", dir2, path1);
1020 } 1003 }
1021 1004
1022 if (stb1.st_mode == 0) 1005 if (stb1.st_mode == 0)
@@ -1051,7 +1034,7 @@ static int add_to_dirlist(const char *filename,
1051{ 1034{
1052 dl_count++; 1035 dl_count++;
1053 dl = xrealloc(dl, dl_count * sizeof(char *)); 1036 dl = xrealloc(dl, dl_count * sizeof(char *));
1054 dl[dl_count - 1] = bb_xstrdup(filename); 1037 dl[dl_count - 1] = xstrdup(filename);
1055 if (cmd_flags & FLAG_r) { 1038 if (cmd_flags & FLAG_r) {
1056 int *pp = (int *) userdata; 1039 int *pp = (int *) userdata;
1057 int path_len = *pp + 1; 1040 int path_len = *pp + 1;
@@ -1077,7 +1060,7 @@ static char **get_dir(char *path)
1077 int path_len = strlen(path); 1060 int path_len = strlen(path);
1078 void *userdata = &path_len; 1061 void *userdata = &path_len;
1079 1062
1080 /* Reset dl_count - there's no need to free dl as bb_xrealloc does 1063 /* Reset dl_count - there's no need to free dl as xrealloc does
1081 * the job nicely. */ 1064 * the job nicely. */
1082 dl_count = 0; 1065 dl_count = 0;
1083 1066
@@ -1089,7 +1072,7 @@ static char **get_dir(char *path)
1089 DIR *dp; 1072 DIR *dp;
1090 struct dirent *ep; 1073 struct dirent *ep;
1091 1074
1092 dp = bb_opendir(path); 1075 dp = warn_opendir(path);
1093 while ((ep = readdir(dp))) { 1076 while ((ep = readdir(dp))) {
1094 if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, "."))) 1077 if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
1095 continue; 1078 continue;
@@ -1104,7 +1087,7 @@ static char **get_dir(char *path)
1104 /* Copy dl so that we can return it. */ 1087 /* Copy dl so that we can return it. */
1105 retval = xmalloc(dl_count * sizeof(char *)); 1088 retval = xmalloc(dl_count * sizeof(char *));
1106 for (i = 0; i < dl_count; i++) 1089 for (i = 0; i < dl_count; i++)
1107 retval[i] = bb_xstrdup(dl[i]); 1090 retval[i] = xstrdup(dl[i]);
1108 1091
1109 return retval; 1092 return retval;
1110} 1093}
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 @@
12 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 12 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
13*/ 13*/
14 14
15#include <string.h>
16#include <unistd.h>
17#include <stdint.h>
18#include <fcntl.h>
19#include "busybox.h" 15#include "busybox.h"
20 16
21enum ConvType { 17enum ConvType {
@@ -30,7 +26,7 @@ static int convert(char *fn)
30 int i; 26 int i;
31 27
32 if (fn != NULL) { 28 if (fn != NULL) {
33 in = bb_xfopen(fn, "rw"); 29 in = xfopen(fn, "rw");
34 /* 30 /*
35 The file is then created with mode read/write and 31 The file is then created with mode read/write and
36 permissions 0666 for glibc 2.0.6 and earlier or 32 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 @@
25 25
26/* no getopt needed */ 26/* no getopt needed */
27 27
28#include <stdio.h>
29#include <string.h>
30#include <stdlib.h>
31#include <regex.h>
32#include <sys/types.h>
33#include <errno.h>
34#include "busybox.h" 28#include "busybox.h"
35 29#include "xregex.h"
36 30
37/* The kinds of value we can have. */ 31/* The kinds of value we can have. */
38enum valtype { 32enum valtype {
@@ -116,9 +110,9 @@ static VALUE *str_value (char *s)
116{ 110{
117 VALUE *v; 111 VALUE *v;
118 112
119 v = xmalloc (sizeof(VALUE)); 113 v = xmalloc(sizeof(VALUE));
120 v->type = string; 114 v->type = string;
121 v->u.s = bb_xstrdup (s); 115 v->u.s = xstrdup(s);
122 return v; 116 return v;
123} 117}
124 118
@@ -148,7 +142,7 @@ static int null (VALUE *v)
148static void tostring (VALUE *v) 142static void tostring (VALUE *v)
149{ 143{
150 if (v->type == integer) { 144 if (v->type == integer) {
151 v->u.s = bb_xasprintf ("%" PF_REZ "d", PF_REZ_TYPE v->u.i); 145 v->u.s = xasprintf("%" PF_REZ "d", PF_REZ_TYPE v->u.i);
152 v->type = string; 146 v->type = string;
153 } 147 }
154} 148}
@@ -366,7 +360,7 @@ static VALUE *eval6 (void)
366 else { 360 else {
367 v = xmalloc (sizeof(VALUE)); 361 v = xmalloc (sizeof(VALUE));
368 v->type = string; 362 v->type = string;
369 v->u.s = bb_xstrndup(l->u.s + i1->u.i - 1, i2->u.i); 363 v->u.s = xstrndup(l->u.s + i1->u.i - 1, i2->u.i);
370 } 364 }
371 freev (l); 365 freev (l);
372 freev (i1); 366 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 @@
10 Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 10 Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
11*/ 11*/
12 12
13#include <ctype.h>
14#include <errno.h>
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
18#include <sys/types.h>
19#include <unistd.h>
20#include "busybox.h" 13#include "busybox.h"
21 14
22static unsigned long flags; 15static unsigned long flags;
@@ -61,7 +54,7 @@ int fold_main(int argc, char **argv)
61 if (*a == '-' && !a[1]) 54 if (*a == '-' && !a[1])
62 break; 55 break;
63 if (isdigit(*a)) { 56 if (isdigit(*a)) {
64 argv[i] = bb_xasprintf("-w%s", a); 57 argv[i] = xasprintf("-w%s", a);
65 } 58 }
66 } 59 }
67 } 60 }
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 @@
11/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */ 11/* BB_AUDIT GNU compatible -c, -q, and -v options in 'fancy' configuration. */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */ 12/* http://www.opengroup.org/onlinepubs/007904975/utilities/head.html */
13 13
14#include <stdio.h>
15#include <stdlib.h>
16#include <limits.h>
17#include <ctype.h>
18#include <unistd.h>
19#include "busybox.h" 14#include "busybox.h"
20 15
21static const char head_opts[] = 16static const char head_opts[] =
@@ -137,7 +132,7 @@ int head_main(int argc, char **argv)
137 bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */ 132 bb_perror_msg("%s", *argv); /* Avoid multibyte problems. */
138 retval = EXIT_FAILURE; 133 retval = EXIT_FAILURE;
139 } 134 }
140 bb_xferror_stdout(); 135 xferror_stdout();
141 } 136 }
142 fmt = header_fmt_str; 137 fmt = header_fmt_str;
143 } while (*++argv); 138 } 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 @@
11/* BB_AUDIT GNU options missing: -d, -F, -i, and -v. */ 11/* BB_AUDIT GNU options missing: -d, -F, -i, and -v. */
12/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */ 12/* http://www.opengroup.org/onlinepubs/007904975/utilities/ln.html */
13 13
14#include <stdio.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <errno.h>
18#include "busybox.h" 14#include "busybox.h"
19 15
20#define LN_SYMLINK 1 16#define LN_SYMLINK 1
@@ -45,7 +41,7 @@ int ln_main(int argc, char **argv)
45 41
46 if (argc == optind + 1) { 42 if (argc == optind + 1) {
47 *--argv = last; 43 *--argv = last;
48 last = bb_get_last_path_component(bb_xstrdup(last)); 44 last = bb_get_last_path_component(xstrdup(last));
49 } 45 }
50 46
51 do { 47 do {
@@ -55,7 +51,7 @@ int ln_main(int argc, char **argv)
55 if (is_directory(src, 51 if (is_directory(src,
56 (flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE, 52 (flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
57 NULL)) { 53 NULL)) {
58 src_name = bb_xstrdup(*argv); 54 src_name = xstrdup(*argv);
59 src = concat_path_file(src, bb_get_last_path_component(src_name)); 55 src = concat_path_file(src, bb_get_last_path_component(src_name));
60 free(src_name); 56 free(src_name);
61 src_name = src; 57 src_name = src;
@@ -69,7 +65,7 @@ int ln_main(int argc, char **argv)
69 65
70 if (flag & LN_BACKUP) { 66 if (flag & LN_BACKUP) {
71 char *backup; 67 char *backup;
72 backup = bb_xasprintf("%s%s", src, suffix); 68 backup = xasprintf("%s%s", src, suffix);
73 if (rename(src, backup) < 0 && errno != ENOENT) { 69 if (rename(src, backup) < 0 && errno != ENOENT) {
74 bb_perror_msg("%s", src); 70 bb_perror_msg("%s", src);
75 status = EXIT_FAILURE; 71 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 {
37/************************************************************************/ 37/************************************************************************/
38 38
39#include "busybox.h" 39#include "busybox.h"
40#include <unistd.h> 40#include <getopt.h>
41#include <errno.h>
42#include <string.h>
43#include <fcntl.h>
44#include <signal.h>
45#include <getopt.h> /* struct option */
46#include <sys/ioctl.h>
47#include <sys/sysmacros.h> /* major() and minor() */
48#include <time.h>
49 41
50/* what is the overall style of the listing */ 42/* what is the overall style of the listing */
51#define STYLE_COLUMNS (1U<<21) /* fill columns */ 43#define STYLE_COLUMNS (1U<<21) /* fill columns */
@@ -535,7 +527,7 @@ static struct dnode **list_dir(const char *path)
535 527
536 dn = NULL; 528 dn = NULL;
537 nfiles = 0; 529 nfiles = 0;
538 dir = bb_opendir(path); 530 dir = warn_opendir(path);
539 if (dir == NULL) { 531 if (dir == NULL) {
540 status = EXIT_FAILURE; 532 status = EXIT_FAILURE;
541 return (NULL); /* could not open the dir */ 533 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 @@
6 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 6 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
7 */ 7 */
8 8
9#include <fcntl.h>
10#include <limits.h>
11#include <stdio.h>
12#include <stdint.h>
13#include <stdlib.h>
14#include <string.h>
15#include <unistd.h>
16
17#include "busybox.h" 9#include "busybox.h"
18 10
19typedef enum { HASH_SHA1, HASH_MD5 } hash_algo_t; 11typedef 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)
129 if (strcmp(file_ptr, "-") == 0) { 121 if (strcmp(file_ptr, "-") == 0) {
130 pre_computed_stream = stdin; 122 pre_computed_stream = stdin;
131 } else { 123 } else {
132 pre_computed_stream = bb_xfopen(file_ptr, "r"); 124 pre_computed_stream = xfopen(file_ptr, "r");
133 } 125 }
134 126
135 while ((line = bb_get_chomped_line_from_file(pre_computed_stream)) != NULL) { 127 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 @@
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 */ 10 */
11 11
12#include <fcntl.h>
13#include <signal.h>
14#include <unistd.h>
15#include "busybox.h" 12#include "busybox.h"
16 13
17int nohup_main(int argc, char *argv[]) 14int nohup_main(int argc, char *argv[])
@@ -25,7 +22,7 @@ int nohup_main(int argc, char *argv[])
25 22
26 if (argc<2) bb_show_usage(); 23 if (argc<2) bb_show_usage();
27 24
28 nullfd = bb_xopen(bb_dev_null, O_WRONLY|O_APPEND); 25 nullfd = xopen(bb_dev_null, O_WRONLY|O_APPEND);
29 // If stdin is a tty, detach from it. 26 // If stdin is a tty, detach from it.
30 27
31 if (isatty(0)) dup2(nullfd, 0); 28 if (isatty(0)) dup2(nullfd, 0);
@@ -38,7 +35,7 @@ int nohup_main(int argc, char *argv[])
38 home = getenv("HOME"); 35 home = getenv("HOME");
39 if (home) { 36 if (home) {
40 home = concat_path_file(home, nohupout); 37 home = concat_path_file(home, nohupout);
41 bb_xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR); 38 xopen3(nohupout, O_CREAT|O_WRONLY|O_APPEND, S_IRUSR|S_IWUSR);
42 } 39 }
43 } 40 }
44 } else dup2(nullfd, 1); 41 } 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 @@
12 * http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html 12 * http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
13 */ 13 */
14 14
15#include <ctype.h>
16#include <math.h>
17#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <time.h>
21#include <unistd.h>
22#include "busybox.h" 15#include "busybox.h"
23 16
24static int global_flags; 17static int global_flags;
@@ -104,7 +97,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
104 } 97 }
105 /* Make the copy */ 98 /* Make the copy */
106 if(end<start) end=start; 99 if(end<start) end=start;
107 str=bb_xstrndup(str+start,end-start); 100 str=xstrndup(str+start,end-start);
108 /* Handle -d */ 101 /* Handle -d */
109 if(flags&FLAG_d) { 102 if(flags&FLAG_d) {
110 for(start=end=0;str[end];end++) 103 for(start=end=0;str[end];end++)
@@ -222,7 +215,6 @@ static int compare_keys(const void *xarg, const void *yarg)
222 /* Perform fallback sort if necessary */ 215 /* Perform fallback sort if necessary */
223 if(!retval && !(global_flags&FLAG_s)) 216 if(!retval && !(global_flags&FLAG_s))
224 retval=strcmp(*(char **)xarg, *(char **)yarg); 217 retval=strcmp(*(char **)xarg, *(char **)yarg);
225//dprintf(2,"reverse=%d\n",flags&FLAG_r);
226 return ((flags&FLAG_r)?-1:1)*retval; 218 return ((flags&FLAG_r)?-1:1)*retval;
227} 219}
228 220
@@ -242,7 +234,7 @@ int sort_main(int argc, char **argv)
242#ifdef CONFIG_FEATURE_SORT_BIG 234#ifdef CONFIG_FEATURE_SORT_BIG
243 case 'o': 235 case 'o':
244 if(outfile) bb_error_msg_and_die("Too many -o."); 236 if(outfile) bb_error_msg_and_die("Too many -o.");
245 outfile=bb_xfopen(optarg,"w"); 237 outfile=xfopen(optarg,"w");
246 break; 238 break;
247 case 't': 239 case 't':
248 if(key_separator || optarg[1]) 240 if(key_separator || optarg[1])
@@ -289,7 +281,7 @@ int sort_main(int argc, char **argv)
289 /* Open input files and read data */ 281 /* Open input files and read data */
290 for(i=argv[optind] ? optind : optind-1;argv[i];i++) { 282 for(i=argv[optind] ? optind : optind-1;argv[i];i++) {
291 if(i<optind || (*argv[i]=='-' && !argv[i][1])) fp=stdin; 283 if(i<optind || (*argv[i]=='-' && !argv[i][1])) fp=stdin;
292 else fp=bb_xfopen(argv[i],"r"); 284 else fp=xfopen(argv[i],"r");
293 for(;;) { 285 for(;;) {
294 line=GET_LINE(fp); 286 line=GET_LINE(fp);
295 if(!line) break; 287 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 @@
12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 12 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
13 */ 13 */
14 14
15#include <stdio.h>
16#include <stdint.h>
17#include <sys/types.h>
18#include <pwd.h>
19#include <grp.h>
20#include <sys/vfs.h>
21#include <time.h>
22#include <getopt.h> /* optind */
23#include <sys/stat.h>
24#include <sys/statfs.h>
25#include <sys/statvfs.h>
26#include <string.h>
27#include "busybox.h" 15#include "busybox.h"
28 16
29/* vars to control behavior */ 17/* vars to control behavior */
@@ -321,7 +309,7 @@ static void print_it(char const *masterformat, char const *filename,
321 char *b; 309 char *b;
322 310
323 /* create a working copy of the format string */ 311 /* create a working copy of the format string */
324 char *format = bb_xstrdup(masterformat); 312 char *format = xstrdup(masterformat);
325 313
326 /* Add 2 to accommodate our conversion of the stat `%s' format string 314 /* Add 2 to accommodate our conversion of the stat `%s' format string
327 * to the printf `%llu' one. */ 315 * 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 @@
21 21
22 */ 22 */
23 23
24//#define TEST
25
26#include "busybox.h" 24#include "busybox.h"
27#include <stddef.h>
28#include <termios.h>
29#include <sys/ioctl.h>
30
31#include <sys/param.h>
32#include <unistd.h>
33
34#ifndef STDIN_FILENO
35# define STDIN_FILENO 0
36#endif
37
38#ifndef STDOUT_FILENO
39# define STDOUT_FILENO 1
40#endif
41
42#include <stdlib.h>
43#include <string.h>
44#include <assert.h>
45#include <ctype.h>
46#include <errno.h>
47#include <limits.h>
48#include <fcntl.h>
49 25
50#define STREQ(a, b) (strcmp ((a), (b)) == 0) 26#define STREQ(a, b) (strcmp ((a), (b)) == 0)
51 27
@@ -469,11 +445,7 @@ static const struct suffix_mult stty_suffixes[] = {
469 {NULL, 0 } 445 {NULL, 0 }
470}; 446};
471 447
472#ifndef TEST
473int stty_main(int argc, char **argv) 448int stty_main(int argc, char **argv)
474#else
475int main(int argc, char **argv)
476#endif
477{ 449{
478 struct termios mode; 450 struct termios mode;
479 void (*output_func)(struct termios *); 451 void (*output_func)(struct termios *);
@@ -541,7 +513,7 @@ int main(int argc, char **argv)
541 513
542 device_name = file_name; 514 device_name = file_name;
543 fclose(stdin); 515 fclose(stdin);
544 bb_xopen(device_name, O_RDONLY | O_NONBLOCK); 516 xopen(device_name, O_RDONLY | O_NONBLOCK);
545 if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1 517 if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1
546 || fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) 518 || fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
547 perror_on_device("%s: couldn't reset non-blocking mode"); 519 perror_on_device("%s: couldn't reset non-blocking mode");
@@ -1299,9 +1271,3 @@ static const char *visible(unsigned int ch)
1299 *bpout = '\0'; 1271 *bpout = '\0';
1300 return (const char *) buf; 1272 return (const char *) buf;
1301} 1273}
1302
1303#ifdef TEST
1304
1305const char *bb_applet_name = "stty";
1306
1307#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 @@
10/* BB_AUDIT SUSv3 compliant */ 10/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/tee.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/tee.html */
12 12
13#include <stdio.h>
14#include <stdlib.h>
15#include <signal.h>
16#include <unistd.h>
17#include "busybox.h" 13#include "busybox.h"
18 14
19int tee_main(int argc, char **argv) 15int tee_main(int argc, char **argv)
@@ -96,7 +92,7 @@ int tee_main(int argc, char **argv)
96 do { /* Now check for (input and) output errors. */ 92 do { /* Now check for (input and) output errors. */
97 /* Checking ferror should be sufficient, but we may want to fclose. 93 /* Checking ferror should be sufficient, but we may want to fclose.
98 * If we do, remember not to close stdin! */ 94 * If we do, remember not to close stdin! */
99 bb_xferror(*p, filenames[(int)(p - files)]); 95 xferror(*p, filenames[(int)(p - files)]);
100 } while (*++p); 96 } while (*++p);
101 97
102 bb_fflush_stdout_and_exit(retval); 98 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 @@
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/uniq.html */
12 12
13#include "busybox.h" 13#include "busybox.h"
14#include <string.h>
15#include <ctype.h>
16#include <unistd.h>
17 14
18static const char uniq_opts[] = "f:s:" "cdu\0\1\2\4"; 15static const char uniq_opts[] = "f:s:" "cdu\0\1\2\4";
19 16
@@ -23,7 +20,7 @@ static FILE *xgetoptfile_uniq_s(char **argv, int read0write2)
23 20
24 if ((n = *argv) != NULL) { 21 if ((n = *argv) != NULL) {
25 if ((*n != '-') || n[1]) { 22 if ((*n != '-') || n[1]) {
26 return bb_xfopen(n, "r\0w" + read0write2); 23 return xfopen(n, "r\0w" + read0write2);
27 } 24 }
28 } 25 }
29 return (read0write2) ? stdout : stdin; 26 return (read0write2) ? stdout : stdin;
@@ -100,7 +97,7 @@ int uniq_main(int argc, char **argv)
100 } 97 }
101 } while (s1); 98 } while (s1);
102 99
103 bb_xferror(in, input_filename); 100 xferror(in, input_filename);
104 101
105 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 102 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
106} 103}
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 @@
12 */ 12 */
13 13
14 14
15#include <stdio.h>
16#include <errno.h>
17#include <getopt.h> /* optind */
18#include <string.h>
19#include <stdlib.h>
20#include "busybox.h" 15#include "busybox.h"
21 16
22static int read_stduu(FILE *src_stream, FILE *dst_stream) 17static int read_stduu(FILE *src_stream, FILE *dst_stream)
@@ -141,7 +136,7 @@ int uudecode_main(int argc, char **argv)
141 if (optind == argc) { 136 if (optind == argc) {
142 src_stream = stdin; 137 src_stream = stdin;
143 } else if (optind + 1 == argc) { 138 } else if (optind + 1 == argc) {
144 src_stream = bb_xfopen(argv[optind], "r"); 139 src_stream = xfopen(argv[optind], "r");
145 } else { 140 } else {
146 bb_show_usage(); 141 bb_show_usage();
147 } 142 }
@@ -174,7 +169,7 @@ int uudecode_main(int argc, char **argv)
174 if (strcmp(outname, "-") == 0) { 169 if (strcmp(outname, "-") == 0) {
175 dst_stream = stdout; 170 dst_stream = stdout;
176 } else { 171 } else {
177 dst_stream = bb_xfopen(outname, "w"); 172 dst_stream = xfopen(outname, "w");
178 chmod(outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO)); 173 chmod(outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO));
179 } 174 }
180 free(line); 175 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 @@
7 * 7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */ 9 */
10#include <stdio.h> 10
11#include <string.h>
12#include <stdlib.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <unistd.h>
16#include "busybox.h" 11#include "busybox.h"
17 12
18/* Conversion table. for base 64 */ 13/* Conversion table. for base 64 */
@@ -92,7 +87,7 @@ int uuencode_main(int argc, char **argv)
92 87
93 switch (argc - optind) { 88 switch (argc - optind) {
94 case 2: 89 case 2:
95 src_stream = bb_xfopen(argv[optind], "r"); 90 src_stream = xfopen(argv[optind], "r");
96 xstat(argv[optind], &stat_buf); 91 xstat(argv[optind], &stat_buf);
97 mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); 92 mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
98 if (src_stream == stdout) { 93 if (src_stream == stdout) {
@@ -128,7 +123,7 @@ int uuencode_main(int argc, char **argv)
128 } 123 }
129 bb_printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n"); 124 bb_printf(tbl == tbl_std ? "\n`\nend\n" : "\n====\n");
130 125
131 bb_xferror(src_stream, "source"); /* TODO - Fix this! */ 126 xferror(src_stream, "source"); /* TODO - Fix this! */
132 127
133 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 128 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
134} 129}
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 @@
16 * reduced size. 16 * reduced size.
17 */ 17 */
18 18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <limits.h>
23#include <time.h>
24#include <assert.h>
25#include <unistd.h>
26#include <sys/wait.h>
27#include "busybox.h" 19#include "busybox.h"
28 20
29int watch_main(int argc, char **argv) 21int watch_main(int argc, char **argv)
@@ -62,7 +54,7 @@ int watch_main(int argc, char **argv)
62 54
63 printf("\033[H\033[J%s %s\n", header, thyme); 55 printf("\033[H\033[J%s %s\n", header, thyme);
64 56
65 waitpid(bb_xspawn(watched_argv),0,0); 57 waitpid(xspawn(watched_argv),0,0);
66 sleep(period); 58 sleep(period);
67 } 59 }
68} 60}
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 @@
3 * Mini start-stop-daemon implementation(s) for busybox 3 * Mini start-stop-daemon implementation(s) for busybox
4 * 4 *
5 * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, 5 * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
6 * public domain.
7 * Adapted for busybox David Kimdon <dwhedon@gordian.com> 6 * Adapted for busybox David Kimdon <dwhedon@gordian.com>
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 9 */
9 10
10#include "busybox.h" 11#include "busybox.h"
11#include <stdio.h> 12#include <getopt.h>
12#include <stdlib.h>
13#include <string.h>
14#include <stdarg.h>
15#include <signal.h>
16#include <errno.h>
17#include <sys/stat.h>
18#include <dirent.h>
19#include <unistd.h>
20#include <getopt.h> /* struct option */
21#include "pwd_.h"
22 13
23static int signal_nr = 15; 14static int signal_nr = 15;
24static int user_id = -1; 15static int user_id = -1;
25static int quiet; 16static int quiet;
26static char *userspec = NULL; 17static char *userspec;
27static char *chuid = NULL; 18static char *chuid;
28static char *cmdname = NULL; 19static char *cmdname;
29static char *execname = NULL; 20static char *execname;
30static char *pidfile = NULL; 21static char *pidfile;
31 22
32struct pid_list { 23struct pid_list {
33 struct pid_list *next; 24 struct pid_list *next;
@@ -136,7 +127,7 @@ static void do_procinit(void)
136 return; 127 return;
137 } 128 }
138 129
139 procdir = bb_xopendir("/proc"); 130 procdir = xopendir("/proc");
140 131
141 foundany = 0; 132 foundany = 0;
142 while ((entry = readdir(procdir)) != NULL) { 133 while ((entry = readdir(procdir)) != NULL) {
@@ -292,12 +283,12 @@ int start_stop_daemon_main(int argc, char **argv)
292 } 283 }
293 *--argv = startas; 284 *--argv = startas;
294 if (opt & SSD_OPT_BACKGROUND) { 285 if (opt & SSD_OPT_BACKGROUND) {
295 bb_xdaemon(0, 0); 286 xdaemon(0, 0);
296 setsid(); 287 setsid();
297 } 288 }
298 if (opt & SSD_OPT_MAKEPID) { 289 if (opt & SSD_OPT_MAKEPID) {
299 /* user wants _us_ to make the pidfile */ 290 /* user wants _us_ to make the pidfile */
300 FILE *pidf = bb_xfopen(pidfile, "w"); 291 FILE *pidf = xfopen(pidfile, "w");
301 292
302 pid_t pidt = getpid(); 293 pid_t pidt = getpid();
303 fprintf(pidf, "%d\n", pidt); 294 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)
155 unsigned int mask; 155 unsigned int mask;
156 int compat_type; 156 int compat_type;
157 157
158 buf = bb_xstrdup(str); 158 buf = xstrdup(str);
159 cp = buf; 159 cp = buf;
160 while (cp && *cp) { 160 while (cp && *cp) {
161 neg = 0; 161 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)
100 int neg; 100 int neg;
101 unsigned int mask; 101 unsigned int mask;
102 102
103 buf = bb_xstrdup(str); 103 buf = xstrdup(str);
104 cp = buf; 104 cp = buf;
105 while (cp && *cp) { 105 while (cp && *cp) {
106 neg = 0; 106 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)
33 else 33 else
34 os = "(unknown os)"; 34 os = "(unknown os)";
35 35
36 ret = bb_xstrdup(os); 36 ret = xstrdup(os);
37 return ret; 37 return ret;
38} 38}
39 39
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)
129 int len; 129 int len;
130#endif 130#endif
131 131
132 cp = str = bb_xstrdup(device); 132 cp = str = xstrdup(device);
133 133
134 /* Skip over /dev/; if it's not present, give up. */ 134 /* Skip over /dev/; if it's not present, give up. */
135 if (strncmp(cp, "/dev/", 5) != 0) 135 if (strncmp(cp, "/dev/", 5) != 0)
@@ -544,7 +544,7 @@ static char *find_fsck(char *type)
544 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s"); 544 tpl = (strncmp(type, "fsck.", 5) ? "%s/fsck.%s" : "%s/%s");
545 545
546 for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) { 546 for(s = strtok(p, ":"); s; s = strtok(NULL, ":")) {
547 s = bb_xasprintf(tpl, s, type); 547 s = xasprintf(tpl, s, type);
548 if (stat(s, &st) == 0) break; 548 if (stat(s, &st) == 0) break;
549 free(s); 549 free(s);
550 } 550 }
@@ -583,7 +583,7 @@ static int execute(const char *type, const char *device, const char *mntpt,
583 return ENOMEM; 583 return ENOMEM;
584 memset(inst, 0, sizeof(struct fsck_instance)); 584 memset(inst, 0, sizeof(struct fsck_instance));
585 585
586 prog = bb_xasprintf("fsck.%s", type); 586 prog = xasprintf("fsck.%s", type);
587 argv[0] = prog; 587 argv[0] = prog;
588 argc = 1; 588 argc = 1;
589 589
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,
226 FILE *f; 226 FILE *f;
227 errcode_t retval; 227 errcode_t retval;
228 228
229 f = bb_xfopen(bad_blocks_file, "r"); 229 f = xfopen(bad_blocks_file, "r");
230 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block); 230 retval = ext2fs_read_bb_FILE(fs, f, bb_list, invalid_block);
231 fclose (f); 231 fclose (f);
232 mke2fs_error_msg_and_die(retval, "read bad blocks from list"); 232 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,
692 char *buf, *token, *next, *p, *arg; 692 char *buf, *token, *next, *p, *arg;
693 int r_usage = 0; 693 int r_usage = 0;
694 694
695 buf = bb_xstrdup(opts); 695 buf = xstrdup(opts);
696 for (token = buf; token && *token; token = next) { 696 for (token = buf; token && *token; token = next) {
697 p = strchr(token, ','); 697 p = strchr(token, ',');
698 next = 0; 698 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,
111{ 111{
112 char *buf, *token, *next, *p, *arg; 112 char *buf, *token, *next, *p, *arg;
113 int journal_usage = 0; 113 int journal_usage = 0;
114 buf = bb_xstrdup(opts); 114 buf = xstrdup(opts);
115 for (token = buf; token && *token; token = next) { 115 for (token = buf; token && *token; token = next) {
116 p = strchr(token, ','); 116 p = strchr(token, ',');
117 next = 0; 117 next = 0;
@@ -264,7 +264,7 @@ char *e2fs_set_sbin_path(void)
264 /* Update our PATH to include /sbin */ 264 /* Update our PATH to include /sbin */
265#define PATH_SET "/sbin" 265#define PATH_SET "/sbin"
266 if (oldpath) 266 if (oldpath)
267 oldpath = bb_xasprintf("%s:%s", PATH_SET, oldpath); 267 oldpath = xasprintf("%s:%s", PATH_SET, oldpath);
268 else 268 else
269 oldpath = PATH_SET; 269 oldpath = PATH_SET;
270 putenv (oldpath); 270 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 @@
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include <errno.h>
14#include <string.h>
15#include <strings.h>
16#include <time.h>
17#include <math.h>
18#include <ctype.h>
19#include <getopt.h>
20
21#include "xregex.h"
22#include "busybox.h" 10#include "busybox.h"
11#include "xregex.h"
12#include <math.h>
23 13
24 14
25#define MAXVARFMT 240 15#define MAXVARFMT 240
@@ -610,7 +600,7 @@ static inline int isalnum_(int c)
610 600
611static FILE *afopen(const char *path, const char *mode) 601static FILE *afopen(const char *path, const char *mode)
612{ 602{
613 return (*path == '-' && *(path+1) == '\0') ? stdin : bb_xfopen(path, mode); 603 return (*path == '-' && *(path+1) == '\0') ? stdin : xfopen(path, mode);
614} 604}
615 605
616/* -------- working with variables (set/get/copy/etc) -------- */ 606/* -------- working with variables (set/get/copy/etc) -------- */
@@ -672,7 +662,7 @@ static var *setvar_p(var *v, char *value)
672/* same as setvar_p but make a copy of string */ 662/* same as setvar_p but make a copy of string */
673static var *setvar_s(var *v, const char *value) 663static var *setvar_s(var *v, const char *value)
674{ 664{
675 return setvar_p(v, (value && *value) ? bb_xstrdup(value) : NULL); 665 return setvar_p(v, (value && *value) ? xstrdup(value) : NULL);
676} 666}
677 667
678/* same as setvar_s but set USER flag */ 668/* same as setvar_s but set USER flag */
@@ -709,7 +699,7 @@ static char *getvar_s(var *v)
709 /* if v is numeric and has no cached string, convert it to string */ 699 /* if v is numeric and has no cached string, convert it to string */
710 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) { 700 if ((v->type & (VF_NUMBER | VF_CACHED)) == VF_NUMBER) {
711 fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE); 701 fmt_num(buf, MAXVARFMT, getvar_s(V[CONVFMT]), v->number, TRUE);
712 v->string = bb_xstrdup(buf); 702 v->string = xstrdup(buf);
713 v->type |= VF_CACHED; 703 v->type |= VF_CACHED;
714 } 704 }
715 return (v->string == NULL) ? "" : v->string; 705 return (v->string == NULL) ? "" : v->string;
@@ -744,7 +734,7 @@ static var *copyvar(var *dest, const var *src)
744 dest->type |= (src->type & ~VF_DONTTOUCH); 734 dest->type |= (src->type & ~VF_DONTTOUCH);
745 dest->number = src->number; 735 dest->number = src->number;
746 if (src->string) 736 if (src->string)
747 dest->string = bb_xstrdup(src->string); 737 dest->string = xstrdup(src->string);
748 } 738 }
749 handle_special(dest); 739 handle_special(dest);
750 return dest; 740 return dest;
@@ -1144,7 +1134,7 @@ static node *chain_node(uint32_t info)
1144 if (seq->programname != programname) { 1134 if (seq->programname != programname) {
1145 seq->programname = programname; 1135 seq->programname = programname;
1146 n = chain_node(OC_NEWSOURCE); 1136 n = chain_node(OC_NEWSOURCE);
1147 n->l.s = bb_xstrdup(programname); 1137 n->l.s = xstrdup(programname);
1148 } 1138 }
1149 1139
1150 n = seq->last; 1140 n = seq->last;
@@ -1433,7 +1423,7 @@ static int awk_split(char *s, node *spl, char **slist)
1433 regmatch_t pmatch[2]; 1423 regmatch_t pmatch[2];
1434 1424
1435 /* in worst case, each char would be a separate field */ 1425 /* in worst case, each char would be a separate field */
1436 *slist = s1 = bb_xstrndup(s, strlen(s) * 2 + 3); 1426 *slist = s1 = xstrndup(s, strlen(s) * 2 + 3);
1437 1427
1438 c[0] = c[1] = (char)spl->info; 1428 c[0] = c[1] = (char)spl->info;
1439 c[2] = c[3] = '\0'; 1429 c[2] = c[3] = '\0';
@@ -1747,7 +1737,7 @@ static char *awk_printf(node *n)
1747 var *v, *arg; 1737 var *v, *arg;
1748 1738
1749 v = nvalloc(1); 1739 v = nvalloc(1);
1750 fmt = f = bb_xstrdup(getvar_s(evaluate(nextarg(&n), v))); 1740 fmt = f = xstrdup(getvar_s(evaluate(nextarg(&n), v)));
1751 1741
1752 i = 0; 1742 i = 0;
1753 while (*f) { 1743 while (*f) {
@@ -1941,7 +1931,7 @@ static var *exec_builtin(node *op, var *res)
1941 case B_up: 1931 case B_up:
1942 to_xxx = toupper; 1932 to_xxx = toupper;
1943lo_cont: 1933lo_cont:
1944 s1 = s = bb_xstrdup(as[0]); 1934 s1 = s = xstrdup(as[0]);
1945 while (*s1) { 1935 while (*s1) {
1946 *s1 = (*to_xxx)(*s1); 1936 *s1 = (*to_xxx)(*s1);
1947 s1++; 1937 s1++;
@@ -2118,7 +2108,7 @@ static var *evaluate(node *op, var *res)
2118 bb_perror_msg_and_die("popen"); 2108 bb_perror_msg_and_die("popen");
2119 X.rsm->is_pipe = 1; 2109 X.rsm->is_pipe = 1;
2120 } else { 2110 } else {
2121 X.rsm->F = bb_xfopen(R.s, opn=='w' ? "w" : "a"); 2111 X.rsm->F = xfopen(R.s, opn=='w' ? "w" : "a");
2122 } 2112 }
2123 } 2113 }
2124 X.F = X.rsm->F; 2114 X.F = X.rsm->F;
@@ -2272,7 +2262,7 @@ re_cont:
2272 X.rsm->F = popen(L.s, "r"); 2262 X.rsm->F = popen(L.s, "r");
2273 X.rsm->is_pipe = TRUE; 2263 X.rsm->is_pipe = TRUE;
2274 } else { 2264 } else {
2275 X.rsm->F = fopen(L.s, "r"); /* not bb_xfopen! */ 2265 X.rsm->F = fopen(L.s, "r"); /* not xfopen! */
2276 } 2266 }
2277 } 2267 }
2278 } else { 2268 } else {
@@ -2564,7 +2554,7 @@ static int is_assignment(const char *expr)
2564{ 2554{
2565 char *exprc, *s, *s0, *s1; 2555 char *exprc, *s, *s0, *s1;
2566 2556
2567 exprc = bb_xstrdup(expr); 2557 exprc = xstrdup(expr);
2568 if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) { 2558 if (!isalnum_(*exprc) || (s = strchr(exprc, '=')) == NULL) {
2569 free(exprc); 2559 free(exprc);
2570 return FALSE; 2560 return FALSE;
@@ -2659,7 +2649,7 @@ int awk_main(int argc, char **argv)
2659 } 2649 }
2660 2650
2661 for (envp=environ; *envp; envp++) { 2651 for (envp=environ; *envp; envp++) {
2662 s = bb_xstrdup(*envp); 2652 s = xstrdup(*envp);
2663 s1 = strchr(s, '='); 2653 s1 = strchr(s, '=');
2664 if (!s1) { 2654 if (!s1) {
2665 goto keep_going; 2655 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)
67 filename_start_ptr = temp + 1; 67 filename_start_ptr = temp + 1;
68 } 68 }
69 69
70 return(bb_xstrdup(filename_start_ptr)); 70 return(xstrdup(filename_start_ptr));
71} 71}
72 72
73static int file_doesnt_exist(const char *filename) 73static int file_doesnt_exist(const char *filename)
@@ -89,7 +89,7 @@ int patch_main(int argc, char **argv)
89 if (ret & 1) 89 if (ret & 1)
90 patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX); 90 patch_level = bb_xgetlarg(p, 10, -1, USHRT_MAX);
91 if (ret & 2) { 91 if (ret & 2) {
92 patch_file = bb_xfopen(i, "r"); 92 patch_file = xfopen(i, "r");
93 } else { 93 } else {
94 patch_file = stdin; 94 patch_file = stdin;
95 } 95 }
@@ -140,7 +140,7 @@ int patch_main(int argc, char **argv)
140 bb_make_directory(new_filename, -1, FILEUTILS_RECUR); 140 bb_make_directory(new_filename, -1, FILEUTILS_RECUR);
141 *line_ptr = '/'; 141 *line_ptr = '/';
142 } 142 }
143 dst_stream = bb_xfopen(new_filename, "w+"); 143 dst_stream = xfopen(new_filename, "w+");
144 backup_filename = NULL; 144 backup_filename = NULL;
145 } else { 145 } else {
146 backup_filename = xmalloc(strlen(new_filename) + 6); 146 backup_filename = xmalloc(strlen(new_filename) + 6);
@@ -150,16 +150,16 @@ int patch_main(int argc, char **argv)
150 bb_perror_msg_and_die("Couldnt create file %s", 150 bb_perror_msg_and_die("Couldnt create file %s",
151 backup_filename); 151 backup_filename);
152 } 152 }
153 dst_stream = bb_xfopen(new_filename, "w"); 153 dst_stream = xfopen(new_filename, "w");
154 } 154 }
155 155
156 if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) { 156 if ((backup_filename == NULL) || file_doesnt_exist(original_filename)) {
157 src_stream = NULL; 157 src_stream = NULL;
158 } else { 158 } else {
159 if (strcmp(original_filename, new_filename) == 0) { 159 if (strcmp(original_filename, new_filename) == 0) {
160 src_stream = bb_xfopen(backup_filename, "r"); 160 src_stream = xfopen(backup_filename, "r");
161 } else { 161 } else {
162 src_stream = bb_xfopen(original_filename, "r"); 162 src_stream = xfopen(original_filename, "r");
163 } 163 }
164 } 164 }
165 165
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)
132 sed_cmd_t *sed_cmd_next = sed_cmd->next; 132 sed_cmd_t *sed_cmd_next = sed_cmd->next;
133 133
134 if(sed_cmd->file) 134 if(sed_cmd->file)
135 bb_xprint_and_close_file(sed_cmd->file); 135 xprint_and_close_file(sed_cmd->file);
136 136
137 if (sed_cmd->beg_match) { 137 if (sed_cmd->beg_match) {
138 regfree(sed_cmd->beg_match); 138 regfree(sed_cmd->beg_match);
@@ -300,7 +300,7 @@ static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval)
300 /* If lines glued together, put backslash back. */ 300 /* If lines glued together, put backslash back. */
301 if(filecmdstr[idx]=='\n') hack=1; 301 if(filecmdstr[idx]=='\n') hack=1;
302 if(idx==start) bb_error_msg_and_die("Empty filename"); 302 if(idx==start) bb_error_msg_and_die("Empty filename");
303 *retval = bb_xstrndup(filecmdstr+start, idx-start+hack+1); 303 *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
304 if(hack) *(idx+*retval)='\\'; 304 if(hack) *(idx+*retval)='\\';
305 305
306 return idx; 306 return idx;
@@ -406,7 +406,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
406 } else if(isspace(*cmdstr)) cmdstr++; 406 } else if(isspace(*cmdstr)) cmdstr++;
407 else break; 407 else break;
408 } 408 }
409 sed_cmd->string = bb_xstrdup(cmdstr); 409 sed_cmd->string = xstrdup(cmdstr);
410 parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0); 410 parse_escapes(sed_cmd->string,sed_cmd->string,strlen(cmdstr),0,0);
411 cmdstr += strlen(cmdstr); 411 cmdstr += strlen(cmdstr);
412 /* handle file cmds: (r)ead */ 412 /* handle file cmds: (r)ead */
@@ -415,7 +415,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
415 bb_error_msg_and_die("Command only uses one address"); 415 bb_error_msg_and_die("Command only uses one address");
416 cmdstr += parse_file_cmd(sed_cmd, cmdstr, &sed_cmd->string); 416 cmdstr += parse_file_cmd(sed_cmd, cmdstr, &sed_cmd->string);
417 if(sed_cmd->cmd=='w') 417 if(sed_cmd->cmd=='w')
418 sed_cmd->file=bb_xfopen(sed_cmd->string,"w"); 418 sed_cmd->file=xfopen(sed_cmd->string,"w");
419 /* handle branch commands */ 419 /* handle branch commands */
420 } else if (strchr(":btT", sed_cmd->cmd)) { 420 } else if (strchr(":btT", sed_cmd->cmd)) {
421 int length; 421 int length;
@@ -423,7 +423,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
423 while(isspace(*cmdstr)) cmdstr++; 423 while(isspace(*cmdstr)) cmdstr++;
424 length = strcspn(cmdstr, semicolon_whitespace); 424 length = strcspn(cmdstr, semicolon_whitespace);
425 if (length) { 425 if (length) {
426 sed_cmd->string = bb_xstrndup(cmdstr, length); 426 sed_cmd->string = xstrndup(cmdstr, length);
427 cmdstr += length; 427 cmdstr += length;
428 } 428 }
429 } 429 }
@@ -466,7 +466,7 @@ static void add_cmd(char *cmdstr)
466 466
467 /* Append this line to any unfinished line from last time. */ 467 /* Append this line to any unfinished line from last time. */
468 if (bbg.add_cmd_line) { 468 if (bbg.add_cmd_line) {
469 cmdstr = bb_xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr); 469 cmdstr = xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
470 free(bbg.add_cmd_line); 470 free(bbg.add_cmd_line);
471 bbg.add_cmd_line = cmdstr; 471 bbg.add_cmd_line = cmdstr;
472 } 472 }
@@ -474,7 +474,7 @@ static void add_cmd(char *cmdstr)
474 /* If this line ends with backslash, request next line. */ 474 /* If this line ends with backslash, request next line. */
475 temp=strlen(cmdstr); 475 temp=strlen(cmdstr);
476 if(temp && cmdstr[temp-1]=='\\') { 476 if(temp && cmdstr[temp-1]=='\\') {
477 if (!bbg.add_cmd_line) bbg.add_cmd_line = bb_xstrdup(cmdstr); 477 if (!bbg.add_cmd_line) bbg.add_cmd_line = xstrdup(cmdstr);
478 bbg.add_cmd_line[temp-1] = 0; 478 bbg.add_cmd_line[temp-1] = 0;
479 return; 479 return;
480 } 480 }
@@ -671,7 +671,7 @@ static sed_cmd_t *branch_to(char *label)
671 671
672static void append(char *s) 672static void append(char *s)
673{ 673{
674 llist_add_to_end(&bbg.append_head, bb_xstrdup(s)); 674 llist_add_to_end(&bbg.append_head, xstrdup(s));
675} 675}
676 676
677static void flush_append(void) 677static void flush_append(void)
@@ -852,7 +852,7 @@ restart:
852 char *tmp = strchr(pattern_space,'\n'); 852 char *tmp = strchr(pattern_space,'\n');
853 853
854 if(tmp) { 854 if(tmp) {
855 tmp=bb_xstrdup(tmp+1); 855 tmp=xstrdup(tmp+1);
856 free(pattern_space); 856 free(pattern_space);
857 pattern_space=tmp; 857 pattern_space=tmp;
858 goto restart; 858 goto restart;
@@ -907,7 +907,7 @@ restart:
907 while ((line = bb_get_chomped_line_from_file(rfile)) 907 while ((line = bb_get_chomped_line_from_file(rfile))
908 != NULL) 908 != NULL)
909 append(line); 909 append(line);
910 bb_xprint_and_close_file(rfile); 910 xprint_and_close_file(rfile);
911 } 911 }
912 912
913 break; 913 break;
@@ -996,7 +996,7 @@ restart:
996 } 996 }
997 case 'g': /* Replace pattern space with hold space */ 997 case 'g': /* Replace pattern space with hold space */
998 free(pattern_space); 998 free(pattern_space);
999 pattern_space = bb_xstrdup(bbg.hold_space ? bbg.hold_space : ""); 999 pattern_space = xstrdup(bbg.hold_space ? bbg.hold_space : "");
1000 break; 1000 break;
1001 case 'G': /* Append newline and hold space to pattern space */ 1001 case 'G': /* Append newline and hold space to pattern space */
1002 { 1002 {
@@ -1019,7 +1019,7 @@ restart:
1019 } 1019 }
1020 case 'h': /* Replace hold space with pattern space */ 1020 case 'h': /* Replace hold space with pattern space */
1021 free(bbg.hold_space); 1021 free(bbg.hold_space);
1022 bbg.hold_space = bb_xstrdup(pattern_space); 1022 bbg.hold_space = xstrdup(pattern_space);
1023 break; 1023 break;
1024 case 'H': /* Append newline and pattern space to hold space */ 1024 case 'H': /* Append newline and pattern space to hold space */
1025 { 1025 {
@@ -1072,7 +1072,7 @@ discard_line:
1072static void add_cmd_block(char *cmdstr) 1072static void add_cmd_block(char *cmdstr)
1073{ 1073{
1074 int go=1; 1074 int go=1;
1075 char *temp=bb_xstrdup(cmdstr),*temp2=temp; 1075 char *temp=xstrdup(cmdstr),*temp2=temp;
1076 1076
1077 while(go) { 1077 while(go) {
1078 int len=strcspn(temp2,"\n"); 1078 int len=strcspn(temp2,"\n");
@@ -1121,14 +1121,14 @@ int sed_main(int argc, char **argv)
1121 FILE *cmdfile; 1121 FILE *cmdfile;
1122 char *line; 1122 char *line;
1123 1123
1124 cmdfile = bb_xfopen(optarg, "r"); 1124 cmdfile = xfopen(optarg, "r");
1125 1125
1126 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) { 1126 while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
1127 add_cmd(line); 1127 add_cmd(line);
1128 getpat=0; 1128 getpat=0;
1129 free(line); 1129 free(line);
1130 } 1130 }
1131 bb_xprint_and_close_file(cmdfile); 1131 xprint_and_close_file(cmdfile);
1132 1132
1133 break; 1133 break;
1134 } 1134 }
@@ -1172,7 +1172,7 @@ int sed_main(int argc, char **argv)
1172 struct stat statbuf; 1172 struct stat statbuf;
1173 int nonstdoutfd; 1173 int nonstdoutfd;
1174 1174
1175 bbg.outname=bb_xstrndup(argv[i],strlen(argv[i])+6); 1175 bbg.outname=xstrndup(argv[i],strlen(argv[i])+6);
1176 strcat(bbg.outname,"XXXXXX"); 1176 strcat(bbg.outname,"XXXXXX");
1177 if(-1==(nonstdoutfd=mkstemp(bbg.outname))) 1177 if(-1==(nonstdoutfd=mkstemp(bbg.outname)))
1178 bb_error_msg_and_die("no temp file"); 1178 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 @@
23 23
24 24
25#include "busybox.h" 25#include "busybox.h"
26#include <string.h>
27#include <strings.h>
28#include <unistd.h>
29#include <sys/ioctl.h>
30#include <time.h>
31#include <fcntl.h>
32#include <signal.h>
33#include <setjmp.h>
34#include <regex.h>
35#include <ctype.h>
36#include <errno.h>
37#define vi_Version BB_VER " " BB_BT
38 26
39#ifdef CONFIG_LOCALE_SUPPORT 27#ifdef CONFIG_LOCALE_SUPPORT
40#define Isprint(c) isprint((c)) 28#define Isprint(c) isprint((c))
@@ -349,7 +337,7 @@ int vi_main(int argc, char **argv)
349 for (; optind < argc; optind++) { 337 for (; optind < argc; optind++) {
350 editing = 1; // 0=exit, 1=one file, 2+ =many files 338 editing = 1; // 0=exit, 1=one file, 2+ =many files
351 free(cfn); 339 free(cfn);
352 cfn = (Byte *) bb_xstrdup(argv[optind]); 340 cfn = (Byte *) xstrdup(argv[optind]);
353 edit_file(cfn); 341 edit_file(cfn);
354 } 342 }
355 } 343 }
@@ -522,7 +510,7 @@ static Byte *get_one_address(Byte * p, int *addr) // get colon addr, if present
522 *q++ = *p; 510 *q++ = *p;
523 *q = '\0'; 511 *q = '\0';
524 } 512 }
525 pat = (Byte *) bb_xstrdup((char *) buf); // save copy of pattern 513 pat = (Byte *) xstrdup((char *) buf); // save copy of pattern
526 if (*p == '/') 514 if (*p == '/')
527 p++; 515 p++;
528 q = char_search(dot, pat, FORWARD, FULL); 516 q = char_search(dot, pat, FORWARD, FULL);
@@ -736,7 +724,7 @@ static void colon(Byte * buf)
736 724
737 // There is a read-able regular file 725 // There is a read-able regular file
738 // make this the current file 726 // make this the current file
739 q = (Byte *) bb_xstrdup((char *) fn); // save the cfn 727 q = (Byte *) xstrdup((char *) fn); // save the cfn
740 free(cfn); // free the old name 728 free(cfn); // free the old name
741 cfn = q; // remember new cfn 729 cfn = q; // remember new cfn
742 730
@@ -788,7 +776,7 @@ static void colon(Byte * buf)
788 if (strlen((char *) args) > 0) { 776 if (strlen((char *) args) > 0) {
789 // user wants a new filename 777 // user wants a new filename
790 free(cfn); 778 free(cfn);
791 cfn = (Byte *) bb_xstrdup((char *) args); 779 cfn = (Byte *) xstrdup((char *) args);
792 } else { 780 } else {
793 // user wants file status info 781 // user wants file status info
794 last_status_cksum = 0; // force status update 782 last_status_cksum = 0; // force status update
@@ -996,7 +984,7 @@ static void colon(Byte * buf)
996 } 984 }
997#endif /* CONFIG_FEATURE_VI_SEARCH */ 985#endif /* CONFIG_FEATURE_VI_SEARCH */
998 } else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version 986 } else if (strncasecmp((char *) cmd, "version", i) == 0) { // show software version
999 psb("%s", vi_Version); 987 psb("%s", BB_VER " " BB_BT);
1000 } else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file 988 } else if (strncasecmp((char *) cmd, "write", i) == 0 // write text to file
1001 || strncasecmp((char *) cmd, "wq", i) == 0 989 || strncasecmp((char *) cmd, "wq", i) == 0
1002 || strncasecmp((char *) cmd, "wn", i) == 0 990 || strncasecmp((char *) cmd, "wn", i) == 0
@@ -2313,7 +2301,7 @@ static Byte *get_input_line(Byte * prompt) // get input line- use "status line"
2313 } 2301 }
2314 refresh(FALSE); 2302 refresh(FALSE);
2315 free(obufp); 2303 free(obufp);
2316 obufp = (Byte *) bb_xstrdup((char *) buf); 2304 obufp = (Byte *) xstrdup((char *) buf);
2317 return (obufp); 2305 return (obufp);
2318} 2306}
2319 2307
@@ -3199,7 +3187,7 @@ key_cmd_mode:
3199 // Stuff the last_modifying_cmd back into stdin 3187 // Stuff the last_modifying_cmd back into stdin
3200 // and let it be re-executed. 3188 // and let it be re-executed.
3201 if (last_modifying_cmd != 0) { 3189 if (last_modifying_cmd != 0) {
3202 ioq = ioq_start = (Byte *) bb_xstrdup((char *) last_modifying_cmd); 3190 ioq = ioq_start = (Byte *) xstrdup((char *) last_modifying_cmd);
3203 } 3191 }
3204 break; 3192 break;
3205#endif /* CONFIG_FEATURE_VI_DOT_CMD */ 3193#endif /* CONFIG_FEATURE_VI_DOT_CMD */
@@ -3214,7 +3202,7 @@ key_cmd_mode:
3214 if (strlen((char *) q) > 1) { // new pat- save it and find 3202 if (strlen((char *) q) > 1) { // new pat- save it and find
3215 // there is a new pat 3203 // there is a new pat
3216 free(last_search_pattern); 3204 free(last_search_pattern);
3217 last_search_pattern = (Byte *) bb_xstrdup((char *) q); 3205 last_search_pattern = (Byte *) xstrdup((char *) q);
3218 goto dc3; // now find the pattern 3206 goto dc3; // now find the pattern
3219 } 3207 }
3220 // user changed mind and erased the "/"- do nothing 3208 // 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 @@
11 */ 11 */
12 12
13#include "busybox.h" 13#include "busybox.h"
14#include <stdio.h>
15#include <unistd.h>
16#include <dirent.h>
17#include <string.h>
18#include <stdlib.h>
19#include <fnmatch.h> 14#include <fnmatch.h>
20#include <time.h>
21#include <ctype.h>
22 15
23static char *pattern; 16static char *pattern;
24#ifdef CONFIG_FEATURE_FIND_PRINT0 17#ifdef CONFIG_FEATURE_FIND_PRINT0
@@ -138,8 +131,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
138 int i; 131 int i;
139 char *cmd_string = ""; 132 char *cmd_string = "";
140 for (i = 0; i < num_matches; i++) 133 for (i = 0; i < num_matches; i++)
141 cmd_string = bb_xasprintf("%s%s%s", cmd_string, exec_str[i], fileName); 134 cmd_string = xasprintf("%s%s%s", cmd_string, exec_str[i], fileName);
142 cmd_string = bb_xasprintf("%s%s", cmd_string, exec_str[num_matches]); 135 cmd_string = xasprintf("%s%s", cmd_string, exec_str[num_matches]);
143 system(cmd_string); 136 system(cmd_string);
144 goto no_match; 137 goto no_match;
145 } 138 }
@@ -300,7 +293,7 @@ int find_main(int argc, char **argv)
300 bb_error_msg_and_die(bb_msg_requires_arg, "-exec"); 293 bb_error_msg_and_die(bb_msg_requires_arg, "-exec");
301 if (*argv[i] == ';') 294 if (*argv[i] == ';')
302 break; 295 break;
303 cmd_string = bb_xasprintf("%s %s", cmd_string, argv[i]); 296 cmd_string = xasprintf("%s %s", cmd_string, argv[i]);
304 } 297 }
305 298
306 if (*cmd_string == 0) 299 if (*cmd_string == 0)
@@ -311,10 +304,10 @@ int find_main(int argc, char **argv)
311 while ((b_pos = strstr(cmd_string, "{}") - cmd_string), (b_pos >= 0)) { 304 while ((b_pos = strstr(cmd_string, "{}") - cmd_string), (b_pos >= 0)) {
312 num_matches++; 305 num_matches++;
313 exec_str = xrealloc(exec_str, (num_matches + 1) * sizeof(char *)); 306 exec_str = xrealloc(exec_str, (num_matches + 1) * sizeof(char *));
314 exec_str[num_matches - 1] = bb_xstrndup(cmd_string, b_pos); 307 exec_str[num_matches - 1] = xstrndup(cmd_string, b_pos);
315 cmd_string += b_pos + 2; 308 cmd_string += b_pos + 2;
316 } 309 }
317 exec_str[num_matches] = bb_xstrdup(cmd_string); 310 exec_str[num_matches] = xstrdup(cmd_string);
318 exec_opt = 1; 311 exec_opt = 1;
319#endif 312#endif
320 } else 313 } 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 @@
17*/ 17*/
18 18
19#include "busybox.h" 19#include "busybox.h"
20#include <stdio.h>
21#include <stdlib.h>
22#include <getopt.h>
23#include <string.h>
24#include <errno.h>
25#include "xregex.h" 20#include "xregex.h"
26 21
27 22
@@ -203,7 +198,7 @@ static int grep_file(FILE *file)
203 /* Add the line to the circular 'before' buffer */ 198 /* Add the line to the circular 'before' buffer */
204 if(lines_before) { 199 if(lines_before) {
205 free(before_buf[curpos]); 200 free(before_buf[curpos]);
206 before_buf[curpos] = bb_xstrdup(line); 201 before_buf[curpos] = xstrdup(line);
207 curpos = (curpos + 1) % lines_before; 202 curpos = (curpos + 1) % lines_before;
208 } 203 }
209 } 204 }
@@ -271,7 +266,7 @@ static void load_regexes_from_file(llist_t *fopt)
271 266
272 fopt = cur->link; 267 fopt = cur->link;
273 free(cur); 268 free(cur);
274 f = bb_xfopen(ffile, "r"); 269 f = xfopen(ffile, "r");
275 while ((line = bb_get_chomped_line_from_file(f)) != NULL) { 270 while ((line = bb_get_chomped_line_from_file(f)) != NULL) {
276 llist_add_to(&pattern_head, 271 llist_add_to(&pattern_head,
277 new_grep_list_data(line, PATTERN_MEM_A)); 272 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 @@
18 */ 18 */
19 19
20#include "busybox.h" 20#include "busybox.h"
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25#include <getopt.h>
26#include <errno.h>
27#include <fcntl.h>
28#include <sys/types.h>
29#include <sys/wait.h>
30 21
31/* COMPAT: SYSV version defaults size (and has a max value of) to 470. 22/* COMPAT: SYSV version defaults size (and has a max value of) to 470.
32 We try to make it as large as possible. */ 23 We try to make it as large as possible. */
@@ -300,7 +291,7 @@ static int xargs_ask_confirmation(void)
300 int c, savec; 291 int c, savec;
301 292
302 if (!tty_stream) { 293 if (!tty_stream) {
303 tty_stream = bb_xfopen(CURRENT_TTY, "r"); 294 tty_stream = xfopen(CURRENT_TTY, "r");
304 /* pranoidal security by vodz */ 295 /* pranoidal security by vodz */
305 fcntl(fileno(tty_stream), F_SETFD, FD_CLOEXEC); 296 fcntl(fileno(tty_stream), F_SETFD, FD_CLOEXEC);
306 } 297 }
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 @@
19#include <errno.h> 19#include <errno.h>
20#include <fcntl.h> 20#include <fcntl.h>
21#include <inttypes.h> 21#include <inttypes.h>
22#include <malloc.h>
22#include <netdb.h> 23#include <netdb.h>
24#include <setjmp.h>
23#include <signal.h> 25#include <signal.h>
24#include <stdio.h> 26#include <stdio.h>
25#include <stdlib.h> 27#include <stdlib.h>
@@ -27,18 +29,26 @@
27#include <string.h> 29#include <string.h>
28#include <strings.h> 30#include <strings.h>
29#include <sys/ioctl.h> 31#include <sys/ioctl.h>
32#include <sys/mman.h>
30#include <sys/socket.h> 33#include <sys/socket.h>
31#include <sys/stat.h> 34#include <sys/stat.h>
35#include <sys/statfs.h>
32#include <sys/time.h> 36#include <sys/time.h>
33#include <sys/types.h> 37#include <sys/types.h>
34#include <sys/wait.h> 38#include <sys/wait.h>
35#include <termios.h> 39#include <termios.h>
40#include <time.h>
36#include <unistd.h> 41#include <unistd.h>
42#include <utime.h>
37 43
38#ifdef CONFIG_SELINUX 44#ifdef CONFIG_SELINUX
39#include <selinux/selinux.h> 45#include <selinux/selinux.h>
40#endif 46#endif
41 47
48#ifdef CONFIG_LOCALE_SUPPORT
49#include <locale.h>
50#endif
51
42#include "pwd_.h" 52#include "pwd_.h"
43#include "grp_.h" 53#include "grp_.h"
44#include "shadow_.h" 54#include "shadow_.h"
@@ -127,8 +137,8 @@ extern int bb_test(int argc, char** argv);
127 137
128extern const char *bb_mode_string(int mode); 138extern const char *bb_mode_string(int mode);
129extern int is_directory(const char *name, int followLinks, struct stat *statBuf); 139extern int is_directory(const char *name, int followLinks, struct stat *statBuf);
130extern DIR *bb_opendir(const char *path); 140extern DIR *warn_opendir(const char *path);
131extern DIR *bb_xopendir(const char *path); 141extern DIR *xopendir(const char *path);
132 142
133extern int remove_file(const char *path, int flags); 143extern int remove_file(const char *path, int flags);
134extern int copy_file(const char *source, const char *dest, int flags); 144extern 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);
161extern char *bb_get_chunk_from_file(FILE *file, int *end); 171extern char *bb_get_chunk_from_file(FILE *file, int *end);
162extern int bb_copyfd_size(int fd1, int fd2, const off_t size); 172extern int bb_copyfd_size(int fd1, int fd2, const off_t size);
163extern int bb_copyfd_eof(int fd1, int fd2); 173extern int bb_copyfd_eof(int fd1, int fd2);
164extern void bb_xprint_and_close_file(FILE *file);
165extern int bb_xprint_file_by_name(const char *filename);
166extern char bb_process_escape_sequence(const char **ptr); 174extern char bb_process_escape_sequence(const char **ptr);
167extern char *bb_get_last_path_component(char *path); 175extern char *bb_get_last_path_component(char *path);
168extern FILE *bb_wfopen(const char *path, const char *mode); 176extern FILE *bb_wfopen(const char *path, const char *mode);
169extern FILE *bb_wfopen_input(const char *filename); 177extern FILE *bb_wfopen_input(const char *filename);
170extern FILE *bb_xfopen(const char *path, const char *mode); 178extern FILE *xfopen(const char *path, const char *mode);
171 179
172extern int bb_fclose_nonstdin(FILE *f); 180extern int bb_fclose_nonstdin(FILE *f);
173extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; 181extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
174 182
175extern void xstat(const char *filename, struct stat *buf); 183extern void xstat(const char *filename, struct stat *buf);
176extern int bb_xsocket(int domain, int type, int protocol); 184extern int xsocket(int domain, int type, int protocol);
177extern pid_t bb_spawn(char **argv); 185extern pid_t spawn(char **argv);
178extern pid_t bb_xspawn(char **argv); 186extern pid_t xspawn(char **argv);
179extern int wait4pid(int pid); 187extern int wait4pid(int pid);
180extern void bb_xdaemon(int nochdir, int noclose); 188extern void xdaemon(int nochdir, int noclose);
181extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); 189extern void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
182extern void bb_xlisten(int s, int backlog); 190extern void xlisten(int s, int backlog);
183extern void bb_xchdir(const char *path); 191extern void xchdir(const char *path);
184extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); 192extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
185extern char *utoa(unsigned n); 193extern char *utoa(unsigned n);
186extern void itoa_to_buf(int n, char *buf, unsigned buflen); 194extern void itoa_to_buf(int n, char *buf, unsigned buflen);
@@ -204,9 +212,9 @@ extern int bb_printf(const char * __restrict format, ...)
204 __attribute__ ((format (printf, 1, 2))); 212 __attribute__ ((format (printf, 1, 2)));
205 213
206//#warning rename to xferror_filename? 214//#warning rename to xferror_filename?
207extern void bb_xferror(FILE *fp, const char *fn); 215extern void xferror(FILE *fp, const char *fn);
208extern void bb_xferror_stdout(void); 216extern void xferror_stdout(void);
209extern void bb_xfflush_stdout(void); 217extern void xfflush_stdout(void);
210 218
211extern void bb_warn_ignoring_args(int n); 219extern void bb_warn_ignoring_args(int n);
212 220
@@ -224,8 +232,8 @@ extern void *xrealloc(void *old, size_t size);
224extern void *xzalloc(size_t size); 232extern void *xzalloc(size_t size);
225extern void *xcalloc(size_t nmemb, size_t size); 233extern void *xcalloc(size_t nmemb, size_t size);
226 234
227extern char *bb_xstrdup (const char *s); 235extern char *xstrdup (const char *s);
228extern char *bb_xstrndup (const char *s, int n); 236extern char *xstrndup (const char *s, int n);
229extern char *safe_strncpy(char *dst, const char *src, size_t size); 237extern char *safe_strncpy(char *dst, const char *src, size_t size);
230extern int safe_strtoi(char *arg, int* value); 238extern int safe_strtoi(char *arg, int* value);
231extern int safe_strtod(char *arg, double* value); 239extern int safe_strtod(char *arg, double* value);
@@ -321,7 +329,6 @@ char *concat_path_file(const char *path, const char *filename);
321char *concat_subpath_file(const char *path, const char *filename); 329char *concat_subpath_file(const char *path, const char *filename);
322char *last_char_is(const char *s, int c); 330char *last_char_is(const char *s, int c);
323 331
324int read_package_field(const char *package_buffer, char **field_name, char **field_value);
325//#warning yuk! 332//#warning yuk!
326char *fgets_str(FILE *file, const char *terminating_string); 333char *fgets_str(FILE *file, const char *terminating_string);
327 334
@@ -458,7 +465,8 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
458void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); 465void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
459void reset_ino_dev_hashtable(void); 466void reset_ino_dev_hashtable(void);
460 467
461char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 468char *xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
469void xprint_and_close_file(FILE *file);
462 470
463#define FAIL_DELAY 3 471#define FAIL_DELAY 3
464extern void bb_do_delay(int seconds); 472extern void bb_do_delay(int seconds);
@@ -476,8 +484,8 @@ extern int correct_password ( const struct passwd *pw );
476extern char *pw_encrypt(const char *clear, const char *salt); 484extern char *pw_encrypt(const char *clear, const char *salt);
477extern int obscure(const char *old, const char *newval, const struct passwd *pwdp); 485extern int obscure(const char *old, const char *newval, const struct passwd *pwdp);
478 486
479extern int bb_xopen(const char *pathname, int flags); 487extern int xopen(const char *pathname, int flags);
480extern int bb_xopen3(const char *pathname, int flags, int mode); 488extern int xopen3(const char *pathname, int flags, int mode);
481extern void xread(int fd, void *buf, size_t count); 489extern void xread(int fd, void *buf, size_t count);
482extern unsigned char xread_char(int fd); 490extern unsigned char xread_char(int fd);
483extern void xlseek(int fd, off_t offset, int whence); 491extern void xlseek(int fd, off_t offset, int whence);
@@ -550,7 +558,7 @@ void md5_begin(md5_ctx_t *ctx);
550void md5_hash(const void *data, size_t length, md5_ctx_t *ctx); 558void md5_hash(const void *data, size_t length, md5_ctx_t *ctx);
551void *md5_end(void *resbuf, md5_ctx_t *ctx); 559void *md5_end(void *resbuf, md5_ctx_t *ctx);
552 560
553extern uint32_t *bb_crc32_filltable (int endian); 561extern uint32_t *crc32_filltable (int endian);
554 562
555#ifndef RB_POWER_OFF 563#ifndef RB_POWER_OFF
556/* Stop system and switch power off if possible. */ 564/* 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
11 11
12LIBBB-n:= 12LIBBB-n:=
13LIBBB-y:= \ 13LIBBB-y:= \
14 bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \ 14 ask_confirmation.c change_identity.c chomp.c \
15 compare_string_array.c concat_path_file.c copy_file.c copyfd.c \ 15 compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
16 crc32.c create_icmp_socket.c create_icmp6_socket.c \ 16 crc32.c create_icmp_socket.c create_icmp6_socket.c \
17 device_open.c dump.c error_msg.c error_msg_and_die.c \ 17 device_open.c dump.c error_msg.c error_msg_and_die.c \
@@ -22,15 +22,14 @@ LIBBB-y:= \
22 kernel_version.c last_char_is.c login.c \ 22 kernel_version.c last_char_is.c login.c \
23 make_directory.c md5.c mode_string.c mtab_file.c \ 23 make_directory.c md5.c mode_string.c mtab_file.c \
24 obscure.c parse_mode.c parse_number.c perror_msg.c \ 24 obscure.c parse_mode.c parse_number.c perror_msg.c \
25 perror_msg_and_die.c print_file.c get_console.c \ 25 perror_msg_and_die.c get_console.c \
26 process_escape_sequence.c procps.c qmodule.c \ 26 process_escape_sequence.c procps.c qmodule.c \
27 read_package_field.c recursive_action.c remove_file.c \ 27 recursive_action.c remove_file.c \
28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \ 28 restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \ 29 safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
30 trim.c u_signal_names.c vdprintf.c verror_msg.c \ 30 trim.c u_signal_names.c vdprintf.c verror_msg.c \
31 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ 31 vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
32 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ 32 xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
33 bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
34 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ 33 get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
35 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ 34 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
36 perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ 35 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))
97$(LIBBB_MOBJ6):$(LIBBB_MSRC6) 96$(LIBBB_MOBJ6):$(LIBBB_MSRC6)
98 $(compile.c) -DL_$(notdir $*) 97 $(compile.c) -DL_$(notdir $*)
99 98
100LIBBB_MSRC7:=$(srcdir)/opendir.c
101LIBBB_MOBJ7:=$(call get-file-subparts, ${LIBBB_MSRC7})
102LIBBB_MOBJ7:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ7))
103$(LIBBB_MOBJ7):$(LIBBB_MSRC7)
104 $(compile.c) -DL_$(notdir $*)
105
106# We need the names of the object files built from MSRC for the L_ defines 99# We need the names of the object files built from MSRC for the L_ defines
107LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \ 100LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \
108 $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) $(LIBBB_MOBJ7) 101 $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6)
109 102
110LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \ 103LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \
111 $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) $(LIBBB_MSRC7) 104 $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6)
112 105
113LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC)) 106LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC))
114 107
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
4 *
5 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
6 */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <stdarg.h>
11#include "libbb.h"
12
13char *bb_xasprintf(const char *format, ...)
14{
15 va_list p;
16 int r;
17 char *string_ptr;
18
19#ifdef HAVE_GNU_EXTENSIONS
20 va_start(p, format);
21 r = vasprintf(&string_ptr, format, p);
22 va_end(p);
23#else
24 va_start(p, format);
25 r = vsnprintf(NULL, 0, format, p);
26 va_end(p);
27 string_ptr = xmalloc(r+1);
28 va_start(p, format);
29 r = vsnprintf(string_ptr, r+1, format, p);
30 va_end(p);
31#endif
32
33 if (r < 0) {
34 bb_perror_msg_and_die("bb_xasprintf");
35 }
36 return string_ptr;
37}
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xbind.c - a bind() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <sys/types.h>
11#include <sys/socket.h>
12#include "libbb.h"
13
14void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
15{
16 if (bind(sockfd, my_addr, addrlen))
17 bb_perror_msg_and_die("bind");
18}
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xchdir.c - a chdir() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9#include <unistd.h>
10#include "libbb.h"
11
12void bb_xchdir(const char *path)
13{
14 if (chdir(path))
15 bb_perror_msg_and_die("chdir(%s)", path);
16}
17
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xdaemon.c - a daemon() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <unistd.h>
11#include "libbb.h"
12
13#ifndef BB_NOMMU
14void bb_xdaemon(int nochdir, int noclose)
15{
16 if (daemon(nochdir, noclose))
17 bb_perror_msg_and_die("daemon");
18}
19#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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xlisten.c - a listen() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <sys/socket.h>
11#include "libbb.h"
12
13void bb_xlisten(int s, int backlog)
14{
15 if (listen(s, backlog))
16 bb_perror_msg_and_die("listen");
17}
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * bb_xsocket.c - a socket() which dies on failure with error message
4 *
5 * Copyright (C) 2006 Denis Vlasenko
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <sys/socket.h>
11#include "libbb.h"
12
13int bb_xsocket(int domain, int type, int protocol)
14{
15 int r = socket(domain, type, protocol);
16 if (r < 0)
17 bb_perror_msg_and_die("socket");
18 return r;
19}
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 @@
12 * not addition '/' if path name already have '/' 12 * not addition '/' if path name already have '/'
13*/ 13*/
14 14
15#include <string.h>
16#include "libbb.h" 15#include "libbb.h"
17 16
18char *concat_path_file(const char *path, const char *filename) 17char *concat_path_file(const char *path, const char *filename)
@@ -24,5 +23,5 @@ char *concat_path_file(const char *path, const char *filename)
24 lc = last_char_is(path, '/'); 23 lc = last_char_is(path, '/');
25 while (*filename == '/') 24 while (*filename == '/')
26 filename++; 25 filename++;
27 return bb_xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename); 26 return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
28} 27}
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 @@
9 */ 9 */
10 10
11#include "libbb.h" 11#include "libbb.h"
12#include <utime.h>
13#include <errno.h>
14 12
15int copy_file(const char *source, const char *dest, int flags) 13int copy_file(const char *source, const char *dest, int flags)
16{ 14{
@@ -77,7 +75,7 @@ int copy_file(const char *source, const char *dest, int flags)
77 } 75 }
78 76
79 /* Recursively copy files in SOURCE. */ 77 /* Recursively copy files in SOURCE. */
80 if ((dp = bb_opendir(source)) == NULL) { 78 if ((dp = opendir(source)) == NULL) {
81 status = -1; 79 status = -1;
82 goto preserve_status; 80 goto preserve_status;
83 } 81 }
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 @@
14 * endian = 0: little-endian 14 * endian = 0: little-endian
15 */ 15 */
16 16
17#include <stdio.h>
18#include <stdlib.h>
19#include "libbb.h" 17#include "libbb.h"
20 18
21uint32_t *bb_crc32_filltable (int endian) { 19uint32_t *crc32_filltable(int endian)
20{
22 21
23 uint32_t *crc_table = xmalloc(256 * sizeof(uint32_t)); 22 uint32_t *crc_table = xmalloc(256 * sizeof(uint32_t));
24 uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320; 23 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 @@
12 */ 12 */
13 13
14#include "libbb.h" 14#include "libbb.h"
15#include <string.h>
16#include <unistd.h>
17#include <ctype.h> /* for isdigit() */
18#include "dump.h" 15#include "dump.h"
19 16
20enum _vflag bb_dump_vflag = FIRST; 17enum _vflag bb_dump_vflag = FIRST;
@@ -232,7 +229,7 @@ static void rewrite(FS * fs)
232 */ 229 */
233 savech = *p2; 230 savech = *p2;
234 p1[1] = '\0'; 231 p1[1] = '\0';
235 pr->fmt = bb_xstrdup(fmtp); 232 pr->fmt = xstrdup(fmtp);
236 *p2 = savech; 233 *p2 = savech;
237 pr->cchar = pr->fmt + (p1 - fmtp); 234 pr->cchar = pr->fmt + (p1 - fmtp);
238 235
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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <limits.h>
11#include <stdio.h>
12#include <string.h>
13#include <dirent.h>
14#include <stdlib.h>
15#include "libbb.h" 10#include "libbb.h"
16 11
17char *find_block_device(char *path) 12char *find_block_device(char *path)
@@ -28,7 +23,7 @@ char *find_block_device(char *path)
28 char devpath[PATH_MAX]; 23 char devpath[PATH_MAX];
29 sprintf(devpath,"/dev/%s", entry->d_name); 24 sprintf(devpath,"/dev/%s", entry->d_name);
30 if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) { 25 if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
31 retpath = bb_xstrdup(devpath); 26 retpath = xstrdup(devpath);
32 break; 27 break;
33 } 28 }
34 } 29 }
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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <getopt.h>
11#include <string.h>
12#include <assert.h>
13#include <stdlib.h>
14#include "libbb.h" 10#include "libbb.h"
11#include <getopt.h>
15 12
16/* Documentation 13/* Documentation
17 14
@@ -438,7 +435,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
438#if defined(CONFIG_AR) || defined(CONFIG_TAR) 435#if defined(CONFIG_AR) || defined(CONFIG_TAR)
439 if((spec_flgs & FIRST_ARGV_IS_OPT)) { 436 if((spec_flgs & FIRST_ARGV_IS_OPT)) {
440 if(argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') { 437 if(argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
441 argv[1] = bb_xasprintf("-%s", argv[1]); 438 argv[1] = xasprintf("-%s", argv[1]);
442 if(ENABLE_FEATURE_CLEAN_UP) 439 if(ENABLE_FEATURE_CLEAN_UP)
443 spec_flgs |= FREE_FIRST_ARGV_IS_OPT; 440 spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
444 } 441 }
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 @@
11 11
12#include "libbb.h" 12#include "libbb.h"
13#include "inet_common.h" 13#include "inet_common.h"
14#include <stdio.h>
15#include <errno.h>
16#include <stdlib.h>
17#include <string.h>
18#include <unistd.h>
19
20#ifdef DEBUG
21# include <resolv.h>
22#endif
23
24 14
25const char bb_INET_default[] = "default"; 15const char bb_INET_default[] = "default";
26 16
@@ -174,7 +164,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
174 pn->addr = *s_in; 164 pn->addr = *s_in;
175 pn->next = INET_nn; 165 pn->next = INET_nn;
176 pn->host = host; 166 pn->host = host;
177 pn->name = bb_xstrdup(name); 167 pn->name = xstrdup(name);
178 INET_nn = pn; 168 INET_nn = pn;
179 169
180 return (0); 170 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 @@
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 9 */
10 10
11#include <features.h>
12#include <stdio.h>
13#include <errno.h>
14#include <fcntl.h>
15#include <string.h>
16#include <unistd.h>
17#include <sys/ioctl.h>
18#include "libbb.h" 11#include "libbb.h"
19 12
20/* For 2.6, use the cleaned up header to get the 64 bit API. */ 13/* For 2.6, use the cleaned up header to get the 64 bit API. */
@@ -59,7 +52,7 @@ char *query_loop(const char *device)
59 52
60 if ((fd = open(device, O_RDONLY)) < 0) return 0; 53 if ((fd = open(device, O_RDONLY)) < 0) return 0;
61 if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo)) 54 if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
62 dev=bb_xasprintf("%ld %s", (long) loopinfo.lo_offset, 55 dev=xasprintf("%ld %s", (long) loopinfo.lo_offset,
63 (char *)loopinfo.lo_file_name); 56 (char *)loopinfo.lo_file_name);
64 close(fd); 57 close(fd);
65 58
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 @@
39 of crypt do not truncate passwords. 39 of crypt do not truncate passwords.
40*/ 40*/
41 41
42#include <ctype.h>
43#include <unistd.h>
44#include <string.h>
45#include <strings.h>
46
47#include "libbb.h" 42#include "libbb.h"
48 43
49static int string_checker_helper(const char *p1, const char *p2) __attribute__ ((__pure__)); 44static 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)
66 /* check string */ 61 /* check string */
67 int ret = string_checker_helper(p1, p2); 62 int ret = string_checker_helper(p1, p2);
68 /* Make our own copy */ 63 /* Make our own copy */
69 char *p = bb_xstrdup(p1); 64 char *p = xstrdup(p1);
70 /* reverse string */ 65 /* reverse string */
71 size = strlen(p); 66 size = strlen(p);
72 67
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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * wrapper for opendir()
4 *
5 * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <sys/types.h>
11#include <dirent.h>
12#include "libbb.h"
13
14#ifdef L_bb_opendir
15DIR *bb_opendir(const char *path)
16{
17 DIR *dp;
18
19 if ((dp = opendir(path)) == NULL) {
20 bb_perror_msg("unable to open `%s'", path);
21 return NULL;
22 }
23 return dp;
24}
25#endif
26
27#ifdef L_bb_xopendir
28DIR *bb_xopendir(const char *path)
29{
30 DIR *dp;
31
32 if ((dp = opendir(path)) == NULL) {
33 bb_perror_msg_and_die("unable to open `%s'", path);
34 }
35 return dp;
36}
37#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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <unistd.h>
13#include "libbb.h"
14
15void bb_xprint_and_close_file(FILE *file)
16{
17 bb_xfflush_stdout();
18 /* Note: Do not use STDOUT_FILENO here, as this is a lib routine
19 * and the calling code may have reassigned stdout. */
20 if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1) {
21 /* bb_copyfd outputs any needed messages, so just die. */
22 exit(bb_default_error_retval);
23 }
24 /* Note: Since we're reading, don't bother checking the return value
25 * of fclose(). The only possible failure is EINTR which
26 * should already have been taken care of. */
27 fclose(file);
28}
29
30/* Returns:
31 * 0 if successful
32 * -1 if 'filename' does not exist or is a directory
33 * exits with default error code if an error occurs
34 */
35
36int bb_xprint_file_by_name(const char *filename)
37{
38 FILE *f;
39
40#if 0
41 /* This check shouldn't be necessary for linux, but is left
42 * here disabled just in case. */
43 struct stat statBuf;
44
45 if(is_directory(filename, TRUE, &statBuf)) {
46 bb_error_msg("%s: Is directory", filename);
47 } else
48#endif
49 if ((f = bb_wfopen(filename, "r")) != NULL) {
50 bb_xprint_and_close_file(f);
51 return 0;
52 }
53
54 return -1;
55}
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)
51 struct stat sb; 51 struct stat sb;
52 52
53 if (!dir) { 53 if (!dir) {
54 dir = bb_xopendir("/proc"); 54 dir = xopendir("/proc");
55 } 55 }
56 for (;;) { 56 for (;;) {
57 if ((entry = readdir(dir)) == NULL) { 57 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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) many different people.
6 * If you wrote this, please acknowledge your work.
7 *
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */
10
11#include <stdlib.h>
12#include <string.h>
13#include "libbb.h"
14
15/*
16 * Gets the next package field from package_buffer, seperated into the field name
17 * and field value, it returns the int offset to the first character of the next field
18 */
19int read_package_field(const char *package_buffer, char **field_name, char **field_value)
20{
21 int offset_name_start = 0;
22 int offset_name_end = 0;
23 int offset_value_start = 0;
24 int offset_value_end = 0;
25 int offset = 0;
26 int next_offset;
27 int name_length;
28 int value_length;
29 int exit_flag = FALSE;
30
31 if (package_buffer == NULL) {
32 *field_name = NULL;
33 *field_value = NULL;
34 return(-1);
35 }
36 while (1) {
37 next_offset = offset + 1;
38 switch (package_buffer[offset]) {
39 case('\0'):
40 exit_flag = TRUE;
41 break;
42 case(':'):
43 if (offset_name_end == 0) {
44 offset_name_end = offset;
45 offset_value_start = next_offset;
46 }
47 /* TODO: Name might still have trailing spaces if ':' isnt
48 * immediately after name */
49 break;
50 case('\n'):
51 /* TODO: The char next_offset may be out of bounds */
52 if (package_buffer[next_offset] != ' ') {
53 exit_flag = TRUE;
54 break;
55 }
56 case('\t'):
57 case(' '):
58 /* increment the value start point if its a just filler */
59 if (offset_name_start == offset) {
60 offset_name_start++;
61 }
62 if (offset_value_start == offset) {
63 offset_value_start++;
64 }
65 break;
66 }
67 if (exit_flag) {
68 /* Check that the names are valid */
69 offset_value_end = offset;
70 name_length = offset_name_end - offset_name_start;
71 value_length = offset_value_end - offset_value_start;
72 if (name_length == 0) {
73 break;
74 }
75 if ((name_length > 0) && (value_length > 0)) {
76 break;
77 }
78
79 /* If not valid, start fresh with next field */
80 exit_flag = FALSE;
81 offset_name_start = offset + 1;
82 offset_name_end = 0;
83 offset_value_start = offset + 1;
84 offset_value_end = offset + 1;
85 offset++;
86 }
87 offset++;
88 }
89 if (name_length == 0) {
90 *field_name = NULL;
91 } else {
92 *field_name = bb_xstrndup(&package_buffer[offset_name_start], name_length);
93 }
94 if (value_length > 0) {
95 *field_value = bb_xstrndup(&package_buffer[offset_value_start], value_length);
96 } else {
97 *field_value = NULL;
98 }
99 return(next_offset);
100}
101
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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdio.h>
11#include <string.h>
12#include <dirent.h>
13#include <sys/stat.h>
14#include <stdlib.h> /* free() */
15#include "libbb.h" 10#include "libbb.h"
16 11
17#undef DEBUG_RECURS_ACTION 12#undef DEBUG_RECURS_ACTION
@@ -82,7 +77,7 @@ int recursive_action(const char *fileName,
82 } else if (status == SKIP) 77 } else if (status == SKIP)
83 return TRUE; 78 return TRUE;
84 } 79 }
85 dir = bb_opendir(fileName); 80 dir = opendir(fileName);
86 if (!dir) { 81 if (!dir) {
87 return FALSE; 82 return FALSE;
88 } 83 }
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)
59 return 0; 59 return 0;
60 } 60 }
61 61
62 if ((dp = bb_opendir(path)) == NULL) { 62 if ((dp = opendir(path)) == NULL) {
63 return -1; 63 return -1;
64 } 64 }
65 65
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
82 82
83 args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt )); 83 args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
84 84
85 args [0] = bb_get_last_path_component ( bb_xstrdup ( shell )); 85 args [0] = bb_get_last_path_component ( xstrdup ( shell ));
86 86
87 if ( loginshell ) 87 if ( loginshell )
88 args [0] = bb_xasprintf ("-%s", args [0]); 88 args [0] = xasprintf ("-%s", args [0]);
89 89
90 if ( command ) { 90 if ( command ) {
91 args [argno++] = "-c"; 91 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 @@
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 8 */
9 9
10#include <stdlib.h>
11#include "libbb.h" 10#include "libbb.h"
12 11
13char *bb_simplify_path(const char *path) 12char *bb_simplify_path(const char *path)
@@ -15,7 +14,7 @@ char *bb_simplify_path(const char *path)
15 char *s, *start, *p; 14 char *s, *start, *p;
16 15
17 if (path[0] == '/') 16 if (path[0] == '/')
18 start = bb_xstrdup(path); 17 start = xstrdup(path);
19 else { 18 else {
20 s = xgetcwd(NULL); 19 s = xgetcwd(NULL);
21 start = concat_path_file(s, path); 20 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 @@
6 * 6 *
7 */ 7 */
8 8
9#include <unistd.h>
10#include <string.h>
11#include <stdlib.h>
12#include <sys/types.h>
13#include <sys/socket.h>
14#include <errno.h>
15#include <netdb.h>
16#include <sys/socket.h>
17#include <netinet/in.h>
18#include <arpa/inet.h>
19#include "libbb.h" 9#include "libbb.h"
20 10
21/* Return network byte ordered port number for a service. 11/* 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)
61 51
62int xconnect(struct sockaddr_in *s_addr) 52int xconnect(struct sockaddr_in *s_addr)
63{ 53{
64 int s = bb_xsocket(AF_INET, SOCK_STREAM, 0); 54 int s = xsocket(AF_INET, SOCK_STREAM, 0);
65 if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) 55 if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
66 { 56 {
67 if (ENABLE_FEATURE_CLEAN_UP) close(s); 57 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 @@
3 * Utility routines. 3 * Utility routines.
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2006 Rob Landley
7 * Copyright (C) 2006 Denis Vlasenko
6 * 8 *
7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 */ 10 */
9 11
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <sys/wait.h>
13#include <stdio.h>
14#include <string.h>
15#include <stdlib.h>
16#include <unistd.h>
17#include <fcntl.h>
18#include "busybox.h" 12#include "busybox.h"
19 13
20#ifndef DMALLOC 14#ifndef DMALLOC
@@ -59,7 +53,7 @@ void *xcalloc(size_t nmemb, size_t size)
59#endif /* DMALLOC */ 53#endif /* DMALLOC */
60 54
61#ifdef L_xstrdup 55#ifdef L_xstrdup
62char * bb_xstrdup (const char *s) 56char * xstrdup (const char *s)
63{ 57{
64 char *t; 58 char *t;
65 59
@@ -76,12 +70,12 @@ char * bb_xstrdup (const char *s)
76#endif 70#endif
77 71
78#ifdef L_xstrndup 72#ifdef L_xstrndup
79char * bb_xstrndup (const char *s, int n) 73char * xstrndup (const char *s, int n)
80{ 74{
81 char *t; 75 char *t;
82 76
83 if (ENABLE_DEBUG && s == NULL) 77 if (ENABLE_DEBUG && s == NULL)
84 bb_error_msg_and_die("bb_xstrndup bug"); 78 bb_error_msg_and_die("xstrndup bug");
85 79
86 t = xmalloc(++n); 80 t = xmalloc(++n);
87 81
@@ -90,7 +84,7 @@ char * bb_xstrndup (const char *s, int n)
90#endif 84#endif
91 85
92#ifdef L_xfopen 86#ifdef L_xfopen
93FILE *bb_xfopen(const char *path, const char *mode) 87FILE *xfopen(const char *path, const char *mode)
94{ 88{
95 FILE *fp; 89 FILE *fp;
96 if ((fp = fopen(path, mode)) == NULL) 90 if ((fp = fopen(path, mode)) == NULL)
@@ -100,14 +94,14 @@ FILE *bb_xfopen(const char *path, const char *mode)
100#endif 94#endif
101 95
102#ifdef L_xopen 96#ifdef L_xopen
103int bb_xopen(const char *pathname, int flags) 97int xopen(const char *pathname, int flags)
104{ 98{
105 return bb_xopen3(pathname, flags, 0777); 99 return xopen3(pathname, flags, 0777);
106} 100}
107#endif 101#endif
108 102
109#ifdef L_xopen3 103#ifdef L_xopen3
110int bb_xopen3(const char *pathname, int flags, int mode) 104int xopen3(const char *pathname, int flags, int mode)
111{ 105{
112 int ret; 106 int ret;
113 107
@@ -175,7 +169,7 @@ unsigned char xread_char(int fd)
175#endif 169#endif
176 170
177#ifdef L_xferror 171#ifdef L_xferror
178void bb_xferror(FILE *fp, const char *fn) 172void xferror(FILE *fp, const char *fn)
179{ 173{
180 if (ferror(fp)) { 174 if (ferror(fp)) {
181 bb_error_msg_and_die("%s", fn); 175 bb_error_msg_and_die("%s", fn);
@@ -184,14 +178,14 @@ void bb_xferror(FILE *fp, const char *fn)
184#endif 178#endif
185 179
186#ifdef L_xferror_stdout 180#ifdef L_xferror_stdout
187void bb_xferror_stdout(void) 181void xferror_stdout(void)
188{ 182{
189 bb_xferror(stdout, bb_msg_standard_output); 183 xferror(stdout, bb_msg_standard_output);
190} 184}
191#endif 185#endif
192 186
193#ifdef L_xfflush_stdout 187#ifdef L_xfflush_stdout
194void bb_xfflush_stdout(void) 188void xfflush_stdout(void)
195{ 189{
196 if (fflush(stdout)) { 190 if (fflush(stdout)) {
197 bb_perror_msg_and_die(bb_msg_standard_output); 191 bb_perror_msg_and_die(bb_msg_standard_output);
@@ -201,7 +195,7 @@ void bb_xfflush_stdout(void)
201 195
202#ifdef L_spawn 196#ifdef L_spawn
203// This does a fork/exec in one call, using vfork(). 197// This does a fork/exec in one call, using vfork().
204pid_t bb_spawn(char **argv) 198pid_t spawn(char **argv)
205{ 199{
206 static int failed; 200 static int failed;
207 pid_t pid; 201 pid_t pid;
@@ -226,9 +220,9 @@ pid_t bb_spawn(char **argv)
226#endif 220#endif
227 221
228#ifdef L_xspawn 222#ifdef L_xspawn
229pid_t bb_xspawn(char **argv) 223pid_t xspawn(char **argv)
230{ 224{
231 pid_t pid = bb_spawn(argv); 225 pid_t pid = spawn(argv);
232 if (pid < 0) bb_perror_msg_and_die("%s", *argv); 226 if (pid < 0) bb_perror_msg_and_die("%s", *argv);
233 return pid; 227 return pid;
234} 228}
@@ -347,3 +341,107 @@ off_t fdlength(int fd)
347 return pos + 1; 341 return pos + 1;
348} 342}
349#endif 343#endif
344
345#ifdef L_xasprintf
346char *xasprintf(const char *format, ...)
347{
348 va_list p;
349 int r;
350 char *string_ptr;
351
352#if 1
353 // GNU extension
354 va_start(p, format);
355 r = vasprintf(&string_ptr, format, p);
356 va_end(p);
357#else
358 // Bloat for systems that haven't got the GNU extension.
359 va_start(p, format);
360 r = vsnprintf(NULL, 0, format, p);
361 va_end(p);
362 string_ptr = xmalloc(r+1);
363 va_start(p, format);
364 r = vsnprintf(string_ptr, r+1, format, p);
365 va_end(p);
366#endif
367
368 if (r < 0) bb_perror_msg_and_die("xasprintf");
369 return string_ptr;
370}
371#endif
372
373#ifdef L_xprint_and_close_file
374void xprint_and_close_file(FILE *file)
375{
376 // copyfd outputs error messages for us.
377 if (bb_copyfd_eof(fileno(file), 1) == -1) exit(bb_default_error_retval);
378
379 fclose(file);
380}
381#endif
382
383#ifdef L_xchdir
384void xchdir(const char *path)
385{
386 if (chdir(path))
387 bb_perror_msg_and_die("chdir(%s)", path);
388}
389#endif
390
391#ifdef L_warn_opendir
392DIR *warn_opendir(const char *path)
393{
394 DIR *dp;
395
396 if ((dp = opendir(path)) == NULL) {
397 bb_perror_msg("unable to open `%s'", path);
398 return NULL;
399 }
400 return dp;
401}
402#endif
403
404#ifdef L_xopendir
405DIR *xopendir(const char *path)
406{
407 DIR *dp;
408
409 if ((dp = opendir(path)) == NULL)
410 bb_perror_msg_and_die("unable to open `%s'", path);
411 return dp;
412}
413#endif
414
415#ifdef L_xdaemon
416#ifndef BB_NOMMU
417void xdaemon(int nochdir, int noclose)
418{
419 if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
420}
421#endif
422#endif
423
424#ifdef L_xbind
425void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
426{
427 if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
428}
429#endif
430
431#ifdef L_xsocket
432int xsocket(int domain, int type, int protocol)
433{
434 int r = socket(domain, type, protocol);
435
436 if (r < 0) bb_perror_msg_and_die("socket");
437
438 return r;
439}
440#endif
441
442#ifdef L_xlisten
443void xlisten(int s, int backlog)
444{
445 if (listen(s, backlog)) bb_perror_msg_and_die("listen");
446}
447#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 @@
9 * 9 *
10 */ 10 */
11 11
12#include <stdio.h>
13#include <string.h>
14#include <sys/types.h>
15#include <unistd.h>
16
17#include "busybox.h" 12#include "busybox.h"
18 13
19/* make sure gr_name isn't taken, make sure gid is kosher 14/* make sure gr_name isn't taken, make sure gid is kosher
@@ -26,7 +21,7 @@ static int group_study(struct group *g)
26 struct group *grp; 21 struct group *grp;
27 const int max = 65000; 22 const int max = 65000;
28 23
29 etc_group = bb_xfopen(bb_path_group_file, "r"); 24 etc_group = xfopen(bb_path_group_file, "r");
30 25
31 /* make sure gr_name isn't taken, make sure gid is kosher */ 26 /* make sure gr_name isn't taken, make sure gid is kosher */
32 desired = g->gr_gid; 27 desired = g->gr_gid;
@@ -67,13 +62,13 @@ static int addgroup(char *group, gid_t gid, const char *user)
67 return 1; 62 return 1;
68 63
69 /* add entry to group */ 64 /* add entry to group */
70 file = bb_xfopen(bb_path_group_file, "a"); 65 file = xfopen(bb_path_group_file, "a");
71 /* group:passwd:gid:userlist */ 66 /* group:passwd:gid:userlist */
72 fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user); 67 fprintf(file, "%s:%s:%d:%s\n", group, "x", gr.gr_gid, user);
73 fclose(file); 68 fclose(file);
74 69
75#if ENABLE_FEATURE_SHADOWPASSWDS 70#if ENABLE_FEATURE_SHADOWPASSWDS
76 file = bb_xfopen(bb_path_gshadow_file, "a"); 71 file = xfopen(bb_path_gshadow_file, "a");
77 fprintf(file, "%s:!::\n", group); 72 fprintf(file, "%s:!::\n", group);
78 fclose(file); 73 fclose(file);
79#endif 74#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 @@
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 9 */
10 10
11#include <stdio.h>
12#include <sys/types.h>
13#include <string.h>
14#include <unistd.h>
15#include <time.h>
16#include <getopt.h>
17#include <sys/stat.h>
18
19#include "busybox.h" 11#include "busybox.h"
20 12
21#define DONT_SET_PASS (1 << 4) 13#define DONT_SET_PASS (1 << 4)
@@ -32,7 +24,7 @@ static int passwd_study(const char *filename, struct passwd *p)
32 const int min = 500; 24 const int min = 500;
33 const int max = 65000; 25 const int max = 65000;
34 26
35 passwd = bb_xfopen(filename, "r"); 27 passwd = xfopen(filename, "r");
36 28
37 /* EDR if uid is out of bounds, set to min */ 29 /* EDR if uid is out of bounds, set to min */
38 if ((p->pw_uid > max) || (p->pw_uid < min)) 30 if ((p->pw_uid > max) || (p->pw_uid < min))
@@ -78,7 +70,7 @@ static void addgroup_wrapper(struct passwd *p)
78{ 70{
79 char *cmd; 71 char *cmd;
80 72
81 cmd = bb_xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name); 73 cmd = xasprintf("addgroup -g %d \"%s\"", p->pw_gid, p->pw_name);
82 system(cmd); 74 system(cmd);
83 free(cmd); 75 free(cmd);
84} 76}
@@ -99,7 +91,7 @@ static int adduser(struct passwd *p, unsigned long flags)
99 int addgroup = !p->pw_gid; 91 int addgroup = !p->pw_gid;
100 92
101 /* make sure everything is kosher and setup uid && gid */ 93 /* make sure everything is kosher and setup uid && gid */
102 file = bb_xfopen(bb_path_passwd_file, "a"); 94 file = xfopen(bb_path_passwd_file, "a");
103 fseek(file, 0, SEEK_END); 95 fseek(file, 0, SEEK_END);
104 96
105 switch (passwd_study(bb_path_passwd_file, p)) { 97 switch (passwd_study(bb_path_passwd_file, p)) {
@@ -119,7 +111,7 @@ static int adduser(struct passwd *p, unsigned long flags)
119 111
120#if ENABLE_FEATURE_SHADOWPASSWDS 112#if ENABLE_FEATURE_SHADOWPASSWDS
121 /* add to shadow if necessary */ 113 /* add to shadow if necessary */
122 file = bb_xfopen(bb_path_shadow_file, "a"); 114 file = xfopen(bb_path_shadow_file, "a");
123 fseek(file, 0, SEEK_END); 115 fseek(file, 0, SEEK_END);
124 fprintf(file, "%s:!:%ld:%d:%d:%d:::\n", 116 fprintf(file, "%s:!:%ld:%d:%d:%d:::\n",
125 p->pw_name, /* username */ 117 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 @@
16 * 16 *
17 */ 17 */
18 18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <string.h>
23#include <sys/ioctl.h>
24#include <errno.h>
25#include <sys/stat.h>
26#include <signal.h>
27#include <fcntl.h>
28#include <stdarg.h>
29#include <ctype.h>
30#include <getopt.h>
31#include <termios.h>
32#include "busybox.h" 19#include "busybox.h"
33 20
34#ifdef CONFIG_FEATURE_UTMP 21#ifdef CONFIG_FEATURE_UTMP
@@ -324,7 +311,7 @@ static void parse_args(int argc, char **argv, struct options *op)
324 const char *p = op->initstring; 311 const char *p = op->initstring;
325 char *q; 312 char *q;
326 313
327 q = op->initstring = bb_xstrdup(op->initstring); 314 q = op->initstring = xstrdup(op->initstring);
328 /* copy optarg into op->initstring decoding \ddd 315 /* copy optarg into op->initstring decoding \ddd
329 octal codes into chars */ 316 octal codes into chars */
330 while (*p) { 317 while (*p) {
@@ -858,7 +845,7 @@ int getty_main(int argc, char **argv)
858 }; 845 };
859 846
860#ifdef DEBUGGING 847#ifdef DEBUGGING
861 dbf = bb_xfopen(DEBUGTERM, "w"); 848 dbf = xfopen(DEBUGTERM, "w");
862 849
863 { 850 {
864 int i; 851 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 @@
3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 3 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
4 */ 4 */
5 5
6#include <fcntl.h>
7#include <stdio.h>
8#include <string.h>
9#include <signal.h>
10#include <sys/stat.h>
11#include <sys/types.h>
12#include <unistd.h>
13#include <utime.h>
14#include <syslog.h>
15#include <time.h>
16#include <sys/resource.h>
17#include <errno.h>
18
19#include "busybox.h" 6#include "busybox.h"
7#include <syslog.h>
20 8
21static char crypt_passwd[128]; 9static char crypt_passwd[128];
22 10
@@ -170,7 +158,7 @@ int passwd_main(int argc, char **argv)
170 bb_show_usage(); 158 bb_show_usage();
171 } 159 }
172 } 160 }
173 myname = (char *) bb_xstrdup(bb_getpwuid(NULL, getuid(), -1)); 161 myname = (char *) xstrdup(bb_getpwuid(NULL, getuid(), -1));
174 /* exits on error */ 162 /* exits on error */
175 if (optind < argc) { 163 if (optind < argc) {
176 name = argv[optind]; 164 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 @@
6 */ 6 */
7 7
8#include "busybox.h" 8#include "busybox.h"
9#include <signal.h>
10#include <syslog.h> 9#include <syslog.h>
11#include <sys/resource.h>
12#include <time.h>
13
14 10
15int su_main ( int argc, char **argv ) 11int su_main ( int argc, char **argv )
16{ 12{
@@ -43,7 +39,7 @@ int su_main ( int argc, char **argv )
43 the user, especially if someone su's from a su-shell. 39 the user, especially if someone su's from a su-shell.
44 But getlogin can fail -- usually due to lack of utmp entry. 40 But getlogin can fail -- usually due to lack of utmp entry.
45 in this case resort to getpwuid. */ 41 in this case resort to getpwuid. */
46 old_user = bb_xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : ""); 42 old_user = xstrdup(USE_FEATURE_UTMP(getlogin() ? : ) (pw = getpwuid(cur_uid)) ? pw->pw_name : "");
47 tty = ttyname(2) ? : "none"; 43 tty = ttyname(2) ? : "none";
48 openlog(bb_applet_name, 0, LOG_AUTH); 44 openlog(bb_applet_name, 0, LOG_AUTH);
49 } 45 }
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 @@
16/* Fixed by Erik Andersen to do passwords the tinylogin way... 16/* Fixed by Erik Andersen to do passwords the tinylogin way...
17 * It now works with md5, sha1, etc passwords. */ 17 * It now works with md5, sha1, etc passwords. */
18 18
19#include <stdio.h>
20#include <stdlib.h>
21#include <sys/vt.h>
22#include <signal.h>
23#include <string.h>
24#include <unistd.h>
25#include <fcntl.h>
26#include <errno.h>
27#include <sys/ioctl.h>
28#include <termios.h>
29
30#include "busybox.h" 19#include "busybox.h"
20#include <sys/vt.h>
31 21
32static struct passwd *pw; 22static struct passwd *pw;
33static struct vt_mode ovtm; 23static struct vt_mode ovtm;
@@ -71,7 +61,7 @@ int vlock_main(int argc, char **argv)
71 bb_error_msg_and_die("Unknown uid %d", getuid()); 61 bb_error_msg_and_die("Unknown uid %d", getuid());
72 } 62 }
73 63
74 vfd = bb_xopen(CURRENT_TTY, O_RDWR); 64 vfd = xopen(CURRENT_TTY, O_RDWR);
75 65
76 if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { 66 if (ioctl(vfd, VT_GETMODE, &vtm) < 0) {
77 bb_perror_msg_and_die("VT_GETMODE"); 67 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 @@
13#define VERSION "2.3.2" 13#define VERSION "2.3.2"
14 14
15#include "busybox.h" 15#include "busybox.h"
16#include <stdio.h> 16#include <sys/syslog.h>
17#include <stdlib.h>
18#include <stdarg.h>
19#include <string.h>
20#include <errno.h>
21#include <time.h>
22#include <dirent.h>
23#include <fcntl.h>
24#include <unistd.h>
25#include <syslog.h>
26#include <signal.h>
27#include <getopt.h>
28#include <sys/ioctl.h>
29#include <sys/wait.h>
30#include <sys/stat.h>
31#include <sys/resource.h>
32 17
33#define arysize(ary) (sizeof(ary)/sizeof((ary)[0])) 18#define arysize(ary) (sizeof(ary)/sizeof((ary)[0]))
34 19
@@ -193,7 +178,7 @@ int crond_main(int ac, char **av)
193 * change directory 178 * change directory
194 */ 179 */
195 180
196 bb_xchdir(CDir); 181 xchdir(CDir);
197 signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original 182 signal(SIGHUP, SIG_IGN); /* hmm.. but, if kill -HUP original
198 * version - his died. ;( 183 * version - his died. ;(
199 */ 184 */
@@ -208,7 +193,7 @@ int crond_main(int ac, char **av)
208 /* reexec for vfork() do continue parent */ 193 /* reexec for vfork() do continue parent */
209 vfork_daemon_rexec(1, 0, ac, av, "-f"); 194 vfork_daemon_rexec(1, 0, ac, av, "-f");
210#else 195#else
211 bb_xdaemon(1, 0); 196 xdaemon(1, 0);
212#endif 197#endif
213 } 198 }
214 199
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 @@
11 */ 11 */
12 12
13#include "busybox.h" 13#include "busybox.h"
14#include <stdio.h>
15#include <stdlib.h>
16#include <stdarg.h>
17#include <string.h>
18#include <errno.h>
19#include <time.h>
20#include <dirent.h>
21#include <fcntl.h>
22#include <unistd.h>
23#include <syslog.h>
24#include <signal.h>
25#include <getopt.h>
26#include <sys/ioctl.h>
27#include <sys/wait.h>
28#include <sys/stat.h>
29#include <sys/resource.h>
30 14
31#ifndef CRONTABS 15#ifndef CRONTABS
32#define CRONTABS "/var/spool/cron/crontabs" 16#define CRONTABS "/var/spool/cron/crontabs"
@@ -47,8 +31,7 @@ static void EditFile(const char *user, const char *file);
47static int GetReplaceStream(const char *user, const char *file); 31static int GetReplaceStream(const char *user, const char *file);
48static int ChangeUser(const char *user, short dochdir); 32static int ChangeUser(const char *user, short dochdir);
49 33
50int 34int crontab_main(int ac, char **av)
51crontab_main(int ac, char **av)
52{ 35{
53 enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE; 36 enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
54 const struct passwd *pas; 37 const struct passwd *pas;
@@ -147,7 +130,7 @@ crontab_main(int ac, char **av)
147 * Change directory to our crontab directory 130 * Change directory to our crontab directory
148 */ 131 */
149 132
150 bb_xchdir(CDir); 133 xchdir(CDir);
151 134
152 /* 135 /*
153 * Handle options as appropriate 136 * Handle options as appropriate
@@ -177,7 +160,7 @@ crontab_main(int ac, char **av)
177 char buf[1024]; 160 char buf[1024];
178 161
179 snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid()); 162 snprintf(tmp, sizeof(tmp), TMPDIR "/crontab.%d", getpid());
180 fd = bb_xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600); 163 fd = xopen3(tmp, O_RDWR|O_CREAT|O_TRUNC|O_EXCL, 0600);
181 chown(tmp, getuid(), getgid()); 164 chown(tmp, getuid(), getgid());
182 if ((fi = fopen(pas->pw_name, "r"))) { 165 if ((fi = fopen(pas->pw_name, "r"))) {
183 while ((n = fread(buf, 1, sizeof(buf), fi)) > 0) 166 while ((n = fread(buf, 1, sizeof(buf), fi)) > 0)
@@ -244,8 +227,7 @@ crontab_main(int ac, char **av)
244 return 0; 227 return 0;
245} 228}
246 229
247static int 230static int GetReplaceStream(const char *user, const char *file)
248GetReplaceStream(const char *user, const char *file)
249{ 231{
250 int filedes[2]; 232 int filedes[2];
251 int pid; 233 int pid;
@@ -284,7 +266,7 @@ GetReplaceStream(const char *user, const char *file)
284 exit(0); 266 exit(0);
285 267
286 bb_default_error_retval = 0; 268 bb_default_error_retval = 0;
287 fd = bb_xopen3(file, O_RDONLY, 0); 269 fd = xopen3(file, O_RDONLY, 0);
288 buf[0] = 0; 270 buf[0] = 0;
289 write(filedes[1], buf, 1); 271 write(filedes[1], buf, 1);
290 while ((n = read(fd, buf, sizeof(buf))) > 0) { 272 while ((n = read(fd, buf, sizeof(buf))) > 0) {
@@ -293,8 +275,7 @@ GetReplaceStream(const char *user, const char *file)
293 exit(0); 275 exit(0);
294} 276}
295 277
296static void 278static void EditFile(const char *user, const char *file)
297EditFile(const char *user, const char *file)
298{ 279{
299 int pid; 280 int pid;
300 281
@@ -324,8 +305,7 @@ EditFile(const char *user, const char *file)
324 wait4(pid, NULL, 0, NULL); 305 wait4(pid, NULL, 0, NULL);
325} 306}
326 307
327static int 308static int ChangeUser(const char *user, short dochdir)
328ChangeUser(const char *user, short dochdir)
329{ 309{
330 struct passwd *pas; 310 struct passwd *pas;
331 311
@@ -349,7 +329,7 @@ ChangeUser(const char *user, short dochdir)
349 if (dochdir) { 329 if (dochdir) {
350 if (chdir(pas->pw_dir) < 0) { 330 if (chdir(pas->pw_dir) < 0) {
351 bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir); 331 bb_perror_msg("chdir failed: %s %s", user, pas->pw_dir);
352 bb_xchdir(TMPDIR); 332 xchdir(TMPDIR);
353 } 333 }
354 } 334 }
355 return(pas->pw_uid); 335 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)
475 if (chdir (mount_point) != 0) 475 if (chdir (mount_point) != 0)
476 devfsd_perror_msg_and_die(mount_point); 476 devfsd_perror_msg_and_die(mount_point);
477 477
478 fd = bb_xopen (".devfsd", O_RDONLY); 478 fd = xopen (".devfsd", O_RDONLY);
479 479
480 if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0) 480 if (fcntl (fd, F_SETFD, FD_CLOEXEC) != 0)
481 devfsd_perror_msg_and_die("FD_CLOEXEC"); 481 devfsd_perror_msg_and_die("FD_CLOEXEC");
@@ -704,7 +704,7 @@ static void process_config_line (const char *line, unsigned long *event_mask)
704 num_args -= 3; 704 num_args -= 3;
705 705
706 for (count = 0; count < num_args; ++count) 706 for (count = 0; count < num_args; ++count)
707 new->u.execute.argv[count] = bb_xstrdup (p[count]); 707 new->u.execute.argv[count] = xstrdup (p[count]);
708 708
709 new->u.execute.argv[num_args] = NULL; 709 new->u.execute.argv[num_args] = NULL;
710 break; 710 break;
@@ -714,8 +714,8 @@ static void process_config_line (const char *line, unsigned long *event_mask)
714 if (num_args != 2) 714 if (num_args != 2)
715 goto process_config_line_err; /* missing path and function in line */ 715 goto process_config_line_err; /* missing path and function in line */
716 716
717 new->u.copy.source = bb_xstrdup (p[0]); 717 new->u.copy.source = xstrdup (p[0]);
718 new->u.copy.destination = bb_xstrdup (p[1]); 718 new->u.copy.destination = xstrdup (p[1]);
719 break; 719 break;
720 case 8: /* IGNORE */ 720 case 8: /* IGNORE */
721 /* FALLTROUGH */ 721 /* 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 @@
13 */ 13 */
14 14
15#include "busybox.h" 15#include "busybox.h"
16#include <string.h>
17#include <fcntl.h>
18#include <errno.h>
19#include <ctype.h>
20#include <sys/ioctl.h>
21#include <sys/sysmacros.h>
22#include <sys/times.h>
23#include <sys/mman.h>
24#include <linux/types.h>
25#include <linux/hdreg.h> 16#include <linux/hdreg.h>
26 17
27#if BB_BIG_ENDIAN && !defined(__USE_XOPEN)
28# define __USE_XOPEN
29#endif
30#include <unistd.h>
31
32/* device types */ 18/* device types */
33/* ------------ */ 19/* ------------ */
34#define NO_DEV 0xffff 20#define NO_DEV 0xffff
@@ -1619,7 +1605,7 @@ static void process_dev(char *devname)
1619 unsigned char args[4] = {WIN_SETFEATURES,0,0,0}; 1605 unsigned char args[4] = {WIN_SETFEATURES,0,0,0};
1620 const char *fmt = " %s\t= %2ld"; 1606 const char *fmt = " %s\t= %2ld";
1621 1607
1622 fd = bb_xopen(devname, O_RDONLY|O_NONBLOCK); 1608 fd = xopen(devname, O_RDONLY|O_NONBLOCK);
1623 printf("\n%s:\n", devname); 1609 printf("\n%s:\n", devname);
1624 1610
1625 if (set_readahead) 1611 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 @@
8 */ 8 */
9 9
10#include "busybox.h" 10#include "busybox.h"
11#include <sys/types.h>
12#include <fcntl.h>
13#include <unistd.h>
14#include <stdlib.h>
15#include <utmp.h> 11#include <utmp.h>
16#include <sys/stat.h>
17#include <errno.h>
18#include <string.h>
19#include <time.h>
20 12
21#ifndef SHUTDOWN_TIME 13#ifndef SHUTDOWN_TIME
22# define SHUTDOWN_TIME 254 14# define SHUTDOWN_TIME 254
@@ -43,7 +35,7 @@ int last_main(int argc, char **argv)
43 if (argc > 1) { 35 if (argc > 1) {
44 bb_show_usage(); 36 bb_show_usage();
45 } 37 }
46 file = bb_xopen(bb_path_wtmp_file, O_RDONLY); 38 file = xopen(bb_path_wtmp_file, O_RDONLY);
47 39
48 printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME"); 40 printf("%-10s %-14s %-18s %-12.12s %s\n", "USER", "TTY", "HOST", "LOGIN", "TIME");
49 while ((n = safe_read(file, (void*)&ut, sizeof(struct utmp))) != 0) { 41 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 @@
31*/ 31*/
32 32
33#include "busybox.h" 33#include "busybox.h"
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <termios.h>
38#include <unistd.h>
39#include <ctype.h>
40 34
41#ifdef CONFIG_FEATURE_LESS_REGEXP 35#ifdef CONFIG_FEATURE_LESS_REGEXP
42#include "xregex.h" 36#include "xregex.h"
@@ -196,7 +190,7 @@ static void add_linenumbers(void)
196 190
197 for (i = 0; i <= num_flines; i++) { 191 for (i = 0; i <= num_flines; i++) {
198 safe_strncpy(current_line, flines[i], 256); 192 safe_strncpy(current_line, flines[i], 256);
199 flines[i] = bb_xasprintf("%5d %s", i + 1, current_line); 193 flines[i] = xasprintf("%5d %s", i + 1, current_line);
200 } 194 }
201} 195}
202 196
@@ -206,15 +200,15 @@ static void data_readlines(void)
206 char current_line[256]; 200 char current_line[256];
207 FILE *fp; 201 FILE *fp;
208 202
209 fp = (inp_stdin) ? stdin : bb_xfopen(filename, "r"); 203 fp = (inp_stdin) ? stdin : xfopen(filename, "r");
210 flines = NULL; 204 flines = NULL;
211 for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) { 205 for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
212 strcpy(current_line, ""); 206 strcpy(current_line, "");
213 fgets(current_line, 256, fp); 207 fgets(current_line, 256, fp);
214 if (fp != stdin) 208 if (fp != stdin)
215 bb_xferror(fp, filename); 209 xferror(fp, filename);
216 flines = xrealloc(flines, (i+1) * sizeof(char *)); 210 flines = xrealloc(flines, (i+1) * sizeof(char *));
217 flines[i] = bb_xstrdup(current_line); 211 flines[i] = xstrdup(current_line);
218 } 212 }
219 num_flines = i - 2; 213 num_flines = i - 2;
220 214
@@ -226,7 +220,7 @@ static void data_readlines(void)
226 fclose(fp); 220 fclose(fp);
227 221
228 if (inp == NULL) 222 if (inp == NULL)
229 inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin; 223 inp = (inp_stdin) ? xfopen(CURRENT_TTY, "r") : stdin;
230 224
231 if (flags & FLAG_N) 225 if (flags & FLAG_N)
232 add_linenumbers(); 226 add_linenumbers();
@@ -357,12 +351,12 @@ static void buffer_init(void)
357 /* Fill the buffer until the end of the file or the 351 /* Fill the buffer until the end of the file or the
358 end of the buffer is reached */ 352 end of the buffer is reached */
359 for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) { 353 for (i = 0; (i < (height - 1)) && (i <= num_flines); i++) {
360 buffer[i] = bb_xstrdup(flines[i]); 354 buffer[i] = xstrdup(flines[i]);
361 } 355 }
362 356
363 /* If the buffer still isn't full, fill it with blank lines */ 357 /* If the buffer still isn't full, fill it with blank lines */
364 for (; i < (height - 1); i++) { 358 for (; i < (height - 1); i++) {
365 buffer[i] = bb_xstrdup(""); 359 buffer[i] = xstrdup("");
366 } 360 }
367} 361}
368 362
@@ -376,7 +370,7 @@ static void buffer_down(int nlines)
376 line_pos += nlines; 370 line_pos += nlines;
377 for (i = 0; i < (height - 1); i++) { 371 for (i = 0; i < (height - 1); i++) {
378 free(buffer[i]); 372 free(buffer[i]);
379 buffer[i] = bb_xstrdup(flines[line_pos + i]); 373 buffer[i] = xstrdup(flines[line_pos + i]);
380 } 374 }
381 } 375 }
382 else { 376 else {
@@ -386,7 +380,7 @@ static void buffer_down(int nlines)
386 line_pos += 1; 380 line_pos += 1;
387 for (i = 0; i < (height - 1); i++) { 381 for (i = 0; i < (height - 1); i++) {
388 free(buffer[i]); 382 free(buffer[i]);
389 buffer[i] = bb_xstrdup(flines[line_pos + i]); 383 buffer[i] = xstrdup(flines[line_pos + i]);
390 } 384 }
391 } 385 }
392 } 386 }
@@ -407,7 +401,7 @@ static void buffer_up(int nlines)
407 line_pos -= nlines; 401 line_pos -= nlines;
408 for (i = 0; i < (height - 1); i++) { 402 for (i = 0; i < (height - 1); i++) {
409 free(buffer[i]); 403 free(buffer[i]);
410 buffer[i] = bb_xstrdup(flines[line_pos + i]); 404 buffer[i] = xstrdup(flines[line_pos + i]);
411 } 405 }
412 } 406 }
413 else { 407 else {
@@ -417,7 +411,7 @@ static void buffer_up(int nlines)
417 line_pos -= 1; 411 line_pos -= 1;
418 for (i = 0; i < (height - 1); i++) { 412 for (i = 0; i < (height - 1); i++) {
419 free(buffer[i]); 413 free(buffer[i]);
420 buffer[i] = bb_xstrdup(flines[line_pos + i]); 414 buffer[i] = xstrdup(flines[line_pos + i]);
421 } 415 }
422 } 416 }
423 } 417 }
@@ -439,10 +433,10 @@ static void buffer_up(int nlines)
439 for (i = 0; i < (height - 1); i++) { 433 for (i = 0; i < (height - 1); i++) {
440 free(buffer[i]); 434 free(buffer[i]);
441 if (i < tilde_line - nlines + 1) 435 if (i < tilde_line - nlines + 1)
442 buffer[i] = bb_xstrdup(flines[line_pos + i]); 436 buffer[i] = xstrdup(flines[line_pos + i]);
443 else { 437 else {
444 if (line_pos >= num_flines - height + 2) 438 if (line_pos >= num_flines - height + 2)
445 buffer[i] = bb_xstrdup("~\n"); 439 buffer[i] = xstrdup("~\n");
446 } 440 }
447 } 441 }
448 } 442 }
@@ -461,7 +455,7 @@ static void buffer_line(int linenum)
461 else if (linenum < (num_flines - height - 2)) { 455 else if (linenum < (num_flines - height - 2)) {
462 for (i = 0; i < (height - 1); i++) { 456 for (i = 0; i < (height - 1); i++) {
463 free(buffer[i]); 457 free(buffer[i]);
464 buffer[i] = bb_xstrdup(flines[linenum + i]); 458 buffer[i] = xstrdup(flines[linenum + i]);
465 } 459 }
466 line_pos = linenum; 460 line_pos = linenum;
467 buffer_print(); 461 buffer_print();
@@ -470,9 +464,9 @@ static void buffer_line(int linenum)
470 for (i = 0; i < (height - 1); i++) { 464 for (i = 0; i < (height - 1); i++) {
471 free(buffer[i]); 465 free(buffer[i]);
472 if (linenum + i < num_flines + 2) 466 if (linenum + i < num_flines + 2)
473 buffer[i] = bb_xstrdup(flines[linenum + i]); 467 buffer[i] = xstrdup(flines[linenum + i]);
474 else 468 else
475 buffer[i] = bb_xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n"); 469 buffer[i] = xstrdup((flags & FLAG_TILDE) ? "\n" : "~\n");
476 } 470 }
477 line_pos = linenum; 471 line_pos = linenum;
478 /* Set past_eof so buffer_down and buffer_up act differently */ 472 /* Set past_eof so buffer_down and buffer_up act differently */
@@ -508,7 +502,7 @@ static void examine_file(void)
508 newline_offset = strlen(filename) - 1; 502 newline_offset = strlen(filename) - 1;
509 filename[newline_offset] = '\0'; 503 filename[newline_offset] = '\0';
510 504
511 files[num_files] = bb_xstrdup(filename); 505 files[num_files] = xstrdup(filename);
512 current_file = num_files + 1; 506 current_file = num_files + 1;
513 num_files++; 507 num_files++;
514 508
@@ -612,7 +606,7 @@ static char *process_regex_on_line(char *line, regex_t *pattern, int action)
612 char *growline = ""; 606 char *growline = "";
613 regmatch_t match_structs; 607 regmatch_t match_structs;
614 608
615 line2 = bb_xstrdup(line); 609 line2 = xstrdup(line);
616 610
617 match_found = 0; 611 match_found = 0;
618 match_status = regexec(pattern, line2, 1, &match_structs, 0); 612 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)
622 match_found = 1; 616 match_found = 1;
623 617
624 if (action) { 618 if (action) {
625 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); 619 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);
626 } 620 }
627 else { 621 else {
628 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); 622 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);
629 } 623 }
630 624
631 line2 += match_structs.rm_eo; 625 line2 += match_structs.rm_eo;
632 match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL); 626 match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
633 } 627 }
634 628
635 growline = bb_xasprintf("%s%s", growline, line2); 629 growline = xasprintf("%s%s", growline, line2);
636 630
637 return (match_found ? growline : line); 631 return (match_found ? growline : line);
638 632
@@ -679,7 +673,7 @@ static void regex_process(void)
679 /* Get rid of all the highlights we added previously */ 673 /* Get rid of all the highlights we added previously */
680 for (i = 0; i <= num_flines; i++) { 674 for (i = 0; i <= num_flines; i++) {
681 current_line = process_regex_on_line(flines[i], &old_pattern, 0); 675 current_line = process_regex_on_line(flines[i], &old_pattern, 0);
682 flines[i] = bb_xstrdup(current_line); 676 flines[i] = xstrdup(current_line);
683 } 677 }
684 } 678 }
685 old_pattern = pattern; 679 old_pattern = pattern;
@@ -693,7 +687,7 @@ static void regex_process(void)
693 /* Run the regex on each line of the current file here */ 687 /* Run the regex on each line of the current file here */
694 for (i = 0; i <= num_flines; i++) { 688 for (i = 0; i <= num_flines; i++) {
695 current_line = process_regex_on_line(flines[i], &pattern, 1); 689 current_line = process_regex_on_line(flines[i], &pattern, 1);
696 flines[i] = bb_xstrdup(current_line); 690 flines[i] = xstrdup(current_line);
697 if (match_found) { 691 if (match_found) {
698 match_lines = xrealloc(match_lines, (j + 1) * sizeof(int)); 692 match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
699 match_lines[j] = i; 693 match_lines[j] = i;
@@ -864,7 +858,7 @@ static void save_input_to_file(void)
864 fgets(current_line, 256, inp); 858 fgets(current_line, 256, inp);
865 current_line[strlen(current_line) - 1] = '\0'; 859 current_line[strlen(current_line) - 1] = '\0';
866 if (strlen(current_line) > 1) { 860 if (strlen(current_line) > 1) {
867 fp = bb_xfopen(current_line, "w"); 861 fp = xfopen(current_line, "w");
868 for (i = 0; i < num_flines; i++) 862 for (i = 0; i < num_flines; i++)
869 fprintf(fp, "%s", flines[i]); 863 fprintf(fp, "%s", flines[i]);
870 fclose(fp); 864 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 @@
8 */ 8 */
9 9
10#include "busybox.h" 10#include "busybox.h"
11#include <stdio.h>
12#include <stdlib.h>
13#include <string.h>
14#include <fcntl.h>
15#include <time.h>
16#include <ctype.h>
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/sysmacros.h> /* major() and minor() */
20 11
21#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF 12#ifdef CONFIG_FEATURE_MAKEDEVS_LEAF
22int makedevs_main(int argc, char **argv) 13int makedevs_main(int argc, char **argv)
@@ -88,13 +79,13 @@ int makedevs_main(int argc, char **argv)
88 unsigned long flags; 79 unsigned long flags;
89 flags = bb_getopt_ulflags(argc, argv, "d:", &line); 80 flags = bb_getopt_ulflags(argc, argv, "d:", &line);
90 if (line) 81 if (line)
91 table = bb_xfopen(line, "r"); 82 table = xfopen(line, "r");
92 83
93 if (optind >= argc || (rootdir=argv[optind])==NULL) { 84 if (optind >= argc || (rootdir=argv[optind])==NULL) {
94 bb_error_msg_and_die("root directory not specified"); 85 bb_error_msg_and_die("root directory not specified");
95 } 86 }
96 87
97 bb_xchdir(rootdir); 88 xchdir(rootdir);
98 89
99 umask(0); 90 umask(0);
100 91
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 @@
10 */ 10 */
11 11
12#include "busybox.h" 12#include "busybox.h"
13#include <sys/stat.h>
14#include <errno.h> /* errno */
15#include <string.h> /* strerror */
16#include <getopt.h> /* optind */
17 13
18int mountpoint_main(int argc, char **argv) 14int mountpoint_main(int argc, char **argv)
19{ 15{
@@ -46,7 +42,7 @@ int mountpoint_main(int argc, char **argv)
46 if (S_ISDIR(st.st_mode)) { 42 if (S_ISDIR(st.st_mode)) {
47 dev_t st_dev = st.st_dev; 43 dev_t st_dev = st.st_dev;
48 ino_t st_ino = st.st_ino; 44 ino_t st_ino = st.st_ino;
49 char *p = bb_xasprintf("%s/..", arg); 45 char *p = xasprintf("%s/..", arg);
50 46
51 if (stat(p, &st) == 0) { 47 if (stat(p, &st) == 0) {
52 short ret = (st_dev != st.st_dev) || 48 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 @@
4 */ 4 */
5 5
6#include "busybox.h" 6#include "busybox.h"
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <sys/mtio.h> 7#include <sys/mtio.h>
11#include <fcntl.h>
12 8
13struct mt_opcodes { 9struct mt_opcodes {
14 char *name; 10 char *name;
@@ -105,7 +101,7 @@ int mt_main(int argc, char **argv)
105 break; 101 break;
106 } 102 }
107 103
108 fd = bb_xopen3(file, mode, 0); 104 fd = xopen3(file, mode, 0);
109 105
110 switch (code->value) { 106 switch (code->value) {
111 case MTTELL: 107 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 @@
21 */ 21 */
22 22
23#include "busybox.h" 23#include "busybox.h"
24#include <stdlib.h>
25#include <stdarg.h>
26#include <stdio.h>
27#include <unistd.h>
28#include <errno.h>
29#include <termios.h>
30#include <signal.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <string.h>
35
36 24
37#define SOH 0x01 25#define SOH 0x01
38#define STX 0x02 26#define STX 0x02
@@ -274,8 +262,8 @@ int rx_main(int argc, char **argv)
274 bb_show_usage(); 262 bb_show_usage();
275 263
276 fn = argv[1]; 264 fn = argv[1];
277 ttyfd = bb_xopen3(CURRENT_TTY, O_RDWR, 0); 265 ttyfd = xopen3(CURRENT_TTY, O_RDWR, 0);
278 filefd = bb_xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666); 266 filefd = xopen3(fn, O_RDWR|O_CREAT|O_TRUNC, 0666);
279 267
280 if (tcgetattr(ttyfd, &tty) < 0) 268 if (tcgetattr(ttyfd, &tty) < 0)
281 bb_error_msg_and_die("%s: tcgetattr failed: %m\n", argv[0]); 269 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 @@
9 */ 9 */
10 10
11#include "busybox.h" 11#include "busybox.h"
12#include <stdio.h>
13#include <fcntl.h>
14#include <unistd.h>
15#include <stdlib.h>
16#include <signal.h>
17 12
18#define OPT_FOREGROUND 0x01 13#define OPT_FOREGROUND 0x01
19#define OPT_TIMER 0x02 14#define OPT_TIMER 0x02
@@ -47,13 +42,13 @@ int watchdog_main(int argc, char **argv)
47 if (!(opts & OPT_FOREGROUND)) 42 if (!(opts & OPT_FOREGROUND))
48 vfork_daemon_rexec(0, 1, argc, argv, "-F"); 43 vfork_daemon_rexec(0, 1, argc, argv, "-F");
49#else 44#else
50 bb_xdaemon(0, 1); 45 xdaemon(0, 1);
51#endif 46#endif
52 47
53 signal(SIGHUP, watchdog_shutdown); 48 signal(SIGHUP, watchdog_shutdown);
54 signal(SIGINT, watchdog_shutdown); 49 signal(SIGINT, watchdog_shutdown);
55 50
56 fd = bb_xopen(argv[argc - 1], O_WRONLY); 51 fd = xopen(argv[argc - 1], O_WRONLY);
57 52
58 while (1) { 53 while (1) {
59 /* 54 /*
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 @@
59 */ 59 */
60 60
61#include "busybox.h" 61#include "busybox.h"
62#include <stdlib.h>
63#include <stdio.h>
64#include <stddef.h>
65#include <errno.h>
66#include <unistd.h>
67#include <dirent.h>
68#include <ctype.h>
69#include <assert.h>
70#include <string.h>
71#include <getopt.h>
72#include <fcntl.h>
73#include <sys/utsname.h> 62#include <sys/utsname.h>
74 63
75#if !defined(CONFIG_FEATURE_2_4_MODULES) && \ 64#if !defined(CONFIG_FEATURE_2_4_MODULES) && \
@@ -804,12 +793,12 @@ static int check_module_name_match(const char *filename, struct stat *statbuf,
804 if (fullname[0] == '\0') 793 if (fullname[0] == '\0')
805 return (FALSE); 794 return (FALSE);
806 else { 795 else {
807 char *tmp, *tmp1 = bb_xstrdup(filename); 796 char *tmp, *tmp1 = xstrdup(filename);
808 tmp = bb_get_last_path_component(tmp1); 797 tmp = bb_get_last_path_component(tmp1);
809 if (strcmp(tmp, fullname) == 0) { 798 if (strcmp(tmp, fullname) == 0) {
810 free(tmp1); 799 free(tmp1);
811 /* Stop searching if we find a match */ 800 /* Stop searching if we find a match */
812 m_filename = bb_xstrdup(filename); 801 m_filename = xstrdup(filename);
813 return (FALSE); 802 return (FALSE);
814 } 803 }
815 free(tmp1); 804 free(tmp1);
@@ -893,7 +882,6 @@ arch_apply_relocation(struct obj_file *f,
893 * (which is .got) similar to branch, 882 * (which is .got) similar to branch,
894 * but is full 32 bits relative */ 883 * but is full 32 bits relative */
895 884
896 assert(got != 0);
897 *loc += got - dot; 885 *loc += got - dot;
898 break; 886 break;
899 887
@@ -902,7 +890,6 @@ arch_apply_relocation(struct obj_file *f,
902 goto bb_use_plt; 890 goto bb_use_plt;
903 891
904 case R_ARM_GOTOFF: /* address relative to the got */ 892 case R_ARM_GOTOFF: /* address relative to the got */
905 assert(got != 0);
906 *loc += v - got; 893 *loc += v - got;
907 break; 894 break;
908 895
@@ -972,7 +959,6 @@ arch_apply_relocation(struct obj_file *f,
972 break; 959 break;
973 960
974 case R_386_GOTPC: 961 case R_386_GOTPC:
975 assert(got != 0);
976 *loc += got - dot; 962 *loc += got - dot;
977 break; 963 break;
978 964
@@ -980,7 +966,6 @@ arch_apply_relocation(struct obj_file *f,
980 goto bb_use_got; 966 goto bb_use_got;
981 967
982 case R_386_GOTOFF: 968 case R_386_GOTOFF:
983 assert(got != 0);
984 *loc += v - got; 969 *loc += v - got;
985 break; 970 break;
986 971
@@ -1102,7 +1087,6 @@ arch_apply_relocation(struct obj_file *f,
1102 1087
1103# ifdef R_68K_GOTOFF 1088# ifdef R_68K_GOTOFF
1104 case R_68K_GOTOFF: 1089 case R_68K_GOTOFF:
1105 assert(got != 0);
1106 *loc += v - got; 1090 *loc += v - got;
1107 break; 1091 break;
1108# endif 1092# endif
@@ -1157,9 +1141,6 @@ arch_apply_relocation(struct obj_file *f,
1157 struct mips_hi16 *next; 1141 struct mips_hi16 *next;
1158 unsigned long insn; 1142 unsigned long insn;
1159 1143
1160 /* The value for the HI16 had best be the same. */
1161 assert(v == l->value);
1162
1163 /* Do the HI16 relocation. Note that we actually don't 1144 /* Do the HI16 relocation. Note that we actually don't
1164 need to know anything about the LO16 itself, except where 1145 need to know anything about the LO16 itself, except where
1165 to find the low 16 bits of the addend needed by the LO16. */ 1146 to find the low 16 bits of the addend needed by the LO16. */
@@ -1408,9 +1389,7 @@ arch_apply_relocation(struct obj_file *f,
1408 case R_390_PLT32: 1389 case R_390_PLT32:
1409 case R_390_PLT16DBL: 1390 case R_390_PLT16DBL:
1410 /* find the plt entry and initialize it. */ 1391 /* find the plt entry and initialize it. */
1411 assert(isym != NULL);
1412 pe = (struct arch_single_entry *) &isym->pltent; 1392 pe = (struct arch_single_entry *) &isym->pltent;
1413 assert(pe->allocated);
1414 if (pe->inited == 0) { 1393 if (pe->inited == 0) {
1415 ip = (unsigned long *)(ifile->plt->contents + pe->offset); 1394 ip = (unsigned long *)(ifile->plt->contents + pe->offset);
1416 ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */ 1395 ip[0] = 0x0d105810; /* basr 1,0; lg 1,10(1); br 1 */
@@ -1440,15 +1419,12 @@ arch_apply_relocation(struct obj_file *f,
1440 break; 1419 break;
1441 1420
1442 case R_390_GOTPC: 1421 case R_390_GOTPC:
1443 assert(got != 0);
1444 *(unsigned long *) loc += got - dot; 1422 *(unsigned long *) loc += got - dot;
1445 break; 1423 break;
1446 1424
1447 case R_390_GOT12: 1425 case R_390_GOT12:
1448 case R_390_GOT16: 1426 case R_390_GOT16:
1449 case R_390_GOT32: 1427 case R_390_GOT32:
1450 assert(isym != NULL);
1451 assert(got != 0);
1452 if (!isym->gotent.inited) 1428 if (!isym->gotent.inited)
1453 { 1429 {
1454 isym->gotent.inited = 1; 1430 isym->gotent.inited = 1;
@@ -1466,7 +1442,6 @@ arch_apply_relocation(struct obj_file *f,
1466# define R_390_GOTOFF32 R_390_GOTOFF 1442# define R_390_GOTOFF32 R_390_GOTOFF
1467# endif 1443# endif
1468 case R_390_GOTOFF32: 1444 case R_390_GOTOFF32:
1469 assert(got != 0);
1470 *loc += v - got; 1445 *loc += v - got;
1471 break; 1446 break;
1472 1447
@@ -1497,7 +1472,6 @@ arch_apply_relocation(struct obj_file *f,
1497 break; 1472 break;
1498 1473
1499 case R_SH_GOTPC: 1474 case R_SH_GOTPC:
1500 assert(got != 0);
1501 *loc = got - dot + rel->r_addend; 1475 *loc = got - dot + rel->r_addend;
1502 break; 1476 break;
1503 1477
@@ -1505,7 +1479,6 @@ arch_apply_relocation(struct obj_file *f,
1505 goto bb_use_got; 1479 goto bb_use_got;
1506 1480
1507 case R_SH_GOTOFF: 1481 case R_SH_GOTOFF:
1508 assert(got != 0);
1509 *loc = v - got; 1482 *loc = v - got;
1510 break; 1483 break;
1511 1484
@@ -1627,7 +1600,6 @@ arch_apply_relocation(struct obj_file *f,
1627 case R_X86_64_GOTPCREL: 1600 case R_X86_64_GOTPCREL:
1628 goto bb_use_got; 1601 goto bb_use_got;
1629# if 0 1602# if 0
1630 assert(isym != NULL);
1631 if (!isym->gotent.reloc_done) 1603 if (!isym->gotent.reloc_done)
1632 { 1604 {
1633 isym->gotent.reloc_done = 1; 1605 isym->gotent.reloc_done = 1;
@@ -1655,12 +1627,10 @@ arch_apply_relocation(struct obj_file *f,
1655bb_use_plt: 1627bb_use_plt:
1656 1628
1657 /* find the plt entry and initialize it if necessary */ 1629 /* find the plt entry and initialize it if necessary */
1658 assert(isym != NULL);
1659 1630
1660#if defined(CONFIG_USE_PLT_LIST) 1631#if defined(CONFIG_USE_PLT_LIST)
1661 for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;) 1632 for (pe = isym->pltent; pe != NULL && pe->addend != rel->r_addend;)
1662 pe = pe->next; 1633 pe = pe->next;
1663 assert(pe != NULL);
1664#else 1634#else
1665 pe = &isym->pltent; 1635 pe = &isym->pltent;
1666#endif 1636#endif
@@ -1734,7 +1704,6 @@ bb_use_plt:
1734#if defined(CONFIG_USE_GOT_ENTRIES) 1704#if defined(CONFIG_USE_GOT_ENTRIES)
1735bb_use_got: 1705bb_use_got:
1736 1706
1737 assert(isym != NULL);
1738 /* needs an entry in the .got: set it, once */ 1707 /* needs an entry in the .got: set it, once */
1739 if (!isym->gotent.inited) { 1708 if (!isym->gotent.inited) {
1740 isym->gotent.inited = 1; 1709 isym->gotent.inited = 1;
@@ -1814,7 +1783,6 @@ static struct obj_section *arch_xsect_init(struct obj_file *f, char *name,
1814 } else { 1783 } else {
1815 myrelsec = obj_create_alloced_section(f, name, 1784 myrelsec = obj_create_alloced_section(f, name,
1816 size, offset); 1785 size, offset);
1817 assert(myrelsec);
1818 } 1786 }
1819 1787
1820 return myrelsec; 1788 return myrelsec;
@@ -3778,14 +3746,14 @@ add_ksymoops_symbols(struct obj_file *f, const char *filename,
3778 }; 3746 };
3779 3747
3780 if (realpath(filename, real)) { 3748 if (realpath(filename, real)) {
3781 absolute_filename = bb_xstrdup(real); 3749 absolute_filename = xstrdup(real);
3782 } 3750 }
3783 else { 3751 else {
3784 int save_errno = errno; 3752 int save_errno = errno;
3785 bb_error_msg("cannot get realpath for %s", filename); 3753 bb_error_msg("cannot get realpath for %s", filename);
3786 errno = save_errno; 3754 errno = save_errno;
3787 perror(""); 3755 perror("");
3788 absolute_filename = bb_xstrdup(filename); 3756 absolute_filename = xstrdup(filename);
3789 } 3757 }
3790 3758
3791 lm_name = strlen(m_name); 3759 lm_name = strlen(m_name);
@@ -4022,7 +3990,7 @@ int insmod_main( int argc, char **argv)
4022 break; 3990 break;
4023 case 'o': /* name the output module */ 3991 case 'o': /* name the output module */
4024 free(m_name); 3992 free(m_name);
4025 m_name = bb_xstrdup(optarg); 3993 m_name = xstrdup(optarg);
4026 break; 3994 break;
4027 case 'L': /* Stub warning */ 3995 case 'L': /* Stub warning */
4028 /* This is needed for compatibility with modprobe. 3996 /* This is needed for compatibility with modprobe.
@@ -4045,7 +4013,7 @@ int insmod_main( int argc, char **argv)
4045 } 4013 }
4046 4014
4047 /* Grab the module name */ 4015 /* Grab the module name */
4048 tmp1 = bb_xstrdup(argv[optind]); 4016 tmp1 = xstrdup(argv[optind]);
4049 tmp = basename(tmp1); 4017 tmp = basename(tmp1);
4050 len = strlen(tmp); 4018 len = strlen(tmp);
4051 4019
@@ -4071,10 +4039,10 @@ int insmod_main( int argc, char **argv)
4071 4039
4072#if defined(CONFIG_FEATURE_2_6_MODULES) 4040#if defined(CONFIG_FEATURE_2_6_MODULES)
4073 if (k_version > 4) 4041 if (k_version > 4)
4074 m_fullName = bb_xasprintf("%s.ko", tmp); 4042 m_fullName = xasprintf("%s.ko", tmp);
4075 else 4043 else
4076#endif 4044#endif
4077 m_fullName = bb_xasprintf("%s.o", tmp); 4045 m_fullName = xasprintf("%s.o", tmp);
4078 4046
4079 if (!m_name) { 4047 if (!m_name) {
4080 m_name = tmp; 4048 m_name = tmp;
@@ -4132,7 +4100,7 @@ int insmod_main( int argc, char **argv)
4132 bb_error_msg_and_die("%s: no module by that name found", m_fullName); 4100 bb_error_msg_and_die("%s: no module by that name found", m_fullName);
4133 } 4101 }
4134 } else 4102 } else
4135 m_filename = bb_xstrdup(argv[optind]); 4103 m_filename = xstrdup(argv[optind]);
4136 4104
4137 if (flag_verbose) 4105 if (flag_verbose)
4138 printf("Using %s\n", m_filename); 4106 printf("Using %s\n", m_filename);
@@ -4334,7 +4302,7 @@ int insmod_ng_main( int argc, char **argv)
4334 struct stat st; 4302 struct stat st;
4335 unsigned long len; 4303 unsigned long len;
4336 void *map; 4304 void *map;
4337 char *filename, *options = bb_xstrdup(""); 4305 char *filename, *options = xstrdup("");
4338 4306
4339 filename = argv[1]; 4307 filename = argv[1];
4340 if (!filename) { 4308 if (!filename) {
@@ -4356,7 +4324,7 @@ int insmod_ng_main( int argc, char **argv)
4356 strcat(options, " "); 4324 strcat(options, " ");
4357 } 4325 }
4358 4326
4359 fd = bb_xopen3(filename, O_RDONLY, 0); 4327 fd = xopen3(filename, O_RDONLY, 0);
4360 4328
4361 fstat(fd, &st); 4329 fstat(fd, &st);
4362 len = st.st_size; 4330 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 @@
13 13
14#include "busybox.h" 14#include "busybox.h"
15#include <sys/utsname.h> 15#include <sys/utsname.h>
16#include <sys/types.h>
17#include <sys/wait.h>
18#include <getopt.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <syslog.h>
22#include <string.h>
23#include <ctype.h>
24#include <fcntl.h>
25#include <fnmatch.h> 16#include <fnmatch.h>
26 17
27struct mod_opt_t { /* one-way list of options to pass to a module */ 18struct 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 )
148 ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) ); 139 ol = opt_list = xmalloc( sizeof( struct mod_opt_t ) );
149 } 140 }
150 141
151 ol-> m_opt_val = bb_xstrdup( opt ); 142 ol-> m_opt_val = xstrdup( opt );
152 ol-> m_next = NULL; 143 ol-> m_next = NULL;
153 144
154 return opt_list; 145 return opt_list;
@@ -160,7 +151,7 @@ static struct mod_opt_t *append_option( struct mod_opt_t *opt_list, char *opt )
160 * dst: pointer to where to store the parsed argument 151 * dst: pointer to where to store the parsed argument
161 * return value: the pointer to the first char after the parsed argument, 152 * return value: the pointer to the first char after the parsed argument,
162 * NULL if there was no argument parsed (only trailing spaces). 153 * NULL if there was no argument parsed (only trailing spaces).
163 * Note that memory is allocated with bb_xstrdup when a new argument was 154 * Note that memory is allocated with xstrdup when a new argument was
164 * parsed. Don't forget to free it! 155 * parsed. Don't forget to free it!
165 */ 156 */
166#define ARG_EMPTY 0x00 157#define ARG_EMPTY 0x00
@@ -185,7 +176,7 @@ static char *parse_command_string( char *src, char **dst )
185 /* Reached the start of an argument 176 /* Reached the start of an argument
186 * By the way, we duplicate a little too much 177 * By the way, we duplicate a little too much
187 * here but what is too much is freed later. */ 178 * here but what is too much is freed later. */
188 *dst = tmp_str = bb_xstrdup( src ); 179 *dst = tmp_str = xstrdup( src );
189 /* Get to the end of that argument */ 180 /* Get to the end of that argument */
190 while( ( *tmp_str != '\0' ) 181 while( ( *tmp_str != '\0' )
191 && ( ( *tmp_str != ' ' ) 182 && ( ( *tmp_str != ' ' )
@@ -309,7 +300,7 @@ static void include_conf ( struct dep_t **first, struct dep_t **current, char *b
309 (*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t )); 300 (*current)-> m_next = (struct dep_t *) xcalloc ( 1, sizeof ( struct dep_t ));
310 (*current) = (*current)-> m_next; 301 (*current) = (*current)-> m_next;
311 } 302 }
312 (*current)-> m_name = bb_xstrdup ( alias ); 303 (*current)-> m_name = xstrdup ( alias );
313 (*current)-> m_isalias = 1; 304 (*current)-> m_isalias = 1;
314 305
315 if (( strcmp ( mod, "off" ) == 0 ) || ( strcmp ( mod, "null" ) == 0 )) { 306 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
319 else { 310 else {
320 (*current)-> m_depcnt = 1; 311 (*current)-> m_depcnt = 1;
321 (*current)-> m_deparr = xmalloc ( 1 * sizeof( char * )); 312 (*current)-> m_deparr = xmalloc ( 1 * sizeof( char * ));
322 (*current)-> m_deparr[0] = bb_xstrdup ( mod ); 313 (*current)-> m_deparr[0] = xstrdup ( mod );
323 } 314 }
324 (*current)-> m_next = 0; 315 (*current)-> m_next = 0;
325 } 316 }
@@ -388,7 +379,7 @@ static struct dep_t *build_dep ( void )
388 k_version = un.release[2] - '0'; 379 k_version = un.release[2] - '0';
389 } 380 }
390 381
391 filename = bb_xasprintf("/lib/modules/%s/modules.dep", un.release ); 382 filename = xasprintf("/lib/modules/%s/modules.dep", un.release );
392 fd = open ( filename, O_RDONLY ); 383 fd = open ( filename, O_RDONLY );
393 if (ENABLE_FEATURE_CLEAN_UP) 384 if (ENABLE_FEATURE_CLEAN_UP)
394 free(filename); 385 free(filename);
@@ -447,7 +438,7 @@ static struct dep_t *build_dep ( void )
447 if (( *(col-2) == '.' ) && ( *(col-1) == 'o' )) 438 if (( *(col-2) == '.' ) && ( *(col-1) == 'o' ))
448 dot = col - 2; 439 dot = col - 2;
449 440
450 mod = bb_xstrndup ( mods, dot - mods ); 441 mod = xstrndup ( mods, dot - mods );
451 442
452 /* enqueue new module */ 443 /* enqueue new module */
453 if ( !current ) { 444 if ( !current ) {
@@ -458,7 +449,7 @@ static struct dep_t *build_dep ( void )
458 current = current-> m_next; 449 current = current-> m_next;
459 } 450 }
460 current-> m_name = mod; 451 current-> m_name = mod;
461 current-> m_path = bb_xstrdup(modpath); 452 current-> m_path = xstrdup(modpath);
462 current-> m_options = NULL; 453 current-> m_options = NULL;
463 current-> m_isalias = 0; 454 current-> m_isalias = 0;
464 current-> m_depcnt = 0; 455 current-> m_depcnt = 0;
@@ -525,7 +516,7 @@ static struct dep_t *build_dep ( void )
525 /* Cope with blank lines */ 516 /* Cope with blank lines */
526 if ((next-deps-ext+1) <= 0) 517 if ((next-deps-ext+1) <= 0)
527 continue; 518 continue;
528 dep = bb_xstrndup ( deps, next - deps - ext + 1 ); 519 dep = xstrndup ( deps, next - deps - ext + 1 );
529 520
530 /* Add the new dependable module name */ 521 /* Add the new dependable module name */
531 current-> m_depcnt++; 522 current-> m_depcnt++;
@@ -562,7 +553,7 @@ static struct dep_t *build_dep ( void )
562 /* Only 2.6 has a modules.alias file */ 553 /* Only 2.6 has a modules.alias file */
563 if (ENABLE_FEATURE_2_6_MODULES) { 554 if (ENABLE_FEATURE_2_6_MODULES) {
564 /* Parse kernel-declared aliases */ 555 /* Parse kernel-declared aliases */
565 filename = bb_xasprintf("/lib/modules/%s/modules.alias", un.release); 556 filename = xasprintf("/lib/modules/%s/modules.alias", un.release);
566 if ((fd = open ( filename, O_RDONLY )) < 0) { 557 if ((fd = open ( filename, O_RDONLY )) < 0) {
567 /* Ok, that didn't work. Fall back to looking in /lib/modules */ 558 /* Ok, that didn't work. Fall back to looking in /lib/modules */
568 fd = open ( "/lib/modules/modules.alias", O_RDONLY ); 559 fd = open ( "/lib/modules/modules.alias", O_RDONLY );
@@ -687,7 +678,7 @@ static int mod_process ( struct mod_list_t *list, int do_insert )
687 printf("%s module %s\n", do_insert?"Loading":"Unloading", list-> m_name ); 678 printf("%s module %s\n", do_insert?"Loading":"Unloading", list-> m_name );
688 } 679 }
689 if (!show_only) { 680 if (!show_only) {
690 int rc2 = wait4pid(bb_spawn(argv)); 681 int rc2 = wait4pid(spawn(argv));
691 682
692 if (do_insert) { 683 if (do_insert) {
693 rc = rc2; /* only last module matters */ 684 rc = rc2; /* only last module matters */
@@ -724,8 +715,8 @@ static int check_pattern( const char* pat_src, const char* mod_src ) {
724 char* mod; 715 char* mod;
725 char* p; 716 char* p;
726 717
727 pat = bb_xstrdup (pat_src); 718 pat = xstrdup (pat_src);
728 mod = bb_xstrdup (mod_src); 719 mod = xstrdup (mod_src);
729 720
730 for (p = pat; (p = strchr(p, '-')); *p++ = '_' ); 721 for (p = pat; (p = strchr(p, '-')); *p++ = '_' );
731 for (p = mod; (p = strchr(p, '-')); *p++ = '_' ); 722 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 @@
65*/ 65*/
66 66
67 67
68#include <unistd.h>
69#include <stdlib.h>
70#include <stdio.h>
71#include <errno.h>
72#include <ctype.h>
73#include <string.h>
74
75#include <sys/socket.h>
76#include <sys/types.h>
77#include <sys/ioctl.h>
78#include <features.h>
79#include <netpacket/packet.h> 68#include <netpacket/packet.h>
80#include <net/ethernet.h> 69#include <net/ethernet.h>
81#include <netdb.h>
82#include <netinet/ether.h> 70#include <netinet/ether.h>
83
84#ifdef __linux__
85#include <linux/if.h> 71#include <linux/if.h>
86#endif
87 72
88#include "busybox.h" 73#include "busybox.h"
89 74
@@ -93,10 +78,10 @@
93 */ 78 */
94#ifdef PF_PACKET 79#ifdef PF_PACKET
95# define whereto_t sockaddr_ll 80# define whereto_t sockaddr_ll
96# define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0) 81# define make_socket() xsocket(PF_PACKET, SOCK_RAW, 0)
97#else 82#else
98# define whereto_t sockaddr 83# define whereto_t sockaddr
99# define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET) 84# define make_socket() xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
100#endif 85#endif
101 86
102#ifdef DEBUG 87#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 @@
10 */ 10 */
11 11
12#include "busybox.h" 12#include "busybox.h"
13
14#include <unistd.h>
15#include <string.h>
16#include <fcntl.h>
17#include <signal.h>
18#include <sys/syslog.h>
19
20#include <pwd.h>
21
22#include <sys/syslog.h> 13#include <sys/syslog.h>
23#include <time.h>
24#include <sys/socket.h>
25#include <errno.h>
26#include <sys/uio.h> 14#include <sys/uio.h>
27 15
28 16
@@ -97,7 +85,7 @@ static void inetbind(void)
97 else 85 else
98 port = se->s_port; 86 port = se->s_port;
99 87
100 s = bb_xsocket(AF_INET, SOCK_STREAM, 0); 88 s = xsocket(AF_INET, SOCK_STREAM, 0);
101 89
102 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); 90 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
103 91
@@ -106,8 +94,8 @@ static void inetbind(void)
106 addr.sin_family = AF_INET; 94 addr.sin_family = AF_INET;
107 addr.sin_port = htons(port); 95 addr.sin_port = htons(port);
108 96
109 bb_xbind(s, (struct sockaddr *)&addr, len); 97 xbind(s, (struct sockaddr *)&addr, len);
110 bb_xlisten(s, 5); 98 xlisten(s, 5);
111 99
112 movefd(s, 0); 100 movefd(s, 0);
113} 101}
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 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15 15
16#include <sys/ioctl.h>
17
18#include <ctype.h>
19#include <errno.h>
20#include <fcntl.h>
21#include <getopt.h>
22#include <signal.h>
23#include <string.h>
24#include <unistd.h>
25
26#include <sys/socket.h>
27
28#include "busybox.h" 16#include "busybox.h"
17#include <getopt.h>
29 18
30typedef struct ftp_host_info_s { 19typedef struct ftp_host_info_s {
31 char *user; 20 char *user;
@@ -175,9 +164,9 @@ static int ftp_receive(ftp_host_info_t *server, FILE *control_stream,
175 /* only make a local file if we know that one exists on the remote server */ 164 /* only make a local file if we know that one exists on the remote server */
176 if (fd_local == -1) { 165 if (fd_local == -1) {
177 if (do_continue) { 166 if (do_continue) {
178 fd_local = bb_xopen(local_path, O_APPEND | O_WRONLY); 167 fd_local = xopen(local_path, O_APPEND | O_WRONLY);
179 } else { 168 } else {
180 fd_local = bb_xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY); 169 fd_local = xopen(local_path, O_CREAT | O_TRUNC | O_WRONLY);
181 } 170 }
182 } 171 }
183 172
@@ -223,7 +212,7 @@ static int ftp_send(ftp_host_info_t *server, FILE *control_stream,
223 if ((local_path[0] == '-') && (local_path[1] == '\0')) { 212 if ((local_path[0] == '-') && (local_path[1] == '\0')) {
224 fd_local = STDIN_FILENO; 213 fd_local = STDIN_FILENO;
225 } else { 214 } else {
226 fd_local = bb_xopen(local_path, O_RDONLY); 215 fd_local = xopen(local_path, O_RDONLY);
227 fstat(fd_local, &sbuf); 216 fstat(fd_local, &sbuf);
228 217
229 sprintf(buf, "ALLO %lu", (unsigned long)sbuf.st_size); 218 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 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15 15
16#include <errno.h>
17#include <arpa/inet.h>
18#include <netdb.h>
19#include <unistd.h>
20#include <string.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <getopt.h>
24#include "busybox.h" 16#include "busybox.h"
17#include <getopt.h>
25 18
26extern char *optarg; /* in unistd.h */ 19extern char *optarg; /* in unistd.h */
27extern int optind, opterr, optopt; /* in unistd.h */ 20extern int optind, opterr, optopt; /* in unistd.h */
@@ -41,7 +34,7 @@ static void do_sethostname(char *s, int isfile)
41 bb_perror_msg_and_die("sethostname"); 34 bb_perror_msg_and_die("sethostname");
42 } 35 }
43 } else { 36 } else {
44 f = bb_xfopen(s, "r"); 37 f = xfopen(s, "r");
45 while (fgets(buf, 255, f) != NULL) { 38 while (fgets(buf, 255, f) != NULL) {
46 if (buf[0] =='#') { 39 if (buf[0] =='#') {
47 continue; 40 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 @@
26 * IPV6 support added by Bart Visscher <magick@linux-fan.com> 26 * IPV6 support added by Bart Visscher <magick@linux-fan.com>
27 */ 27 */
28 28
29#include <stdio.h>
30#include <stdlib.h>
31#include <string.h> /* strcmp and friends */
32#include <ctype.h> /* isdigit and friends */
33#include <stddef.h> /* offsetof */
34#include <unistd.h>
35#include <netdb.h>
36#include <sys/ioctl.h>
37#include <net/if.h> 29#include <net/if.h>
38#include <net/if_arp.h> 30#include <net/if_arp.h>
39#include <netinet/in.h> 31#include <netinet/in.h>
@@ -329,7 +321,7 @@ int ifconfig_main(int argc, char **argv)
329 } 321 }
330 322
331 /* Create a channel to the NET kernel. */ 323 /* Create a channel to the NET kernel. */
332 sockfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); 324 sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
333 325
334 /* get interface name */ 326 /* get interface name */
335 safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ); 327 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 @@
17 17
18/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */ 18/* TODO: standardise execute() return codes to return 0 for success and 1 for failure */
19 19
20#include <sys/stat.h> 20#include "busybox.h"
21#include <sys/utsname.h> 21#include <sys/utsname.h>
22#include <sys/wait.h>
23
24#include <ctype.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <fnmatch.h> 22#include <fnmatch.h>
28#include <getopt.h> 23#include <getopt.h>
29#include <stdarg.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <unistd.h>
34
35#include "busybox.h"
36 24
37#define MAX_OPT_DEPTH 10 25#define MAX_OPT_DEPTH 10
38#define EUNBALBRACK 10001 26#define EUNBALBRACK 10001
@@ -628,7 +616,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
628 616
629 defn = xzalloc(sizeof(struct interfaces_file_t)); 617 defn = xzalloc(sizeof(struct interfaces_file_t));
630 618
631 f = bb_xfopen(filename, "r"); 619 f = xfopen(filename, "r");
632 620
633 while ((buf = bb_get_chomped_line_from_file(f)) != NULL) { 621 while ((buf = bb_get_chomped_line_from_file(f)) != NULL) {
634 char *buf_ptr = buf; 622 char *buf_ptr = buf;
@@ -649,7 +637,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
649 currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches); 637 currmap->match = xrealloc(currmap->match, sizeof(currmap->match) * currmap->max_matches);
650 } 638 }
651 639
652 currmap->match[currmap->n_matches++] = bb_xstrdup(firstword); 640 currmap->match[currmap->n_matches++] = xstrdup(firstword);
653 } 641 }
654 currmap->max_mappings = 0; 642 currmap->max_mappings = 0;
655 currmap->n_mappings = 0; 643 currmap->n_mappings = 0;
@@ -701,7 +689,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
701 return NULL; 689 return NULL;
702 } 690 }
703 691
704 currif->iface = bb_xstrdup(iface_name); 692 currif->iface = xstrdup(iface_name);
705 693
706 currif->address_family = get_address_family(addr_fams, address_family_name); 694 currif->address_family = get_address_family(addr_fams, address_family_name);
707 if (!currif->address_family) { 695 if (!currif->address_family) {
@@ -741,7 +729,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
741 } 729 }
742 730
743 /* Add the interface to the list */ 731 /* Add the interface to the list */
744 llist_add_to_end(&(defn->autointerfaces), bb_xstrdup(firstword)); 732 llist_add_to_end(&(defn->autointerfaces), xstrdup(firstword));
745 debug_noise("\nauto %s\n", firstword); 733 debug_noise("\nauto %s\n", firstword);
746 } 734 }
747 currently_processing = NONE; 735 currently_processing = NONE;
@@ -775,8 +763,8 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
775 opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options); 763 opt = xrealloc(currif->option, sizeof(*opt) * currif->max_options);
776 currif->option = opt; 764 currif->option = opt;
777 } 765 }
778 currif->option[currif->n_options].name = bb_xstrdup(firstword); 766 currif->option[currif->n_options].name = xstrdup(firstword);
779 currif->option[currif->n_options].value = bb_xstrdup(buf_ptr); 767 currif->option[currif->n_options].value = xstrdup(buf_ptr);
780 if (!currif->option[currif->n_options].name) { 768 if (!currif->option[currif->n_options].name) {
781 perror(filename); 769 perror(filename);
782 return NULL; 770 return NULL;
@@ -796,14 +784,14 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
796 bb_error_msg("duplicate script in mapping \"%s\"", buf); 784 bb_error_msg("duplicate script in mapping \"%s\"", buf);
797 return NULL; 785 return NULL;
798 } else { 786 } else {
799 currmap->script = bb_xstrdup(next_word(&buf_ptr)); 787 currmap->script = xstrdup(next_word(&buf_ptr));
800 } 788 }
801 } else if (strcmp(firstword, "map") == 0) { 789 } else if (strcmp(firstword, "map") == 0) {
802 if (currmap->max_mappings == currmap->n_mappings) { 790 if (currmap->max_mappings == currmap->n_mappings) {
803 currmap->max_mappings = currmap->max_mappings * 2 + 1; 791 currmap->max_mappings = currmap->max_mappings * 2 + 1;
804 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings); 792 currmap->mapping = xrealloc(currmap->mapping, sizeof(char *) * currmap->max_mappings);
805 } 793 }
806 currmap->mapping[currmap->n_mappings] = bb_xstrdup(next_word(&buf_ptr)); 794 currmap->mapping[currmap->n_mappings] = xstrdup(next_word(&buf_ptr));
807 currmap->n_mappings++; 795 currmap->n_mappings++;
808 } else { 796 } else {
809 bb_error_msg("misplaced option \"%s\"", buf); 797 bb_error_msg("misplaced option \"%s\"", buf);
@@ -833,7 +821,7 @@ static char *setlocalenv(char *format, const char *name, const char *value)
833 char *here; 821 char *here;
834 char *there; 822 char *there;
835 823
836 result = bb_xasprintf(format, name, value); 824 result = xasprintf(format, name, value);
837 825
838 for (here = there = result; *there != '=' && *there; there++) { 826 for (here = there = result; *there != '=' && *there; there++) {
839 if (*there == '-') 827 if (*there == '-')
@@ -922,7 +910,7 @@ static int execute_all(struct interface_defn_t *ifd, const char *opt)
922 } 910 }
923 } 911 }
924 912
925 buf = bb_xasprintf("run-parts /etc/network/if-%s.d", opt); 913 buf = xasprintf("run-parts /etc/network/if-%s.d", opt);
926 if (doit(buf) != 1) { 914 if (doit(buf) != 1) {
927 return 0; 915 return 0;
928 } 916 }
@@ -1013,7 +1001,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map)
1013 int i, status; 1001 int i, status;
1014 pid_t pid; 1002 pid_t pid;
1015 1003
1016 char *logical = bb_xstrdup(physical); 1004 char *logical = xstrdup(physical);
1017 1005
1018 /* Run the mapping script. */ 1006 /* Run the mapping script. */
1019 pid = popen2(&in, &out, map->script, physical, NULL); 1007 pid = popen2(&in, &out, map->script, physical, NULL);
@@ -1158,7 +1146,7 @@ int ifupdown_main(int argc, char **argv)
1158 /* iface_down */ 1146 /* iface_down */
1159 const llist_t *list = state_list; 1147 const llist_t *list = state_list;
1160 while (list) { 1148 while (list) {
1161 llist_add_to_end(&target_list, bb_xstrdup(list->data)); 1149 llist_add_to_end(&target_list, xstrdup(list->data));
1162 list = list->link; 1150 list = list->link;
1163 } 1151 }
1164 target_list = defn->autointerfaces; 1152 target_list = defn->autointerfaces;
@@ -1178,15 +1166,15 @@ int ifupdown_main(int argc, char **argv)
1178 int okay = 0; 1166 int okay = 0;
1179 int cmds_ret; 1167 int cmds_ret;
1180 1168
1181 iface = bb_xstrdup(target_list->data); 1169 iface = xstrdup(target_list->data);
1182 target_list = target_list->link; 1170 target_list = target_list->link;
1183 1171
1184 pch = strchr(iface, '='); 1172 pch = strchr(iface, '=');
1185 if (pch) { 1173 if (pch) {
1186 *pch = '\0'; 1174 *pch = '\0';
1187 liface = bb_xstrdup(pch + 1); 1175 liface = xstrdup(pch + 1);
1188 } else { 1176 } else {
1189 liface = bb_xstrdup(iface); 1177 liface = xstrdup(iface);
1190 } 1178 }
1191 1179
1192 if (!force) { 1180 if (!force) {
@@ -1263,7 +1251,7 @@ int ifupdown_main(int argc, char **argv)
1263 llist_t *iface_state = find_iface_state(state_list, iface); 1251 llist_t *iface_state = find_iface_state(state_list, iface);
1264 1252
1265 if (cmds == iface_up) { 1253 if (cmds == iface_up) {
1266 char *newiface = bb_xasprintf("%s=%s", iface, liface); 1254 char *newiface = xasprintf("%s=%s", iface, liface);
1267 if (iface_state == NULL) { 1255 if (iface_state == NULL) {
1268 llist_add_to_end(&state_list, newiface); 1256 llist_add_to_end(&state_list, newiface);
1269 } else { 1257 } else {
@@ -1281,7 +1269,7 @@ int ifupdown_main(int argc, char **argv)
1281 if (!no_act) { 1269 if (!no_act) {
1282 FILE *state_fp = NULL; 1270 FILE *state_fp = NULL;
1283 1271
1284 state_fp = bb_xfopen(statefile, "w"); 1272 state_fp = xfopen(statefile, "w");
1285 while (state_list) { 1273 while (state_list) {
1286 if (state_list->data) { 1274 if (state_list->data) {
1287 fputs(state_list->data, state_fp); 1275 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 @@
128 * 128 *
129 */ 129 */
130 130
131#include <sys/param.h>
132#include <sys/stat.h>
133#include <sys/ioctl.h>
134#include <sys/socket.h>
135#include <sys/un.h>
136#include <sys/file.h>
137#include <sys/wait.h>
138#include <sys/resource.h>
139
140
141#include <netinet/in.h>
142#include <arpa/inet.h>
143
144#include <errno.h>
145#include <signal.h>
146#include <netdb.h>
147#include <syslog.h>
148#include <stdio.h>
149#include <stdlib.h>
150#include <unistd.h>
151#include <string.h>
152#include <ctype.h>
153#include <time.h>
154
155#include "busybox.h" 131#include "busybox.h"
132#include <syslog.h>
156 133
157//#define CONFIG_FEATURE_INETD_RPC 134//#define CONFIG_FEATURE_INETD_RPC
158//#define CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO 135//#define CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO
@@ -1314,7 +1291,7 @@ inetd_main (int argc, char *argv[])
1314 /* reexec for vfork() do continue parent */ 1291 /* reexec for vfork() do continue parent */
1315 vfork_daemon_rexec (0, 0, argc, argv, "-f"); 1292 vfork_daemon_rexec (0, 0, argc, argv, "-f");
1316#else 1293#else
1317 bb_xdaemon (0, 0); 1294 xdaemon (0, 0);
1318#endif 1295#endif
1319 } else { 1296 } else {
1320 setsid (); 1297 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 @@
10 */ 10 */
11 11
12#include "busybox.h" 12#include "busybox.h"
13 13#include <syslog.h>
14#include <sys/syslog.h>
15#include <sys/socket.h>
16#include <sys/ioctl.h>
17#include <errno.h>
18#include <string.h>
19#include <unistd.h>
20#include <net/if.h> 14#include <net/if.h>
21#include <netinet/ether.h> 15#include <netinet/ether.h>
22 16
@@ -107,7 +101,7 @@ int nameif_main(int argc, char **argv)
107 if (strlen(*a) > IF_NAMESIZE) 101 if (strlen(*a) > IF_NAMESIZE)
108 serror("interface name `%s' too long", *a); 102 serror("interface name `%s' too long", *a);
109 ch = xzalloc(sizeof(mactable_t)); 103 ch = xzalloc(sizeof(mactable_t));
110 ch->ifname = bb_xstrdup(*a++); 104 ch->ifname = xstrdup(*a++);
111 ch->mac = cc_macaddr(*a++); 105 ch->mac = cc_macaddr(*a++);
112 if (clist) 106 if (clist)
113 clist->prev = ch; 107 clist->prev = ch;
@@ -115,7 +109,7 @@ int nameif_main(int argc, char **argv)
115 clist = ch; 109 clist = ch;
116 } 110 }
117 } else { 111 } else {
118 ifh = bb_xfopen(fname, "r"); 112 ifh = xfopen(fname, "r");
119 113
120 while ((line = bb_get_line_from_file(ifh)) != NULL) { 114 while ((line = bb_get_line_from_file(ifh)) != NULL) {
121 char *line_ptr; 115 char *line_ptr;
@@ -128,7 +122,7 @@ int nameif_main(int argc, char **argv)
128 } 122 }
129 name_length = strcspn(line_ptr, " \t"); 123 name_length = strcspn(line_ptr, " \t");
130 ch = xzalloc(sizeof(mactable_t)); 124 ch = xzalloc(sizeof(mactable_t));
131 ch->ifname = bb_xstrndup(line_ptr, name_length); 125 ch->ifname = xstrndup(line_ptr, name_length);
132 if (name_length > IF_NAMESIZE) 126 if (name_length > IF_NAMESIZE)
133 serror("interface name `%s' too long", ch->ifname); 127 serror("interface name `%s' too long", ch->ifname);
134 line_ptr += name_length; 128 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)
54 alarm(wsecs); 54 alarm(wsecs);
55 } 55 }
56 56
57 if (infile) cfd = bb_xopen(infile, O_RDWR); 57 if (infile) cfd = xopen(infile, O_RDWR);
58 else { 58 else {
59 opt = 1; 59 opt = 1;
60 sfd = bb_xsocket(AF_INET, SOCK_STREAM, 0); 60 sfd = xsocket(AF_INET, SOCK_STREAM, 0);
61 fcntl(sfd, F_SETFD, FD_CLOEXEC); 61 fcntl(sfd, F_SETFD, FD_CLOEXEC);
62 setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt)); 62 setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof (opt));
63 address.sin_family = AF_INET; 63 address.sin_family = AF_INET;
@@ -67,13 +67,13 @@ int nc_main(int argc, char **argv)
67 if (lport != 0) { 67 if (lport != 0) {
68 address.sin_port = lport; 68 address.sin_port = lport;
69 69
70 bb_xbind(sfd, (struct sockaddr *) &address, sizeof(address)); 70 xbind(sfd, (struct sockaddr *) &address, sizeof(address));
71 } 71 }
72 72
73 if (do_listen) { 73 if (do_listen) {
74 socklen_t addrlen = sizeof(address); 74 socklen_t addrlen = sizeof(address);
75 75
76 bb_xlisten(sfd, do_listen); 76 xlisten(sfd, do_listen);
77 77
78 // If we didn't specify a port number, query and print it to stderr. 78 // If we didn't specify a port number, query and print it to stderr.
79 79
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 @@
26 * remove ridiculous amounts of bloat. 26 * remove ridiculous amounts of bloat.
27 */ 27 */
28 28
29#include <stdio.h> 29#include "busybox.h"
30#include <stdlib.h> 30#include "inet_common.h"
31#include <string.h>
32#include <errno.h>
33#include <assert.h>
34#include <unistd.h>
35#include <fcntl.h>
36#include <getopt.h> 31#include <getopt.h>
37#include <sys/types.h>
38#include <sys/ioctl.h>
39#include <net/route.h> 32#include <net/route.h>
40#include <net/if.h> 33#include <net/if.h>
41#include "busybox.h" 34
42#include "inet_common.h"
43 35
44#ifndef RTF_UP 36#ifndef RTF_UP
45/* Keep this in sync with /usr/src/linux/include/linux/route.h */ 37/* Keep this in sync with /usr/src/linux/include/linux/route.h */
@@ -166,8 +158,6 @@ static void INET_setroute(int action, char **args)
166 const char *netmask = NULL; 158 const char *netmask = NULL;
167 int skfd, isnet, xflag; 159 int skfd, isnet, xflag;
168 160
169 assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
170
171 /* Grab the -net or -host options. Remember they were transformed. */ 161 /* Grab the -net or -host options. Remember they were transformed. */
172 xflag = kw_lookup(tbl_hash_net_host, &args); 162 xflag = kw_lookup(tbl_hash_net_host, &args);
173 163
@@ -335,7 +325,7 @@ static void INET_setroute(int action, char **args)
335 } 325 }
336 326
337 /* Create a socket to the INET kernel. */ 327 /* Create a socket to the INET kernel. */
338 skfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); 328 skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
339 329
340 if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { 330 if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
341 bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); 331 bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
@@ -353,9 +343,6 @@ static void INET6_setroute(int action, char **args)
353 int prefix_len, skfd; 343 int prefix_len, skfd;
354 const char *devname; 344 const char *devname;
355 345
356 assert((action == RTACTION_ADD) || (action == RTACTION_DEL));
357
358 {
359 /* We know args isn't NULL from the check in route_main. */ 346 /* We know args isn't NULL from the check in route_main. */
360 const char *target = *args++; 347 const char *target = *args++;
361 348
@@ -374,7 +361,6 @@ static void INET6_setroute(int action, char **args)
374 bb_error_msg_and_die("resolving %s", target); 361 bb_error_msg_and_die("resolving %s", target);
375 } 362 }
376 } 363 }
377 }
378 364
379 /* Clean out the RTREQ structure. */ 365 /* Clean out the RTREQ structure. */
380 memset((char *) &rt, 0, sizeof(struct in6_rtmsg)); 366 memset((char *) &rt, 0, sizeof(struct in6_rtmsg));
@@ -429,7 +415,7 @@ static void INET6_setroute(int action, char **args)
429 } 415 }
430 416
431 /* Create a socket to the INET6 kernel. */ 417 /* Create a socket to the INET6 kernel. */
432 skfd = bb_xsocket(AF_INET6, SOCK_DGRAM, 0); 418 skfd = xsocket(AF_INET6, SOCK_DGRAM, 0);
433 419
434 rt.rtmsg_ifindex = 0; 420 rt.rtmsg_ifindex = 0;
435 421
@@ -503,7 +489,7 @@ void displayroutes(int noresolve, int netstatfmt)
503 struct sockaddr_in s_addr; 489 struct sockaddr_in s_addr;
504 struct in_addr mask; 490 struct in_addr mask;
505 491
506 FILE *fp = bb_xfopen("/proc/net/route", "r"); 492 FILE *fp = xfopen("/proc/net/route", "r");
507 493
508 bb_printf("Kernel IP routing table\n" 494 bb_printf("Kernel IP routing table\n"
509 "Destination Gateway Genmask" 495 "Destination Gateway Genmask"
@@ -573,7 +559,7 @@ static void INET6_displayroutes(int noresolve)
573 int iflags, metric, refcnt, use, prefix_len, slen; 559 int iflags, metric, refcnt, use, prefix_len, slen;
574 struct sockaddr_in6 snaddr6; 560 struct sockaddr_in6 snaddr6;
575 561
576 FILE *fp = bb_xfopen("/proc/net/ipv6_route", "r"); 562 FILE *fp = xfopen("/proc/net/ipv6_route", "r");
577 563
578 bb_printf("Kernel IPv6 routing table\n%-44s%-40s" 564 bb_printf("Kernel IPv6 routing table\n%-44s%-40s"
579 "Flags Metric Ref Use Iface\n", 565 "Flags Metric Ref Use Iface\n",
@@ -699,7 +685,7 @@ int route_main(int argc, char **argv)
699#endif 685#endif
700 displayroutes(noresolve, opt & ROUTE_OPT_e); 686 displayroutes(noresolve, opt & ROUTE_OPT_e);
701 687
702 bb_xferror_stdout(); 688 xferror_stdout();
703 bb_fflush_stdout_and_exit(EXIT_SUCCESS); 689 bb_fflush_stdout_and_exit(EXIT_SUCCESS);
704 } 690 }
705 691
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 @@
19 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 19 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
20 * ------------------------------------------------------------------------- */ 20 * ------------------------------------------------------------------------- */
21 21
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <sys/types.h>
26#include <sys/socket.h>
27#include <sys/stat.h>
28#include <netdb.h>
29#include <netinet/in.h>
30#include <arpa/inet.h>
31#include <unistd.h>
32#include <fcntl.h>
33
34#include "busybox.h" 22#include "busybox.h"
35 23
36 24
@@ -159,7 +147,7 @@ static int tftp(const int cmd, const struct hostent *host,
159 char *buf=xmalloc(tftp_bufsize += 4); 147 char *buf=xmalloc(tftp_bufsize += 4);
160 148
161 if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { 149 if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
162 /* need to unlink the localfile, so don't use bb_xsocket here. */ 150 /* need to unlink the localfile, so don't use xsocket here. */
163 bb_perror_msg("socket"); 151 bb_perror_msg("socket");
164 return EXIT_FAILURE; 152 return EXIT_FAILURE;
165 } 153 }
@@ -167,7 +155,7 @@ static int tftp(const int cmd, const struct hostent *host,
167 len = sizeof(sa); 155 len = sizeof(sa);
168 156
169 memset(&sa, 0, len); 157 memset(&sa, 0, len);
170 bb_xbind(socketfd, (struct sockaddr *)&sa, len); 158 xbind(socketfd, (struct sockaddr *)&sa, len);
171 159
172 sa.sin_family = host->h_addrtype; 160 sa.sin_family = host->h_addrtype;
173 sa.sin_port = port; 161 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)
357 struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr; 357 struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
358 struct IFADDRLIST *st_ifaddrlist; 358 struct IFADDRLIST *st_ifaddrlist;
359 359
360 fd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); 360 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
361 361
362 ifc.ifc_len = sizeof(ibuf); 362 ifc.ifc_len = sizeof(ibuf);
363 ifc.ifc_buf = (caddr_t)ibuf; 363 ifc.ifc_buf = (caddr_t)ibuf;
@@ -457,7 +457,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
457 struct IFADDRLIST *al; 457 struct IFADDRLIST *al;
458 char buf[256], tdevice[256], device[256]; 458 char buf[256], tdevice[256], device[256];
459 459
460 f = bb_xfopen(route, "r"); 460 f = xfopen(route, "r");
461 461
462 /* Find the appropriate interface */ 462 /* Find the appropriate interface */
463 n = 0; 463 n = 0;
@@ -875,7 +875,7 @@ gethostinfo(const char *host)
875 hi = xcalloc(1, sizeof(*hi)); 875 hi = xcalloc(1, sizeof(*hi));
876 addr = inet_addr(host); 876 addr = inet_addr(host);
877 if ((int32_t)addr != -1) { 877 if ((int32_t)addr != -1) {
878 hi->name = bb_xstrdup(host); 878 hi->name = xstrdup(host);
879 hi->n = 1; 879 hi->n = 1;
880 hi->addrs = xcalloc(1, sizeof(hi->addrs[0])); 880 hi->addrs = xcalloc(1, sizeof(hi->addrs[0]));
881 hi->addrs[0] = addr; 881 hi->addrs[0] = addr;
@@ -885,7 +885,7 @@ gethostinfo(const char *host)
885 hp = xgethostbyname(host); 885 hp = xgethostbyname(host);
886 if (hp->h_addrtype != AF_INET || hp->h_length != 4) 886 if (hp->h_addrtype != AF_INET || hp->h_length != 4)
887 bb_perror_msg_and_die("bad host %s", host); 887 bb_perror_msg_and_die("bad host %s", host);
888 hi->name = bb_xstrdup(hp->h_name); 888 hi->name = xstrdup(hp->h_name);
889 for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p) 889 for (n = 0, p = hp->h_addr_list; *p != NULL; ++n, ++p)
890 continue; 890 continue;
891 hi->n = n; 891 hi->n = n;
@@ -1081,11 +1081,11 @@ traceroute_main(int argc, char *argv[])
1081 bb_perror_msg_and_die("unknown protocol %s", cp); 1081 bb_perror_msg_and_die("unknown protocol %s", cp);
1082 1082
1083 /* Insure the socket fds won't be 0, 1 or 2 */ 1083 /* Insure the socket fds won't be 0, 1 or 2 */
1084 do n = bb_xopen(bb_dev_null, O_RDONLY); while (n < 2); 1084 do n = xopen(bb_dev_null, O_RDONLY); while (n < 2);
1085 if (n > 2) 1085 if (n > 2)
1086 close(n); 1086 close(n);
1087 1087
1088 s = bb_xsocket(AF_INET, SOCK_RAW, pe->p_proto); 1088 s = xsocket(AF_INET, SOCK_RAW, pe->p_proto);
1089 1089
1090#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG 1090#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
1091 if (op & USAGE_OP_DEBUG) 1091 if (op & USAGE_OP_DEBUG)
@@ -1096,7 +1096,7 @@ traceroute_main(int argc, char *argv[])
1096 (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, 1096 (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
1097 sizeof(on)); 1097 sizeof(on));
1098 1098
1099 sndsock = bb_xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); 1099 sndsock = xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
1100 1100
1101#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE 1101#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
1102#if defined(IP_OPTIONS) 1102#if defined(IP_OPTIONS)
@@ -1248,7 +1248,7 @@ traceroute_main(int argc, char *argv[])
1248 1248
1249 outip->ip_src = from->sin_addr; 1249 outip->ip_src = from->sin_addr;
1250#ifndef IP_HDRINCL 1250#ifndef IP_HDRINCL
1251 bb_xbind(sndsock, (struct sockaddr *)from, sizeof(*from)); 1251 xbind(sndsock, (struct sockaddr *)from, sizeof(*from));
1252#endif 1252#endif
1253 1253
1254 fprintf(stderr, "traceroute to %s (%s)", hostname, inet_ntoa(to->sin_addr)); 1254 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 @@
20 20
21#define COMBINED_BINARY 21#define COMBINED_BINARY
22 22
23#define xfopen bb_xfopen
24
25void udhcp_background(const char *pidfile); 23void udhcp_background(const char *pidfile);
26void udhcp_start_log_and_pid(const char *client_server, const char *pidfile); 24void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
27void udhcp_logging(int level, const char *fmt, ...); 25void 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)
149 149
150 envp = xzalloc(sizeof(char *) * (num_options + 5)); 150 envp = xzalloc(sizeof(char *) * (num_options + 5));
151 j = 0; 151 j = 0;
152 envp[j++] = bb_xasprintf("interface=%s", client_config.interface); 152 envp[j++] = xasprintf("interface=%s", client_config.interface);
153 envp[j++] = bb_xasprintf("PATH=%s", 153 envp[j++] = xasprintf("PATH=%s",
154 getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin"); 154 getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin");
155 envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/"); 155 envp[j++] = xasprintf("HOME=%s", getenv("HOME") ? : "/");
156 156
157 if (packet == NULL) return envp; 157 if (packet == NULL) return envp;
158 158
@@ -170,7 +170,7 @@ static char **fill_envp(struct dhcpMessage *packet)
170 /* Fill in a subnet bits option for things like /24 */ 170 /* Fill in a subnet bits option for things like /24 */
171 if (dhcp_options[i].code == DHCP_SUBNET) { 171 if (dhcp_options[i].code == DHCP_SUBNET) {
172 memcpy(&subnet, temp, 4); 172 memcpy(&subnet, temp, 4);
173 envp[j++] = bb_xasprintf("mask=%d", mton(&subnet)); 173 envp[j++] = xasprintf("mask=%d", mton(&subnet));
174 } 174 }
175 } 175 }
176 if (packet->siaddr) { 176 if (packet->siaddr) {
@@ -180,12 +180,12 @@ static char **fill_envp(struct dhcpMessage *packet)
180 if (!(over & FILE_FIELD) && packet->file[0]) { 180 if (!(over & FILE_FIELD) && packet->file[0]) {
181 /* watch out for invalid packets */ 181 /* watch out for invalid packets */
182 packet->file[sizeof(packet->file) - 1] = '\0'; 182 packet->file[sizeof(packet->file) - 1] = '\0';
183 envp[j++] = bb_xasprintf("boot_file=%s", packet->file); 183 envp[j++] = xasprintf("boot_file=%s", packet->file);
184 } 184 }
185 if (!(over & SNAME_FIELD) && packet->sname[0]) { 185 if (!(over & SNAME_FIELD) && packet->sname[0]) {
186 /* watch out for invalid packets */ 186 /* watch out for invalid packets */
187 packet->sname[sizeof(packet->sname) - 1] = '\0'; 187 packet->sname[sizeof(packet->sname) - 1] = '\0';
188 envp[j++] = bb_xasprintf("sname=%s", packet->sname); 188 envp[j++] = xasprintf("sname=%s", packet->sname);
189 } 189 }
190 return envp; 190 return envp;
191} 191}
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 @@
9 9
10/* BB_AUDIT SUSv3 N/A */ 10/* BB_AUDIT SUSv3 N/A */
11 11
12#include <stdlib.h>
13#include <unistd.h>
14#include <fcntl.h>
15#include <sys/ioctl.h>
16#include <net/if.h>
17#include <string.h>
18#include <limits.h>
19#include "busybox.h" 12#include "busybox.h"
13#include <net/if.h>
20 14
21/* Stuff from linux/if_vlan.h, kernel version 2.4.23 */ 15/* Stuff from linux/if_vlan.h, kernel version 2.4.23 */
22enum vlan_ioctl_cmds { 16enum vlan_ioctl_cmds {
@@ -124,7 +118,7 @@ int vconfig_main(int argc, char **argv)
124 118
125 /* Don't bother closing the filedes. It will be closed on cleanup. */ 119 /* Don't bother closing the filedes. It will be closed on cleanup. */
126 /* Will die if 802.1q is not present */ 120 /* Will die if 802.1q is not present */
127 bb_xopen3(conf_file_name, O_RDONLY, 0); 121 xopen3(conf_file_name, O_RDONLY, 0);
128 122
129 memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); 123 memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
130 124
@@ -159,7 +153,7 @@ int vconfig_main(int argc, char **argv)
159 } 153 }
160 } 154 }
161 155
162 fd = bb_xsocket(AF_INET, SOCK_STREAM, 0); 156 fd = xsocket(AF_INET, SOCK_STREAM, 0);
163 if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) { 157 if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) {
164 bb_perror_msg_and_die("ioctl error for %s", *argv); 158 bb_perror_msg_and_die("ioctl error for %s", *argv);
165 } 159 }
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 @@
7 */ 7 */
8 8
9#include "busybox.h" 9#include "busybox.h"
10#include <errno.h>
11#include <signal.h>
12#include <sys/ioctl.h>
13#include <getopt.h> 10#include <getopt.h>
14 11
15 12
@@ -221,7 +218,7 @@ int wget_main(int argc, char **argv)
221 if (use_proxy) { 218 if (use_proxy) {
222 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy"); 219 proxy = getenv(target.is_ftp ? "ftp_proxy" : "http_proxy");
223 if (proxy && *proxy) { 220 if (proxy && *proxy) {
224 parse_url(bb_xstrdup(proxy), &server); 221 parse_url(xstrdup(proxy), &server);
225 } else { 222 } else {
226 use_proxy = 0; 223 use_proxy = 0;
227 } 224 }
@@ -263,7 +260,7 @@ int wget_main(int argc, char **argv)
263 output = stdout; 260 output = stdout;
264 quiet_flag = TRUE; 261 quiet_flag = TRUE;
265 } else { 262 } else {
266 output = bb_xfopen(fname_out, (do_continue ? "a" : "w")); 263 output = xfopen(fname_out, (do_continue ? "a" : "w"));
267 } 264 }
268 265
269 /* 266 /*
@@ -396,9 +393,9 @@ read_response:
396 } 393 }
397 if (strcasecmp(buf, "location") == 0) { 394 if (strcasecmp(buf, "location") == 0) {
398 if (s[0] == '/') 395 if (s[0] == '/')
399 target.path = bb_xstrdup(s+1); 396 target.path = xstrdup(s+1);
400 else { 397 else {
401 parse_url(bb_xstrdup(s), &target); 398 parse_url(xstrdup(s), &target);
402 if (use_proxy == 0) { 399 if (use_proxy == 0) {
403 server.host = target.host; 400 server.host = target.host;
404 server.port = target.port; 401 server.port = target.port;
@@ -419,7 +416,7 @@ read_response:
419 * FTP session 416 * FTP session
420 */ 417 */
421 if (! target.user) 418 if (! target.user)
422 target.user = bb_xstrdup("anonymous:busybox@"); 419 target.user = xstrdup("anonymous:busybox@");
423 420
424 sfp = open_socket(&s_in); 421 sfp = open_socket(&s_in);
425 if (ftpcmd(NULL, NULL, sfp, buf) != 220) 422 if (ftpcmd(NULL, NULL, sfp, buf) != 220)
@@ -556,7 +553,7 @@ void parse_url(char *url, struct host_info *h)
556 *sp++ = '\0'; 553 *sp++ = '\0';
557 h->path = sp; 554 h->path = sp;
558 } else 555 } else
559 h->path = bb_xstrdup(""); 556 h->path = xstrdup("");
560 557
561 up = strrchr(h->host, '@'); 558 up = strrchr(h->host, '@');
562 if (up != NULL) { 559 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 @@
15 */ 15 */
16 16
17#include "busybox.h" 17#include "busybox.h"
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <sys/stat.h>
22#include <sys/types.h>
23#include <dirent.h>
24#include <string.h>
25#include <errno.h>
26#include <fcntl.h>
27 18
28/* 19/*
29 * Function Prototypes 20 * Function Prototypes
@@ -202,8 +193,8 @@ int sysctl_write_setting(const char *setting, int output)
202 return -2; 193 return -2;
203 } 194 }
204 195
205 tmpname = bb_xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name); 196 tmpname = xasprintf("%s%.*s", PROC_PATH, (int)(equals - name), name);
206 outname = bb_xstrdup(tmpname + strlen(PROC_PATH)); 197 outname = xstrdup(tmpname + strlen(PROC_PATH));
207 198
208 while ((cptr = strchr(tmpname, '.')) != NULL) 199 while ((cptr = strchr(tmpname, '.')) != NULL)
209 *cptr = '/'; 200 *cptr = '/';
@@ -258,7 +249,7 @@ int sysctl_read_setting(const char *setting, int output)
258 bb_error_msg(ERR_INVALID_KEY, setting); 249 bb_error_msg(ERR_INVALID_KEY, setting);
259 250
260 tmpname = concat_path_file(PROC_PATH, name); 251 tmpname = concat_path_file(PROC_PATH, name);
261 outname = bb_xstrdup(tmpname + strlen(PROC_PATH)); 252 outname = xstrdup(tmpname + strlen(PROC_PATH));
262 253
263 while ((cptr = strchr(tmpname, '.')) != NULL) 254 while ((cptr = strchr(tmpname, '.')) != NULL)
264 *cptr = '/'; 255 *cptr = '/';
@@ -309,7 +300,7 @@ int sysctl_display_all(const char *path, int output, int show_table)
309 char *tmpdir; 300 char *tmpdir;
310 struct stat ts; 301 struct stat ts;
311 302
312 if (!(dp = bb_opendir(path))) { 303 if (!(dp = opendir(path))) {
313 retval = -1; 304 retval = -1;
314 } else { 305 } else {
315 while ((de = readdir(dp)) != NULL) { 306 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 @@
29 */ 29 */
30 30
31#include "busybox.h" 31#include "busybox.h"
32#include <sys/types.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <unistd.h>
36#include <string.h>
37#include <sys/ioctl.h>
38 32
39//#define CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */ 33//#define CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE /* + 2k */
40 34
41#ifdef CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE
42#include <time.h>
43#include <fcntl.h>
44#include <netinet/in.h> /* htons */
45#endif
46
47
48typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q); 35typedef int (*cmp_t)(procps_status_t *P, procps_status_t *Q);
49 36
50static procps_status_t *top; /* Hehe */ 37static procps_status_t *top; /* Hehe */
@@ -116,7 +103,7 @@ static struct jiffy_counts jif, prev_jif;
116 103
117static void get_jiffy_counts(void) 104static void get_jiffy_counts(void)
118{ 105{
119 FILE* fp = bb_xfopen("stat", "r"); 106 FILE* fp = xfopen("stat", "r");
120 prev_jif = jif; 107 prev_jif = jif;
121 if (fscanf(fp, "cpu %lld %lld %lld %lld %lld %lld %lld %lld", 108 if (fscanf(fp, "cpu %lld %lld %lld %lld %lld %lld %lld %lld",
122 &jif.usr,&jif.nic,&jif.sys,&jif.idle, 109 &jif.usr,&jif.nic,&jif.sys,&jif.idle,
@@ -196,7 +183,7 @@ static unsigned long display_generic(int scr_width)
196 unsigned int needs_conversion = 1; 183 unsigned int needs_conversion = 1;
197 184
198 /* read memory info */ 185 /* read memory info */
199 fp = bb_xfopen("meminfo", "r"); 186 fp = xfopen("meminfo", "r");
200 187
201 /* 188 /*
202 * Old kernels (such as 2.4.x) had a nice summary of memory info that 189 * 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)
238 fclose(fp); 225 fclose(fp);
239 226
240 /* read load average as a string */ 227 /* read load average as a string */
241 fp = bb_xfopen("loadavg", "r"); 228 fp = xfopen("loadavg", "r");
242 buf[0] = '\0'; 229 buf[0] = '\0';
243 fgets(buf, sizeof(buf), fp); 230 fgets(buf, sizeof(buf), fp);
244 end = strchr(buf, ' '); 231 end = strchr(buf, ' ');
@@ -414,7 +401,7 @@ int top_main(int argc, char **argv)
414 } 401 }
415 402
416 /* change to /proc */ 403 /* change to /proc */
417 bb_xchdir("/proc"); 404 xchdir("/proc");
418#ifdef CONFIG_FEATURE_USE_TERMIOS 405#ifdef CONFIG_FEATURE_USE_TERMIOS
419 tcgetattr(0, (void *) &initial_settings); 406 tcgetattr(0, (void *) &initial_settings);
420 memcpy(&new_settings, &initial_settings, sizeof(struct termios)); 407 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)
6011{ 6011{
6012#ifdef CONFIG_ASH_EXPAND_PRMT 6012#ifdef CONFIG_ASH_EXPAND_PRMT
6013 free(cmdedit_prompt); 6013 free(cmdedit_prompt);
6014 cmdedit_prompt = bb_xstrdup(s); 6014 cmdedit_prompt = xstrdup(s);
6015#else 6015#else
6016 cmdedit_prompt = s; 6016 cmdedit_prompt = s;
6017#endif 6017#endif
@@ -8105,7 +8105,7 @@ static int dotcmd(int argc, char **argv)
8105 int status = 0; 8105 int status = 0;
8106 8106
8107 for (sp = cmdenviron; sp; sp = sp->next) 8107 for (sp = cmdenviron; sp; sp = sp->next)
8108 setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED); 8108 setvareq(xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
8109 8109
8110 if (argc >= 2) { /* That's what SVR2 does */ 8110 if (argc >= 2) { /* That's what SVR2 does */
8111 char *fullname; 8111 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)
216 printf("\033[7m%c\033[0m", c); 216 printf("\033[7m%c\033[0m", c);
217 } else 217 } else
218#endif 218#endif
219 putchar(c); 219 if (initial_settings.c_lflag & ECHO) putchar(c);
220 if (++cmdedit_x >= cmdedit_termw) { 220 if (++cmdedit_x >= cmdedit_termw) {
221 /* terminal is scrolled down */ 221 /* terminal is scrolled down */
222 cmdedit_y++; 222 cmdedit_y++;
@@ -546,8 +546,8 @@ static void cmdedit_init(void)
546 my_euid = geteuid(); 546 my_euid = geteuid();
547 entry = getpwuid(my_euid); 547 entry = getpwuid(my_euid);
548 if (entry) { 548 if (entry) {
549 user_buf = bb_xstrdup(entry->pw_name); 549 user_buf = xstrdup(entry->pw_name);
550 home_pwd_buf = bb_xstrdup(entry->pw_dir); 550 home_pwd_buf = xstrdup(entry->pw_dir);
551 } 551 }
552#endif 552#endif
553 553
@@ -634,7 +634,7 @@ static void username_tab_completion(char *ud, char *with_shash_flg)
634 while ((entry = getpwent()) != NULL) { 634 while ((entry = getpwent()) != NULL) {
635 /* Null usernames should result in all users as possible completions. */ 635 /* Null usernames should result in all users as possible completions. */
636 if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) { 636 if ( /*!userlen || */ !strncmp(ud, entry->pw_name, userlen)) {
637 add_match(bb_xasprintf("~%s", entry->pw_name), '/'); 637 add_match(xasprintf("~%s", entry->pw_name), '/');
638 } 638 }
639 } 639 }
640 640
@@ -684,7 +684,7 @@ static int path_parse(char ***p, int flags)
684 *p = xmalloc(npth * sizeof(char *)); 684 *p = xmalloc(npth * sizeof(char *));
685 685
686 tmp = pth; 686 tmp = pth;
687 (*p)[0] = bb_xstrdup(tmp); 687 (*p)[0] = xstrdup(tmp);
688 npth = 1; /* count words is + 1 count ':' */ 688 npth = 1; /* count words is + 1 count ':' */
689 689
690 for (;;) { 690 for (;;) {
@@ -1114,7 +1114,7 @@ static void input_tab(int *lastWasTab)
1114 if (!matches) 1114 if (!matches)
1115 return; /* not found */ 1115 return; /* not found */
1116 /* find minimal match */ 1116 /* find minimal match */
1117 tmp1 = bb_xstrdup(matches[0]); 1117 tmp1 = xstrdup(matches[0]);
1118 for (tmp = tmp1; *tmp; tmp++) 1118 for (tmp = tmp1; *tmp; tmp++)
1119 for (len_found = 1; len_found < num_matches; len_found++) 1119 for (len_found = 1; len_found < num_matches; len_found++)
1120 if (matches[len_found][(tmp - tmp1)] != *tmp) { 1120 if (matches[len_found][(tmp - tmp1)] != *tmp) {
@@ -1175,7 +1175,7 @@ static void get_previous_history(void)
1175{ 1175{
1176 if(command_ps[0] != 0 || history[cur_history] == 0) { 1176 if(command_ps[0] != 0 || history[cur_history] == 0) {
1177 free(history[cur_history]); 1177 free(history[cur_history]);
1178 history[cur_history] = bb_xstrdup(command_ps); 1178 history[cur_history] = xstrdup(command_ps);
1179 } 1179 }
1180 cur_history--; 1180 cur_history--;
1181} 1181}
@@ -1856,7 +1856,7 @@ rewrite_line:
1856 for(i = 0; i < (MAX_HISTORY-1); i++) 1856 for(i = 0; i < (MAX_HISTORY-1); i++)
1857 history[i] = history[i+1]; 1857 history[i] = history[i+1];
1858 } 1858 }
1859 history[i++] = bb_xstrdup(command); 1859 history[i++] = xstrdup(command);
1860 cur_history = i; 1860 cur_history = i;
1861 n_history = i; 1861 n_history = i;
1862#if defined(CONFIG_FEATURE_SH_FANCY_PROMPT) 1862#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)
1320 * variable. */ 1320 * variable. */
1321 int export_me=0; 1321 int export_me=0;
1322 char *name, *value; 1322 char *name, *value;
1323 name = bb_xstrdup(child->argv[i]); 1323 name = xstrdup(child->argv[i]);
1324 debug_printf("Local environment set: %s\n", name); 1324 debug_printf("Local environment set: %s\n", name);
1325 value = strchr(name, '='); 1325 value = strchr(name, '=');
1326 if (value) 1326 if (value)
@@ -2753,7 +2753,7 @@ int hush_main(int argc, char **argv)
2753 debug_printf("\nrunning script '%s'\n", argv[optind]); 2753 debug_printf("\nrunning script '%s'\n", argv[optind]);
2754 global_argv = argv+optind; 2754 global_argv = argv+optind;
2755 global_argc = argc-optind; 2755 global_argc = argc-optind;
2756 input = bb_xfopen(argv[optind], "r"); 2756 input = xfopen(argv[optind], "r");
2757 opt = parse_file_outer(input); 2757 opt = parse_file_outer(input);
2758 2758
2759#ifdef CONFIG_FEATURE_CLEAN_UP 2759#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)
710 return NULL; 710 return NULL;
711 } 711 }
712 712
713 token = bb_xstrndup(string, *ix); 713 token = xstrndup(string, *ix);
714 714
715 return token; 715 return token;
716} 716}
@@ -751,7 +751,7 @@ static int expand_arguments(char *command)
751 751
752 /* We need a clean copy, so strsep can mess up the copy while 752 /* We need a clean copy, so strsep can mess up the copy while
753 * we write stuff into the original (in a minute) */ 753 * we write stuff into the original (in a minute) */
754 cmd = cmd_copy = bb_xstrdup(command); 754 cmd = cmd_copy = xstrdup(command);
755 *command = '\0'; 755 *command = '\0';
756 for (ix = 0, tmpcmd = cmd; 756 for (ix = 0, tmpcmd = cmd;
757 (tmpcmd = strsep_space(cmd, &ix)) != NULL; cmd += ix, ix=0) { 757 (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)
1123 prog->argv[argc_l] = NULL; 1123 prog->argv[argc_l] = NULL;
1124 1124
1125 if (!return_command) { 1125 if (!return_command) {
1126 job->text = bb_xstrdup(*command_ptr); 1126 job->text = xstrdup(*command_ptr);
1127 } else { 1127 } else {
1128 /* This leaves any trailing spaces, which is a bit sloppy */ 1128 /* This leaves any trailing spaces, which is a bit sloppy */
1129 job->text = bb_xstrndup(*command_ptr, return_command - *command_ptr); 1129 job->text = xstrndup(*command_ptr, return_command - *command_ptr);
1130 } 1130 }
1131 1131
1132 *command_ptr = return_command; 1132 *command_ptr = return_command;
@@ -1543,7 +1543,7 @@ int lash_main(int argc_l, char **argv_l)
1543 input = NULL; 1543 input = NULL;
1544 if (local_pending_command != 0) 1544 if (local_pending_command != 0)
1545 bb_error_msg_and_die("multiple -c arguments"); 1545 bb_error_msg_and_die("multiple -c arguments");
1546 local_pending_command = bb_xstrdup(argv[optind]); 1546 local_pending_command = xstrdup(argv[optind]);
1547 optind++; 1547 optind++;
1548 argv = argv+optind; 1548 argv = argv+optind;
1549 break; 1549 break;
@@ -1575,7 +1575,7 @@ int lash_main(int argc_l, char **argv_l)
1575 } 1575 }
1576 } else if (!local_pending_command && argv[optind]) { 1576 } else if (!local_pending_command && argv[optind]) {
1577 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); 1577 //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1578 input = bb_xfopen(argv[optind], "r"); 1578 input = xfopen(argv[optind], "r");
1579 /* be lazy, never mark this closed */ 1579 /* be lazy, never mark this closed */
1580 llist_add_to(&close_me_list, (void *)(long)fileno(input)); 1580 llist_add_to(&close_me_list, (void *)(long)fileno(input));
1581 } 1581 }
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 @@
18 */ 18 */
19 19
20#include "busybox.h" 20#include "busybox.h"
21#include <stdio.h>
22#include <stdlib.h>
23#include <signal.h> /* for our signal() handlers */
24#include <string.h> /* strncpy() */
25#include <errno.h> /* errno and friends */
26#include <unistd.h>
27#include <ctype.h>
28#include <sys/syslog.h> 21#include <sys/syslog.h>
29#include <sys/klog.h> 22#include <sys/klog.h>
30 23
@@ -66,7 +59,7 @@ int klogd_main(int argc, char **argv)
66#ifdef BB_NOMMU 59#ifdef BB_NOMMU
67 vfork_daemon_rexec(0, 1, argc, argv, "-n"); 60 vfork_daemon_rexec(0, 1, argc, argv, "-n");
68#else 61#else
69 bb_xdaemon(0, 1); 62 xdaemon(0, 1);
70#endif 63#endif
71 } 64 }
72 } 65 }
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 @@
14 */ 14 */
15 15
16#include "busybox.h" 16#include "busybox.h"
17#include <stdio.h>
18#include <stdlib.h>
19#include <ctype.h>
20#include <errno.h>
21#include <fcntl.h>
22#include <getopt.h>
23#include <netdb.h>
24#include <paths.h> 17#include <paths.h>
25#include <signal.h>
26#include <stdarg.h>
27#include <stdbool.h> 18#include <stdbool.h>
28#include <time.h>
29#include <string.h>
30#include <unistd.h>
31#include <sys/socket.h>
32#include <sys/types.h>
33#include <sys/un.h> 19#include <sys/un.h>
34#include <sys/param.h>
35 20
36/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ 21/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
37#define SYSLOG_NAMES 22#define SYSLOG_NAMES
@@ -368,7 +353,7 @@ static void message(char *fmt, ...)
368static void init_RemoteLog(void) 353static void init_RemoteLog(void)
369{ 354{
370 memset(&remoteaddr, 0, sizeof(remoteaddr)); 355 memset(&remoteaddr, 0, sizeof(remoteaddr));
371 remotefd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); 356 remotefd = xsocket(AF_INET, SOCK_DGRAM, 0);
372 remoteaddr.sin_family = AF_INET; 357 remoteaddr.sin_family = AF_INET;
373 remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; 358 remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list;
374 remoteaddr.sin_port = htons(RemotePort); 359 remoteaddr.sin_port = htons(RemotePort);
@@ -537,7 +522,7 @@ static void doSyslogd(void)
537 memset(&sunx, 0, sizeof(sunx)); 522 memset(&sunx, 0, sizeof(sunx));
538 sunx.sun_family = AF_UNIX; 523 sunx.sun_family = AF_UNIX;
539 strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); 524 strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
540 sock_fd = bb_xsocket(AF_UNIX, SOCK_DGRAM, 0); 525 sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
541 addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); 526 addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
542 if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { 527 if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
543 bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); 528 bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);
@@ -623,7 +608,7 @@ int syslogd_main(int argc, char **argv)
623#endif 608#endif
624#ifdef CONFIG_FEATURE_REMOTE_LOG 609#ifdef CONFIG_FEATURE_REMOTE_LOG
625 case 'R': 610 case 'R':
626 RemoteHost = bb_xstrdup(optarg); 611 RemoteHost = xstrdup(optarg);
627 if ((p = strchr(RemoteHost, ':'))) { 612 if ((p = strchr(RemoteHost, ':'))) {
628 RemotePort = atoi(p + 1); 613 RemotePort = atoi(p + 1);
629 *p = '\0'; 614 *p = '\0';
@@ -672,7 +657,7 @@ int syslogd_main(int argc, char **argv)
672#ifdef BB_NOMMU 657#ifdef BB_NOMMU
673 vfork_daemon_rexec(0, 1, argc, argv, "-n"); 658 vfork_daemon_rexec(0, 1, argc, argv, "-n");
674#else 659#else
675 bb_xdaemon(0, 1); 660 xdaemon(0, 1);
676#endif 661#endif
677 } 662 }
678 doSyslogd(); 663 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 @@
12 * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be) 12 * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
13 */ 13 */
14 14
15#include <stdio.h>
16#include <stdlib.h>
17#include <unistd.h>
18#include <fcntl.h>
19#include <errno.h>
20#include <ctype.h>
21#include <string.h>
22#include <stdint.h>
23#include <sys/ioctl.h>
24#include "busybox.h" 15#include "busybox.h"
25 16
26#define DEFAULTFBDEV FB_0 17#define DEFAULTFBDEV FB_0
@@ -186,7 +177,7 @@ static int readmode(struct fb_var_screeninfo *base, const char *fn,
186 char buf[256]; 177 char buf[256];
187 char *p = buf; 178 char *p = buf;
188 179
189 f = bb_xfopen(fn, "r"); 180 f = xfopen(fn, "r");
190 while (!feof(f)) { 181 while (!feof(f)) {
191 fgets(buf, sizeof(buf), f); 182 fgets(buf, sizeof(buf), f);
192 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) { 183 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
@@ -396,7 +387,7 @@ int fbset_main(int argc, char **argv)
396 } 387 }
397 } 388 }
398 389
399 fh = bb_xopen(fbdev, O_RDONLY); 390 fh = xopen(fbdev, O_RDONLY);
400 if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) 391 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
401 bb_perror_msg_and_die("fbset(ioctl)"); 392 bb_perror_msg_and_die("fbset(ioctl)");
402 if (g_options & OPT_READMODE) { 393 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 @@
9 * 5 July 2003 -- modified for Busybox by Erik Andersen 9 * 5 July 2003 -- modified for Busybox by Erik Andersen
10 */ 10 */
11 11
12#include <stdio.h>
13#include <string.h>
14#include <fcntl.h>
15#include <errno.h>
16#include <unistd.h>
17#include <stdlib.h>
18#include <sys/stat.h>
19#include <sys/ioctl.h>
20#include "busybox.h" 12#include "busybox.h"
21 13
22 14
@@ -60,10 +52,10 @@ static void print_and_flush(const char * __restrict format, ...)
60 va_start(arg, format); 52 va_start(arg, format);
61 bb_vfprintf(stdout, format, arg); 53 bb_vfprintf(stdout, format, arg);
62 va_end(arg); 54 va_end(arg);
63 bb_xfflush_stdout(); 55 xfflush_stdout();
64} 56}
65 57
66static void bb_xioctl(int fd, int request, void *argp, const char *string) 58static void xioctl(int fd, int request, void *argp, const char *string)
67{ 59{
68 if (ioctl (fd, request, argp) < 0) { 60 if (ioctl (fd, request, argp) < 0) {
69 bb_perror_msg_and_die(string); 61 bb_perror_msg_and_die(string);
@@ -95,9 +87,9 @@ int fdformat_main(int argc,char **argv)
95 87
96 88
97 /* O_RDWR for formatting and verifying */ 89 /* O_RDWR for formatting and verifying */
98 fd = bb_xopen(*argv,O_RDWR ); 90 fd = xopen(*argv,O_RDWR );
99 91
100 bb_xioctl(fd, FDGETPRM, &param, "FDGETPRM");/*original message was: "Could not determine current format type" */ 92 xioctl(fd, FDGETPRM, &param, "FDGETPRM");/*original message was: "Could not determine current format type" */
101 93
102 print_and_flush("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n", 94 print_and_flush("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n",
103 (param.head == 2) ? "Double" : "Single", 95 (param.head == 2) ? "Double" : "Single",
@@ -105,22 +97,22 @@ int fdformat_main(int argc,char **argv)
105 97
106 /* FORMAT */ 98 /* FORMAT */
107 print_and_flush("Formatting ... ", NULL); 99 print_and_flush("Formatting ... ", NULL);
108 bb_xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG"); 100 xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
109 101
110 /* n == track */ 102 /* n == track */
111 for (n = 0; n < param.track; n++) 103 for (n = 0; n < param.track; n++)
112 { 104 {
113 descr.head = 0; 105 descr.head = 0;
114 descr.track = n; 106 descr.track = n;
115 bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK"); 107 xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
116 print_and_flush("%3d\b\b\b", n); 108 print_and_flush("%3d\b\b\b", n);
117 if (param.head == 2) { 109 if (param.head == 2) {
118 descr.head = 1; 110 descr.head = 1;
119 bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK"); 111 xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
120 } 112 }
121 } 113 }
122 114
123 bb_xioctl(fd,FDFMTEND,NULL,"FDFMTEND"); 115 xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
124 print_and_flush("done\n", NULL); 116 print_and_flush("done\n", NULL);
125 117
126 /* VERIFY */ 118 /* 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 @@
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 */ 10 */
11 11
12#include <stdio.h>
13#include <string.h>
14#include <sys/types.h>
15#include <fcntl.h>
16#include <sys/ioctl.h>
17#include <stdlib.h>
18#include <unistd.h>
19#include "busybox.h" 12#include "busybox.h"
20 13
21/* From <linux/fd.h> */ 14/* From <linux/fd.h> */
@@ -28,7 +21,7 @@ int freeramdisk_main(int argc, char **argv)
28 21
29 if (argc != 2) bb_show_usage(); 22 if (argc != 2) bb_show_usage();
30 23
31 fd = bb_xopen(argv[1], O_RDWR); 24 fd = xopen(argv[1], O_RDWR);
32 25
33 // Act like freeramdisk, fdflush, or both depending on configuration. 26 // Act like freeramdisk, fdflush, or both depending on configuration.
34 result = ioctl(fd, (ENABLE_FREERAMDISK && bb_applet_name[1]=='r') 27 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 @@
31 * 31 *
32 */ 32 */
33 33
34#include <stdio.h>
35#include <stdlib.h>
36#include <string.h>
37#include <unistd.h>
38#include <ctype.h>
39#include <getopt.h>
40
41#include "busybox.h" 34#include "busybox.h"
35#include <getopt.h>
42 36
43/* NON_OPT is the code that is returned when a non-option is found in '+' 37/* NON_OPT is the code that is returned when a non-option is found in '+'
44 mode */ 38 mode */
@@ -86,7 +80,7 @@ const char *normalize(const char *arg)
86 free(BUFFER); 80 free(BUFFER);
87 81
88 if (!quote) { /* Just copy arg */ 82 if (!quote) { /* Just copy arg */
89 BUFFER=bb_xstrdup(arg); 83 BUFFER=xstrdup(arg);
90 return BUFFER; 84 return BUFFER;
91 } 85 }
92 86
@@ -215,7 +209,7 @@ void add_longopt(const char *name,int has_arg)
215 long_options[long_options_nr-1].has_arg=has_arg; 209 long_options[long_options_nr-1].has_arg=has_arg;
216 long_options[long_options_nr-1].flag=NULL; 210 long_options[long_options_nr-1].flag=NULL;
217 long_options[long_options_nr-1].val=LONG_OPT; 211 long_options[long_options_nr-1].val=LONG_OPT;
218 long_options[long_options_nr-1].name=bb_xstrdup(name); 212 long_options[long_options_nr-1].name=xstrdup(name);
219 } 213 }
220 long_options_nr++; 214 long_options_nr++;
221} 215}
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 @@
11 11
12#include "busybox.h" 12#include "busybox.h"
13#include <getopt.h> 13#include <getopt.h>
14#include <string.h>
15#include "dump.h" 14#include "dump.h"
16 15
17static void bb_dump_addfile(char *name) 16static void bb_dump_addfile(char *name)
@@ -20,7 +19,7 @@ static void bb_dump_addfile(char *name)
20 FILE *fp; 19 FILE *fp;
21 char *buf; 20 char *buf;
22 21
23 fp = bb_xfopen(name, "r"); 22 fp = xfopen(name, "r");
24 23
25 while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) { 24 while ((buf = bb_get_chomped_line_from_file(fp)) != NULL) {
26 p = skip_whitespace(buf); 25 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 @@
10 */ 10 */
11 11
12#include "busybox.h" 12#include "busybox.h"
13#include <ctype.h>
14#include <errno.h>
15#include <sys/mman.h>
16#include <sys/sysmacros.h>
17#include "xregex.h" 13#include "xregex.h"
18 14
19#define DEV_PATH "/dev" 15#define DEV_PATH "/dev"
@@ -146,7 +142,7 @@ static void make_device(char *path, int delete)
146 break; 142 break;
147 } 143 }
148 if ((s2-s+1) & (1<<delete)) 144 if ((s2-s+1) & (1<<delete))
149 command = bb_xstrndup(pos, end-pos); 145 command = xstrndup(pos, end-pos);
150 } 146 }
151 147
152 pos = end2; 148 pos = end2;
@@ -180,7 +176,7 @@ static void make_device(char *path, int delete)
180 int rc; 176 int rc;
181 char *s; 177 char *s;
182 178
183 s=bb_xasprintf("MDEV=%s",device_name); 179 s=xasprintf("MDEV=%s",device_name);
184 putenv(s); 180 putenv(s);
185 rc = system(command); 181 rc = system(command);
186 s[4]=0; 182 s[4]=0;
@@ -232,7 +228,7 @@ int mdev_main(int argc, char *argv[])
232 char *env_path; 228 char *env_path;
233 RESERVE_CONFIG_BUFFER(temp,PATH_MAX); 229 RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
234 230
235 bb_xchdir(DEV_PATH); 231 xchdir(DEV_PATH);
236 232
237 /* Scan */ 233 /* Scan */
238 234
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 @@
62 * removed getopt based parser and added a hand rolled one. 62 * removed getopt based parser and added a hand rolled one.
63 */ 63 */
64 64
65#include <stdio.h>
66#include <time.h>
67#include <unistd.h>
68#include <string.h>
69#include <signal.h>
70#include <fcntl.h>
71#include <ctype.h>
72#include <stdlib.h>
73#include <stdint.h>
74#include <termios.h>
75#include <sys/ioctl.h>
76#include <sys/param.h>
77#include <mntent.h>
78#include "busybox.h" 65#include "busybox.h"
66#include <mntent.h>
79 67
80#define MINIX_ROOT_INO 1 68#define MINIX_ROOT_INO 1
81#define MINIX_LINK_MAX 250 69#define MINIX_LINK_MAX 250
@@ -304,7 +292,7 @@ static inline int get_size(const char *file)
304 int fd; 292 int fd;
305 long size; 293 long size;
306 294
307 fd = bb_xopen3(file, O_RDWR, 0); 295 fd = xopen3(file, O_RDWR, 0);
308 if (ioctl(fd, BLKGETSIZE, &size) >= 0) { 296 if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
309 close(fd); 297 close(fd);
310 return (size * 512); 298 return (size * 512);
@@ -678,7 +666,7 @@ static void get_list_blocks(char *filename)
678 FILE *listfile; 666 FILE *listfile;
679 unsigned long blockno; 667 unsigned long blockno;
680 668
681 listfile = bb_xfopen(filename, "r"); 669 listfile = xfopen(filename, "r");
682 while (!feof(listfile)) { 670 while (!feof(listfile)) {
683 fscanf(listfile, "%ld\n", &blockno); 671 fscanf(listfile, "%ld\n", &blockno);
684 mark_zone(blockno); 672 mark_zone(blockno);
@@ -817,7 +805,7 @@ goodbye:
817 tmp += dirsize; 805 tmp += dirsize;
818 *(short *) tmp = 2; 806 *(short *) tmp = 2;
819 strcpy(tmp + 2, ".badblocks"); 807 strcpy(tmp + 2, ".badblocks");
820 DEV = bb_xopen3(device_name, O_RDWR, 0); 808 DEV = xopen3(device_name, O_RDWR, 0);
821 if (fstat(DEV, &statbuf) < 0) 809 if (fstat(DEV, &statbuf) < 0)
822 bb_error_msg_and_die("unable to stat %s", device_name); 810 bb_error_msg_and_die("unable to stat %s", device_name);
823 if (!S_ISBLK(statbuf.st_mode)) 811 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[])
20 20
21 // Figure out how big the device is and announce our intentions. 21 // Figure out how big the device is and announce our intentions.
22 22
23 fd = bb_xopen(argv[1],O_RDWR); 23 fd = xopen(argv[1],O_RDWR);
24 len = fdlength(fd); 24 len = fdlength(fd);
25 pagesize = getpagesize(); 25 pagesize = getpagesize();
26 printf("Setting up swapspace version 1, size = %ld bytes\n", (long)(len-pagesize)); 26 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 @@
11 * 11 *
12 * Termios corrects by Vladimir Oleynik <dzo@simtreas.ru> 12 * Termios corrects by Vladimir Oleynik <dzo@simtreas.ru>
13 * 13 *
14 * This program is free software; you can redistribute it and/or modify 14 * Licensed under GPLv2 or later, see file License in this tarball for details.
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */ 15 */
29 16
30#include <stdio.h>
31#include <fcntl.h>
32#include <signal.h>
33#include <stdlib.h>
34#include <unistd.h>
35#include <sys/ioctl.h>
36#include "busybox.h" 17#include "busybox.h"
37 18
38 19
@@ -76,7 +57,7 @@ int more_main(int argc, char **argv)
76 if(isatty(STDOUT_FILENO)) { 57 if(isatty(STDOUT_FILENO)) {
77 cin = fopen(CURRENT_TTY, "r"); 58 cin = fopen(CURRENT_TTY, "r");
78 if (!cin) 59 if (!cin)
79 cin = bb_xfopen(CONSOLE_DEV, "r"); 60 cin = xfopen(CONSOLE_DEV, "r");
80 please_display_more_prompt = 2; 61 please_display_more_prompt = 2;
81#ifdef CONFIG_FEATURE_USE_TERMIOS 62#ifdef CONFIG_FEATURE_USE_TERMIOS
82 cin_fileno = fileno(cin); 63 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 @@
23*/ 23*/
24 24
25#include "busybox.h" 25#include "busybox.h"
26#include <unistd.h>
27#include <errno.h>
28#include <string.h>
29#include <mntent.h> 26#include <mntent.h>
30#include <ctype.h>
31#include <fcntl.h> // for CONFIG_FEATURE_MOUNT_LOOP
32#include <sys/ioctl.h> // for CONFIG_FEATURE_MOUNT_LOOP
33 27
34// These two aren't always defined in old headers 28// These two aren't always defined in old headers
35#ifndef MS_BIND 29#ifndef MS_BIND
@@ -89,12 +83,12 @@ struct {
89static void append_mount_options(char **oldopts, char *newopts) 83static void append_mount_options(char **oldopts, char *newopts)
90{ 84{
91 if(*oldopts && **oldopts) { 85 if(*oldopts && **oldopts) {
92 char *temp=bb_xasprintf("%s,%s",*oldopts,newopts); 86 char *temp=xasprintf("%s,%s",*oldopts,newopts);
93 free(*oldopts); 87 free(*oldopts);
94 *oldopts=temp; 88 *oldopts=temp;
95 } else { 89 } else {
96 if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts); 90 if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts);
97 *oldopts = bb_xstrdup(newopts); 91 *oldopts = xstrdup(newopts);
98 } 92 }
99} 93}
100 94
@@ -165,7 +159,7 @@ static llist_t *get_block_backed_filesystems(void)
165 if(*fs=='#' || *fs=='*') continue; 159 if(*fs=='#' || *fs=='*') continue;
166 if(!*fs) continue; 160 if(!*fs) continue;
167 161
168 llist_add_to_end(&list,bb_xstrdup(fs)); 162 llist_add_to_end(&list,xstrdup(fs));
169 } 163 }
170 if (ENABLE_FEATURE_CLEAN_UP) fclose(f); 164 if (ENABLE_FEATURE_CLEAN_UP) fclose(f);
171 } 165 }
@@ -367,7 +361,7 @@ report_error:
367 361
368int mount_main(int argc, char **argv) 362int mount_main(int argc, char **argv)
369{ 363{
370 char *cmdopts = bb_xstrdup(""), *fstabname, *fstype=0, *storage_path=0; 364 char *cmdopts = xstrdup(""), *fstabname, *fstype=0, *storage_path=0;
371 FILE *fstab; 365 FILE *fstab;
372 int i, opt, all = FALSE, rc = 0; 366 int i, opt, all = FALSE, rc = 0;
373 struct mntent mtpair[2], *mtcur = mtpair; 367 struct mntent mtpair[2], *mtcur = mtpair;
@@ -493,7 +487,7 @@ int mount_main(int argc, char **argv)
493 // Mount the last thing we found. 487 // Mount the last thing we found.
494 488
495 mtcur = mtnext; 489 mtcur = mtnext;
496 mtcur->mnt_opts=bb_xstrdup(mtcur->mnt_opts); 490 mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
497 append_mount_options(&(mtcur->mnt_opts),cmdopts); 491 append_mount_options(&(mtcur->mnt_opts),cmdopts);
498 rc = singlemount(mtcur, 0); 492 rc = singlemount(mtcur, 0);
499 free(mtcur->mnt_opts); 493 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 @@
26 */ 26 */
27 27
28#include "busybox.h" 28#include "busybox.h"
29#include <unistd.h>
30#include <string.h>
31#include <errno.h>
32#include <time.h>
33#include <sys/utsname.h> 29#include <sys/utsname.h>
34#undef TRUE 30#undef TRUE
35#undef FALSE 31#undef FALSE
@@ -391,7 +387,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
391 } 387 }
392 sprintf(new_opts, "%s%saddr=%s", 388 sprintf(new_opts, "%s%saddr=%s",
393 old_opts, *old_opts ? "," : "", s); 389 old_opts, *old_opts ? "," : "", s);
394 *mount_opts = bb_xstrdup(new_opts); 390 *mount_opts = xstrdup(new_opts);
395 391
396 /* Set default options. 392 /* Set default options.
397 * rsize/wsize (and bsize, for ver >= 3) are left 0 in order to 393 * 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,
459 else if (!strcmp(opt, "mountport")) 455 else if (!strcmp(opt, "mountport"))
460 mountport = val; 456 mountport = val;
461 else if (!strcmp(opt, "mounthost")) 457 else if (!strcmp(opt, "mounthost"))
462 mounthost=bb_xstrndup(opteq+1, 458 mounthost=xstrndup(opteq+1,
463 strcspn(opteq+1," \t\n\r,")); 459 strcspn(opteq+1," \t\n\r,"));
464 else if (!strcmp(opt, "mountprog")) 460 else if (!strcmp(opt, "mountprog"))
465 mountprog = val; 461 mountprog = val;
@@ -729,7 +725,7 @@ int nfsmount(const char *spec, const char *node, int *flags,
729 if (!bg) 725 if (!bg)
730 goto fail; 726 goto fail;
731 if (!running_bg) { 727 if (!running_bg) {
732 prev_bg_host = bb_xstrdup(hostname); 728 prev_bg_host = xstrdup(hostname);
733 if (retry > 0) 729 if (retry > 0)
734 retval = EX_BG; 730 retval = EX_BG;
735 goto fail; 731 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 @@
4 * 4 *
5 * Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it) 5 * Copyright (C) 1994,1996 Alessandro Rubini (rubini@ipvvis.unipv.it)
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 8 */
21 9
22/* 10/*
@@ -44,17 +32,8 @@
44 * Paul Mundt <lethal@linux-sh.org>. 32 * Paul Mundt <lethal@linux-sh.org>.
45 */ 33 */
46 34
47#include <errno.h>
48#include <stdio.h>
49#include <fcntl.h>
50#include <stdlib.h>
51#include <unistd.h>
52#include <string.h>
53#include <sys/types.h>
54#include <sys/stat.h>
55#include <sys/utsname.h>
56
57#include "busybox.h" 35#include "busybox.h"
36#include <sys/utsname.h>
58 37
59#define S_LEN 128 38#define S_LEN 128
60 39
@@ -138,7 +117,7 @@ int readprofile_main(int argc, char **argv)
138 to_write = 1; /* sth different from sizeof(int) */ 117 to_write = 1; /* sth different from sizeof(int) */
139 } 118 }
140 119
141 fd = bb_xopen(defaultpro,O_WRONLY); 120 fd = xopen(defaultpro,O_WRONLY);
142 121
143 if (write(fd, &multiplier, to_write) != to_write) 122 if (write(fd, &multiplier, to_write) != to_write)
144 bb_perror_msg_and_die("error writing %s", defaultpro); 123 bb_perror_msg_and_die("error writing %s", defaultpro);
@@ -151,7 +130,7 @@ int readprofile_main(int argc, char **argv)
151 * Use an fd for the profiling buffer, to skip stdio overhead 130 * Use an fd for the profiling buffer, to skip stdio overhead
152 */ 131 */
153 132
154 proFd = bb_xopen(proFile,O_RDONLY); 133 proFd = xopen(proFile,O_RDONLY);
155 134
156 if (((int)(len=lseek(proFd,0,SEEK_END)) < 0) 135 if (((int)(len=lseek(proFd,0,SEEK_END)) < 0)
157 || (lseek(proFd,0,SEEK_SET) < 0)) 136 || (lseek(proFd,0,SEEK_SET) < 0))
@@ -198,7 +177,7 @@ int readprofile_main(int argc, char **argv)
198 177
199 total = 0; 178 total = 0;
200 179
201 map = bb_xfopen(mapFile, "r"); 180 map = xfopen(mapFile, "r");
202 181
203 while (fgets(mapline,S_LEN,map)) { 182 while (fgets(mapline,S_LEN,map)) {
204 if (sscanf(mapline,"%llx %s %s",&fn_add,mode,fn_name) != 3) 183 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)
66 } else while (getmntent_r(fp,&me,path,sizeof(path))) { 66 } else while (getmntent_r(fp,&me,path,sizeof(path))) {
67 m = xmalloc(sizeof(struct mtab_list)); 67 m = xmalloc(sizeof(struct mtab_list));
68 m->next = mtl; 68 m->next = mtl;
69 m->device = bb_xstrdup(me.mnt_fsname); 69 m->device = xstrdup(me.mnt_fsname);
70 m->dir = bb_xstrdup(me.mnt_dir); 70 m->dir = xstrdup(me.mnt_dir);
71 mtl = m; 71 mtl = m;
72 } 72 }
73 endmntent(fp); 73 endmntent(fp);