aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-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
26 files changed, 143 insertions, 425 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index cae7f99ed..4f688e77a 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -11,7 +11,7 @@ srcdir=$(top_srcdir)/libbb
LIBBB-n:=
LIBBB-y:= \
- bb_asprintf.c ask_confirmation.c change_identity.c chomp.c \
+ ask_confirmation.c change_identity.c chomp.c \
compare_string_array.c concat_path_file.c copy_file.c copyfd.c \
crc32.c create_icmp_socket.c create_icmp6_socket.c \
device_open.c dump.c error_msg.c error_msg_and_die.c \
@@ -22,15 +22,14 @@ LIBBB-y:= \
kernel_version.c last_char_is.c login.c \
make_directory.c md5.c mode_string.c mtab_file.c \
obscure.c parse_mode.c parse_number.c perror_msg.c \
- perror_msg_and_die.c print_file.c get_console.c \
+ perror_msg_and_die.c get_console.c \
process_escape_sequence.c procps.c qmodule.c \
- read_package_field.c recursive_action.c remove_file.c \
+ recursive_action.c remove_file.c \
restricted_shell.c run_parts.c run_shell.c safe_read.c safe_write.c \
safe_strncpy.c setup_environment.c sha1.c simplify_path.c \
trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
- bb_xsocket.c bb_xdaemon.c bb_xbind.c bb_xlisten.c bb_xchdir.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
@@ -97,18 +96,12 @@ LIBBB_MOBJ6:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ6))
$(LIBBB_MOBJ6):$(LIBBB_MSRC6)
$(compile.c) -DL_$(notdir $*)
-LIBBB_MSRC7:=$(srcdir)/opendir.c
-LIBBB_MOBJ7:=$(call get-file-subparts, ${LIBBB_MSRC7})
-LIBBB_MOBJ7:=$(patsubst %,$(LIBBB_DIR)/%, $(LIBBB_MOBJ7))
-$(LIBBB_MOBJ7):$(LIBBB_MSRC7)
- $(compile.c) -DL_$(notdir $*)
-
# We need the names of the object files built from MSRC for the L_ defines
LIBBB_ALL_MOBJ:=$(LIBBB_MOBJ0) $(LIBBB_MOBJ1) $(LIBBB_MOBJ2) $(LIBBB_MOBJ3) \
- $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6) $(LIBBB_MOBJ7)
+ $(LIBBB_MOBJ4) $(LIBBB_MOBJ5) $(LIBBB_MOBJ6)
LIBBB_ALL_MSRC:=$(LIBBB_MSRC0) $(LIBBB_MSRC1) $(LIBBB_MSRC2) $(LIBBB_MSRC3) \
- $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6) $(LIBBB_MSRC7)
+ $(LIBBB_MSRC4) $(LIBBB_MSRC5) $(LIBBB_MSRC6)
LIBBB-y:=$(sort $(LIBBB-y) $(LIBBB_ALL_MSRC))
diff --git a/libbb/bb_asprintf.c b/libbb/bb_asprintf.c
deleted file mode 100644
index 2bef0b59d..000000000
--- a/libbb/bb_asprintf.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Copyright (C) 2002,2005 Vladimir Oleynik <dzo@simtreas.ru>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include "libbb.h"
-
-char *bb_xasprintf(const char *format, ...)
-{
- va_list p;
- int r;
- char *string_ptr;
-
-#ifdef HAVE_GNU_EXTENSIONS
- va_start(p, format);
- r = vasprintf(&string_ptr, format, p);
- va_end(p);
-#else
- va_start(p, format);
- r = vsnprintf(NULL, 0, format, p);
- va_end(p);
- string_ptr = xmalloc(r+1);
- va_start(p, format);
- r = vsnprintf(string_ptr, r+1, format, p);
- va_end(p);
-#endif
-
- if (r < 0) {
- bb_perror_msg_and_die("bb_xasprintf");
- }
- return string_ptr;
-}
diff --git a/libbb/bb_xbind.c b/libbb/bb_xbind.c
deleted file mode 100644
index b53f8239a..000000000
--- a/libbb/bb_xbind.c
+++ /dev/null
@@ -1,18 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xbind.c - a bind() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
-{
- if (bind(sockfd, my_addr, addrlen))
- bb_perror_msg_and_die("bind");
-}
diff --git a/libbb/bb_xchdir.c b/libbb/bb_xchdir.c
deleted file mode 100644
index 2c2ff27cd..000000000
--- a/libbb/bb_xchdir.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xchdir.c - a chdir() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xchdir(const char *path)
-{
- if (chdir(path))
- bb_perror_msg_and_die("chdir(%s)", path);
-}
-
diff --git a/libbb/bb_xdaemon.c b/libbb/bb_xdaemon.c
deleted file mode 100644
index 218b5247f..000000000
--- a/libbb/bb_xdaemon.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xdaemon.c - a daemon() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <unistd.h>
-#include "libbb.h"
-
-#ifndef BB_NOMMU
-void bb_xdaemon(int nochdir, int noclose)
-{
- if (daemon(nochdir, noclose))
- bb_perror_msg_and_die("daemon");
-}
-#endif
diff --git a/libbb/bb_xlisten.c b/libbb/bb_xlisten.c
deleted file mode 100644
index e135d4836..000000000
--- a/libbb/bb_xlisten.c
+++ /dev/null
@@ -1,17 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xlisten.c - a listen() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-void bb_xlisten(int s, int backlog)
-{
- if (listen(s, backlog))
- bb_perror_msg_and_die("listen");
-}
diff --git a/libbb/bb_xsocket.c b/libbb/bb_xsocket.c
deleted file mode 100644
index c14dd7862..000000000
--- a/libbb/bb_xsocket.c
+++ /dev/null
@@ -1,19 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * bb_xsocket.c - a socket() which dies on failure with error message
- *
- * Copyright (C) 2006 Denis Vlasenko
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/socket.h>
-#include "libbb.h"
-
-int bb_xsocket(int domain, int type, int protocol)
-{
- int r = socket(domain, type, protocol);
- if (r < 0)
- bb_perror_msg_and_die("socket");
- return r;
-}
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c
index 415b6a2fb..ef0d3282d 100644
--- a/libbb/concat_path_file.c
+++ b/libbb/concat_path_file.c
@@ -12,7 +12,6 @@
* not addition '/' if path name already have '/'
*/
-#include <string.h>
#include "libbb.h"
char *concat_path_file(const char *path, const char *filename)
@@ -24,5 +23,5 @@ char *concat_path_file(const char *path, const char *filename)
lc = last_char_is(path, '/');
while (*filename == '/')
filename++;
- return bb_xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
+ return xasprintf("%s%s%s", path, (lc==NULL ? "/" : ""), filename);
}
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 38a2cb9c3..d2794e7d6 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -9,8 +9,6 @@
*/
#include "libbb.h"
-#include <utime.h>
-#include <errno.h>
int copy_file(const char *source, const char *dest, int flags)
{
@@ -77,7 +75,7 @@ int copy_file(const char *source, const char *dest, int flags)
}
/* Recursively copy files in SOURCE. */
- if ((dp = bb_opendir(source)) == NULL) {
+ if ((dp = opendir(source)) == NULL) {
status = -1;
goto preserve_status;
}
diff --git a/libbb/crc32.c b/libbb/crc32.c
index 03609952d..538a13622 100644
--- a/libbb/crc32.c
+++ b/libbb/crc32.c
@@ -14,11 +14,10 @@
* endian = 0: little-endian
*/
-#include <stdio.h>
-#include <stdlib.h>
#include "libbb.h"
-uint32_t *bb_crc32_filltable (int endian) {
+uint32_t *crc32_filltable(int endian)
+{
uint32_t *crc_table = xmalloc(256 * sizeof(uint32_t));
uint32_t polynomial = endian ? 0x04c11db7 : 0xedb88320;
diff --git a/libbb/dump.c b/libbb/dump.c
index f1d5df2d6..28f745fb6 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -12,9 +12,6 @@
*/
#include "libbb.h"
-#include <string.h>
-#include <unistd.h>
-#include <ctype.h> /* for isdigit() */
#include "dump.h"
enum _vflag bb_dump_vflag = FIRST;
@@ -232,7 +229,7 @@ static void rewrite(FS * fs)
*/
savech = *p2;
p1[1] = '\0';
- pr->fmt = bb_xstrdup(fmtp);
+ pr->fmt = xstrdup(fmtp);
*p2 = savech;
pr->cchar = pr->fmt + (p1 - fmtp);
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 675f8d2f5..71b79b8d0 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -7,11 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <limits.h>
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <stdlib.h>
#include "libbb.h"
char *find_block_device(char *path)
@@ -28,7 +23,7 @@ char *find_block_device(char *path)
char devpath[PATH_MAX];
sprintf(devpath,"/dev/%s", entry->d_name);
if(!stat(devpath, &st) && S_ISBLK(st.st_mode) && st.st_rdev == dev) {
- retpath = bb_xstrdup(devpath);
+ retpath = xstrdup(devpath);
break;
}
}
diff --git a/libbb/getopt_ulflags.c b/libbb/getopt_ulflags.c
index a57951305..19c96914d 100644
--- a/libbb/getopt_ulflags.c
+++ b/libbb/getopt_ulflags.c
@@ -7,11 +7,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <getopt.h>
-#include <string.h>
-#include <assert.h>
-#include <stdlib.h>
#include "libbb.h"
+#include <getopt.h>
/* Documentation
@@ -438,7 +435,7 @@ bb_getopt_ulflags (int argc, char **argv, const char *applet_opts, ...)
#if defined(CONFIG_AR) || defined(CONFIG_TAR)
if((spec_flgs & FIRST_ARGV_IS_OPT)) {
if(argv[1] && argv[1][0] != '-' && argv[1][0] != '\0') {
- argv[1] = bb_xasprintf("-%s", argv[1]);
+ argv[1] = xasprintf("-%s", argv[1]);
if(ENABLE_FEATURE_CLEAN_UP)
spec_flgs |= FREE_FIRST_ARGV_IS_OPT;
}
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index feb0c42f3..75a03fda4 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -11,16 +11,6 @@
#include "libbb.h"
#include "inet_common.h"
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef DEBUG
-# include <resolv.h>
-#endif
-
const char bb_INET_default[] = "default";
@@ -174,7 +164,7 @@ int INET_rresolve(char *name, size_t len, struct sockaddr_in *s_in,
pn->addr = *s_in;
pn->next = INET_nn;
pn->host = host;
- pn->name = bb_xstrdup(name);
+ pn->name = xstrdup(name);
INET_nn = pn;
return (0);
diff --git a/libbb/loop.c b/libbb/loop.c
index 0b05cd75f..da41d1e76 100644
--- a/libbb/loop.c
+++ b/libbb/loop.c
@@ -8,13 +8,6 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <features.h>
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
#include "libbb.h"
/* For 2.6, use the cleaned up header to get the 64 bit API. */
@@ -59,7 +52,7 @@ char *query_loop(const char *device)
if ((fd = open(device, O_RDONLY)) < 0) return 0;
if (!ioctl(fd, BB_LOOP_GET_STATUS, &loopinfo))
- dev=bb_xasprintf("%ld %s", (long) loopinfo.lo_offset,
+ dev=xasprintf("%ld %s", (long) loopinfo.lo_offset,
(char *)loopinfo.lo_file_name);
close(fd);
diff --git a/libbb/obscure.c b/libbb/obscure.c
index 3353df949..9ac6bcd82 100644
--- a/libbb/obscure.c
+++ b/libbb/obscure.c
@@ -39,11 +39,6 @@
of crypt do not truncate passwords.
*/
-#include <ctype.h>
-#include <unistd.h>
-#include <string.h>
-#include <strings.h>
-
#include "libbb.h"
static int string_checker_helper(const char *p1, const char *p2) __attribute__ ((__pure__));
@@ -66,7 +61,7 @@ static int string_checker(const char *p1, const char *p2)
/* check string */
int ret = string_checker_helper(p1, p2);
/* Make our own copy */
- char *p = bb_xstrdup(p1);
+ char *p = xstrdup(p1);
/* reverse string */
size = strlen(p);
diff --git a/libbb/opendir.c b/libbb/opendir.c
deleted file mode 100644
index e284db0db..000000000
--- a/libbb/opendir.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * wrapper for opendir()
- *
- * Copyright (C) 2006 Bernhard Fischer <busybox@busybox.net>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <sys/types.h>
-#include <dirent.h>
-#include "libbb.h"
-
-#ifdef L_bb_opendir
-DIR *bb_opendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg("unable to open `%s'", path);
- return NULL;
- }
- return dp;
-}
-#endif
-
-#ifdef L_bb_xopendir
-DIR *bb_xopendir(const char *path)
-{
- DIR *dp;
-
- if ((dp = opendir(path)) == NULL) {
- bb_perror_msg_and_die("unable to open `%s'", path);
- }
- return dp;
-}
-#endif
diff --git a/libbb/print_file.c b/libbb/print_file.c
deleted file mode 100644
index ea5d1d222..000000000
--- a/libbb/print_file.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include "libbb.h"
-
-void bb_xprint_and_close_file(FILE *file)
-{
- bb_xfflush_stdout();
- /* Note: Do not use STDOUT_FILENO here, as this is a lib routine
- * and the calling code may have reassigned stdout. */
- if (bb_copyfd_eof(fileno(file), STDOUT_FILENO) == -1) {
- /* bb_copyfd outputs any needed messages, so just die. */
- exit(bb_default_error_retval);
- }
- /* Note: Since we're reading, don't bother checking the return value
- * of fclose(). The only possible failure is EINTR which
- * should already have been taken care of. */
- fclose(file);
-}
-
-/* Returns:
- * 0 if successful
- * -1 if 'filename' does not exist or is a directory
- * exits with default error code if an error occurs
- */
-
-int bb_xprint_file_by_name(const char *filename)
-{
- FILE *f;
-
-#if 0
- /* This check shouldn't be necessary for linux, but is left
- * here disabled just in case. */
- struct stat statBuf;
-
- if(is_directory(filename, TRUE, &statBuf)) {
- bb_error_msg("%s: Is directory", filename);
- } else
-#endif
- if ((f = bb_wfopen(filename, "r")) != NULL) {
- bb_xprint_and_close_file(f);
- return 0;
- }
-
- return -1;
-}
diff --git a/libbb/procps.c b/libbb/procps.c
index 0d4877cb6..8fd5c1f86 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -51,7 +51,7 @@ procps_status_t * procps_scan(int save_user_arg0)
struct stat sb;
if (!dir) {
- dir = bb_xopendir("/proc");
+ dir = xopendir("/proc");
}
for (;;) {
if ((entry = readdir(dir)) == NULL) {
diff --git a/libbb/read_package_field.c b/libbb/read_package_field.c
deleted file mode 100644
index 9e5590347..000000000
--- a/libbb/read_package_field.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) many different people.
- * If you wrote this, please acknowledge your work.
- *
- * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include "libbb.h"
-
-/*
- * Gets the next package field from package_buffer, seperated into the field name
- * and field value, it returns the int offset to the first character of the next field
- */
-int read_package_field(const char *package_buffer, char **field_name, char **field_value)
-{
- int offset_name_start = 0;
- int offset_name_end = 0;
- int offset_value_start = 0;
- int offset_value_end = 0;
- int offset = 0;
- int next_offset;
- int name_length;
- int value_length;
- int exit_flag = FALSE;
-
- if (package_buffer == NULL) {
- *field_name = NULL;
- *field_value = NULL;
- return(-1);
- }
- while (1) {
- next_offset = offset + 1;
- switch (package_buffer[offset]) {
- case('\0'):
- exit_flag = TRUE;
- break;
- case(':'):
- if (offset_name_end == 0) {
- offset_name_end = offset;
- offset_value_start = next_offset;
- }
- /* TODO: Name might still have trailing spaces if ':' isnt
- * immediately after name */
- break;
- case('\n'):
- /* TODO: The char next_offset may be out of bounds */
- if (package_buffer[next_offset] != ' ') {
- exit_flag = TRUE;
- break;
- }
- case('\t'):
- case(' '):
- /* increment the value start point if its a just filler */
- if (offset_name_start == offset) {
- offset_name_start++;
- }
- if (offset_value_start == offset) {
- offset_value_start++;
- }
- break;
- }
- if (exit_flag) {
- /* Check that the names are valid */
- offset_value_end = offset;
- name_length = offset_name_end - offset_name_start;
- value_length = offset_value_end - offset_value_start;
- if (name_length == 0) {
- break;
- }
- if ((name_length > 0) && (value_length > 0)) {
- break;
- }
-
- /* If not valid, start fresh with next field */
- exit_flag = FALSE;
- offset_name_start = offset + 1;
- offset_name_end = 0;
- offset_value_start = offset + 1;
- offset_value_end = offset + 1;
- offset++;
- }
- offset++;
- }
- if (name_length == 0) {
- *field_name = NULL;
- } else {
- *field_name = bb_xstrndup(&package_buffer[offset_name_start], name_length);
- }
- if (value_length > 0) {
- *field_value = bb_xstrndup(&package_buffer[offset_value_start], value_length);
- } else {
- *field_value = NULL;
- }
- return(next_offset);
-}
-
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c
index a30addc4f..d491b781b 100644
--- a/libbb/recursive_action.c
+++ b/libbb/recursive_action.c
@@ -7,11 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdio.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#include <stdlib.h> /* free() */
#include "libbb.h"
#undef DEBUG_RECURS_ACTION
@@ -82,7 +77,7 @@ int recursive_action(const char *fileName,
} else if (status == SKIP)
return TRUE;
}
- dir = bb_opendir(fileName);
+ dir = opendir(fileName);
if (!dir) {
return FALSE;
}
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 2fa6596ee..92534a1c5 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -59,7 +59,7 @@ int remove_file(const char *path, int flags)
return 0;
}
- if ((dp = bb_opendir(path)) == NULL) {
+ if ((dp = opendir(path)) == NULL) {
return -1;
}
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index d5dc37b54..86cb0b056 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -82,10 +82,10 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
- args [0] = bb_get_last_path_component ( bb_xstrdup ( shell ));
+ args [0] = bb_get_last_path_component ( xstrdup ( shell ));
if ( loginshell )
- args [0] = bb_xasprintf ("-%s", args [0]);
+ args [0] = xasprintf ("-%s", args [0]);
if ( command ) {
args [argno++] = "-c";
diff --git a/libbb/simplify_path.c b/libbb/simplify_path.c
index 171798e60..b714c66b6 100644
--- a/libbb/simplify_path.c
+++ b/libbb/simplify_path.c
@@ -7,7 +7,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <stdlib.h>
#include "libbb.h"
char *bb_simplify_path(const char *path)
@@ -15,7 +14,7 @@ char *bb_simplify_path(const char *path)
char *s, *start, *p;
if (path[0] == '/')
- start = bb_xstrdup(path);
+ start = xstrdup(path);
else {
s = xgetcwd(NULL);
start = concat_path_file(s, path);
diff --git a/libbb/xconnect.c b/libbb/xconnect.c
index 39052b87b..ce1081d59 100644
--- a/libbb/xconnect.c
+++ b/libbb/xconnect.c
@@ -6,16 +6,6 @@
*
*/
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-#include <netdb.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
#include "libbb.h"
/* Return network byte ordered port number for a service.
@@ -61,7 +51,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
int xconnect(struct sockaddr_in *s_addr)
{
- int s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
+ int s = xsocket(AF_INET, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
{
if (ENABLE_FEATURE_CLEAN_UP) close(s);
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 8562a4fcb..699d09c67 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -3,18 +3,12 @@
* Utility routines.
*
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
+ * Copyright (C) 2006 Rob Landley
+ * Copyright (C) 2006 Denis Vlasenko
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
#include "busybox.h"
#ifndef DMALLOC
@@ -59,7 +53,7 @@ void *xcalloc(size_t nmemb, size_t size)
#endif /* DMALLOC */
#ifdef L_xstrdup
-char * bb_xstrdup (const char *s)
+char * xstrdup (const char *s)
{
char *t;
@@ -76,12 +70,12 @@ char * bb_xstrdup (const char *s)
#endif
#ifdef L_xstrndup
-char * bb_xstrndup (const char *s, int n)
+char * xstrndup (const char *s, int n)
{
char *t;
if (ENABLE_DEBUG && s == NULL)
- bb_error_msg_and_die("bb_xstrndup bug");
+ bb_error_msg_and_die("xstrndup bug");
t = xmalloc(++n);
@@ -90,7 +84,7 @@ char * bb_xstrndup (const char *s, int n)
#endif
#ifdef L_xfopen
-FILE *bb_xfopen(const char *path, const char *mode)
+FILE *xfopen(const char *path, const char *mode)
{
FILE *fp;
if ((fp = fopen(path, mode)) == NULL)
@@ -100,14 +94,14 @@ FILE *bb_xfopen(const char *path, const char *mode)
#endif
#ifdef L_xopen
-int bb_xopen(const char *pathname, int flags)
+int xopen(const char *pathname, int flags)
{
- return bb_xopen3(pathname, flags, 0777);
+ return xopen3(pathname, flags, 0777);
}
#endif
#ifdef L_xopen3
-int bb_xopen3(const char *pathname, int flags, int mode)
+int xopen3(const char *pathname, int flags, int mode)
{
int ret;
@@ -175,7 +169,7 @@ unsigned char xread_char(int fd)
#endif
#ifdef L_xferror
-void bb_xferror(FILE *fp, const char *fn)
+void xferror(FILE *fp, const char *fn)
{
if (ferror(fp)) {
bb_error_msg_and_die("%s", fn);
@@ -184,14 +178,14 @@ void bb_xferror(FILE *fp, const char *fn)
#endif
#ifdef L_xferror_stdout
-void bb_xferror_stdout(void)
+void xferror_stdout(void)
{
- bb_xferror(stdout, bb_msg_standard_output);
+ xferror(stdout, bb_msg_standard_output);
}
#endif
#ifdef L_xfflush_stdout
-void bb_xfflush_stdout(void)
+void xfflush_stdout(void)
{
if (fflush(stdout)) {
bb_perror_msg_and_die(bb_msg_standard_output);
@@ -201,7 +195,7 @@ void bb_xfflush_stdout(void)
#ifdef L_spawn
// This does a fork/exec in one call, using vfork().
-pid_t bb_spawn(char **argv)
+pid_t spawn(char **argv)
{
static int failed;
pid_t pid;
@@ -226,9 +220,9 @@ pid_t bb_spawn(char **argv)
#endif
#ifdef L_xspawn
-pid_t bb_xspawn(char **argv)
+pid_t xspawn(char **argv)
{
- pid_t pid = bb_spawn(argv);
+ pid_t pid = spawn(argv);
if (pid < 0) bb_perror_msg_and_die("%s", *argv);
return pid;
}
@@ -347,3 +341,107 @@ off_t fdlength(int fd)
return pos + 1;
}
#endif
+
+#ifdef L_xasprintf
+char *xasprintf(const char *format, ...)
+{
+ va_list p;
+ int r;
+ char *string_ptr;
+
+#if 1
+ // GNU extension
+ va_start(p, format);
+ r = vasprintf(&string_ptr, format, p);
+ va_end(p);
+#else
+ // Bloat for systems that haven't got the GNU extension.
+ va_start(p, format);
+ r = vsnprintf(NULL, 0, format, p);
+ va_end(p);
+ string_ptr = xmalloc(r+1);
+ va_start(p, format);
+ r = vsnprintf(string_ptr, r+1, format, p);
+ va_end(p);
+#endif
+
+ if (r < 0) bb_perror_msg_and_die("xasprintf");
+ return string_ptr;
+}
+#endif
+
+#ifdef L_xprint_and_close_file
+void xprint_and_close_file(FILE *file)
+{
+ // copyfd outputs error messages for us.
+ if (bb_copyfd_eof(fileno(file), 1) == -1) exit(bb_default_error_retval);
+
+ fclose(file);
+}
+#endif
+
+#ifdef L_xchdir
+void xchdir(const char *path)
+{
+ if (chdir(path))
+ bb_perror_msg_and_die("chdir(%s)", path);
+}
+#endif
+
+#ifdef L_warn_opendir
+DIR *warn_opendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL) {
+ bb_perror_msg("unable to open `%s'", path);
+ return NULL;
+ }
+ return dp;
+}
+#endif
+
+#ifdef L_xopendir
+DIR *xopendir(const char *path)
+{
+ DIR *dp;
+
+ if ((dp = opendir(path)) == NULL)
+ bb_perror_msg_and_die("unable to open `%s'", path);
+ return dp;
+}
+#endif
+
+#ifdef L_xdaemon
+#ifndef BB_NOMMU
+void xdaemon(int nochdir, int noclose)
+{
+ if (daemon(nochdir, noclose)) bb_perror_msg_and_die("daemon");
+}
+#endif
+#endif
+
+#ifdef L_xbind
+void xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen)
+{
+ if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind");
+}
+#endif
+
+#ifdef L_xsocket
+int xsocket(int domain, int type, int protocol)
+{
+ int r = socket(domain, type, protocol);
+
+ if (r < 0) bb_perror_msg_and_die("socket");
+
+ return r;
+}
+#endif
+
+#ifdef L_xlisten
+void xlisten(int s, int backlog)
+{
+ if (listen(s, backlog)) bb_perror_msg_and_die("listen");
+}
+#endif