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
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