Compare commits

..
31 Commits
Author SHA1 Message Date
Denys Vlasenko 4316dff48a httpd: fix handling of range requests
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-09-18 14:07:21 +02:00
Denys Vlasenko ee72302ac5 unzip: do not use CDF.extra_len, read local file header. Closes 9536
While at it, shorten many field and variable names.

function                                             old     new   delta
unzip_main                                          2334    2376     +42

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 13:58:42 +01:00
Cristian Ionescu-Idbohrn 50504d3a3b unzip: remove now-pointless lseek which returns current position
archival/unzip.c: In function 'read_next_cdf':
archival/unzip.c:271:8: warning: variable 'org' set but
                                 not used [-Wunused-but-set-variable]
  off_t org;
        ^~~

Signed-off-by: Cristian Ionescu-Idbohrn <cristian.ionescu-idbohrn@axis.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 13:58:42 +01:00
Denys Vlasenko f8692dc6a0 typo fix in config help text
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 13:58:25 +01:00
Denys Vlasenko fa654812e7 unzip: properly use CDF to find compressed files. Closes 9536
function                                             old     new   delta
unzip_main                                          2437    2350     -87

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-19 13:58:25 +01:00
Denys Vlasenko dac762a702 wget: fix for brain-damaged HTTP servers. Closes 9471
write(3, "GET / HTTP/1.1\r\nUser-Agent: Wget\r\nConnection: close\r\n\r\n", 74) = 74
shutdown(3, SHUT_WR)    = 0
alarm(900)              = 900
read(3, "", 1024)       = 0
write(2, "wget: error getting response\n", 29) = 29
exit(1)

The peer simply does not return anything. It closes its connection.

Probably it detects wget closing its writing end: shutdown(3, SHUT_WR).

The point it, closing write side of the socket is _valid_ for HTTP.
wget sent the full request, it won't be sending anything more:
it will only receive the response, and that's it.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-16 17:33:54 +01:00
Denys Vlasenko 889425812b Bump version to 1.26.2
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 17:01:20 +01:00
Denys Vlasenko 8e38108d03 ash: fix open fds leaking in redirects. Closes 9561
commit e19923f665 deleted clearredir()
call in shellexec():

	ash: [REDIR] Remove redundant CLOEXEC calls
	Upstream commit:

	Now that we're marking file descriptors as CLOEXEC in savefd, we no longer
	need to close them on exec or in setinputfd.

but it missed one place where we don't set CLOEXEC. Fixing this.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Waldemar Brodkorb add927e3d1 modutils: remove special handling of uClibc
Commit 3a45b87ac3 (modutils: support finit_module syscall) introduced
macro finit_module. But it is not defined for uClibc.

The compilation for busybox fails for MIPS with:
With uClibc, we get following build errors:

  modutils/lib.a(modutils.o): In function `bb_init_module':
  modutils.c:(.text.bb_init_module+0x94): undefined reference to `finit_module'
  modutils.c:(.text.bb_init_module+0xa0): undefined reference to `finit_module'

We can just use syscall() without any need for the
uClibc wrappers.

Newer versions of uClibc-ng (>1.0.20) will remove the
module syscall wrappers.

Found via Buildroot autobuilders:
http://autobuild.buildroot.net/results/556/55655daef23788fb3967f801ec8b79e9bed7122b/build-end.log

function                                             old     new   delta
bb_delete_module                                      26      32      +6
bb_init_module                                        90      95      +5
delete_module                                         37       -     -37
init_module                                           53       -     -53
------------------------------------------------------------------------------
(add/remove: 0/4 grow/shrink: 2/0 up/down: 11/-90)            Total: -79 bytes

Reported-by: Rahul Bedarkar <rahul.bedarkar@imgtec.com>
Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Jörg Krause 7bcc3c46a7 Fix dependency for IFUPDOWN_UDHCPC_CMD_OPTIONS
Commit a8c696bf09 makes ifup and ifdown
individually selectable, but forgets to update the dependency to
IFUPDOWN_UDHCPC_CMD_OPTIONS, so it is not selectable anymore.

This patch fixes the dependency by checking for IFUP or IFDOWN, instead
of the obsolete IFUPDOWN.

Also, it drops dependency on UDHCPC: udhcpc on the target system
does not have to come from the _same_ binary.

Signed-off-by: Jörg Krause <joerg.krause@embedded.rocks>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Denys Vlasenko 9c806db4b7 hush: correct exitcode for unterminated ')' - exitcode2.tests testcase
function                                             old     new   delta
parse_stream                                        2595    2609     +14

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Ron Yorston 568cabf98a ash: fix error code regression
The commit 'ash,hush: set exit code 127 in "sh /does/not/exist" case'
only partly implemented the dash commit '[ERROR] Allow the originator
of EXERROR to set the exit status'.  This resulted in incorrect error
codes for a syntax error:

   $ )
   $ echo $?
   0

or a redirection error for a special builtin:

   $ rm -f xxx
   $ eval cat <xxx
   $ echo $?
   0

Signed-off-by: Ron Yorston <rmy@pobox.com>
Reported-by: Martijn Dekker <martijn@inlv.org>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Denys Vlasenko e94d2c5f24 tcpudp: define SO_ORIGINAL_DST directly, not via include
musl does not like including linux/netfilter_ipv4.h
(enum / #define collision in two headers, resulting in "3 = 3"
type situation in enum definition).

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-10 16:55:51 +01:00
Denys Vlasenko a12eb9c64d Bump version to 1.26.1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-02 01:43:37 +01:00
Denys Vlasenko 1a6aca3d60 depmod: don't build it if MODPROBE_SMALL=y
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:13:48 +01:00
Denys Vlasenko fe3f55c540 make_single_applets.sh: SH_IS_HUSH needs special handling too
Well, in fact it works (make oldconfig throws only a warning when it sees
both SH_IS_HUSH=y and SH_IS_NONE=y), but let's be nice.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 28251dfa64 Make it possible to select "sh" and "bash" aliases without selecting ash or hush
The same can be done for msh, but we are probably better off just deleting it
in a next versio or two.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 9982d88a61 Make RMMOD=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko e5dc0d0120 Make INSMOD=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 890b1feaa0 Remove FEATURE_IFUPDOWN_IP_BUILTIN and FEATURE_IFUPDOWN_IFCONFIG_BUILTIN
They merely enable ip or ifconfig/route. There is already a way to do this
on the same menuconfig page.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko d28cd9900a modprobe-small: make applets individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 909edacc5e Make DPKG=y and DPKG_DEB=y by default
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko ed6fb36124 Selinux complains about deprecated selinux/flask.h, stop including it
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 048c043ae6 Make FEATURE_USERNAME_COMPLETION=y by default
This matches bash behavior on Fedora

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko f2200af1a8 make_single_applets.sh: a tool to check single-applet builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko c2f3655842 fix breakage found by mass one-applet builds
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 05069b4682 ip: make ip aliases individually selectable
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 8d0dedf1f6 shell: move "config" blocks above their use in coditional includes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko e1065da652 Tweak some config defaults; fix MODPROBE_SMALL ordering in "make config"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 2169b25b15 ash: clarify uclibc glob() bug in comment
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
Denys Vlasenko 18a7bee736 ash: error out if ASH_INTERNAL_GLOB is not selected on uClibc
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
2017-01-01 13:01:04 +01:00
351 changed files with 4141 additions and 15154 deletions

No files matched your search

-3
View File
@@ -178,6 +178,3 @@ Mike Frysinger <vapier@gentoo.org>
Jie Zhang <jie.zhang@analog.com>
fixed two bugs in msh and hush (exitcode of killed processes)
Maxime Coste <mawww@kakoune.org>
paste implementation
+16 -31
View File
@@ -22,7 +22,7 @@ config DESKTOP
If you are preparing your build to be used on an embedded box
where you have tighter control over the entire set of userspace
tools, you can unselect this option for smaller code size.
tools, you can unselect this option for smaller code size.
config EXTRA_COMPAT
bool "Provide compatible behavior for rare corner cases (bigger code)"
@@ -33,19 +33,6 @@ config EXTRA_COMPAT
some GNU extensions in libc. You probably only need this option
if you plan to run busybox on desktop.
config FEDORA_COMPAT
bool "Building for Fedora distribution"
default n
help
This option makes some tools behave like they do on Fedora.
At the time of this writing (2017-08) this only affects uname:
normally, uname -p (processor) and uname -i (platform)
are shown as "unknown", but with this option uname -p
shows the same string as uname -m (machine type),
and so does uname -i unless machine type is i486/i586/i686 -
then uname -i shows "i386".
config INCLUDE_SUSv2
bool "Enable obsolete features removed before SUSv3"
default y
@@ -63,6 +50,17 @@ config USE_PORTABLE_CODE
compiler other than gcc.
If you do use gcc, this option may needlessly increase code size.
config PLATFORM_LINUX
bool "Enable Linux-specific applets and features"
default y
help
For the most part, busybox requires only POSIX compatibility
from the target system, but some applets and features use
Linux-specific interfaces.
Answering 'N' here will disable such applets and hide the
corresponding configuration options.
config SHOW_USAGE
bool "Show applet usage messages"
default y
@@ -126,14 +124,14 @@ config INSTALL_NO_USR
never to /usr/bin or /usr/sbin.
config PAM
bool "Support PAM (Pluggable Authentication Modules)"
bool "Support for PAM (Pluggable Authentication Modules)"
default n
help
Use PAM in some busybox applets (currently login and httpd) instead
of direct access to password database.
config LONG_OPTS
bool "Support --long-options"
bool "Support for --long-options"
default y
help
Enable this if you want busybox applets to use the gnu --long-option
@@ -200,7 +198,7 @@ config PID_FILE_PATH
specify a pidfile path.
config FEATURE_SUID
bool "Support SUID/SGID handling"
bool "Support for SUID/SGID handling"
default y
help
With this option you can install the busybox binary belonging
@@ -340,17 +338,6 @@ config FEATURE_HAVE_RPC
# This is automatically selected if any of enabled applets need it.
# You do not need to select it manually.
config PLATFORM_LINUX
bool #No description makes it a hidden option
default n
#help
# For the most part, busybox requires only POSIX compatibility
# from the target system, but some applets and features use
# Linux-specific interfaces.
#
# This is automatically selected if any applet or feature requires
# Linux-specific interfaces. You do not need to select it manually.
comment 'Build Options'
config STATIC
@@ -624,8 +611,6 @@ config DEBUG_SANITIZE
catch bad memory accesses (e.g. buffer overflows), but will make
the executable larger and slow down runtime a bit.
This adds -fsanitize=foo options to gcc command line.
If you aren't developing/testing busybox, say N here.
config UNIT_TEST
@@ -640,7 +625,7 @@ config WERROR
bool "Abort compilation on any warning"
default n
help
This adds -Werror to gcc command line.
Selecting this will add -Werror to gcc command line.
Most people should answer N.
+1 -1
View File
@@ -1,5 +1,5 @@
VERSION = 1
PATCHLEVEL = 27
PATCHLEVEL = 26
SUBLEVEL = 2
EXTRAVERSION =
NAME = Unnamed
-3
View File
@@ -36,9 +36,6 @@ echo ''
#0000040 114 105 135 040 133 055 141 040 101 103 124 111 117 116 106 111
# 042514 020135 026533 020141 041501 044524 047117 044506
echo "#define UNPACKED_USAGE_LENGTH `$loc/usage | wc -c`"
echo
echo '#define PACKED_USAGE \'
## Breaks on big-endian systems!
## # Extra effort to avoid using "od -t x1": -t is not available
+10
View File
@@ -8,22 +8,32 @@ menu "Archival Utilities"
config FEATURE_SEAMLESS_XZ
bool "Make tar, rpm, modprobe etc understand .xz data"
default y
help
Make tar, rpm, modprobe etc understand .xz data.
config FEATURE_SEAMLESS_LZMA
bool "Make tar, rpm, modprobe etc understand .lzma data"
default y
help
Make tar, rpm, modprobe etc understand .lzma data.
config FEATURE_SEAMLESS_BZ2
bool "Make tar, rpm, modprobe etc understand .bz2 data"
default y
help
Make tar, rpm, modprobe etc understand .bz2 data.
config FEATURE_SEAMLESS_GZ
bool "Make tar, rpm, modprobe etc understand .gz data"
default y
help
Make tar, rpm, modprobe etc understand .gz data.
config FEATURE_SEAMLESS_Z
bool "Make tar, rpm, modprobe etc understand .Z data"
default n # it is ancient
help
Make tar, rpm, modprobe etc understand .Z data.
INSERT
+1 -1
View File
@@ -31,7 +31,7 @@
//config: probably say N here: most compilers come with their own ar utility.
//config:
//config:config FEATURE_AR_LONG_FILENAMES
//config: bool "Support long filenames (not needed for debs)"
//config: bool "Support for long filenames (not needed for debs)"
//config: default y
//config: depends on AR
//config: help
+48 -74
View File
@@ -7,11 +7,6 @@
#include "libbb.h"
#include "bb_archive.h"
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
/* lzop_main() uses bbunpack(), need this: */
//kbuild:lib-$(CONFIG_LZOP) += bbunzip.o
//kbuild:lib-$(CONFIG_LZOPCAT) += bbunzip.o
@@ -26,12 +21,11 @@ enum {
OPT_STDOUT = 1 << 0,
OPT_FORCE = 1 << 1,
/* only some decompressors: */
OPT_KEEP = 1 << 2,
OPT_VERBOSE = 1 << 3,
OPT_QUIET = 1 << 4,
OPT_DECOMPRESS = 1 << 5,
OPT_TEST = 1 << 6,
SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
OPT_VERBOSE = 1 << 2,
OPT_QUIET = 1 << 3,
OPT_DECOMPRESS = 1 << 4,
OPT_TEST = 1 << 5,
SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
};
static
@@ -133,7 +127,7 @@ int FAST_FUNC bbunpack(char **argv,
if (!(option_mask32 & SEAMLESS_MAGIC)) {
init_transformer_state(&xstate);
/*xstate.signature_skipped = 0; - already is */
xstate.signature_skipped = 0;
/*xstate.src_fd = STDIN_FILENO; - already is */
xstate.dst_fd = STDOUT_FILENO;
status = unpacker(&xstate);
@@ -188,11 +182,8 @@ int FAST_FUNC bbunpack(char **argv,
}
/* Delete _source_ file */
del = filename;
if (option_mask32 & OPT_KEEP) /* ... unless -k */
del = NULL;
}
if (del)
xunlink(del);
xunlink(del);
free_name:
if (new_name != filename)
free(new_name);
@@ -206,7 +197,7 @@ int FAST_FUNC bbunpack(char **argv,
}
#if ENABLE_UNCOMPRESS \
|| ENABLE_FEATURE_BZIP2_DECOMPRESS \
|| ENABLE_BUNZIP2 || ENABLE_BZCAT \
|| ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
|| ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
static
@@ -249,16 +240,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc UNUSED_PARAM, char **argv)
{
// (N)compress 4.2.4.4:
// -d If given, decompression is done instead
// -c Write output on stdout, don't remove original
// -b Parameter limits the max number of bits/code
// -f Forces output file to be generated
// -v Write compression statistics
// -V Output vesion and compile options
// -r Recursive. If a filename is a directory, descend into it and compress everything
getopt32(argv, "cf");
argv += optind;
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
@@ -291,12 +273,11 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
* Ken Turkowski, Dave Mack and Peter Jannesen.
*/
//usage:#define gunzip_trivial_usage
//usage: "[-cfkt] [FILE]..."
//usage: "[-cft] [FILE]..."
//usage:#define gunzip_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage: "\n -t Test file integrity"
//usage:
//usage:#define gunzip_example_usage
@@ -314,7 +295,6 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config:config GUNZIP
//config: bool "gunzip"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: gunzip is used to decompress archives created by gzip.
//config: You can use the `-t' option to test the integrity of
@@ -323,7 +303,6 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config:config ZCAT
//config: bool "zcat"
//config: default y
//config: select FEATURE_GZIP_DECOMPRESS
//config: help
//config: Alias to "gunzip -c".
//config:
@@ -331,11 +310,14 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
//config: bool "Enable long options"
//config: default y
//config: depends on (GUNZIP || ZCAT) && LONG_OPTS
//config: help
//config: Enable use of long options.
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_ZCAT(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
#if ENABLE_FEATURE_GZIP_DECOMPRESS
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
#if ENABLE_GUNZIP || ENABLE_ZCAT
static
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
{
@@ -391,7 +373,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
applet_long_options = gunzip_longopts;
#endif
getopt32(argv, "cfkvqdtn");
getopt32(argv, "cfvqdtn");
argv += optind;
/* If called as zcat...
@@ -403,7 +385,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
}
#endif /* FEATURE_GZIP_DECOMPRESS */
#endif
/*
@@ -413,12 +395,11 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//usage:#define bunzip2_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage: "[-cf] [FILE]..."
//usage:#define bunzip2_full_usage "\n\n"
//usage: "Decompress FILEs (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:#define bzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define bzcat_full_usage "\n\n"
@@ -427,7 +408,6 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config:config BUNZIP2
//config: bool "bunzip2"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: bunzip2 is a compression utility using the Burrows-Wheeler block
//config: sorting text compression algorithm, and Huffman coding. Compression
@@ -441,18 +421,18 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
//config:config BZCAT
//config: bool "bzcat"
//config: default y
//config: select FEATURE_BZIP2_DECOMPRESS
//config: help
//config: Alias to "bunzip2 -c".
//applet:IF_BUNZIP2(APPLET(bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_BZCAT(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
#if ENABLE_FEATURE_BZIP2_DECOMPRESS || ENABLE_BUNZIP2 || ENABLE_BZCAT
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
#if ENABLE_BUNZIP2 || ENABLE_BZCAT
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, "cfkvqdt");
getopt32(argv, "cfvqdt");
argv += optind;
if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
option_mask32 |= OPT_STDOUT;
@@ -471,26 +451,44 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//usage:#define unlzma_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage: "[-cf] [FILE]..."
//usage:#define unlzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define lzma_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage: "-d [-cf] [FILE]..."
//usage:#define lzma_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define lzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define lzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//usage:
//usage:#define unxz_trivial_usage
//usage: "[-cf] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage:
//usage:#define xz_trivial_usage
//usage: "-d [-cf] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define xzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//config:config UNLZMA
//config: bool "unlzma"
@@ -524,7 +522,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: IOW: you'll get lzma applet, but it will always require -d option.
//config:
//config:config FEATURE_LZMA_FAST
//config: bool "Optimize for speed"
//config: bool "Optimize unlzma for speed"
//config: default n
//config: depends on UNLZMA || LZCAT || LZMA
//config: help
@@ -532,9 +530,8 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
//config: a 1K bigger binary.
//applet:IF_UNLZMA(APPLET(unlzma, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_LZCAT(APPLET_ODDNAME(lzcat, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzcat))
//applet:IF_LZMA( APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
//kbuild:lib-$(CONFIG_LZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_LZMA) += bbunzip.o
@@ -542,7 +539,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
{
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
IF_LZMA(int opts =) getopt32(argv, "cfvqdt");
# if ENABLE_LZMA
/* lzma without -d or -t? */
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
@@ -558,28 +555,6 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
#endif
//usage:#define unxz_trivial_usage
//usage: "[-cfk] [FILE]..."
//usage:#define unxz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define xz_trivial_usage
//usage: "-d [-cfk] [FILE]..."
//usage:#define xz_full_usage "\n\n"
//usage: "Decompress FILE (or stdin)\n"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define xzcat_trivial_usage
//usage: "[FILE]..."
//usage:#define xzcat_full_usage "\n\n"
//usage: "Decompress to stdout"
//config:config UNXZ
//config: bool "unxz"
//config: default y
@@ -600,9 +575,8 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
//config: IOW: you'll get xz applet, but it will always require -d option.
//applet:IF_UNXZ(APPLET(unxz, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_XZCAT(APPLET_ODDNAME(xzcat, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xzcat))
//applet:IF_XZ( APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
//kbuild:lib-$(CONFIG_XZCAT) += bbunzip.o
//kbuild:lib-$(CONFIG_XZ) += bbunzip.o
@@ -610,7 +584,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unxz_main(int argc UNUSED_PARAM, char **argv)
{
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
IF_XZ(int opts =) getopt32(argv, "cfvqdt");
# if ENABLE_XZ
/* xz without -d or -t? */
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
+6 -19
View File
@@ -19,15 +19,6 @@
//config:
//config: Unless you have a specific application which requires bzip2, you
//config: should probably say N here.
//config:
//config:config FEATURE_BZIP2_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on BZIP2 || BUNZIP2 || BZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for bzip2.
//config: This will be automatically selected if bunzip2 or bzcat is
//config: enabled.
//applet:IF_BZIP2(APPLET(bzip2, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_BZIP2) += bzip2.o
@@ -37,13 +28,9 @@
//usage:#define bzip2_full_usage "\n\n"
//usage: "Compress FILEs (or stdin) with bzip2 algorithm\n"
//usage: "\n -1..9 Compression level"
//usage: IF_FEATURE_BZIP2_DECOMPRESS(
//usage: "\n -d Decompress"
//usage: "\n -t Test file integrity"
//usage: )
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
#include "libbb.h"
#include "bb_archive.h"
@@ -197,13 +184,13 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs");
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
if (opt & 0x30) // -d and/or -t
opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs");
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
if (opt & 0x18) // -d and/or -t
return bunzip2_main(argc, argv);
opt >>= 6;
opt >>= 5;
#else
opt >>= 4;
opt >>= 3;
#endif
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
opt |= 0x100; /* if nothing else, assume -9 */
@@ -214,6 +201,6 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
}
argv += optind;
option_mask32 &= 0xf; /* ignore all except -cfkv */
option_mask32 &= 0x7; /* ignore all except -cfv */
return bbunpack(argv, compressStream, append_ext, "bz2");
}
+2 -2
View File
@@ -29,7 +29,7 @@
//config: should probably say N here.
//config:
//config:config FEATURE_CPIO_O
//config: bool "Support archive creation"
//config: bool "Support for archive creation"
//config: default y
//config: depends on CPIO
//config: help
@@ -37,7 +37,7 @@
//config: format only.
//config:
//config:config FEATURE_CPIO_P
//config: bool "Support passthrough mode"
//config: bool "Support for passthrough mode"
//config: default y
//config: depends on FEATURE_CPIO_O
//config: help
+17 -13
View File
@@ -18,7 +18,7 @@
* known difference between busybox dpkg and the official dpkg that i don't
* consider important, its worth keeping a note of differences anyway, just to
* make it easier to maintain.
* - the first value for the confflile: field isn't placed on a new line.
* - the first value for the confflile: field isnt placed on a new line.
* - when installing a package the status: field is placed at the end of the
* section, rather than just after the package: field.
*
@@ -110,7 +110,7 @@ typedef struct common_node_s {
edge_t **edge;
} common_node_t;
/* Currently it doesn't store packages that have state-status of not-installed
/* Currently it doesnt store packages that have state-status of not-installed
* So it only really has to be the size of the maximum number of packages
* likely to be installed at any one time, so there is a bit of leeway here */
#define STATUS_HASH_PRIME 8191
@@ -205,7 +205,7 @@ static int search_name_hashtable(const char *key)
return probe_address;
}
/* this DOESN'T add the key to the hashtable
/* this DOESNT add the key to the hashtable
* TODO make it consistent with search_name_hashtable
*/
static unsigned search_status_hashtable(const char *key)
@@ -467,7 +467,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
version = strchr(field2, '(');
if (version == NULL) {
edge->operator = VER_ANY;
/* Get the versions hash number, adding it if the number isn't already in there */
/* Get the versions hash number, adding it if the number isnt already in there */
edge->version = search_name_hashtable("ANY");
} else {
/* Skip leading ' ' or '(' */
@@ -496,7 +496,7 @@ static void add_split_dependencies(common_node_t *parent_node, const char *whole
/* Truncate version at trailing ' ' or ')' */
version[strcspn(version, " )")] = '\0';
/* Get the versions hash number, adding it if the number isn't already in there */
/* Get the versions hash number, adding it if the number isnt already in there */
edge->version = search_name_hashtable(version);
}
@@ -562,7 +562,7 @@ static int read_package_field(const char *package_buffer, char **field_name, cha
offset_name_end = offset;
offset_value_start = next_offset;
}
/* TODO: Name might still have trailing spaces if ':' isn't
/* TODO: Name might still have trailing spaces if ':' isnt
* immediately after name */
break;
case '\n':
@@ -776,7 +776,7 @@ static void index_status_file(const char *filename)
const unsigned package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
status_node = xmalloc(sizeof(status_node_t));
/* fill_package_struct doesn't handle the status field */
/* fill_package_struct doesnt handle the status field */
status_line = strstr(control_buffer, "Status:");
if (status_line != NULL) {
status_line += 7;
@@ -850,7 +850,7 @@ static void write_status_file(deb_file_t **deb_file)
if (status_hashtable[status_num] != NULL) {
const char *status_from_hashtable = name_hashtable[status_hashtable[status_num]->status];
if (strcmp(status_from_file, status_from_hashtable) != 0) {
/* New status isn't exactly the same as old status */
/* New status isnt exactly the same as old status */
const int state_status = get_status(status_num, 3);
if ((strcmp("installed", name_hashtable[state_status]) == 0)
|| (strcmp("unpacked", name_hashtable[state_status]) == 0)
@@ -919,7 +919,7 @@ static void write_status_file(deb_file_t **deb_file)
}
}
}
/* If the package from the status file wasn't handle above, do it now*/
/* If the package from the status file wasnt handle above, do it now*/
if (!write_flag) {
fprintf(new_status_file, "%s\n\n", control_buffer);
}
@@ -946,7 +946,7 @@ static void write_status_file(deb_file_t **deb_file)
if (errno != ENOENT)
bb_error_msg_and_die("can't create backup status file");
/* Its ok if renaming the status file fails because status
* file doesn't exist, maybe we are starting from scratch */
* file doesnt exist, maybe we are starting from scratch */
bb_error_msg("no status file found, creating new one");
}
@@ -1061,7 +1061,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
}
/* Check dependentcies */
/* Check dependendcies */
for (i = 0; i < PACKAGE_HASH_PRIME; i++) {
int status_num = 0;
int number_of_alternatives = 0;
@@ -1244,7 +1244,7 @@ static void run_package_script_or_die(const char *package_name, const char *scri
script_path = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, script_type);
/* If the file doesn't exist it isn't fatal */
/* If the file doesnt exist is isnt fatal */
result = access(script_path, F_OK) ? EXIT_SUCCESS : system(script_path);
free(script_path);
if (result)
@@ -1839,7 +1839,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
) {
status_node = xmalloc(sizeof(status_node_t));
status_node->package = deb_file[deb_count]->package;
/* reinstreq isn't changed to "ok" until the package control info
/* reinstreq isnt changed to "ok" until the package control info
* is written to the status file*/
status_node->status = search_name_hashtable("install reinstreq not-installed");
status_hashtable[status_num] = status_node;
@@ -1938,6 +1938,10 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
for (i = 0; i < STATUS_HASH_PRIME; i++) {
free(status_hashtable[i]);
}
free(status_hashtable);
free(package_hashtable);
free(name_hashtable);
}
return EXIT_SUCCESS;
+16 -25
View File
@@ -48,9 +48,11 @@ aa: 85.1% -- replaced with aa.gz
//config: bool "Enable long options"
//config: default y
//config: depends on GZIP && LONG_OPTS
//config: help
//config: Enable use of long options, increases size by about 106 Bytes
//config:
//config:config GZIP_FAST
//config: int "Trade memory for speed (0:small,slow - 2:fast,big)"
//config: int "Trade memory for gzip speed (0:small,slow - 2:fast,big)"
//config: default 0
//config: range 0 2
//config: depends on GZIP
@@ -70,33 +72,22 @@ aa: 85.1% -- replaced with aa.gz
//config: is 6. If levels 1-3 are specified, 4 is used.
//config: If this option is not selected, -N options are ignored and -9
//config: is used.
//config:
//config:config FEATURE_GZIP_DECOMPRESS
//config: bool "Enable decompression"
//config: default y
//config: depends on GZIP || GUNZIP || ZCAT
//config: help
//config: Enable -d (--decompress) and -t (--test) options for gzip.
//config: This will be automatically selected if gunzip or zcat is
//config: enabled.
//applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_GZIP) += gzip.o
//usage:#define gzip_trivial_usage
//usage: "[-cfk" IF_FEATURE_GZIP_DECOMPRESS("dt") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
//usage:#define gzip_full_usage "\n\n"
//usage: "Compress FILEs (or stdin)\n"
//usage: IF_FEATURE_GZIP_LEVELS(
//usage: "\n -1..9 Compression level"
//usage: )
//usage: IF_FEATURE_GZIP_DECOMPRESS(
//usage: IF_GUNZIP(
//usage: "\n -d Decompress"
//usage: "\n -t Test file integrity"
//usage: )
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -k Keep input files"
//usage:
//usage:#define gzip_example_usage
//usage: "$ ls -la /tmp/busybox*\n"
@@ -276,7 +267,7 @@ enum {
* input file length plus MIN_LOOKAHEAD.
*/
#if !ENABLE_FEATURE_GZIP_LEVELS
#ifndef ENABLE_FEATURE_GZIP_LEVELS
max_chain_length = 4096,
/* To speed up deflation, hash chains are never searched beyond this length.
@@ -315,7 +306,7 @@ enum {
struct globals {
#if ENABLE_FEATURE_GZIP_LEVELS
#ifdef ENABLE_FEATURE_GZIP_LEVELS
unsigned max_chain_length;
unsigned max_lazy_match;
unsigned good_match;
@@ -2163,7 +2154,7 @@ static const char gzip_longopts[] ALIGN1 =
"to-stdout\0" No_argument "c"
"force\0" No_argument "f"
"verbose\0" No_argument "v"
#if ENABLE_FEATURE_GZIP_DECOMPRESS
#if ENABLE_GUNZIP
"decompress\0" No_argument "d"
"uncompress\0" No_argument "d"
"test\0" No_argument "t"
@@ -2190,14 +2181,14 @@ static const char gzip_longopts[] ALIGN1 =
*/
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if ENABLE_FEATURE_GZIP_DECOMPRESS
#if ENABLE_GUNZIP
int gzip_main(int argc, char **argv)
#else
int gzip_main(int argc UNUSED_PARAM, char **argv)
#endif
{
unsigned opt;
#if ENABLE_FEATURE_GZIP_LEVELS
#ifdef ENABLE_FEATURE_GZIP_LEVELS
static const struct {
uint8_t good;
uint8_t chain_shift;
@@ -2220,13 +2211,13 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
applet_long_options = gzip_longopts;
#endif
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
if (opt & 0x30) // -d and/or -t
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x18) // -d and/or -t
return gunzip_main(argc, argv);
#endif
#if ENABLE_FEATURE_GZIP_LEVELS
opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */
#ifdef ENABLE_FEATURE_GZIP_LEVELS
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
if (opt == 0)
opt = 1 << 6; /* default: 6 */
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
@@ -2235,7 +2226,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
nice_match = gzip_level_config[opt].nice2 * 2;
#endif
option_mask32 &= 0xf; /* retain only -cfkv */
option_mask32 &= 0x7; /* retain only -cfv */
/* Allocate all global buffers (for DYN_ALLOC option) */
ALLOC(uch, G1.l_buf, INBUFSIZ);
+4 -7
View File
@@ -51,19 +51,16 @@ lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_UNLZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_LZOPCAT) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
# 'bzip2 -d', bunzip2 or bzcat selects FEATURE_BZIP2_DECOMPRESS
lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_FEATURE_UNZIP_BZIP2) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_BZCAT) += open_transformer.o decompress_bunzip2.o
lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_LZCAT) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_LZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_FEATURE_UNZIP_LZMA) += open_transformer.o decompress_unlzma.o
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_XZCAT) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_XZ) += open_transformer.o decompress_unxz.o
lib-$(CONFIG_FEATURE_UNZIP_XZ) += open_transformer.o decompress_unxz.o
# 'gzip -d', gunzip or zcat selects FEATURE_GZIP_DECOMPRESS
lib-$(CONFIG_FEATURE_GZIP_DECOMPRESS) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_ZCAT) += open_transformer.o decompress_gunzip.o
lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o
lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
+2 -4
View File
@@ -127,9 +127,8 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
if (hard_link) {
res = link(hard_link, dst_name);
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
/* shared message */
bb_perror_msg("can't create %slink "
"%s to %s", "hard",
"from %s to %s", "hard",
dst_name,
hard_link);
}
@@ -182,9 +181,8 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
if (res != 0
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
) {
/* shared message */
bb_perror_msg("can't create %slink "
"%s to %s", "sym",
"from %s to %s", "sym",
dst_name,
file_header->link_target);
}
+4 -4
View File
@@ -134,7 +134,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
if (bit_count >= 24) {
bits = bd->inbufBits & ((1U << bit_count) - 1);
bits = bd->inbufBits & ((1 << bit_count) - 1);
bits_wanted -= bit_count;
bits <<= bits_wanted;
bit_count = 0;
@@ -158,11 +158,11 @@ static int get_next_block(bunzip_data *bd)
{
struct group_data *hufGroup;
int dbufCount, dbufSize, groupCount, *base, *limit, selector,
i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
i, j, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
int runCnt = runCnt; /* for compiler */
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
uint32_t *dbuf;
unsigned origPtr, t;
unsigned origPtr;
dbuf = bd->dbuf;
dbufSize = bd->dbufSize;
@@ -308,7 +308,7 @@ static int get_next_block(bunzip_data *bd)
base = hufGroup->base - 1;
limit = hufGroup->limit - 1;
/* Calculate permute[]. Concurrently, initialize temp[] and limit[]. */
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
pp = 0;
for (i = minLen; i <= maxLen; i++) {
int k;
+5 -26
View File
@@ -278,10 +278,9 @@ unpack_lzma_stream(transformer_state_t *xstate)
if (state >= LZMA_NUM_LIT_STATES) {
int match_byte;
uint32_t pos;
uint32_t pos = buffer_pos - rep0;
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
while (pos >= header.dict_size)
pos += header.dict_size;
match_byte = buffer[pos];
do {
@@ -337,11 +336,9 @@ unpack_lzma_stream(transformer_state_t *xstate)
);
if (!rc_is_bit_1(rc, prob2)) {
#if ENABLE_FEATURE_LZMA_FAST
uint32_t pos;
uint32_t pos = buffer_pos - rep0;
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
while (pos >= header.dict_size)
pos += header.dict_size;
previous_byte = buffer[pos];
goto one_byte1;
@@ -432,25 +429,10 @@ unpack_lzma_stream(transformer_state_t *xstate)
}
len += LZMA_MATCH_MIN_LEN;
/*
* LZMA SDK has this optimized:
* it precalculates size and copies many bytes
* in a loop with simpler checks, a-la:
* do
* *(dest) = *(dest + ofs);
* while (++dest != lim);
* and
* do {
* buffer[buffer_pos++] = buffer[pos];
* if (++pos == header.dict_size)
* pos = 0;
* } while (--cur_len != 0);
* Our code is slower (more checks per byte copy):
*/
IF_NOT_FEATURE_LZMA_FAST(string:)
do {
uint32_t pos = buffer_pos - rep0;
if ((int32_t)pos < 0)
while (pos >= header.dict_size)
pos += header.dict_size;
previous_byte = buffer[pos];
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
@@ -466,9 +448,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
} while (len != 0 && buffer_pos < header.dst_size);
/* FIXME: ...........^^^^^
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
* It probably should, but it is a "do we accidentally
* unpack more bytes than expected?" check - which
* never happens for well-formed compression data...
*/
}
}
+2 -2
View File
@@ -486,11 +486,11 @@ static __always_inline void XZ_FUNC rc_normalize(struct rc_dec *rc)
}
/*
* Decode one bit. In some versions, this function has been split in three
* Decode one bit. In some versions, this function has been splitted in three
* functions so that the compiler is supposed to be able to more easily avoid
* an extra branch. In this particular version of the LZMA decoder, this
* doesn't seem to be a good idea (tested with GCC 3.3.6, 3.4.6, and 4.3.3
* on x86). Using a non-split version results in nicer looking code too.
* on x86). Using a non-splitted version results in nicer looking code too.
*
* NOTE: This must return an int. Do not make it return a bool or the speed
* of the code generated by GCC 3.x decreases 10-15 %. (GCC 4.3 doesn't care,
+19 -37
View File
@@ -33,13 +33,13 @@
//config:
//config:config UNLZOP
//config: bool "unlzop"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: default y
//config: help
//config: Lzop decompresion.
//config:
//config:config LZOPCAT
//config: bool "lzopcat"
//config: default n # INCOMPAT: upstream lzop does not provide such tool
//config: default y
//config: help
//config: Alias to "unlzop -c".
//config:
@@ -53,22 +53,19 @@
//config: and take up 3.2K of code.
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_UNLZOP( APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
//applet:IF_UNLZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
//applet:IF_LZOPCAT(APPLET_ODDNAME(lzopcat, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, lzopcat))
//kbuild:lib-$(CONFIG_LZOP) += lzop.o
//kbuild:lib-$(CONFIG_UNLZOP) += lzop.o
//kbuild:lib-$(CONFIG_LZOPCAT) += lzop.o
//usage:#define lzop_trivial_usage
//usage: "[-cfUvd123456789CF] [FILE]..."
//usage: "[-cfvd123456789CF] [FILE]..."
//usage:#define lzop_full_usage "\n\n"
//usage: " -1..9 Compression level"
//usage: "\n -d Decompress"
//usage: "\n -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -U Delete input files"
///////: "\n -k Keep input files" (default, so why bother documenting?)
//usage: "\n -v Verbose"
//usage: "\n -F Don't store or verify checksum"
//usage: "\n -C Also write checksum of compressed block"
@@ -80,12 +77,10 @@
//usage: "\n -F Don't verify checksum"
//usage:
//usage:#define unlzop_trivial_usage
//usage: "[-cfkvF] [FILE]..."
//usage: "[-cfvF] [FILE]..."
//usage:#define unlzop_full_usage "\n\n"
//usage: " -c Write to stdout"
//usage: "\n -f Force"
//usage: "\n -U Delete input files"
///////: "\n -k Keep input files" (default, so why bother documenting?)
//usage: "\n -v Verbose"
//usage: "\n -F Don't verify checksum"
@@ -476,33 +471,27 @@ struct globals {
//#define LZOP_VERSION_STRING "1.01"
//#define LZOP_VERSION_DATE "Apr 27th 2003"
// lzop wants to be weird:
// unlike all other compressosrs, its -k "keep" option is the default,
// and -U is used to delete the source. We will invert the bit after getopt().
#define OPTION_STRING "cfUvqdt123456789CFk"
#define OPTION_STRING "cfvqdt123456789CF"
/* Note: must be kept in sync with archival/bbunzip.c */
enum {
OPT_STDOUT = (1 << 0),
OPT_FORCE = (1 << 1),
OPT_KEEP = (1 << 2),
OPT_VERBOSE = (1 << 3),
OPT_QUIET = (1 << 4),
OPT_DECOMPRESS = (1 << 5),
OPT_TEST = (1 << 6),
OPT_1 = (1 << 7),
OPT_2 = (1 << 8),
OPT_3 = (1 << 9),
OPT_4 = (1 << 10),
OPT_5 = (1 << 11),
OPT_6 = (1 << 12),
OPT_VERBOSE = (1 << 2),
OPT_QUIET = (1 << 3),
OPT_DECOMPRESS = (1 << 4),
OPT_TEST = (1 << 5),
OPT_1 = (1 << 6),
OPT_2 = (1 << 7),
OPT_3 = (1 << 8),
OPT_4 = (1 << 9),
OPT_5 = (1 << 10),
OPT_6 = (1 << 11),
OPT_789 = (7 << 12),
OPT_7 = (1 << 13),
OPT_8 = (1 << 14),
OPT_9 = (1 << 15),
OPT_C = (1 << 16),
OPT_F = (1 << 17),
OPT_k = (1 << 18),
OPT_789 = OPT_7 | OPT_8 | OPT_9
OPT_C = (1 << 15),
OPT_F = (1 << 16),
};
/**********************************************************************/
@@ -1135,13 +1124,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
{
getopt32(argv, OPTION_STRING);
argv += optind;
/* -U is "anti -k", invert bit for bbunpack(): */
option_mask32 ^= OPT_KEEP;
/* -k disables -U (if any): */
/* opt_complementary = "k-U"; - nope, only handles -Uk, not -kU */
if (option_mask32 & OPT_k)
option_mask32 |= OPT_KEEP;
/* lzopcat? */
if (ENABLE_LZOPCAT && applet_name[4] == 'c')
option_mask32 |= (OPT_STDOUT | OPT_DECOMPRESS);
+35 -29
View File
@@ -49,15 +49,13 @@
//config: create compressed archives. It's probably the most widely used
//config: UNIX archive program.
//config:
//config:config FEATURE_TAR_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on TAR && LONG_OPTS
//config:
//config:config FEATURE_TAR_CREATE
//config: bool "Enable -c (archive creation)"
//config: bool "Enable archive creation"
//config: default y
//config: depends on TAR
//config: help
//config: If you enable this option you'll be able to create
//config: tar archives using the `-c' option.
//config:
//config:config FEATURE_TAR_AUTODETECT
//config: bool "Autodetect compressed tarballs"
@@ -76,7 +74,7 @@
//config: a list of files to include or exclude from an archive.
//config:
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
//config: bool "Support old tar header format"
//config: bool "Support for old tar header format"
//config: default y
//config: depends on TAR || DPKG
//config: help
@@ -95,12 +93,22 @@
//config: tarballs still exist.
//config:
//config:config FEATURE_TAR_GNU_EXTENSIONS
//config: bool "Support GNU tar extensions (long filenames)"
//config: bool "Support for GNU tar extensions (long filenames)"
//config: default y
//config: depends on TAR || DPKG
//config: help
//config: With this option busybox supports GNU long filenames and
//config: linknames.
//config:
//config:config FEATURE_TAR_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on TAR && LONG_OPTS
//config: help
//config: Enable use of long options, increases size by about 400 Bytes
//config:
//config:config FEATURE_TAR_TO_COMMAND
//config: bool "Support writing to an external program (--to-command)"
//config: bool "Support for writing to an external program"
//config: default y
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
//config: help
@@ -113,17 +121,20 @@
//config: default y
//config: depends on TAR
//config: help
//config: Enable use of user and group names in tar. This affects contents
//config: Enables use of user and group names in tar. This affects contents
//config: listings (-t) and preserving permissions when unpacking (-p).
//config: +200 bytes.
//config:
//config:config FEATURE_TAR_NOPRESERVE_TIME
//config: bool "Enable -m (do not preserve time) GNU option"
//config: bool "Enable -m (do not preserve time) option"
//config: default y
//config: depends on TAR
//config: help
//config: With this option busybox supports GNU tar -m
//config: (do not preserve time) option.
//config:
//config:config FEATURE_TAR_SELINUX
//config: bool "Support extracting SELinux labels"
//config: bool "Support for extracting SELinux labels"
//config: default n
//config: depends on TAR && SELINUX
//config: help
@@ -529,8 +540,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
/*
* Check to see if we are dealing with a hard link.
* If so -
* Treat the first occurrence of a given dev/inode as a file while
* treating any additional occurrences as hard links. This is done
* Treat the first occurance of a given dev/inode as a file while
* treating any additional occurances as hard links. This is done
* by adding the file information to the HardLinkInfo linked list.
*/
tbInfo->hlInfo = NULL;
@@ -1216,26 +1227,21 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
USE_FOR_NOMMU(const char *xformer_prog;)
if (opt & OPT_COMPRESS) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_Z(xformer = unpack_Z_stream;))
if (opt & OPT_COMPRESS)
USE_FOR_MMU(xformer = unpack_Z_stream;)
USE_FOR_NOMMU(xformer_prog = "uncompress";)
}
if (opt & OPT_GZIP) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_GZ(xformer = unpack_gz_stream;))
if (opt & OPT_GZIP)
USE_FOR_MMU(xformer = unpack_gz_stream;)
USE_FOR_NOMMU(xformer_prog = "gunzip";)
}
if (opt & OPT_BZIP2) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_BZ2(xformer = unpack_bz2_stream;))
if (opt & OPT_BZIP2)
USE_FOR_MMU(xformer = unpack_bz2_stream;)
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
}
if (opt & OPT_LZMA) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_LZMA(xformer = unpack_lzma_stream;))
if (opt & OPT_LZMA)
USE_FOR_MMU(xformer = unpack_lzma_stream;)
USE_FOR_NOMMU(xformer_prog = "unlzma";)
}
if (opt & OPT_XZ) {
USE_FOR_MMU(IF_FEATURE_SEAMLESS_XZ(xformer = unpack_xz_stream;))
if (opt & OPT_XZ)
USE_FOR_MMU(xformer = unpack_xz_stream;)
USE_FOR_NOMMU(xformer_prog = "unxz";)
}
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
/* Can't lseek over pipes */
+132 -176
View File
@@ -34,23 +34,6 @@
//config: ZIP files without deleted/updated files, SFX archives etc,
//config: you can reduce code size by unselecting this option.
//config: To support less trivial ZIPs, say Y.
//config:
//config:config FEATURE_UNZIP_BZIP2
//config: bool "Support compression method 12 (bzip2)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
// FEATURE_UNZIP_CDF is needed, otherwise we can't find start of next file
// DESKTOP is needed to get back uncompressed length
//config:
//config:config FEATURE_UNZIP_LZMA
//config: bool "Support compression method 14 (lzma)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
//config:
//config:config FEATURE_UNZIP_XZ
//config: bool "Support compression method 95 (xz)"
//config: default y
//config: depends on FEATURE_UNZIP_CDF && DESKTOP
//applet:IF_UNZIP(APPLET(unzip, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_UNZIP) += unzip.o
@@ -113,7 +96,6 @@ typedef union {
#define FIX_ENDIANNESS_ZIP(zip) \
do { if (BB_BIG_ENDIAN) { \
(zip).fmt.method = SWAP_LE16((zip).fmt.method ); \
(zip).fmt.crc32 = SWAP_LE32((zip).fmt.crc32 ); \
(zip).fmt.cmpsize = SWAP_LE32((zip).fmt.cmpsize ); \
(zip).fmt.ucmpsize = SWAP_LE32((zip).fmt.ucmpsize ); \
@@ -240,7 +222,7 @@ static uint32_t find_cdf_offset(void)
end = 0;
dbg("Looking for cdf_offset starting from 0x%"OFF_FMT"x", end);
xlseek(zip_fd, end, SEEK_SET);
xlseek(zip_fd, end, SEEK_SET);
buf = xzalloc(PEEK_FROM_END);
full_read(zip_fd, buf, PEEK_FROM_END);
@@ -337,65 +319,32 @@ static void unzip_create_leading_dirs(const char *fn)
static void unzip_extract(zip_header_t *zip, int dst_fd)
{
transformer_state_t xstate;
if (zip->fmt.method == 0) {
/* Method 0 - stored (not compressed) */
off_t size = zip->fmt.ucmpsize;
if (size)
bb_copyfd_exact_size(zip_fd, dst_fd, size);
return;
}
init_transformer_state(&xstate);
xstate.bytes_in = zip->fmt.cmpsize;
xstate.src_fd = zip_fd;
xstate.dst_fd = dst_fd;
if (zip->fmt.method == 8) {
} else {
/* Method 8 - inflate */
transformer_state_t xstate;
init_transformer_state(&xstate);
xstate.bytes_in = zip->fmt.cmpsize;
xstate.src_fd = zip_fd;
xstate.dst_fd = dst_fd;
if (inflate_unzip(&xstate) < 0)
bb_error_msg_and_die("inflate error");
/* Validate decompression - crc */
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
bb_error_msg_and_die("crc error");
}
/* Validate decompression - size */
if (zip->fmt.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
}
}
#if ENABLE_FEATURE_UNZIP_BZIP2
else if (zip->fmt.method == 12) {
/* Tested. Unpacker reads too much, but we use CDF
* and will seek to the correct beginning of next file.
*/
xstate.bytes_out = unpack_bz2_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_LZMA
else if (zip->fmt.method == 14) {
/* Not tested yet */
xstate.bytes_out = unpack_lzma_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
#if ENABLE_FEATURE_UNZIP_XZ
else if (zip->fmt.method == 95) {
/* Not tested yet */
xstate.bytes_out = unpack_xz_stream(&xstate);
if (xstate.bytes_out < 0)
bb_error_msg_and_die("inflate error");
}
#endif
else {
bb_error_msg_and_die("unsupported method %u", zip->fmt.method);
}
/* Validate decompression - size */
if (zip->fmt.ucmpsize != xstate.bytes_out) {
/* Don't die. Who knows, maybe len calculation
* was botched somewhere. After all, crc matched! */
bb_error_msg("bad length");
}
/* TODO? method 12: bzip2, method 14: LZMA */
}
static void my_fgets80(char *buf80)
@@ -660,9 +609,14 @@ int unzip_main(int argc, char **argv)
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
FIX_ENDIANNESS_ZIP(zip);
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
bb_error_msg_and_die("zip flag %s is not supported",
"8 (streaming)");
if ((zip.fmt.method != 0)
&& (zip.fmt.method != 8)
) {
/* TODO? method 12: bzip2, method 14: LZMA */
bb_error_msg_and_die("unsupported method %d", zip.fmt.method);
}
if (zip.fmt.zip_flags & SWAP_LE16(0x0009)) {
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
}
}
#if ENABLE_FEATURE_UNZIP_CDF
@@ -706,8 +660,7 @@ int unzip_main(int argc, char **argv)
if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
/* 0x0001 - encrypted */
bb_error_msg_and_die("zip flag %s is not supported",
"1 (encryption)");
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
}
dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
(unsigned)zip.fmt.cmpsize,
@@ -730,123 +683,126 @@ int unzip_main(int argc, char **argv)
if (find_list_entry(zreject, dst_fn)
|| (zaccept && !find_list_entry(zaccept, dst_fn))
) { /* Skip entry */
goto skip_cmpsize;
}
if (listing) {
/* List entry */
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
(zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0
(zip.fmt.moddate) & 0x1f, // dd: 0x001f
(zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00
(zip.fmt.modtime >> 11), // hh: 0xf800
(zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0
// seconds/2 not shown, encoded in -- 0x001f
);
if (!verbose) {
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( "%9u " "%s " "%s\n",
(unsigned)zip.fmt.ucmpsize,
dtbuf,
dst_fn);
i = 'n';
} else {
if (listing) {
/* List entry */
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
(zip.fmt.moddate >> 5) & 0xf, // mm: 0x01e0
(zip.fmt.moddate) & 0x1f, // dd: 0x001f
(zip.fmt.moddate >> 9) + 1980, // yy: 0xfe00
(zip.fmt.modtime >> 11), // hh: 0xf800
(zip.fmt.modtime >> 5) & 0x3f // mm: 0x07e0
// seconds/2 not shown, encoded in -- 0x001f
);
if (!verbose) {
// " Length Date Time Name\n"
// "--------- ---------- ----- ----"
printf( "%9u " "%s " "%s\n",
(unsigned)zip.fmt.ucmpsize,
dtbuf,
dst_fn);
} else {
unsigned long percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
if ((int32_t)percents < 0)
percents = 0; /* happens if ucmpsize < cmpsize */
percents = percents * 100;
if (zip.fmt.ucmpsize)
percents /= zip.fmt.ucmpsize;
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
(unsigned)zip.fmt.ucmpsize,
zip.fmt.method == 0 ? "Stored" : "Defl:N", /* Defl is method 8 */
/* TODO: show other methods?
* 1 - Shrunk
* 2 - Reduced with compression factor 1
* 3 - Reduced with compression factor 2
* 4 - Reduced with compression factor 3
* 5 - Reduced with compression factor 4
* 6 - Imploded
* 7 - Reserved for Tokenizing compression algorithm
* 9 - Deflate64
* 10 - PKWARE Data Compression Library Imploding
* 11 - Reserved by PKWARE
* 12 - BZIP2
* 14 - LZMA
*/
(unsigned)zip.fmt.cmpsize,
(unsigned)percents,
dtbuf,
zip.fmt.crc32,
dst_fn);
total_size += zip.fmt.cmpsize;
}
total_usize += zip.fmt.ucmpsize;
i = 'n';
} else if (dst_fd == STDOUT_FILENO) {
/* Extracting to STDOUT */
i = -1;
} else if (last_char_is(dst_fn, '/')) {
/* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (!quiet) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
xfunc_die();
}
} else {
if (!S_ISDIR(stat_buf.st_mode)) {
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "directory");
}
}
i = 'n';
} else {
char method6[7];
unsigned long percents;
sprintf(method6, "%6u", zip.fmt.method);
if (zip.fmt.method == 0) {
strcpy(method6, "Stored");
}
if (zip.fmt.method == 8) {
strcpy(method6, "Defl:N");
/* normal, maximum, fast, superfast */
IF_DESKTOP(method6[5] = "NXFS"[(zip.fmt.zip_flags >> 1) & 3];)
}
percents = zip.fmt.ucmpsize - zip.fmt.cmpsize;
if ((int32_t)percents < 0)
percents = 0; /* happens if ucmpsize < cmpsize */
percents = percents * 100;
if (zip.fmt.ucmpsize)
percents /= zip.fmt.ucmpsize;
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
// "-------- ------ ------- ---- ---------- ----- -------- ----"
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
(unsigned)zip.fmt.ucmpsize,
method6,
(unsigned)zip.fmt.cmpsize,
(unsigned)percents,
dtbuf,
zip.fmt.crc32,
dst_fn);
total_size += zip.fmt.cmpsize;
}
total_usize += zip.fmt.ucmpsize;
goto skip_cmpsize;
}
if (dst_fd == STDOUT_FILENO) {
/* Extracting to STDOUT */
goto do_extract;
}
if (last_char_is(dst_fn, '/')) {
/* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
if (!quiet) {
printf(" creating: %s\n", dst_fn);
}
unzip_create_leading_dirs(dst_fn);
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
xfunc_die();
}
} else {
if (!S_ISDIR(stat_buf.st_mode)) {
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "directory");
}
}
goto skip_cmpsize;
}
/* Extract file */
check_file:
/* Extract file */
if (stat(dst_fn, &stat_buf) == -1) {
/* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
if (stat(dst_fn, &stat_buf) == -1) {
/* File does not exist */
if (errno != ENOENT) {
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
}
i = 'y';
} else {
/* File already exists */
if (overwrite == O_NEVER) {
i = 'n';
} else if (S_ISREG(stat_buf.st_mode)) {
/* File is regular file */
if (overwrite == O_ALWAYS) {
i = 'y';
} else {
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
i = key_buf[0];
}
} else {
/* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
}
}
goto do_open_and_extract;
}
/* File already exists */
if (overwrite == O_NEVER) {
goto skip_cmpsize;
}
if (!S_ISREG(stat_buf.st_mode)) {
/* File is not regular file */
bb_error_msg_and_die("'%s' exists but is not a %s",
dst_fn, "regular file");
}
/* File is regular file */
if (overwrite == O_ALWAYS)
goto do_open_and_extract;
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
my_fgets80(key_buf);
switch (key_buf[0]) {
switch (i) {
case 'A':
overwrite = O_ALWAYS;
case 'y': /* Open file and fall into unzip */
do_open_and_extract:
unzip_create_leading_dirs(dst_fn);
#if ENABLE_FEATURE_UNZIP_CDF
dst_fd = xopen3(dst_fn, O_WRONLY | O_CREAT | O_TRUNC, file_mode);
#else
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
#endif
do_extract:
case -1: /* Unzip */
if (!quiet) {
printf(/* zip.fmt.method == 0
? " extracting: %s\n"
@@ -861,8 +817,8 @@ int unzip_main(int argc, char **argv)
case 'N':
overwrite = O_NEVER;
case 'n': /* Skip entry data */
skip_cmpsize:
case 'n':
/* Skip entry data */
unzip_skip(zip.fmt.cmpsize);
break;
@@ -876,7 +832,7 @@ int unzip_main(int argc, char **argv)
goto check_file;
default:
printf("error: invalid response [%c]\n", (char)key_buf[0]);
printf("error: invalid response [%c]\n", (char)i);
goto check_file;
}
+13 -4
View File
@@ -265,6 +265,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -382,7 +387,7 @@ CONFIG_FEATURE_KILL_REMOVED=y
CONFIG_FEATURE_KILL_DELAY=1
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
@@ -452,12 +457,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
CONFIG_FEATURE_INSMOD_TRY_MMAP=y
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -516,6 +524,7 @@ CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_UUID=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_VOLUMEID=y
CONFIG_FEATURE_VOLUMEID_EXT=y
CONFIG_FEATURE_VOLUMEID_BTRFS=y
@@ -870,9 +879,9 @@ CONFIG_FEATURE_SH_IS_HUSH=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+6 -4
View File
@@ -277,6 +277,7 @@ CONFIG_TRUE=y
# CONFIG_WHOAMI is not set
# CONFIG_YES is not set
# CONFIG_FEATURE_PRESERVE_HARDLINKS is not set
# CONFIG_FEATURE_AUTOWIDTH is not set
# CONFIG_FEATURE_HUMAN_READABLE is not set
# CONFIG_FEATURE_MD5_SHA1_SUM_CHECK is not set
@@ -391,7 +392,7 @@ CONFIG_FEATURE_VI_MAX_LEN=0
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_LINUXRC is not set
# CONFIG_HALT is not set
@@ -526,6 +527,7 @@ CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
# CONFIG_MKSWAP is not set
# CONFIG_FEATURE_MKSWAP_UUID is not set
# CONFIG_MORE is not set
# CONFIG_FEATURE_USE_TERMIOS is not set
CONFIG_VOLUMEID=y
# CONFIG_FEATURE_VOLUMEID_EXT is not set
# CONFIG_FEATURE_VOLUMEID_BTRFS is not set
@@ -871,9 +873,9 @@ CONFIG_SV_DEFAULT_SERVICE_DIR=""
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+13 -4
View File
@@ -276,6 +276,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -399,7 +404,7 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_HALT=y
@@ -467,12 +472,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -532,6 +540,7 @@ CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
CONFIG_MKSWAP=y
CONFIG_FEATURE_MKSWAP_UUID=y
CONFIG_MORE=y
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_VOLUMEID=y
CONFIG_FEATURE_VOLUMEID_EXT=y
CONFIG_FEATURE_VOLUMEID_BTRFS=y
@@ -884,9 +893,9 @@ CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_ASH_GETOPTS=y
CONFIG_ASH_ECHO=y
CONFIG_ASH_PRINTF=y
CONFIG_ASH_TEST=y
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
+13 -4
View File
@@ -94,6 +94,7 @@ CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@@ -288,6 +289,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -416,7 +422,7 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -487,12 +493,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -927,9 +936,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+13 -4
View File
@@ -174,6 +174,7 @@ CONFIG_MD5_SMALL=1
CONFIG_SHA3_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@@ -389,6 +390,11 @@ CONFIG_FEATURE_VERBOSE=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -523,7 +529,7 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -597,12 +603,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -1072,9 +1081,9 @@ CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_ASH_GETOPTS=y
CONFIG_ASH_ECHO=y
CONFIG_ASH_PRINTF=y
CONFIG_ASH_TEST=y
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_HELP=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
+13 -4
View File
@@ -112,6 +112,7 @@ CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@@ -311,6 +312,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -439,7 +445,7 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -511,12 +517,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -959,9 +968,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+13 -4
View File
@@ -102,6 +102,7 @@ CONFIG_MD5_SMALL=1
CONFIG_SHA3_SMALL=1
# CONFIG_FEATURE_FAST_TOP is not set
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
# CONFIG_FEATURE_EDITING is not set
CONFIG_FEATURE_EDITING_MAX_LEN=0
# CONFIG_FEATURE_EDITING_VI is not set
@@ -315,6 +316,11 @@ CONFIG_FEATURE_VERBOSE=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -449,7 +455,7 @@ CONFIG_FEATURE_USE_INITTAB=y
CONFIG_FEATURE_KILL_DELAY=0
CONFIG_FEATURE_INIT_SCTTY=y
CONFIG_FEATURE_INIT_SYSLOG=y
CONFIG_FEATURE_INIT_QUIET=y
CONFIG_FEATURE_EXTRA_QUIET=y
CONFIG_FEATURE_INIT_COREDUMPS=y
CONFIG_LINUXRC=y
CONFIG_INIT_TERMINAL_TYPE="linux"
@@ -522,12 +528,15 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# Options common to multiple modutils
#
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_INSMOD_TRY_MMAP is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
CONFIG_DEFAULT_MODULES_DIR="/system/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
@@ -987,9 +996,9 @@ CONFIG_SOFTLIMIT=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_HELP is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
+10 -4
View File
@@ -94,6 +94,7 @@ CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
CONFIG_FEATURE_FAST_TOP=y
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@@ -288,6 +289,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -416,7 +422,7 @@ CONFIG_TELINIT_PATH=""
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
@@ -930,9 +936,9 @@ CONFIG_ASH_BASH_COMPAT=y
CONFIG_ASH_JOB_CONTROL=y
CONFIG_ASH_ALIAS=y
CONFIG_ASH_GETOPTS=y
CONFIG_ASH_ECHO=y
CONFIG_ASH_PRINTF=y
CONFIG_ASH_TEST=y
CONFIG_ASH_BUILTIN_ECHO=y
CONFIG_ASH_BUILTIN_PRINTF=y
CONFIG_ASH_BUILTIN_TEST=y
CONFIG_ASH_CMDCMD=y
# CONFIG_ASH_MAIL is not set
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
+10 -4
View File
@@ -93,6 +93,7 @@ CONFIG_PASSWORD_MINLEN=6
CONFIG_MD5_SMALL=1
CONFIG_FEATURE_FAST_TOP=y
# CONFIG_FEATURE_ETC_NETWORKS is not set
CONFIG_FEATURE_USE_TERMIOS=y
CONFIG_FEATURE_EDITING=y
CONFIG_FEATURE_EDITING_MAX_LEN=1024
# CONFIG_FEATURE_EDITING_VI is not set
@@ -286,6 +287,11 @@ CONFIG_YES=y
#
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
#
# Common options for ls, more and telnet
#
CONFIG_FEATURE_AUTOWIDTH=y
#
# Common options for df, du, ls
#
@@ -413,7 +419,7 @@ CONFIG_TELINIT_PATH=""
CONFIG_FEATURE_KILL_DELAY=0
# CONFIG_FEATURE_INIT_SCTTY is not set
# CONFIG_FEATURE_INIT_SYSLOG is not set
# CONFIG_FEATURE_INIT_QUIET is not set
# CONFIG_FEATURE_EXTRA_QUIET is not set
# CONFIG_FEATURE_INIT_COREDUMPS is not set
# CONFIG_LINUXRC is not set
CONFIG_INIT_TERMINAL_TYPE=""
@@ -906,9 +912,9 @@ CONFIG_ASH=y
# CONFIG_ASH_JOB_CONTROL is not set
# CONFIG_ASH_ALIAS is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_ECHO is not set
# CONFIG_ASH_PRINTF is not set
# CONFIG_ASH_TEST is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
+6 -2
View File
@@ -42,14 +42,18 @@
//config: depends on LOADFONT || SETFONT
//config:
//config:config FEATURE_LOADFONT_PSF2
//config: bool "Support PSF2 console fonts"
//config: bool "Support for PSF2 console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//config: help
//config: Support PSF2 console fonts.
//config:
//config:config FEATURE_LOADFONT_RAW
//config: bool "Support old (raw) console fonts"
//config: bool "Support for old (raw) console fonts"
//config: default y
//config: depends on LOADFONT || SETFONT
//config: help
//config: Support old (raw) console fonts.
//applet:IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_SETFONT(APPLET(setfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
-2
View File
@@ -56,8 +56,6 @@ int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
#if ENABLE_STTY
return stty_main(2, (char**)args);
#else
/* Make sure stdout gets drained before we execvp */
fflush_all();
execvp("stty", (char**)args);
#endif
}
+2
View File
@@ -19,6 +19,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on SETCONSOLE && LONG_OPTS
//config: help
//config: Support long options for the setconsole applet.
//applet:IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
+15 -1
View File
@@ -27,11 +27,25 @@ config FEATURE_PRESERVE_HARDLINKS
help
Allow cp and mv to preserve hard links.
comment "Common options for ls, more and telnet"
depends on LS || MORE || TELNET
config FEATURE_AUTOWIDTH
bool "Calculate terminal & column widths"
default y
depends on LS || MORE || TELNET
help
This option allows utilities such as 'ls', 'more' and 'telnet'
to determine the width of the screen, which can allow them to
display additional text or avoid wrapping text onto the next line.
If you leave this disabled, your utilities will be especially
primitive and will be unable to determine the current screen width.
comment "Common options for df, du, ls"
depends on DF || DU || LS
config FEATURE_HUMAN_READABLE
bool "Support human readable output (example 13k, 23M, 235G)"
bool "Support for human readable output (example 13k, 23M, 235G)"
default y
depends on DF || DU || LS
help
+8 -1
View File
@@ -14,5 +14,12 @@ lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
lib-$(CONFIG_LESS) += cat.o # less too
lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
lib-$(CONFIG_ADDUSER) += chown.o # used by adduser
lib-$(CONFIG_ADDGROUP) += chown.o # used by addgroup
lib-$(CONFIG_ADDGROUP) += chown.o # used by adduser
lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_SH_IS_ASH) += echo.o # used by ash
lib-$(CONFIG_BASH_IS_ASH) += echo.o # used by ash
lib-$(CONFIG_HUSH) += echo.o # used by hush
lib-$(CONFIG_SH_IS_HUSH) += echo.o # used by hush
lib-$(CONFIG_BASH_IS_HUSH) += echo.o # used by hush
lib-$(CONFIG_FTPD) += ls.o # used by ftpd
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
+1 -1
View File
@@ -35,7 +35,7 @@
#include "libbb.h"
#include "unicode.h"
/* We often use "unsigned" instead of "int", it's easier to div on most CPUs */
/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
#define THURSDAY 4 /* for reformation */
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
+22 -134
View File
@@ -12,168 +12,56 @@
//config: help
//config: cat is used to concatenate files and print them to the standard
//config: output. Enable this option if you wish to enable the 'cat' utility.
//config:
//config:config FEATURE_CATV
//config: bool "cat -v[etA]"
//config: default y
//config: depends on CAT
//config: help
//config: Display nonprinting characters as escape sequences
//applet:IF_CAT(APPLET(cat, BB_DIR_BIN, BB_SUID_DROP))
//applet:IF_CAT(APPLET_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
//kbuild:lib-$(CONFIG_CAT) += cat.o
//kbuild:lib-$(CONFIG_CAT) += cat.o
/* BB_AUDIT SUSv3 compliant */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
//usage:#define cat_trivial_usage
//usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..."
//usage: "[FILE]..."
//usage:#define cat_full_usage "\n\n"
//usage: "Print FILEs to stdout\n"
//usage: "\n -n Number output lines"
//usage: "\n -b Number nonempty lines"
//usage: IF_FEATURE_CATV(
//usage: "\n -v Show nonprinting characters as ^x or M-x"
//usage: "\n -t ...and tabs as ^I"
//usage: "\n -e ...and end lines with $"
//usage: "\n -A Same as -vte"
//usage: )
/*
Longopts not implemented yet:
--number-nonblank number nonempty output lines, overrides -n
--number number all output lines
--show-nonprinting use ^ and M- notation, except for LFD and TAB
--show-all equivalent to -vet
Not implemented yet:
-E, --show-ends display $ at end of each line (-e sans -v)
-T, --show-tabs display TAB characters as ^I (-t sans -v)
-s, --squeeze-blank suppress repeated empty output lines
*/
//usage: "Concatenate FILEs and print them to stdout"
//usage:
//usage:#define cat_example_usage
//usage: "$ cat /proc/uptime\n"
//usage: "110716.72 17.67"
#include "libbb.h"
#include "common_bufsiz.h"
#if ENABLE_FEATURE_CATV
/*
* cat -v implementation for busybox
*
* Copyright (C) 2006 Rob Landley <rob@landley.net>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* Rob had "cat -v" implemented as a separate applet, catv.
* See "cat -v considered harmful" at
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz
* From USENIX Summer Conference Proceedings, 1983
* """
* The talk reviews reasons for UNIX's popularity and shows, using UCB cat
* as a primary example, how UNIX has grown fat. cat isn't for printing
* files with line numbers, it isn't for compressing multiple blank lines,
* it's not for looking at non-printing ASCII characters, it's for
* concatenating files.
* We are reminded that ls isn't the place for code to break a single column
* into multiple ones, and that mailnews shouldn't have its own more
* processing or joke encryption code.
* """
*
* I agree with the argument. Unfortunately, this ship has sailed (1983...).
* There are dozens of Linux distros and each of them has "cat" which supports -v.
* It's unrealistic for us to "reeducate" them to use our, incompatible way
* to achieve "cat -v" effect. The actuall effect would be "users pissed off
* by gratuitous incompatibility".
*/
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
static int catv(unsigned opts, char **argv)
/* This is a NOFORK applet. Be very careful! */
int bb_cat(char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
int retval = EXIT_SUCCESS;
BUILD_BUG_ON(CATV_OPT_e != VISIBLE_ENDLINE);
BUILD_BUG_ON(CATV_OPT_t != VISIBLE_SHOW_TABS);
#if 0 /* These consts match, we can just pass "opts" to visible() */
if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE;
if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS;
#endif
if (!*argv)
argv = (char**) &bb_argv_dash;
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
#define read_buf bb_common_bufsiz1
setup_common_bufsiz();
do {
fd = open_or_warn_stdin(*argv);
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
if (fd >= 0) {
/* This is not a xfunc - never exits */
off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
if (fd != STDIN_FILENO)
close(fd);
if (r >= 0)
continue;
}
for (;;) {
int i, res;
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;
if (res <= 0)
break;
for (i = 0; i < res; i++) {
unsigned char c = read_buf[i];
char buf[sizeof("M-^c")];
visible(c, buf, opts);
fputs(buf, stdout);
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)
close(fd);
retval = EXIT_FAILURE;
} while (*++argv);
fflush_stdout_and_exit(retval);
return retval;
}
#endif
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc UNUSED_PARAM, char **argv)
{
struct number_state ns;
unsigned opts;
IF_FEATURE_CATV(opt_complementary = "Aetv"; /* -A == -vet */)
/* -u is ignored ("unbuffered") */
opts = getopt32(argv, IF_FEATURE_CATV("etvA")"nbu");
getopt32(argv, "u");
argv += optind;
#if ENABLE_FEATURE_CATV
if (opts & 7)
return catv(opts, argv);
//BUG: -v,-e,-t,-A ignore -nb
opts >>= 4;
#endif
#define CAT_OPT_n (1<<0)
#define CAT_OPT_b (1<<1)
#define CAT_OPT_u (1<<2)
if (!(opts & (CAT_OPT_n|CAT_OPT_b))) /* no -n or -b */
return bb_cat(argv);
if (!*argv)
*--argv = (char*)"-";
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
ns.empty_str = "\n";
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
return bb_cat(argv);
}
+96
View File
@@ -0,0 +1,96 @@
/* vi: set sw=4 ts=4: */
/*
* cat -v implementation for busybox
*
* Copyright (C) 2006 Rob Landley <rob@landley.net>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* See "Cat -v considered harmful" at
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
//config:config CATV
//config: bool "catv"
//config: default y
//config: help
//config: Display nonprinting characters as escape sequences (like some
//config: implementations' cat -v option).
//applet:IF_CATV(APPLET(catv, BB_DIR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_CATV) += catv.o
//usage:#define catv_trivial_usage
//usage: "[-etv] [FILE]..."
//usage:#define catv_full_usage "\n\n"
//usage: "Display nonprinting characters as ^x or M-x\n"
//usage: "\n -e End each line with $"
//usage: "\n -t Show tabs as ^I"
//usage: "\n -v Don't use ^x or M-x escapes"
#include "libbb.h"
#include "common_bufsiz.h"
#define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2)
struct BUG_const_mismatch {
char BUG_const_mismatch[
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
? 1 : -1
];
};
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc UNUSED_PARAM, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
unsigned opts;
opts = getopt32(argv, "etv");
argv += optind;
#if 0 /* These consts match, we can just pass "opts" to visible() */
if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE;
if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS;
#endif
/* Read from stdin if there's nothing else to do. */
if (!argv[0])
*--argv = (char*)"-";
#define read_buf bb_common_bufsiz1
setup_common_bufsiz();
do {
fd = open_or_warn_stdin(*argv);
if (fd < 0) {
retval = EXIT_FAILURE;
continue;
}
for (;;) {
int i, res;
res = read(fd, read_buf, COMMON_BUFSIZE);
if (res < 0)
retval = EXIT_FAILURE;
if (res <= 0)
break;
for (i = 0; i < res; i++) {
unsigned char c = read_buf[i];
if (opts & CATV_OPT_v) {
putchar(c);
} else {
char buf[sizeof("M-^c")];
visible(c, buf, opts);
fputs(buf, stdout);
}
}
}
if (ENABLE_FEATURE_CLEAN_UP && fd)
close(fd);
} while (*++argv);
fflush_stdout_and_exit(retval);
}
+2
View File
@@ -17,6 +17,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on CHOWN && LONG_OPTS
//config: help
//config: Enable use of long options
//applet:IF_CHOWN(APPLET_NOEXEC(chown, chown, BB_DIR_BIN, BB_SUID_DROP, chown))
+2 -2
View File
@@ -17,9 +17,9 @@
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
//usage:#define cksum_trivial_usage
//usage: "FILE..."
//usage: "FILES..."
//usage:#define cksum_full_usage "\n\n"
//usage: "Calculate the CRC32 checksums of FILEs"
//usage: "Calculate the CRC32 checksums of FILES"
#include "libbb.h"
#include "common_bufsiz.h"
+2 -2
View File
@@ -18,11 +18,11 @@
//config: cp is used to copy files and directories.
//config:
//config:config FEATURE_CP_LONG_OPTIONS
//config: bool "Enable long options"
//config: bool "Enable long options for cp"
//config: default y
//config: depends on CP && LONG_OPTS
//config: help
//config: Enable long options.
//config: Enable long options for cp.
//config: Also add support for --parents option.
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
+10 -9
View File
@@ -41,7 +41,7 @@
//config: default y
//config: depends on DD
//config: help
//config: Enable support for writing a certain number of bytes in and out,
//config: Enables support for writing a certain number of bytes in and out,
//config: at a time, and performing conversions on the data stream.
//config:
//config:config FEATURE_DD_STATUS
@@ -49,7 +49,7 @@
//config: default y
//config: depends on DD
//config: help
//config: Enable support for status=noxfer/none option.
//config: Enables support for status=noxfer/none option.
//applet:IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
@@ -133,8 +133,9 @@ enum {
/* end of input flags */
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
FLAG_COUNT = 1 << 7,
FLAG_STATUS_NONE = 1 << 8,
FLAG_STATUS_NOXFER = 1 << 9,
FLAG_STATUS = 1 << 8,
FLAG_STATUS_NONE = 1 << 9,
FLAG_STATUS_NOXFER = 1 << 10,
};
static void dd_output_status(int UNUSED_PARAM cur_signal)
@@ -395,7 +396,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
n = index_in_strings(status_words, val);
if (n < 0)
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, "status");
G.flags |= FLAG_STATUS_NONE << n;
G.flags |= FLAG_STATUS << n;
/*continue;*/
}
#endif
@@ -531,11 +532,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
if (write_and_stats(ibuf, n, obs, outfile))
goto out_status;
}
}
if (G.flags & FLAG_FSYNC) {
if (fsync(ofd) < 0)
goto die_outfile;
if (G.flags & FLAG_FSYNC) {
if (fsync(ofd) < 0)
goto die_outfile;
}
}
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
+5 -3
View File
@@ -29,9 +29,11 @@
//config: default y
//config: depends on DF
//config: help
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//config: This option enables -a, -i and -B.
//config:
//config: -a Show all filesystems
//config: -i Inodes
//config: -B <SIZE> Blocksize
//applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
+1 -1
View File
@@ -2,7 +2,7 @@
/*
* dos2unix for BusyBox
*
* dos2unix '\n' converter 0.5.0
* dos2unix '\n' convertor 0.5.0
* based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997)
* Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>.
* All rights reserved.
+4 -5
View File
@@ -26,17 +26,16 @@
//config:
//config:# this entry also appears in shell/Config.in, next to the echo builtin
//config:config FEATURE_FANCY_ECHO
//config: bool "Enable -n and -e options"
//config: bool "Enable echo options (-n and -e)"
//config: default y
//config: depends on ECHO || ASH_ECHO || HUSH_ECHO
//config: depends on ECHO || ASH_BUILTIN_ECHO || HUSH
//config: help
//config: This adds options (-n and -e) to echo.
//applet:IF_ECHO(APPLET_NOFORK(echo, echo, BB_DIR_BIN, BB_SUID_DROP, echo))
//kbuild:lib-$(CONFIG_ECHO) += echo.o
//kbuild:lib-$(CONFIG_ASH_ECHO) += echo.o
//kbuild:lib-$(CONFIG_HUSH_ECHO) += echo.o
/* BB_AUDIT SUSv3 compliant -- unless configured as fancy echo. */
/* http://www.opengroup.org/onlinepubs/007904975/utilities/echo.html */
+2
View File
@@ -35,6 +35,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on ENV && LONG_OPTS
//config: help
//config: Support long options for the env applet.
//applet:IF_ENV(APPLET_NOEXEC(env, env, BB_DIR_USR_BIN, BB_SUID_DROP, env))
+8 -5
View File
@@ -8,13 +8,13 @@
* David MacKenzie <djm@gnu.ai.mit.edu>
*
* Options for expand:
* -t num --tabs NUM Convert tabs to num spaces (default 8 spaces).
* -t num --tabs=NUM Convert tabs to num spaces (default 8 spaces).
* -i --initial Only convert initial tabs on each line to spaces.
*
* Options for unexpand:
* -a --all Convert all blanks, instead of just initial blanks.
* -f --first-only Convert only leading sequences of blanks (default).
* -t num --tabs NUM Have tabs num characters apart instead of 8.
* -t num --tabs=NUM Have tabs num characters apart instead of 8.
*
* Busybox version (C) 2007 by Tito Ragusa <farmatito@tiscali.it>
*
@@ -30,6 +30,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on EXPAND && LONG_OPTS
//config: help
//config: Support long options for the expand applet.
//config:
//config:config UNEXPAND
//config: bool "unexpand"
@@ -41,9 +43,10 @@
//config: bool "Enable long options"
//config: default y
//config: depends on UNEXPAND && LONG_OPTS
//config: help
//config: Support long options for the unexpand applet.
//applet:IF_EXPAND(APPLET(expand, BB_DIR_USR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_UNEXPAND(APPLET_ODDNAME(unexpand, expand, BB_DIR_USR_BIN, BB_SUID_DROP, unexpand))
//kbuild:lib-$(CONFIG_EXPAND) += expand.o
@@ -55,7 +58,7 @@
//usage: "Convert tabs to spaces, writing to stdout\n"
//usage: IF_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i,--initial Don't convert tabs after non blanks"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: "\n -t,--tabs=N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_EXPAND_LONG_OPTIONS(
//usage: "\n -i Don't convert tabs after non blanks"
@@ -69,7 +72,7 @@
//usage: IF_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a,--all Convert all blanks"
//usage: "\n -f,--first-only Convert only leading blanks"
//usage: "\n -t,--tabs N Tabstops every N chars"
//usage: "\n -t,--tabs=N Tabstops every N chars"
//usage: )
//usage: IF_NOT_FEATURE_UNEXPAND_LONG_OPTIONS(
//usage: "\n -a Convert all blanks"
-219
View File
@@ -1,219 +0,0 @@
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config FACTOR
//config: bool "factor"
//config: default y
//config: help
//config: factor factorizes integers
//applet:IF_FACTOR(APPLET(factor, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_FACTOR) += factor.o
//usage:#define factor_trivial_usage
//usage: "[NUMBER]..."
//usage:#define factor_full_usage "\n\n"
//usage: "Print prime factors"
#include "libbb.h"
#if 0
# define dbg(...) bb_error_msg(__VA_ARGS__)
#else
# define dbg(...) ((void)0)
#endif
typedef unsigned long long wide_t;
#if ULLONG_MAX == (UINT_MAX * UINT_MAX + 2 * UINT_MAX)
/* "unsigned" is half as wide as ullong */
typedef unsigned half_t;
#define HALF_MAX UINT_MAX
#define HALF_FMT ""
#elif ULLONG_MAX == (ULONG_MAX * ULONG_MAX + 2 * ULONG_MAX)
/* long is half as wide as ullong */
typedef unsigned long half_t;
#define HALF_MAX ULONG_MAX
#define HALF_FMT "l"
#else
#error Cant find an integer type which is half as wide as ullong
#endif
static half_t isqrt_odd(wide_t N)
{
half_t s = isqrt(N);
/* Subtract 1 from even s, odd s won't change: */
/* (doesnt work for zero, but we know that s != 0 here) */
s = (s - 1) | 1;
return s;
}
static NOINLINE void factorize(wide_t N)
{
half_t factor;
half_t max_factor;
// unsigned count3;
// unsigned count5;
// unsigned count7;
// ^^^^^^^^^^^^^^^ commented-out simple sieving code (easier to grasp).
// Faster sieving, using one word for potentially up to 6 counters:
// count upwards in each mask, counter "triggers" when it sets its mask to "100[0]..."
// 10987654321098765432109876543210 - bits 31-0 in 32-bit word
// 17777713333311111777775555333 - bit masks for counters for primes 3,5,7,11,13,17
// 100000100001000010001001 - value for adding 1 to each mask
// 10000010000010000100001000100 - value for checking that any mask reached msb
enum {
SHIFT_3 = 1 << 0,
SHIFT_5 = 1 << 3,
SHIFT_7 = 1 << 7,
INCREMENT_EACH = SHIFT_3 | SHIFT_5 | SHIFT_7,
MULTIPLE_OF_3 = 1 << 2,
MULTIPLE_OF_5 = 1 << 6,
MULTIPLE_OF_7 = 1 << 11,
MULTIPLE_DETECTED = MULTIPLE_OF_3 | MULTIPLE_OF_5 | MULTIPLE_OF_7,
};
unsigned sieve_word;
if (N < 4)
goto end;
while (!(N & 1)) {
printf(" 2");
N >>= 1;
}
/* The code needs to be optimized for the case where
* there are large prime factors. For example,
* this is not hard:
* 8262075252869367027 = 3 7 17 23 47 101 113 127 131 137 823
* (the largest factor to test is only ~sqrt(823) = 28)
* but this is:
* 18446744073709551601 = 53 348051774975651917
* the last factor requires testing up to
* 589959129 - about 100 million iterations.
* The slowest case (largest prime) for N < 2^64 is
* factor 18446744073709551557 (0xffffffffffffffc5).
*/
max_factor = isqrt_odd(N);
// count3 = 3;
// count5 = 6;
// count7 = 9;
sieve_word = 0
/* initial count for SHIFT_n is (n-1)/2*3: */
+ (MULTIPLE_OF_3 - 3 * SHIFT_3)
+ (MULTIPLE_OF_5 - 6 * SHIFT_5)
+ (MULTIPLE_OF_7 - 9 * SHIFT_7)
//+ (MULTIPLE_OF_11 - 15 * SHIFT_11)
//+ (MULTIPLE_OF_13 - 18 * SHIFT_13)
//+ (MULTIPLE_OF_17 - 24 * SHIFT_17)
;
factor = 3;
for (;;) {
/* The division is the most costly part of the loop.
* On 64bit CPUs, takes at best 12 cycles, often ~20.
*/
while ((N % factor) == 0) { /* not likely */
N = N / factor;
printf(" %"HALF_FMT"u", factor);
max_factor = isqrt_odd(N);
}
next_factor:
if (factor >= max_factor)
break;
factor += 2;
/* Rudimentary wheel sieving: skip multiples of 3, 5 and 7:
* Every third odd number is divisible by three and thus isn't a prime:
* 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47...
* ^ ^ ^ ^ ^ ^ ^ _ ^ ^ _ ^ ^ ^ ^
* (^ = primes, _ = would-be-primes-if-not-divisible-by-5)
* The numbers with space under them are excluded by sieve 3.
*/
// count7--;
// count5--;
// count3--;
// if (count3 && count5 && count7)
// continue;
sieve_word += INCREMENT_EACH;
if (!(sieve_word & MULTIPLE_DETECTED))
continue;
/*
* "factor" is multiple of 3 33% of the time (count3 reached 0),
* else, multiple of 5 13% of the time,
* else, multiple of 7 7.6% of the time.
* Cumulatively, with 3,5,7 sieving we are here 54.3% of the time.
*/
// if (count3 == 0)
// count3 = 3;
if (sieve_word & MULTIPLE_OF_3)
sieve_word -= SHIFT_3 * 3;
// if (count5 == 0)
// count5 = 5;
if (sieve_word & MULTIPLE_OF_5)
sieve_word -= SHIFT_5 * 5;
// if (count7 == 0)
// count7 = 7;
if (sieve_word & MULTIPLE_OF_7)
sieve_word -= SHIFT_7 * 7;
goto next_factor;
}
end:
if (N > 1)
printf(" %llu", N);
bb_putchar('\n');
}
static void factorize_numstr(const char *numstr)
{
wide_t N;
/* Leading + is ok (coreutils compat) */
if (*numstr == '+')
numstr++;
N = bb_strtoull(numstr, NULL, 10);
if (errno)
bb_show_usage();
printf("%llu:", N);
factorize(N);
}
int factor_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int factor_main(int argc UNUSED_PARAM, char **argv)
{
//// coreutils has undocumented option ---debug (three dashes)
//getopt32(argv, "");
//argv += optind;
argv++;
if (!*argv) {
/* Read from stdin, several numbers per line are accepted */
for (;;) {
char *numstr, *line;
line = xmalloc_fgetline(stdin);
if (!line)
return EXIT_SUCCESS;
numstr = line;
for (;;) {
char *end;
numstr = skip_whitespace(numstr);
if (!numstr[0])
break;
end = skip_non_whitespace(numstr);
if (*end != '\0')
*end++ = '\0';
factorize_numstr(numstr);
numstr = end;
}
free(line);
}
}
do {
/* Leading spaces are ok (coreutils compat) */
factorize_numstr(skip_whitespace(*argv));
} while (*++argv);
return EXIT_SUCCESS;
}
+3 -1
View File
@@ -14,9 +14,11 @@
//config: from files.
//config:
//config:config FEATURE_FANCY_HEAD
//config: bool "Enable -c, -q, and -v"
//config: bool "Enable head options (-c, -q, and -v)"
//config: default y
//config: depends on HEAD
//config: help
//config: This enables the head options (-c, -q, and -v).
//applet:IF_HEAD(APPLET_NOEXEC(head, head, BB_DIR_USR_BIN, BB_SUID_DROP, head))
+2
View File
@@ -15,6 +15,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on INSTALL && LONG_OPTS
//config: help
//config: Support long options for the install applet.
//applet:IF_INSTALL(APPLET(install, BB_DIR_USR_BIN, BB_SUID_DROP))
-41
View File
@@ -1,41 +0,0 @@
/*
* link implementation for busybox
*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config LINK
//config: bool "link"
//config: default y
//config: help
//config: link creates hard links between files.
//applet:IF_LINK(APPLET_NOFORK(link, link, BB_DIR_BIN, BB_SUID_DROP, link))
//kbuild:lib-$(CONFIG_LINK) += link.o
//usage:#define link_trivial_usage
//usage: "FILE LINK"
//usage:#define link_full_usage "\n\n"
//usage: "Create hard LINK to FILE"
#include "libbb.h"
/* This is a NOFORK applet. Be very careful! */
int link_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int link_main(int argc UNUSED_PARAM, char **argv)
{
opt_complementary = "=2"; /* exactly 2 params */
getopt32(argv, "");
argv += optind;
if (link(argv[0], argv[1]) != 0) {
/* shared message */
bb_perror_msg_and_die("can't create %slink "
"%s to %s", "hard",
argv[1], argv[0]
);
}
return EXIT_SUCCESS;
}
+319 -241
View File
@@ -37,21 +37,22 @@
//config: bool "Enable filetyping options (-p and -F)"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls options (-p and -F).
//config:
//config:config FEATURE_LS_FOLLOWLINKS
//config: bool "Enable symlinks dereferencing (-L)"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls option (-L).
//config:
//config:config FEATURE_LS_RECURSIVE
//config: bool "Enable recursion (-R)"
//config: default y
//config: depends on LS
//config:
//config:config FEATURE_LS_WIDTH
//config: bool "Enable -w WIDTH and window size autodetection"
//config: default y
//config: depends on LS
//config: help
//config: Enable the ls option (-R).
//config:
//config:config FEATURE_LS_SORTFILES
//config: bool "Sort the file names"
@@ -101,17 +102,18 @@
//usage: IF_FEATURE_LS_FOLLOWLINKS("LH")
//usage: IF_FEATURE_LS_RECURSIVE("R")
//usage: IF_FEATURE_LS_FILETYPES("Fp") "lins"
//usage: IF_FEATURE_LS_TIMESTAMPS("e")
//usage: IF_FEATURE_HUMAN_READABLE("h")
//usage: IF_FEATURE_LS_SORTFILES("rSXv")
//usage: IF_FEATURE_LS_TIMESTAMPS("ctu")
//usage: IF_SELINUX("kZ") "]"
//usage: IF_FEATURE_LS_WIDTH(" [-w WIDTH]") " [FILE]..."
//usage: IF_SELINUX("kKZ") "]"
//usage: IF_FEATURE_AUTOWIDTH(" [-w WIDTH]") " [FILE]..."
//usage:#define ls_full_usage "\n\n"
//usage: "List directory contents\n"
//usage: "\n -1 One column output"
//usage: "\n -a Include entries which start with ."
//usage: "\n -A Like -a, but exclude . and .."
////usage: "\n -C List by columns" - don't show, this is a default anyway
//usage: "\n -C List by columns"
//usage: "\n -x List by lines"
//usage: "\n -d List directory entries instead of contents"
//usage: IF_FEATURE_LS_FOLLOWLINKS(
@@ -130,34 +132,29 @@
//usage: "\n -n List numeric UIDs and GIDs instead of names"
//usage: "\n -s List allocated blocks"
//usage: IF_FEATURE_LS_TIMESTAMPS(
//usage: "\n -lc List ctime"
//usage: "\n -lu List atime"
//usage: "\n -e List full date and time"
//usage: )
//usage: IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(
//usage: "\n --full-time List full date and time"
//usage: ))
//usage: IF_FEATURE_HUMAN_READABLE(
//usage: "\n -h Human readable sizes (1K 243M 2G)"
//usage: "\n -h List sizes in human readable format (1K 243M 2G)"
//usage: )
//usage: IF_FEATURE_LS_SORTFILES(
//usage: IF_LONG_OPTS(
//usage: "\n --group-directories-first"
//usage: )
//usage: "\n -r Sort in reverse order"
//usage: "\n -S Sort by size"
//usage: "\n -X Sort by extension"
//usage: "\n -v Sort by version"
//usage: )
//usage: IF_FEATURE_LS_TIMESTAMPS(
//usage: "\n -t Sort by mtime"
//usage: "\n -tc Sort by ctime"
//usage: "\n -tu Sort by atime"
//usage: "\n -c With -l: sort by ctime"
//usage: "\n -t With -l: sort by mtime"
//usage: "\n -u With -l: sort by atime"
//usage: )
//usage: "\n -r Reverse sort order"
//usage: IF_SELINUX(
//usage: "\n -k List security context"
//usage: "\n -K List security context in long format"
//usage: "\n -Z List security context and permission"
//usage: )
//usage: IF_FEATURE_LS_WIDTH(
//usage: "\n -w N Format N columns wide"
//usage: IF_FEATURE_AUTOWIDTH(
//usage: "\n -w N Assume the terminal is N columns wide"
//usage: )
//usage: IF_FEATURE_LS_COLOR(
//usage: "\n --color[={always,never,auto}] Control coloring"
@@ -192,90 +189,187 @@ TERMINAL_WIDTH = 80, /* use 79 if terminal has linefold bug */
SPLIT_FILE = 0,
SPLIT_DIR = 1,
SPLIT_SUBDIR = 2,
/* Bits in G.all_fmt: */
/* 51306 lrwxrwxrwx 1 root root 2 May 11 01:43 /bin/view -> vi* */
/* what file information will be listed */
LIST_INO = 1 << 0,
LIST_BLOCKS = 1 << 1,
LIST_MODEBITS = 1 << 2,
LIST_NLINKS = 1 << 3,
LIST_ID_NAME = 1 << 4,
LIST_ID_NUMERIC = 1 << 5,
LIST_CONTEXT = 1 << 6,
LIST_SIZE = 1 << 7,
LIST_DATE_TIME = 1 << 8,
LIST_FULLTIME = 1 << 9,
LIST_SYMLINK = 1 << 10,
LIST_FILETYPE = 1 << 11, /* show / suffix for dirs */
LIST_CLASSIFY = 1 << 12, /* requires LIST_FILETYPE, also show *,|,@,= suffixes */
LIST_MASK = (LIST_CLASSIFY << 1) - 1,
/* what files will be displayed */
DISP_DIRNAME = 1 << 13, /* 2 or more items? label directories */
DISP_HIDDEN = 1 << 14, /* show filenames starting with . */
DISP_DOT = 1 << 15, /* show . and .. */
DISP_NOLIST = 1 << 16, /* show directory as itself, not contents */
DISP_RECURSIVE = 1 << 17, /* show directory and everything below it */
DISP_ROWS = 1 << 18, /* print across rows */
DISP_MASK = ((DISP_ROWS << 1) - 1) & ~(DISP_DIRNAME - 1),
/* what is the overall style of the listing */
STYLE_COLUMNAR = 1 << 19, /* many records per line */
STYLE_LONG = 2 << 19, /* one record per line, extended info */
STYLE_SINGLE = 3 << 19, /* one record per line */
STYLE_MASK = STYLE_SINGLE,
/* which of the three times will be used */
TIME_CHANGE = (1 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_ACCESS = (2 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
TIME_MASK = (3 << 21) * ENABLE_FEATURE_LS_TIMESTAMPS,
/* how will the files be sorted (CONFIG_FEATURE_LS_SORTFILES) */
SORT_REVERSE = 1 << 23,
SORT_NAME = 0, /* sort by file name */
SORT_SIZE = 1 << 24, /* sort by file size */
SORT_ATIME = 2 << 24, /* sort by last access time */
SORT_CTIME = 3 << 24, /* sort by last change time */
SORT_MTIME = 4 << 24, /* sort by last modification time */
SORT_VERSION = 5 << 24, /* sort by version */
SORT_EXT = 6 << 24, /* sort by file name extension */
SORT_DIR = 7 << 24, /* sort by file or directory */
SORT_MASK = (7 << 24) * ENABLE_FEATURE_LS_SORTFILES,
LIST_LONG = LIST_MODEBITS | LIST_NLINKS | LIST_ID_NAME | LIST_SIZE | \
LIST_DATE_TIME | LIST_SYMLINK,
};
/* -Cadi1l Std options, busybox always supports */
/* -Cadil1 Std options, busybox always supports */
/* -gnsxA Std options, busybox always supports */
/* -Q GNU option, busybox always supports */
/* -k Std option, busybox always supports (by ignoring) */
/* It means "for -s, show sizes in kbytes" */
/* Seems to only affect "POSIXLY_CORRECT=1 ls -sk" */
/* since otherwise -s shows kbytes anyway */
/* -k SELinux option, busybox always supports (ignores if !SELinux) */
/* Std has -k which means "show sizes in kbytes" */
/* -LHRctur Std options, busybox optionally supports */
/* -Fp Std options, busybox optionally supports */
/* -SXvhTw GNU options, busybox optionally supports */
/* -T WIDTH Ignored (we don't use tabs on output) */
/* -Z SELinux mandated option, busybox optionally supports */
/* -KZ SELinux mandated options, busybox optionally supports */
/* (coreutils 8.4 has no -K, remove it?) */
/* -e I think we made this one up (looks similar to GNU --full-time) */
/* We already used up all 32 bits, if we need to add more, candidates for removal: */
/* -K, -T, -e (add --full-time instead) */
static const char ls_options[] ALIGN1 =
"Cadi1lgnsxAk" /* 12 opts, total 12 */
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 14 */
IF_FEATURE_LS_RECURSIVE("R") /* 1, 15 */
IF_SELINUX("Z") /* 1, 16 */
"Q" /* 1, 17 */
IF_FEATURE_LS_TIMESTAMPS("ctu") /* 3, 20 */
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 24 */
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 26 */
IF_FEATURE_HUMAN_READABLE("h") /* 1, 27 */
IF_FEATURE_LS_WIDTH("T:w:") /* 2, 29 */
;
"Cadil1gnsxQAk" /* 13 opts, total 13 */
IF_FEATURE_LS_TIMESTAMPS("cetu") /* 4, 17 */
IF_FEATURE_LS_SORTFILES("SXrv") /* 4, 21 */
IF_FEATURE_LS_FILETYPES("Fp") /* 2, 23 */
IF_FEATURE_LS_RECURSIVE("R") /* 1, 24 */
IF_SELINUX("KZ") /* 2, 26 */
IF_FEATURE_LS_FOLLOWLINKS("LH") /* 2, 28 */
IF_FEATURE_HUMAN_READABLE("h") /* 1, 29 */
IF_FEATURE_AUTOWIDTH("T:w:") /* 2, 31 */
/* with --color, we use all 32 bits */;
enum {
OPT_C = (1 << 0),
OPT_a = (1 << 1),
OPT_d = (1 << 2),
OPT_i = (1 << 3),
OPT_1 = (1 << 4),
OPT_l = (1 << 5),
//OPT_C = (1 << 0),
//OPT_a = (1 << 1),
//OPT_d = (1 << 2),
//OPT_i = (1 << 3),
//OPT_l = (1 << 4),
//OPT_1 = (1 << 5),
OPT_g = (1 << 6),
OPT_n = (1 << 7),
OPT_s = (1 << 8),
OPT_x = (1 << 9),
OPT_A = (1 << 10),
//OPT_k = (1 << 11),
//OPT_n = (1 << 7),
//OPT_s = (1 << 8),
//OPT_x = (1 << 9),
OPT_Q = (1 << 10),
//OPT_A = (1 << 11),
//OPT_k = (1 << 12),
OPTBIT_F = 12,
OPTBIT_p, /* 13 */
OPTBIT_c = 13,
OPTBIT_e,
OPTBIT_t,
OPTBIT_u,
OPTBIT_S = OPTBIT_c + 4 * ENABLE_FEATURE_LS_TIMESTAMPS,
OPTBIT_X, /* 18 */
OPTBIT_r,
OPTBIT_v,
OPTBIT_F = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
OPTBIT_p, /* 22 */
OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES,
OPTBIT_Z = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
OPTBIT_Q = OPTBIT_Z + 1 * ENABLE_SELINUX,
OPTBIT_c, /* 17 */
OPTBIT_t, /* 18 */
OPTBIT_u, /* 19 */
OPTBIT_S = OPTBIT_c + 3 * ENABLE_FEATURE_LS_TIMESTAMPS,
OPTBIT_X, /* 21 */
OPTBIT_r, /* 22 */
OPTBIT_v, /* 23 */
OPTBIT_L = OPTBIT_S + 4 * ENABLE_FEATURE_LS_SORTFILES,
OPTBIT_H, /* 25 */
OPTBIT_K = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
OPTBIT_Z, /* 25 */
OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX,
OPTBIT_H, /* 27 */
OPTBIT_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
OPTBIT_w, /* 28 */
OPTBIT_full_time = OPTBIT_T + 2 * ENABLE_FEATURE_LS_WIDTH,
OPTBIT_dirs_first,
OPTBIT_color, /* 31 */
/* with long opts, we use all 32 bits */
OPTBIT_w, /* 30 */
OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH,
OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
OPT_R = (1 << OPTBIT_R) * ENABLE_FEATURE_LS_RECURSIVE,
OPT_Z = (1 << OPTBIT_Z) * ENABLE_SELINUX,
OPT_Q = (1 << OPTBIT_Q),
OPT_c = (1 << OPTBIT_c) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_e = (1 << OPTBIT_e) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_t = (1 << OPTBIT_t) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_u = (1 << OPTBIT_u) * ENABLE_FEATURE_LS_TIMESTAMPS,
OPT_S = (1 << OPTBIT_S) * ENABLE_FEATURE_LS_SORTFILES,
OPT_X = (1 << OPTBIT_X) * ENABLE_FEATURE_LS_SORTFILES,
OPT_r = (1 << OPTBIT_r) * ENABLE_FEATURE_LS_SORTFILES,
OPT_v = (1 << OPTBIT_v) * ENABLE_FEATURE_LS_SORTFILES,
OPT_F = (1 << OPTBIT_F) * ENABLE_FEATURE_LS_FILETYPES,
OPT_p = (1 << OPTBIT_p) * ENABLE_FEATURE_LS_FILETYPES,
OPT_R = (1 << OPTBIT_R) * ENABLE_FEATURE_LS_RECURSIVE,
OPT_K = (1 << OPTBIT_K) * ENABLE_SELINUX,
OPT_Z = (1 << OPTBIT_Z) * ENABLE_SELINUX,
OPT_L = (1 << OPTBIT_L) * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPT_H = (1 << OPTBIT_H) * ENABLE_FEATURE_LS_FOLLOWLINKS,
OPT_h = (1 << OPTBIT_h) * ENABLE_FEATURE_HUMAN_READABLE,
OPT_T = (1 << OPTBIT_T) * ENABLE_FEATURE_LS_WIDTH,
OPT_w = (1 << OPTBIT_w) * ENABLE_FEATURE_LS_WIDTH,
OPT_full_time = (1 << OPTBIT_full_time ) * ENABLE_LONG_OPTS,
OPT_dirs_first = (1 << OPTBIT_dirs_first) * ENABLE_LONG_OPTS,
OPT_color = (1 << OPTBIT_color ) * ENABLE_FEATURE_LS_COLOR,
OPT_T = (1 << OPTBIT_T) * ENABLE_FEATURE_AUTOWIDTH,
OPT_w = (1 << OPTBIT_w) * ENABLE_FEATURE_AUTOWIDTH,
OPT_color = (1 << OPTBIT_color) * ENABLE_FEATURE_LS_COLOR,
};
/* TODO: simple toggles may be stored as OPT_xxx bits instead */
static const uint32_t opt_flags[] = {
STYLE_COLUMNAR, /* C */
DISP_HIDDEN | DISP_DOT, /* a */
DISP_NOLIST, /* d */
LIST_INO, /* i */
LIST_LONG | STYLE_LONG, /* l */
STYLE_SINGLE, /* 1 */
LIST_LONG | STYLE_LONG, /* g (don't show owner) - handled via OPT_g. assumes l */
LIST_ID_NUMERIC | LIST_LONG | STYLE_LONG, /* n (assumes l) */
LIST_BLOCKS, /* s */
DISP_ROWS | STYLE_COLUMNAR, /* x */
0, /* Q (quote filename) - handled via OPT_Q */
DISP_HIDDEN, /* A */
ENABLE_SELINUX * (LIST_CONTEXT|STYLE_SINGLE), /* k (ignored if !SELINUX) */
#if ENABLE_FEATURE_LS_TIMESTAMPS
TIME_CHANGE | (ENABLE_FEATURE_LS_SORTFILES * SORT_CTIME), /* c */
LIST_FULLTIME, /* e */
ENABLE_FEATURE_LS_SORTFILES * SORT_MTIME, /* t */
TIME_ACCESS | (ENABLE_FEATURE_LS_SORTFILES * SORT_ATIME), /* u */
#endif
#if ENABLE_FEATURE_LS_SORTFILES
SORT_SIZE, /* S */
SORT_EXT, /* X */
SORT_REVERSE, /* r */
SORT_VERSION, /* v */
#endif
#if ENABLE_FEATURE_LS_FILETYPES
LIST_FILETYPE | LIST_CLASSIFY, /* F */
LIST_FILETYPE, /* p */
#endif
#if ENABLE_FEATURE_LS_RECURSIVE
DISP_RECURSIVE, /* R */
#endif
#if ENABLE_SELINUX
LIST_MODEBITS|LIST_NLINKS|LIST_CONTEXT|LIST_SIZE|LIST_DATE_TIME|STYLE_SINGLE, /* K */
LIST_MODEBITS|LIST_ID_NAME|LIST_CONTEXT|STYLE_SINGLE, /* Z */
#endif
(1U << 31)
/* options after Z are not processed through opt_flags */
};
/*
* a directory entry and its stat info
*/
@@ -305,7 +399,9 @@ struct dnode {
mode_t dn_mode; /* obtained with lstat OR stat, depending on -L etc */
off_t dn_size;
#if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES
time_t dn_time;
time_t dn_atime;
time_t dn_mtime;
time_t dn_ctime;
#endif
ino_t dn_ino;
blkcnt_t dn_blocks;
@@ -326,8 +422,8 @@ struct globals {
# define G_show_color 0
#endif
smallint exit_code;
smallint show_dirname;
#if ENABLE_FEATURE_LS_WIDTH
unsigned all_fmt;
#if ENABLE_FEATURE_AUTOWIDTH
unsigned terminal_width;
# define G_terminal_width (G.terminal_width)
#else
@@ -343,7 +439,7 @@ struct globals {
setup_common_bufsiz(); \
/* we have to zero it out because of NOEXEC */ \
memset(&G, 0, sizeof(G)); \
IF_FEATURE_LS_WIDTH(G_terminal_width = TERMINAL_WIDTH;) \
IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
} while (0)
@@ -400,12 +496,11 @@ static char bold(mode_t mode)
#if ENABLE_FEATURE_LS_FILETYPES
static char append_char(mode_t mode)
{
if (!(option_mask32 & (OPT_F|OPT_p)))
if (!(G.all_fmt & LIST_FILETYPE))
return '\0';
if (S_ISDIR(mode))
return '/';
if (!(option_mask32 & OPT_F))
if (!(G.all_fmt & LIST_CLASSIFY))
return '\0';
if (S_ISREG(mode) && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
return '*';
@@ -436,8 +531,8 @@ static unsigned calc_name_len(const char *name)
}
/* Return the number of used columns.
* Note that only columnar output uses return value.
* -l and -1 modes don't care.
* Note that only STYLE_COLUMNAR uses return value.
* STYLE_SINGLE and STYLE_LONG don't care.
* coreutils 7.2 also supports:
* ls -b (--escape) = octal escapes (although it doesn't look like working)
* ls -N (--literal) = not escape at all
@@ -470,14 +565,13 @@ static unsigned print_name(const char *name)
}
/* Return the number of used columns.
* Note that only columnar output uses return value,
* -l and -1 modes don't care.
* Note that only STYLE_COLUMNAR uses return value,
* STYLE_SINGLE and STYLE_LONG don't care.
*/
static NOINLINE unsigned display_single(const struct dnode *dn)
{
unsigned column = 0;
char *lpath;
int opt;
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
struct stat statbuf;
char append;
@@ -486,61 +580,50 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
#if ENABLE_FEATURE_LS_FILETYPES
append = append_char(dn->dn_mode);
#endif
opt = option_mask32;
/* Do readlink early, so that if it fails, error message
* does not appear *inside* the "ls -l" line */
lpath = NULL;
if (opt & OPT_l)
if (G.all_fmt & LIST_SYMLINK)
if (S_ISLNK(dn->dn_mode))
lpath = xmalloc_readlink_or_warn(dn->fullname);
if (opt & OPT_i) /* show inode# */
if (G.all_fmt & LIST_INO)
column += printf("%7llu ", (long long) dn->dn_ino);
//TODO: -h should affect -s too:
if (opt & OPT_s) /* show allocated blocks */
if (G.all_fmt & LIST_BLOCKS)
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
if (opt & OPT_l) {
/* long listing: show mode */
if (G.all_fmt & LIST_MODEBITS)
column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
/* long listing: show number of links */
if (G.all_fmt & LIST_NLINKS)
column += printf("%4lu ", (long) dn->dn_nlink);
/* long listing: show user/group */
if (opt & OPT_n) {
if (opt & OPT_g)
column += printf("%-8u ", (int) dn->dn_gid);
else
column += printf("%-8u %-8u ",
(int) dn->dn_uid,
(int) dn->dn_gid);
}
if (G.all_fmt & LIST_ID_NUMERIC) {
if (option_mask32 & OPT_g)
column += printf("%-8u ", (int) dn->dn_gid);
else
column += printf("%-8u %-8u ",
(int) dn->dn_uid,
(int) dn->dn_gid);
}
#if ENABLE_FEATURE_LS_USERNAME
else {
if (opt & OPT_g) {
column += printf("%-8.8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
}
else if (G.all_fmt & LIST_ID_NAME) {
if (option_mask32 & OPT_g) {
column += printf("%-8.8s ",
get_cached_groupname(dn->dn_gid));
} else {
column += printf("%-8.8s %-8.8s ",
get_cached_username(dn->dn_uid),
get_cached_groupname(dn->dn_gid));
}
#endif
#if ENABLE_SELINUX
}
if (opt & OPT_Z) {
column += printf("%-32s ", dn->sid ? dn->sid : "?");
freecon(dn->sid);
}
if (opt & OPT_l) {
#endif
/* long listing: show size */
if (G.all_fmt & LIST_SIZE) {
if (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) {
column += printf("%4u, %3u ",
dn->dn_rdev_maj,
dn->dn_rdev_min);
} else {
if (opt & OPT_h) {
if (option_mask32 & OPT_h) {
column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
/* print size, show one fractional, use suffixes */
make_human_readable_str(dn->dn_size, 1, 0)
@@ -549,22 +632,25 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
column += printf("%9"OFF_FMT"u ", dn->dn_size);
}
}
}
#if ENABLE_FEATURE_LS_TIMESTAMPS
/* long listing: show {m,c,a}time */
if (opt & OPT_full_time) { /* --full-time */
/* coreutils 8.4 ls --full-time prints:
if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
char *filetime;
const time_t *ttime = &dn->dn_mtime;
if (G.all_fmt & TIME_ACCESS)
ttime = &dn->dn_atime;
if (G.all_fmt & TIME_CHANGE)
ttime = &dn->dn_ctime;
filetime = ctime(ttime);
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
if (G.all_fmt & LIST_FULLTIME) { /* -e */
/* Note: coreutils 8.4 ls --full-time prints:
* 2009-07-13 17:49:27.000000000 +0200
* we don't show fractional seconds.
*/
char buf[sizeof("YYYY-mm-dd HH:MM:SS TIMEZONE")];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %z",
localtime(&dn->dn_time));
column += printf("%s ", buf);
} else { /* ordinary time format */
/* G.current_time_t is ~== time(NULL) */
char *filetime = ctime(&dn->dn_time);
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
time_t age = G.current_time_t - dn->dn_time;
column += printf("%.24s ", filetime);
} else { /* LIST_DATE_TIME */
/* G.current_time_t ~== time(NULL) */
time_t age = G.current_time_t - *ttime;
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
/* less than 6 months old */
/* "mmm dd hh:mm " */
@@ -577,8 +663,14 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
}
column += 13;
}
#endif
}
#endif
#if ENABLE_SELINUX
if (G.all_fmt & LIST_CONTEXT) {
column += printf("%-32s ", dn->sid ? dn->sid : "unknown");
freecon(dn->sid);
}
#endif
#if ENABLE_FEATURE_LS_COLOR
if (G_show_color) {
@@ -597,9 +689,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
if (lpath) {
printf(" -> ");
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
if ((opt & (OPT_F|OPT_p))
|| G_show_color
) {
if ((G.all_fmt & LIST_FILETYPE) || G_show_color) {
mode_t mode = dn->dn_mode_stat;
if (!mode)
if (stat(dn->fullname, &statbuf) == 0)
@@ -621,7 +711,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
}
}
#if ENABLE_FEATURE_LS_FILETYPES
if (opt & (OPT_F|OPT_p)) {
if (G.all_fmt & LIST_FILETYPE) {
if (append) {
putchar(append);
column++;
@@ -637,9 +727,9 @@ static void display_files(struct dnode **dn, unsigned nfiles)
unsigned i, ncols, nrows, row, nc;
unsigned column;
unsigned nexttab;
unsigned column_width = 0; /* used only by coulmnal output */
unsigned column_width = 0; /* used only by STYLE_COLUMNAR */
if (option_mask32 & (OPT_l|OPT_1)) {
if (G.all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */
ncols = 1;
} else {
/* find the longest file name, use that as the column width */
@@ -648,11 +738,10 @@ static void display_files(struct dnode **dn, unsigned nfiles)
if (column_width < len)
column_width = len;
}
column_width += 2
+ ((option_mask32 & OPT_Z) ? 33 : 0) /* context width */
+ ((option_mask32 & OPT_i) ? 8 : 0) /* inode# width */
+ ((option_mask32 & OPT_s) ? 5 : 0) /* "alloc block" width */
;
column_width += 2 +
IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + )
((G.all_fmt & LIST_INO) ? 8 : 0) +
((G.all_fmt & LIST_BLOCKS) ? 5 : 0);
ncols = (unsigned)G_terminal_width / column_width;
}
@@ -670,7 +759,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
for (row = 0; row < nrows; row++) {
for (nc = 0; nc < ncols; nc++) {
/* reach into the array based on the column and row */
if (option_mask32 & OPT_x)
if (G.all_fmt & DISP_ROWS)
i = (row * ncols) + nc; /* display across row */
else
i = (nc * nrows) + row; /* display by column */
@@ -703,7 +792,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
if ((option_mask32 & OPT_L) || force_follow) {
#if ENABLE_SELINUX
if (option_mask32 & OPT_Z) {
if (is_selinux_enabled()) {
getfilecon(fullname, &cur->sid);
}
#endif
@@ -716,7 +805,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
cur->dn_mode_stat = statbuf.st_mode;
} else {
#if ENABLE_SELINUX
if (option_mask32 & OPT_Z) {
if (is_selinux_enabled()) {
lgetfilecon(fullname, &cur->sid);
}
#endif
@@ -733,11 +822,9 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
cur->dn_mode = statbuf.st_mode ;
cur->dn_size = statbuf.st_size ;
#if ENABLE_FEATURE_LS_TIMESTAMPS || ENABLE_FEATURE_LS_SORTFILES
cur->dn_time = statbuf.st_mtime ;
if (option_mask32 & OPT_u)
cur->dn_time = statbuf.st_atime;
if (option_mask32 & OPT_c)
cur->dn_time = statbuf.st_ctime;
cur->dn_atime = statbuf.st_atime ;
cur->dn_mtime = statbuf.st_mtime ;
cur->dn_ctime = statbuf.st_ctime ;
#endif
cur->dn_ino = statbuf.st_ino ;
cur->dn_blocks = statbuf.st_blocks;
@@ -851,30 +938,33 @@ static int sortcmp(const void *a, const void *b)
{
struct dnode *d1 = *(struct dnode **)a;
struct dnode *d2 = *(struct dnode **)b;
unsigned opt = option_mask32;
unsigned sort_opts = G.all_fmt & SORT_MASK;
off_t dif;
dif = 0; /* assume sort by name */
dif = 0; /* assume SORT_NAME */
// TODO: use pre-initialized function pointer
// instead of branch forest
if (opt & OPT_dirs_first) {
dif = S_ISDIR(d2->dn_mode) - S_ISDIR(d1->dn_mode);
if (dif != 0)
goto maybe_invert_and_ret;
}
if (opt & OPT_S) { /* sort by size */
if (sort_opts == SORT_SIZE) {
dif = (d2->dn_size - d1->dn_size);
} else
if (opt & OPT_t) { /* sort by time */
dif = (d2->dn_time - d1->dn_time);
if (sort_opts == SORT_ATIME) {
dif = (d2->dn_atime - d1->dn_atime);
} else
if (sort_opts == SORT_CTIME) {
dif = (d2->dn_ctime - d1->dn_ctime);
} else
if (sort_opts == SORT_MTIME) {
dif = (d2->dn_mtime - d1->dn_mtime);
} else
if (sort_opts == SORT_DIR) {
dif = S_ISDIR(d2->dn_mode) - S_ISDIR(d1->dn_mode);
} else
#if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1
if (opt & OPT_v) { /* sort by version */
if (sort_opts == SORT_VERSION) {
dif = strverscmp(d1->name, d2->name);
} else
#endif
if (opt & OPT_X) { /* sort by extension */
if (sort_opts == SORT_EXT) {
dif = strcmp(strchrnul(d1->name, '.'), strchrnul(d2->name, '.'));
}
if (dif == 0) {
@@ -883,17 +973,18 @@ static int sortcmp(const void *a, const void *b)
dif = strcoll(d1->name, d2->name);
else
dif = strcmp(d1->name, d2->name);
} else {
/* Make dif fit into an int */
if (sizeof(dif) > sizeof(int)) {
enum { BITS_TO_SHIFT = 8 * (sizeof(dif) - sizeof(int)) };
/* shift leaving only "int" worth of bits */
/* (this requires dif != 0, and here it is nonzero) */
}
/* Make dif fit into an int */
if (sizeof(dif) > sizeof(int)) {
enum { BITS_TO_SHIFT = 8 * (sizeof(dif) - sizeof(int)) };
/* shift leaving only "int" worth of bits */
if (dif != 0) {
dif = 1 | (int)((uoff_t)dif >> BITS_TO_SHIFT);
}
}
maybe_invert_and_ret:
return (opt & OPT_r) ? -(int)dif : (int)dif;
return (G.all_fmt & SORT_REVERSE) ? -(int)dif : (int)dif;
}
static void dnsort(struct dnode **dn, int size)
@@ -932,13 +1023,13 @@ static struct dnode **scan_one_dir(const char *path, unsigned *nfiles_p)
/* are we going to list the file- it may be . or .. or a hidden file */
if (entry->d_name[0] == '.') {
if (!(option_mask32 & (OPT_a|OPT_A)))
continue; /* skip all dotfiles if no -a/-A */
if (!(option_mask32 & OPT_a)
&& (!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2]))
if ((!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2]))
&& !(G.all_fmt & DISP_DOT)
) {
continue; /* if only -A, skip . and .. but show other dotfiles */
continue;
}
if (!(G.all_fmt & DISP_HIDDEN))
continue;
}
fullname = concat_path_file(path, entry->d_name);
cur = my_stat(fullname, bb_basename(fullname), 0);
@@ -1006,7 +1097,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
struct dnode **subdnp;
for (; *dn; dn++) {
if (G.show_dirname || (option_mask32 & OPT_R)) {
if (G.all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
if (!first)
bb_putchar('\n');
first = 0;
@@ -1014,16 +1105,15 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
}
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
#if ENABLE_DESKTOP
if (option_mask32 & (OPT_s|OPT_l)) {
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
}
#endif
if (nfiles > 0) {
/* list all files at this level */
sort_and_display_files(subdnp, nfiles);
if (ENABLE_FEATURE_LS_RECURSIVE
&& (option_mask32 & OPT_R)
&& (G.all_fmt & DISP_RECURSIVE)
) {
struct dnode **dnd;
unsigned dndirs;
@@ -1045,7 +1135,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
int ls_main(int argc UNUSED_PARAM, char **argv)
{ /* ^^^^^^^^^^^^^^^^^ note: if FTPD, argc can be wrong, see ftpd.c */
{
struct dnode **dnd;
struct dnode **dnf;
struct dnode **dnp;
@@ -1067,25 +1157,23 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
* 'auto', 'tty', 'if-tty'
* (and substrings: "--color=alwa" work too)
*/
static const char ls_longopts[] ALIGN1 =
"color\0" Optional_argument "\xff"; /* no short equivalent */
static const char color_str[] ALIGN1 =
"always\0""yes\0""force\0"
"auto\0""tty\0""if-tty\0";
/* need to initialize since --color has _an optional_ argument */
const char *color_opt = color_str; /* "always" */
#endif
#if ENABLE_LONG_OPTS
static const char ls_longopts[] ALIGN1 =
"full-time\0" No_argument "\xff"
"group-directories-first\0" No_argument "\xfe"
"color\0" Optional_argument "\xfd"
;
#endif
INIT_G();
init_unicode();
#if ENABLE_FEATURE_LS_WIDTH
if (ENABLE_FEATURE_LS_SORTFILES)
G.all_fmt = SORT_NAME;
#if ENABLE_FEATURE_AUTOWIDTH
/* obtain the terminal width */
G_terminal_width = get_terminal_width(STDIN_FILENO);
/* go one less... */
@@ -1093,12 +1181,10 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#endif
/* process options */
IF_LONG_OPTS(applet_long_options = ls_longopts;)
IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
opt_complementary =
/* -n and -g imply -l */
"nl:gl"
/* --full-time implies -l */
IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l"))
/* -e implies -l */
IF_FEATURE_LS_TIMESTAMPS("el")
/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html:
* in some pairs of opts, only last one takes effect:
*/
@@ -1110,28 +1196,25 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
":x-1:1-x" /* bylines/oneline (not in SuS, but in GNU coreutils 8.4) */
IF_FEATURE_LS_TIMESTAMPS(":c-u:u-c") /* mtime/atime */
/* -w NUM: */
IF_FEATURE_LS_WIDTH(":w+");
IF_FEATURE_AUTOWIDTH(":w+");
opt = getopt32(argv, ls_options
IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
IF_FEATURE_AUTOWIDTH(, NULL, &G_terminal_width)
IF_FEATURE_LS_COLOR(, &color_opt)
);
#if 0 /* option bits debug */
bb_error_msg("opt:0x%08x l:%x H:%x color:%x dirs:%x", opt, OPT_l, OPT_H, OPT_color, OPT_dirs_first);
if (opt & OPT_c ) bb_error_msg("-c");
if (opt & OPT_l ) bb_error_msg("-l");
if (opt & OPT_H ) bb_error_msg("-H");
if (opt & OPT_color ) bb_error_msg("--color");
if (opt & OPT_dirs_first) bb_error_msg("--group-directories-first");
if (opt & OPT_full_time ) bb_error_msg("--full-time");
exit(0);
#endif
for (i = 0; opt_flags[i] != (1U << 31); i++) {
if (opt & (1 << i)) {
uint32_t flags = opt_flags[i];
#if ENABLE_SELINUX
if (opt & OPT_Z) {
if (!is_selinux_enabled())
option_mask32 &= ~OPT_Z;
if (flags & STYLE_MASK)
G.all_fmt &= ~STYLE_MASK;
if (flags & SORT_MASK)
G.all_fmt &= ~SORT_MASK;
if (flags & TIME_MASK)
G.all_fmt &= ~TIME_MASK;
G.all_fmt |= flags;
}
}
#endif
#if ENABLE_FEATURE_LS_COLOR
/* set G_show_color = 1/0 */
@@ -1159,35 +1242,27 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
#endif
/* sort out which command line options take precedence */
if (ENABLE_FEATURE_LS_RECURSIVE && (opt & OPT_d))
option_mask32 &= ~OPT_R; /* no recurse if listing only dir */
if (!(opt & OPT_l)) { /* not -l? */
if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
/* when to sort by time? -t[cu] sorts by time even with -l */
/* (this is achieved by opt_flags[] element for -t) */
/* without -l, bare -c or -u enable sort too */
/* (with -l, bare -c or -u just select which time to show) */
if (opt & (OPT_c|OPT_u)) {
option_mask32 |= OPT_t;
}
}
if (ENABLE_FEATURE_LS_RECURSIVE && (G.all_fmt & DISP_NOLIST))
G.all_fmt &= ~DISP_RECURSIVE; /* no recurse if listing only dir */
if (ENABLE_FEATURE_LS_TIMESTAMPS && ENABLE_FEATURE_LS_SORTFILES) {
if (G.all_fmt & TIME_CHANGE)
G.all_fmt = (G.all_fmt & ~SORT_MASK) | SORT_CTIME;
if (G.all_fmt & TIME_ACCESS)
G.all_fmt = (G.all_fmt & ~SORT_MASK) | SORT_ATIME;
}
if ((G.all_fmt & STYLE_MASK) != STYLE_LONG) /* not -l? */
G.all_fmt &= ~(LIST_ID_NUMERIC|LIST_ID_NAME|LIST_FULLTIME);
/* choose a display format if one was not already specified by an option */
if (!(option_mask32 & (OPT_l|OPT_1|OPT_x|OPT_C)))
option_mask32 |= (isatty(STDOUT_FILENO) ? OPT_C : OPT_1);
if (ENABLE_FTPD && applet_name[0] == 'f') {
/* ftpd secret backdoor. dirs first are much nicer */
option_mask32 |= OPT_dirs_first;
}
if (!(G.all_fmt & STYLE_MASK))
G.all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNAR : STYLE_SINGLE);
argv += optind;
if (!argv[0])
*--argv = (char*)".";
if (argv[1])
G.show_dirname = 1; /* 2 or more items? label directories */
G.all_fmt |= DISP_DIRNAME; /* 2 or more items? label directories */
/* stuff the command line file names into a dnode array */
dn = NULL;
@@ -1195,7 +1270,10 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
do {
cur = my_stat(*argv, *argv,
/* follow links on command line unless -l, -s or -F: */
!(option_mask32 & (OPT_l|OPT_s|OPT_F))
!((G.all_fmt & STYLE_MASK) == STYLE_LONG
|| (G.all_fmt & LIST_BLOCKS)
|| (option_mask32 & OPT_F)
)
/* ... or if -H: */
|| (option_mask32 & OPT_H)
/* ... or if -L, but my_stat always follows links if -L */
@@ -1224,7 +1302,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
break;
}
if (option_mask32 & OPT_d) {
if (G.all_fmt & DISP_NOLIST) {
sort_and_display_files(dnp, nfiles);
} else {
dnd = splitdnarray(dnp, SPLIT_DIR);
+2 -1
View File
@@ -45,6 +45,7 @@
//config: help
//config: Enabling the -c options allows files to be checked
//config: against pre-calculated hash values.
//config:
//config: -s and -w are useful options when verifying checksums.
//applet:IF_MD5SUM(APPLET_NOEXEC(md5sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, md5sum))
@@ -166,7 +167,7 @@ static uint8_t *hash_file(const char *filename, unsigned sha3_width)
} context;
uint8_t *hash_value;
void FAST_FUNC (*update)(void*, const void*, size_t);
unsigned FAST_FUNC (*final)(void*, void*);
void FAST_FUNC (*final)(void*, void*);
char hash_algo;
src_fd = open_or_warn_stdin(filename);
+2
View File
@@ -23,6 +23,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on MKDIR && LONG_OPTS
//config: help
//config: Support long options for the mkdir applet.
//applet:IF_MKDIR(APPLET_NOFORK(mkdir, mkdir, BB_DIR_BIN, BB_SUID_DROP, mkdir))
+2
View File
@@ -21,6 +21,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on MV && LONG_OPTS
//config: help
//config: Support long options for the mv applet.
//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
-101
View File
@@ -1,101 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config NL
//config: bool "nl"
//config: default y
//config: help
//config: nl is used to number lines of files.
//applet:IF_NL(APPLET(nl, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NL) += nl.o
//usage:#define nl_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage:#define nl_full_usage "\n\n"
//usage: "Write FILEs to standard output with line numbers added\n"
//usage: "\n -b STYLE Which lines to number - a: all, t: nonempty, n: none"
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^TODO: support "pBRE": number only lines thatmatch regexp BRE"
////usage: "\n -f STYLE footer lines"
////usage: "\n -h STYLE header lines"
////usage: "\n -d CC use CC for separating logical pages"
//usage: "\n -i N Line number increment"
////usage: "\n -l NUMBER group of NUMBER empty lines counted as one"
////usage: "\n -n FORMAT lneft justified, no leading zeros; rn or rz"
////usage: "\n -p do not reset line numbers at logical pages (huh?)"
//usage: "\n -s STRING Use STRING as line number separator"
//usage: "\n -v N Start from N"
//usage: "\n -w N Width of line numbers"
/* By default, selects -v1 -i1 -l1 -sTAB -w6 -nrn -hn -bt -fn */
#include "libbb.h"
void FAST_FUNC print_numbered_lines(struct number_state *ns, const char *filename)
{
FILE *fp = fopen_or_warn_stdin(filename);
unsigned N = ns->start;
char *line;
while ((line = xmalloc_fgetline(fp)) != NULL) {
if (ns->all
|| (ns->nonempty && line[0])
) {
printf("%*u%s%s\n", ns->width, N, ns->sep, line);
N += ns->inc;
} else if (ns->empty_str)
fputs(ns->empty_str, stdout);
free(line);
}
fclose(fp);
}
int nl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nl_main(int argc UNUSED_PARAM, char **argv)
{
struct number_state ns;
const char *opt_b = "t";
enum {
OPT_p = (1 << 0),
};
#if ENABLE_LONG_OPTS
static const char nl_longopts[] ALIGN1 =
"body-numbering\0" Required_argument "b"
// "footer-numbering\0" Required_argument "f" - not implemented yet
// "header-numbering\0" Required_argument "h" - not implemented yet
// "section-delimiter\0" Required_argument "d" - not implemented yet
"line-increment\0" Required_argument "i"
// "join-blank-lines\0" Required_argument "l" - not implemented yet
// "number-format\0" Required_argument "n" - not implemented yet
"no-renumber\0" No_argument "p" // no-op so far
"number-separator\0" Required_argument "s"
"starting-line-number\0"Required_argument "v"
"number-width\0" Required_argument "w"
;
applet_long_options = nl_longopts;
#endif
ns.width = 6;
ns.start = 1;
ns.inc = 1;
ns.sep = "\t";
getopt32(argv, "pw:+s:v:+i:+b:", &ns.width, &ns.sep, &ns.start, &ns.inc, &opt_b);
ns.all = (opt_b[0] == 'a');
ns.nonempty = (opt_b[0] == 't');
ns.empty_str = xasprintf("%*s\n", ns.width + (int)strlen(ns.sep), "");
argv += optind;
if (!*argv)
*--argv = (char*)"-";
do {
print_numbered_lines(&ns, *argv);
} while (*++argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
-51
View File
@@ -1,51 +0,0 @@
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see LICENSE in this source tree
*/
//config:config NPROC
//config: bool "nproc"
//config: default y
//config: help
//config: Print number of CPUs
//applet:IF_NPROC(APPLET(nproc, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_NPROC) += nproc.o
//usage:#define nproc_trivial_usage
//usage: ""
//TODO: "[--all] [--ignore=N]"
//usage:#define nproc_full_usage "\n\n"
//usage: "Print number of CPUs"
#include <sched.h>
#include "libbb.h"
int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
{
unsigned long mask[1024];
unsigned i, count = 0;
//applet_long_options = ...;
//getopt32(argv, "");
//if --all, count /sys/devices/system/cpu/cpuN dirs, else:
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
for (i = 0; i < ARRAY_SIZE(mask); i++) {
unsigned long m = mask[i];
while (m) {
if (m & 1)
count++;
m >>= 1;
}
}
}
if (count == 0)
count++;
printf("%u\n", count);
return 0;
}
-140
View File
@@ -1,140 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* paste.c - implementation of the posix paste command
*
* Written by Maxime Coste <mawww@kakoune.org>
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
//config:config PASTE
//config: bool "paste"
//config: default y
//config: help
//config: paste is used to paste lines of different files together
//config: and write the result to stdout
//applet:IF_PASTE(APPLET_NOEXEC(paste, paste, BB_DIR_USR_BIN, BB_SUID_DROP, paste))
//kbuild:lib-$(CONFIG_PASTE) += paste.o
//usage:#define paste_trivial_usage
//usage: "[OPTIONS] [FILE]..."
//usage:#define paste_full_usage "\n\n"
//usage: "Paste lines from each input file, separated with tab\n"
//usage: "\n -d LIST Use delimiters from LIST, not tab"
//usage: "\n -s Serial: one file at a time"
//usage:
//usage:#define paste_example_usage
//usage: "# write out directory in four columns\n"
//usage: "$ ls | paste - - - -\n"
//usage: "# combine pairs of lines from a file into single lines\n"
//usage: "$ paste -s -d '\\t\\n' file\n"
#include "libbb.h"
static void paste_files(FILE** files, int file_cnt, char* delims, int del_cnt)
{
char *line;
char delim;
int active_files = file_cnt;
int i;
while (active_files > 0) {
int del_idx = 0;
for (i = 0; i < file_cnt; ++i) {
if (files[i] == NULL)
continue;
line = xmalloc_fgetline(files[i]);
if (!line) {
fclose_if_not_stdin(files[i]);
files[i] = NULL;
--active_files;
continue;
}
fputs(line, stdout);
free(line);
delim = '\n';
if (i != file_cnt - 1) {
delim = delims[del_idx++];
if (del_idx == del_cnt)
del_idx = 0;
}
if (delim != '\0')
fputc(delim, stdout);
}
}
}
static void paste_files_separate(FILE** files, char* delims, int del_cnt)
{
char *line, *next_line;
char delim;
int i;
for (i = 0; files[i]; ++i) {
int del_idx = 0;
line = NULL;
while ((next_line = xmalloc_fgetline(files[i])) != NULL) {
if (line) {
fputs(line, stdout);
free(line);
delim = delims[del_idx++];
if (del_idx == del_cnt)
del_idx = 0;
if (delim != '\0')
fputc(delim, stdout);
}
line = next_line;
}
if (line) {
/* coreutils adds \n even if this is a final line
* of the last file and it was not \n-terminated.
*/
printf("%s\n", line);
free(line);
}
fclose_if_not_stdin(files[i]);
}
}
#define PASTE_OPT_DELIMITERS (1 << 0)
#define PASTE_OPT_SEPARATE (1 << 1)
int paste_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int paste_main(int argc UNUSED_PARAM, char **argv)
{
char *delims = (char*)"\t";
int del_cnt = 1;
unsigned opt;
int i;
opt = getopt32(argv, "d:s", &delims);
argv += optind;
if (opt & PASTE_OPT_DELIMITERS) {
if (!delims[0])
bb_error_msg_and_die("-d '' is not supported");
/* unknown mappings are not changed: "\z" -> '\\' 'z' */
/* trailing backslash, if any, is preserved */
del_cnt = strcpy_and_process_escape_sequences(delims, delims) - delims;
/* note: handle NUL properly (do not stop at it!): try -d'\t\0\t' */
}
if (!argv[0])
(--argv)[0] = (char*) "-";
for (i = 0; argv[i]; ++i) {
argv[i] = (void*) fopen_or_warn_stdin(argv[i]);
if (!argv[i])
xfunc_die();
}
if (opt & PASTE_OPT_SEPARATE)
paste_files_separate((FILE**)argv, delims, del_cnt);
else
paste_files((FILE**)argv, i, delims, del_cnt);
fflush_stdout_and_exit(0);
}
+1 -4
View File
@@ -49,9 +49,6 @@
//kbuild:lib-$(CONFIG_PRINTF) += printf.o
//kbuild:lib-$(CONFIG_ASH_PRINTF) += printf.o
//kbuild:lib-$(CONFIG_HUSH_PRINTF) += printf.o
//usage:#define printf_trivial_usage
//usage: "FORMAT [ARG]..."
//usage:#define printf_full_usage "\n\n"
@@ -420,7 +417,7 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
argv++;
if (!argv[1]) {
if (ENABLE_ASH_PRINTF
if (ENABLE_ASH_BUILTIN_PRINTF
&& applet_name[0] != 'p'
) {
bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
+2 -3
View File
@@ -16,8 +16,7 @@
//config: help
//config: rm is used to remove files or directories.
//applet:IF_RM(APPLET_NOEXEC(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
/* was NOFORK, but then "rm -i FILE" can't be ^C'ed if run by hush */
//applet:IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
//kbuild:lib-$(CONFIG_RM) += rm.o
@@ -37,7 +36,7 @@
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
/* This is a NOFORK applet. Be very careful! */
int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int rm_main(int argc UNUSED_PARAM, char **argv)
+2 -3
View File
@@ -12,8 +12,7 @@
//config: help
//config: print a sequence of numbers
//applet:IF_SEQ(APPLET_NOEXEC(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
/* was NOFORK, but then "seq 1 999999999" can't be ^C'ed if run by hush */
//applet:IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
//kbuild:lib-$(CONFIG_SEQ) += seq.o
@@ -27,7 +26,7 @@
#include "libbb.h"
/* This is a NOEXEC applet. Be very careful! */
/* This is a NOFORK applet. Be very careful! */
int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int seq_main(int argc, char **argv)
-106
View File
@@ -1,106 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
//config:config SHRED
//config: bool "shred"
//config: default y
//config: help
//config: Overwrite a file to hide its contents, and optionally delete it
//applet:IF_SHRED(APPLET(shred, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_SHRED) += shred.o
//usage:#define shred_trivial_usage
//usage: "FILE..."
//usage:#define shred_full_usage "\n\n"
//usage: "Overwrite/delete FILEs\n"
//usage: "\n -f Chmod to ensure writability"
//usage: "\n -n N Overwrite N times (default 3)"
//usage: "\n -z Final overwrite with zeros"
//usage: "\n -u Remove file"
//-x and -v are accepted but have no effect
/* shred (GNU coreutils) 8.25:
-f, --force change permissions to allow writing if necessary
-u truncate and remove file after overwriting
-z, --zero add a final overwrite with zeros to hide shredding
-n, --iterations=N overwrite N times instead of the default (3)
-v, --verbose show progress
-x, --exact do not round file sizes up to the next full block; this is the default for non-regular files
--random-source=FILE get random bytes from FILE
-s, --size=N shred this many bytes (suffixes like K, M, G accepted)
--remove[=HOW] like -u but give control on HOW to delete; See below
*/
#include "libbb.h"
int shred_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int shred_main(int argc UNUSED_PARAM, char **argv)
{
int rand_fd = rand_fd; /* for compiler */
int zero_fd;
unsigned num_iter = 3;
unsigned opt;
enum {
OPT_f = (1 << 0),
OPT_u = (1 << 1),
OPT_z = (1 << 2),
OPT_n = (1 << 3),
OPT_v = (1 << 4),
OPT_x = (1 << 5),
};
opt = getopt32(argv, "fuzn:+vx", &num_iter);
argv += optind;
zero_fd = xopen("/dev/zero", O_RDONLY);
if (num_iter != 0)
rand_fd = xopen("/dev/urandom", O_RDONLY);
if (!*argv)
bb_show_usage();
for (;;) {
struct stat sb;
const char *fname;
unsigned i;
int fd;
fname = *argv++;
if (!fname)
break;
fd = -1;
if (opt & OPT_f) {
fd = open(fname, O_WRONLY);
if (fd < 0)
chmod(fname, 0666);
}
if (fd < 0)
fd = xopen(fname, O_WRONLY);
if (fstat(fd, &sb) == 0 && sb.st_size > 0) {
off_t size = sb.st_size;
for (i = 0; i < num_iter; i++) {
bb_copyfd_size(rand_fd, fd, size);
fdatasync(fd);
xlseek(fd, 0, SEEK_SET);
}
if (opt & OPT_z) {
bb_copyfd_size(zero_fd, fd, size);
fdatasync(fd);
}
if (opt & OPT_u) {
ftruncate(fd, 0);
xunlink(fname);
}
xclose(fd);
}
}
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -53,7 +53,7 @@ static void shuffle_lines(char **lines, unsigned numlines)
/* RAND_MAX can be as small as 32767 */
if (i > RAND_MAX)
r ^= rand() << 15;
r %= i + 1;
r %= i;
tmp = lines[i];
lines[i] = lines[r];
lines[r] = tmp;
+1 -1
View File
@@ -9,7 +9,7 @@
//config: bool "split"
//config: default y
//config: help
//config: Split a file into pieces.
//config: split a file into pieces.
//config:
//config:config FEATURE_SPLIT_FANCY
//config: bool "Fancy extensions"
+4 -3
View File
@@ -26,12 +26,13 @@
//config: from files.
//config:
//config:config FEATURE_FANCY_TAIL
//config: bool "Enable -q, -s, -v, and -F options"
//config: bool "Enable extra tail options (-q, -s, -v, and -F)"
//config: default y
//config: depends on TAIL
//config: help
//config: These options are provided by GNU tail, but
//config: are not specific in the SUSv3 standard:
//config: The options (-q, -s, -v and -F) are provided by GNU tail, but
//config: are not specific in the SUSv3 standard.
//config:
//config: -q Never output headers giving file names
//config: -s SEC Wait SEC seconds between reads with -f
//config: -v Always output headers giving file names
+9 -8
View File
@@ -42,20 +42,21 @@
//config:config FEATURE_TEST_64
//config: bool "Extend test to 64 bit"
//config: default y
//config: depends on TEST || TEST1 || TEST2 || ASH_TEST || HUSH_TEST
//config: depends on TEST || TEST1 || TEST2 || ASH_BUILTIN_TEST || HUSH
//config: help
//config: Enable 64-bit support in test.
//applet:IF_TEST(APPLET_NOFORK(test, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST1(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST2(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST1(APPLET_NOFORK([, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//applet:IF_TEST2(APPLET_NOFORK([[, test, BB_DIR_USR_BIN, BB_SUID_DROP, test))
//kbuild:lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST1) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_TEST2) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_ASH_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_HUSH_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_ASH_BUILTIN_TEST) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_HUSH) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_SH_IS_HUSH) += test.o test_ptr_hack.o
//kbuild:lib-$(CONFIG_BASH_IS_HUSH) += test.o test_ptr_hack.o
/* "test --help" is special-cased to ignore --help */
//usage:#define test_trivial_usage NOUSAGE_STR
@@ -842,7 +843,7 @@ int test_main(int argc, char **argv)
const char *arg0;
arg0 = bb_basename(argv[0]);
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_BUILTIN_TEST || ENABLE_HUSH)
&& (arg0[0] == '[')
) {
--argc;
+1 -1
View File
@@ -157,7 +157,7 @@ int uname_main(int argc UNUSED_PARAM, char **argv)
strcpy(uname_info.processor, unknown_str);
strcpy(uname_info.platform, unknown_str);
strcpy(uname_info.os, CONFIG_UNAME_OSNAME);
#if ENABLE_FEDORA_COMPAT
#if 0
/* Fedora does something like this */
strcpy(uname_info.processor, uname_info.name.machine);
strcpy(uname_info.platform, uname_info.name.machine);
+2 -9
View File
@@ -26,7 +26,6 @@
//usage: "\n -c Prefix lines by the number of occurrences"
//usage: "\n -d Only print duplicate lines"
//usage: "\n -u Only print unique lines"
//usage: "\n -i Ignore case"
//usage: "\n -f N Skip first N fields"
//usage: "\n -s N Skip first N chars (after any skipped fields)"
//usage: "\n -w N Compare N characters in line"
@@ -55,13 +54,12 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
OPT_f = 0x8,
OPT_s = 0x10,
OPT_w = 0x20,
OPT_i = 0x40,
};
skip_fields = skip_chars = 0;
max_chars = INT_MAX;
opt = getopt32(argv, "cduf:+s:+w:+i", &skip_fields, &skip_chars, &max_chars);
opt = getopt32(argv, "cduf:+s:+w:+", &skip_fields, &skip_chars, &max_chars);
argv += optind;
input_filename = argv[0];
@@ -108,12 +106,7 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
++cur_compare;
}
if (!old_line)
break;
if ((opt & OPT_i)
? strncasecmp(old_compare, cur_compare, max_chars)
: strncmp(old_compare, cur_compare, max_chars)
) {
if (!old_line || strncmp(old_compare, cur_compare, max_chars)) {
break;
}
-7
View File
@@ -38,13 +38,6 @@ int usleep_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
}
/* Safe wrt NOFORK? (noforks are not allowed to run for
* a long time). Try "usleep 99999999" + ^C + "echo $?"
* in hush with FEATURE_SH_NOFORK=y.
* At least on uclibc, usleep() thanslates to nanosleep()
* which returns early on any signal (even caught one),
* and uclibc does not loop back on EINTR.
*/
usleep(xatou(argv[1]));
return EXIT_SUCCESS;
+3 -9
View File
@@ -47,16 +47,10 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
line = xmalloc_fgets_str_len(src_stream, "\n", &line_len);
if (!line)
break;
/* Handle both Unix and MSDOS text.
* Note: space should not be trimmed, some encoders use it instead of "`"
* for padding of last incomplete 4-char block.
*/
/* Handle both Unix and MSDOS text, and stray trailing spaces */
str_len = line_len;
while (--str_len >= 0
&& (line[str_len] == '\n' || line[str_len] == '\r')
) {
while (--str_len >= 0 && isspace(line[str_len]))
line[str_len] = '\0';
}
if (strcmp(line, "end") == 0) {
return; /* the only non-error exit */
@@ -71,7 +65,7 @@ static void FAST_FUNC read_stduu(FILE *src_stream, FILE *dst_stream, int flags U
encoded_len = line[0] * 4 / 3;
/* Check that line is not too short. (we tolerate
* overly _long_ line to accommodate possible extra "`").
* overly _long_ line to accommodate possible extra '`').
* Empty line case is also caught here. */
if (str_len <= encoded_len) {
break; /* go to bb_error_msg_and_die("short file"); */
+2 -2
View File
@@ -40,11 +40,11 @@
//config: in specified files.
//config:
//config:config FEATURE_WC_LARGE
//config: bool "Support very large counts"
//config: bool "Support very large files in wc"
//config: default y
//config: depends on WC
//config: help
//config: Use "unsigned long long" for counter variables.
//config: Use "unsigned long long" in wc for counter variables.
//applet:IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
+5 -47
View File
@@ -23,14 +23,6 @@
//config: help
//config: who is used to show who is logged on.
//config:
// procps-ng has this variation of "who":
//config:config W
//config: bool "w"
//config: default y
//config: depends on FEATURE_UTMP
//config: help
//config: w is used to show who is logged on.
//config:
//config:config USERS
//config: bool "users"
//config: default y
@@ -38,14 +30,11 @@
//config: help
//config: Print users currently logged on.
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_USERS(APPLET_ODDNAME(users, who, BB_DIR_USR_BIN, BB_SUID_DROP, users))
//applet:IF_W( APPLET_ODDNAME(w, who, BB_DIR_USR_BIN, BB_SUID_DROP, w))
//applet:IF_WHO( APPLET( who, BB_DIR_USR_BIN, BB_SUID_DROP))
//applet:IF_WHO(APPLET(who, BB_DIR_USR_BIN, BB_SUID_DROP))
//kbuild:lib-$(CONFIG_USERS) += who.o
//kbuild:lib-$(CONFIG_W) += who.o
//kbuild:lib-$(CONFIG_WHO) += who.o
//kbuild:lib-$(CONFIG_WHO) += who.o
/* BB_AUDIT SUSv3 _NOT_ compliant -- missing options -b, -d, -l, -m, -p, -q, -r, -s, -t, -T, -u; Missing argument 'file'. */
@@ -54,31 +43,6 @@
//usage:#define users_full_usage "\n\n"
//usage: "Print the users currently logged on"
//usage:#define w_trivial_usage
//usage: ""
//usage:#define w_full_usage "\n\n"
//usage: "Show who is logged on"
//
// procps-ng 3.3.10:
// "\n -h, --no-header"
// "\n -u, --no-current"
// Ignores the username while figuring out the current process
// and cpu times. To demonstrate this, do a "su" and do a "w" and a "w -u".
// "\n -s, --short"
// Short format. Don't print the login time, JCPU or PCPU times.
// "\n -f, --from"
// Toggle printing the from (remote hostname) field.
// The default is for the from field to not be printed
// "\n -i, --ip-addr"
// Display IP address instead of hostname for from field.
// "\n -o, --old-style"
// Old style output. Prints blank space for idle times less than one minute.
// Example output:
// 17:28:00 up 4 days, 22:41, 4 users, load average: 0.84, 0.97, 0.90
// USER TTY LOGIN@ IDLE JCPU PCPU WHAT
// root tty1 Thu18 4days 4:33m 0.07s /bin/sh /etc/xdg/xfce4/xinitrc -- vt
// root pts/1 Mon13 3:24m 1:01 0.01s w
//usage:#define who_trivial_usage
//usage: "[-a]"
//usage:#define who_full_usage "\n\n"
@@ -109,17 +73,14 @@ static void idle_string(char *str6, time_t t)
int who_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int who_main(int argc UNUSED_PARAM, char **argv)
{
#define CNT_APPLET (ENABLE_USERS + ENABLE_W + ENABLE_WHO)
int do_users = (ENABLE_USERS && (CNT_APPLET == 1 || applet_name[0] == 'u'));
int do_w = (ENABLE_W && (CNT_APPLET == 1 || applet_name[1] == '\0'));
int do_who = (ENABLE_WHO && (CNT_APPLET == 1 || applet_name[1] == 'h'));
struct utmpx *ut;
unsigned opt;
int do_users = (ENABLE_USERS && (!ENABLE_WHO || applet_name[0] == 'u'));
const char *fmt = "%s";
opt_complementary = "=0";
opt = getopt32(argv, do_who ? "aH" : "");
if ((opt & 2) || do_w) /* -H or we are w */
opt = getopt32(argv, do_users ? "" : "aH");
if (opt & 2) // -H
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
setutxent();
@@ -153,9 +114,6 @@ int who_main(int argc UNUSED_PARAM, char **argv)
(int)sizeof(ut->ut_user), ut->ut_user,
(int)sizeof(ut->ut_line), ut->ut_line,
str6,
// TODO: with LANG=en_US.UTF-8, who from coreutils 8.25 shows
// TIME col as "2017-04-06 18:47" (the default format is "Apr 6 18:47").
// The former format looks saner to me. Switch to it unconditionally?
ctime(&seconds) + 4,
(int)sizeof(ut->ut_host), ut->ut_host
);
+1 -2
View File
@@ -17,8 +17,7 @@
//config: yes is used to repeatedly output a specific string, or
//config: the default string `y'.
//applet:IF_YES(APPLET_NOEXEC(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
/* was NOFORK, but then yes can't be ^C'ed if run by hush */
//applet:IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
//kbuild:lib-$(CONFIG_YES) += yes.o
File renamed without changes.
+2
View File
@@ -41,6 +41,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on RUN_PARTS && LONG_OPTS
//config: help
//config: Support long options for the run-parts applet.
//config:
//config:config FEATURE_RUN_PARTS_FANCY
//config: bool "Support additional arguments"
+8 -5
View File
@@ -64,19 +64,22 @@ Misc options:
//config: termination of system-level processes, usually the ones
//config: started during the startup of the system.
//config:
//config:config FEATURE_START_STOP_DAEMON_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on START_STOP_DAEMON && LONG_OPTS
//config:
//config:config FEATURE_START_STOP_DAEMON_FANCY
//config: bool "Support additional arguments"
//config: default y
//config: depends on START_STOP_DAEMON
//config: help
//config: Support additional arguments.
//config: -o|--oknodo ignored since we exit with 0 anyway
//config: -v|--verbose
//config: -N|--nicelevel N
//config:
//config:config FEATURE_START_STOP_DAEMON_LONG_OPTIONS
//config: bool "Enable long options"
//config: default y
//config: depends on START_STOP_DAEMON && LONG_OPTS
//config: help
//config: Support long options for the start-stop-daemon applet.
//applet:IF_START_STOP_DAEMON(APPLET_ODDNAME(start-stop-daemon, start_stop_daemon, BB_DIR_SBIN, BB_SUID_DROP, start_stop_daemon))
+6 -36
View File
@@ -33,7 +33,6 @@ roughly are:
* do not expect shared global variables/buffers to be in their
"initialized" state. Examples: xfunc_error_retval can be != 1,
bb_common_bufsiz1 can be scribbled over, ...
(although usually xfunc_error_retval's state is not a problem).
* do not expect that stdio wasn't used before. Calling set[v]buf()
can be disastrous.
* ...
@@ -52,9 +51,6 @@ xargs, find, shells do it (grep for "spawn_and_wait" and
This poses much more serious limitations on what applet can do:
* all NOEXEC limitations apply.
* do not run for a long time or wait for user input:
hush shell only handles signals (like ^C) after you return
from APPLET_main().
* do not ever exit() or exec().
- xfuncs are okay. They are using special trick to return
to the caller applet instead of dying when they detect "x" condition.
@@ -85,44 +81,18 @@ are probably not worth the effort.
Any NOFORK applet is also a NOEXEC applet.
Calling NOFORK applets
API to call NOFORK applets is two functions:
run_nofork_applet(appno, argv)
spawn_and_wait(argv) // only if FEATURE_PREFER_APPLETS=y
First one is directly used by shells if FEATURE_SH_NOFORK=y.
Second one is used by many applets, but main users are xargs and find.
It itself calls run_nofork_applet(), if argv[0] turned out to be a name
of a NOFORK applet.
run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval,
applet_name. Thus, for example, caller does not need to worry about
option_mask32 getting trashed.
Calling NOEXEC applets
It's the same trusty spawn_and_wait(argv). If FEATURE_PREFER_APPLETS=y,
it does NOEXEC trick. It resets xfunc_error_retval = 1 and
logmode = LOGMODE_STDIO in the child.
Relevant CONFIG options
FEATURE_PREFER_APPLETS
BB_EXECVP(cmd, argv) will try to exec /proc/self/exe
if command's name matches some applet name;
if command's name matches some applet name
applet tables will contain NOFORK/NOEXEC bits
spawn_and_wait(argv) will do NOFORK/NOEXEC tricks
//TODO: the above two things probably should have separate options?
FEATURE_SH_STANDALONE
FEATURE_SH_STANDALONE (needs FEATURE_PREFER_APPLETS=y)
shells will try to exec /proc/self/exe if command's name matches
some applet name; shells will do NOEXEC trick on NOEXEC applets
some applet name
shells will do NOEXEC trick on NOEXEC applets
//TODO: split (same as for PREFER_APPLETS)
FEATURE_SH_NOFORK
FEATURE_SH_NOFORK (needs FEATURE_PREFER_APPLETS=y)
shells will do NOFORK trick on NOFORK applets
+1 -7
View File
@@ -22,7 +22,7 @@ POSIX Tools supported only as shell built-ins (ash shell):
POSIX Tools not supported:
asa, at, batch, bc, c99, command, compress, csplit, ex, fc, file,
gencat, getconf, iconv, join, link, locale, localedef, lp, m4,
mailx, newgrp, nl, pathchk, pax, pr, qalter, qdel, qhold, qmove,
mailx, newgrp, nl, paste, pathchk, pax, pr, qalter, qdel, qhold, qmove,
qmsg, qrerun, qrls, qselect, qsig, qstat, qsub, tabs, talk, tput,
tsort, unlink, uucp, uustat, uux
@@ -469,12 +469,6 @@ od POSIX options
-x | no | no |
od Busybox specific options: None
paste POSIX options
option | exists | compliant | remarks
-d list | yes | yes |
-s | yes | yes |
paste Busybox specific options: None
patch POSIX options
option | exists | compliant | remarks
-D define | no | no |
+5 -5
View File
@@ -45,7 +45,7 @@ intention.
</td></tr><tr><th valign=top align=left>Required knowledge: </th>
<td valign=top align=left>You have to know what it means to catch SIGINT or SIGQUIT and how
processes are waiting for other processes (children) they spawned.
processes are waiting for other processes (childs) they spawned.
</td></tr></table>
@@ -366,7 +366,7 @@ signal, it has to take care of communicating the signal status
itself.
<p>Some programs don't do this. On SIGINT, they do cleanup and exit
immediately, but the calling shell isn't told about the non-normal exit
immediatly, but the calling shell isn't told about the non-normal exit
and it will call the next program in the script.
<p>As a result, the user hits SIGINT and while one program exits, the
@@ -446,7 +446,7 @@ handlers, so it is portable.
<code>trap</code> command. Here, the same as for C programs apply. If
the intention of SIGINT is to end your program, you have to exit in a
way that the calling programs "sees" that you have been killed. If
you don't catch SIGINT, this happened automatically, but of you catch
you don't catch SIGINT, this happend automatically, but of you catch
SIGINT, i.e. to do cleanup work, you have to end the program by
killing yourself, not by calling exit.
@@ -466,7 +466,7 @@ files (which isn't really portable in C, though).
bourne shell. Every language implementation that lets you catch SIGINT
should also give you the option to reset the signal and kill yourself.
<P>It is always desirable to exit the right way, even if you don't
<P>It is always desireable to exit the right way, even if you don't
expect your usual callers to depend on it, some unusual one will come
along. This proper exit status will be needed for WCE and will not
hurt when the calling shell uses IUE or WUE.
@@ -565,7 +565,7 @@ comments the scripts echo.
<th>What happens when a shellscript called emacs, the user did not use
<code>C-c</code> and the script has additional commands in it?</th>
<th>What happens if a non-interactive child catches SIGINT?</th>
<th>To behave properly, children must do what?</th>
<th>To behave properly, childs must do what?</th>
</tr>
<tr valign=top align=left>
+1 -1
View File
@@ -329,7 +329,7 @@ With "const int" compiler may fail to optimize it out and will reserve
a real storage in rodata for it! (Hopefully, newer gcc will get better
at it...). With "define", you have slight risk of polluting namespace
(#define doesn't allow you to redefine the name in the inner scopes),
and complex "define" are evaluated each time they used, not once
and complex "define" are evaluated each time they uesd, not once
at declarations like enums. Also, the preprocessor does _no_ type checking
whatsoever, making it much more error prone.
+1 -1
View File
@@ -1071,7 +1071,7 @@ int fsck_main(int argc UNUSED_PARAM, char **argv)
new_args(); /* G.args[G.num_args - 1] is the last, NULL element */
if (!notitle)
puts("fsck (busybox "BB_VER")");
puts("fsck (busybox "BB_VER", "BB_BT")");
/* Even plain "fsck /dev/hda1" needs fstab to get fs type,
* so we are scanning it anyway */
+1 -1
View File
@@ -12,7 +12,7 @@ config FEATURE_ALLOW_EXEC
default y
depends on VI || AWK
help
Enables vi and awk features which allow user to execute
Enables vi and awk features which allows user to execute
shell commands (using system() C call).
endmenu
+18 -21
View File
@@ -88,6 +88,8 @@
//config: bool "Enable long options"
//config: default y
//config: depends on DIFF && LONG_OPTS
//config: help
//config: Enable use of long options.
//config:
//config:config FEATURE_DIFF_DIR
//config: bool "Enable directory support"
@@ -295,6 +297,17 @@ static int search(const int *c, int k, int y, const struct cand *list)
}
}
static unsigned isqrt(unsigned n)
{
unsigned x = 1;
while (1) {
const unsigned y = x;
x = ((n / x) + x) >> 1;
if (x <= (y + 1) && x >= (y - 1))
return x;
}
}
static void stone(const int *a, int n, const int *b, int *J, int pref)
{
const unsigned isq = isqrt(n);
@@ -715,19 +728,9 @@ static int diffreg(char *file[2])
fp[0] = stdin;
fp[1] = stdin;
for (i = 0; i < 2; i++) {
int fd = STDIN_FILENO;
if (!LONE_DASH(file[i])) {
if (!(option_mask32 & FLAG(N))) {
fd = open_or_warn(file[i], O_RDONLY);
if (fd == -1)
goto out;
} else {
/* -N: if some file does not exist compare it like empty */
fd = open(file[i], O_RDONLY);
if (fd == -1)
fd = xopen("/dev/null", O_RDONLY);
}
}
int fd = open_or_warn_stdin(file[i]);
if (fd == -1)
goto out;
/* Our diff implementation is using seek.
* When we meet non-seekable file, we must make a temp copy.
*/
@@ -988,23 +991,17 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
argv += optind;
while (L_arg)
label[!!label[0]] = llist_pop(&L_arg);
/* Compat: "diff file name_which_doesnt_exist" exits with 2 */
xfunc_error_retval = 2;
for (i = 0; i < 2; i++) {
file[i] = argv[i];
/* Compat: "diff file name_which_doesnt_exist" exits with 2 */
if (LONE_DASH(file[i])) {
fstat(STDIN_FILENO, &stb[i]);
gotstdin++;
} else if (option_mask32 & FLAG(N)) {
if (stat(file[i], &stb[i]))
xstat("/dev/null", &stb[i]);
} else {
} else
xstat(file[i], &stb[i]);
}
}
xfunc_error_retval = 1;
if (gotstdin && (S_ISDIR(stb[0].st_mode) || S_ISDIR(stb[1].st_mode)))
bb_error_msg_and_die("can't compare stdin to a directory");
+4 -4
View File
@@ -337,7 +337,7 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
if (isdigit(*my_str)) {
*linenum = strtol(my_str, (char**)&pos, 10);
/* endstr shouldn't ever equal NULL */
/* endstr shouldnt ever equal NULL */
} else if (*my_str == '$') {
*linenum = -1;
pos++;
@@ -444,7 +444,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
free(fname);
break;
}
/* Ignore case (gnu extension) */
/* Ignore case (gnu exension) */
case 'i':
case 'I':
cflags |= REG_ICASE;
@@ -587,7 +587,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
free(match);
free(replace);
}
/* if it wasn't a single-letter command that takes no arguments
/* if it wasnt a single-letter command that takes no arguments
* then it must be an invalid command.
*/
else if (idx >= IDX_nul) { /* not d,D,g,G,h,H,l,n,N,p,P,q,x,=,{,} */
@@ -751,7 +751,7 @@ static void do_subst_w_backrefs(char *line, char *replace)
continue;
}
/* I _think_ it is impossible to get '\' to be
* the last char in replace string. Thus we don't check
* the last char in replace string. Thus we dont check
* for replace[i] == NUL. (counterexample anyone?) */
/* if we find a backslash escaped character, print the character */
pipe_putc(replace[i]);
+56 -62
View File
@@ -30,7 +30,7 @@
//config: you may wish to use something else.
//config:
//config:config FEATURE_VI_MAX_LEN
//config: int "Maximum screen width"
//config: int "Maximum screen width in vi"
//config: range 256 16384
//config: default 4096
//config: depends on VI
@@ -39,7 +39,7 @@
//config: Make it smaller than 4k only if you are very limited on memory.
//config:
//config:config FEATURE_VI_8BIT
//config: bool "Allow to display 8-bit chars (otherwise shows dots)"
//config: bool "Allow vi to display 8-bit chars (otherwise shows dots)"
//config: default n
//config: depends on VI
//config: help
@@ -53,7 +53,7 @@
//config: default y
//config: depends on VI
//config: help
//config: Enable a limited set of colon commands. This does not
//config: Enable a limited set of colon commands for vi. This does not
//config: provide an "ex" mode.
//config:
//config:config FEATURE_VI_YANKMARK
@@ -61,14 +61,16 @@
//config: default y
//config: depends on VI
//config: help
//config: This will enable you to use yank and put, as well as mark.
//config: This will enable you to use yank and put, as well as mark in
//config: busybox vi.
//config:
//config:config FEATURE_VI_SEARCH
//config: bool "Enable search and replace cmds"
//config: default y
//config: depends on VI
//config: help
//config: Select this if you wish to be able to do search and replace.
//config: Select this if you wish to be able to do search and replace in
//config: busybox vi.
//config:
//config:config FEATURE_VI_REGEX_SEARCH
//config: bool "Enable regex in search and replace"
@@ -82,15 +84,16 @@
//config: default y
//config: depends on VI
//config: help
//config: Selecting this option will make vi signal aware. This will support
//config: SIGWINCH to deal with Window Changes, catch ^Z and ^C and alarms.
//config: Selecting this option will make busybox vi signal aware. This will
//config: make busybox vi support SIGWINCH to deal with Window Changes, catch
//config: Ctrl-Z and Ctrl-C and alarms.
//config:
//config:config FEATURE_VI_DOT_CMD
//config: bool "Remember previous cmd and \".\" cmd"
//config: default y
//config: depends on VI
//config: help
//config: Make vi remember the last command and be able to repeat it.
//config: Make busybox vi remember the last command and be able to repeat it.
//config:
//config:config FEATURE_VI_READONLY
//config: bool "Enable -R option and \"view\" mode"
@@ -101,23 +104,25 @@
//config: open a file in read-only mode.
//config:
//config:config FEATURE_VI_SETOPTS
//config: bool "Enable settable options, ai ic showmatch"
//config: bool "Enable set-able options, ai ic showmatch"
//config: default y
//config: depends on VI
//config: help
//config: Enable the editor to set some (ai, ic, showmatch) options.
//config:
//config:config FEATURE_VI_SET
//config: bool "Support :set"
//config: bool "Support for :set"
//config: default y
//config: depends on VI
//config: help
//config: Support for ":set".
//config:
//config:config FEATURE_VI_WIN_RESIZE
//config: bool "Handle window resize"
//config: default y
//config: depends on VI
//config: help
//config: Behave nicely with terminals that get resized.
//config: Make busybox vi behave nicely with terminals that get resized.
//config:
//config:config FEATURE_VI_ASK_TERMINAL
//config: bool "Use 'tell me cursor position' ESC sequence to measure window"
@@ -128,16 +133,15 @@
//config: this option makes vi perform a last-ditch effort to find it:
//config: position cursor to 999,999 and ask terminal to report real
//config: cursor position using "ESC [ 6 n" escape sequence, then read stdin.
//config: This is not clean but helps a lot on serial lines and such.
//config:
//config: This is not clean but helps a lot on serial lines and such.
//config:config FEATURE_VI_UNDO
//config: bool "Support undo command \"u\""
//config: bool "Support undo command 'u'"
//config: default y
//config: depends on VI
//config: help
//config: Support the 'u' command to undo insertion, deletion, and replacement
//config: of text.
//config:
//config:config FEATURE_VI_UNDO_QUEUE
//config: bool "Enable undo operation queuing"
//config: default y
@@ -148,7 +152,6 @@
//config: reached, the contents of the queue are committed to the undo stack.
//config: This increases the size of the undo code and allows some undo
//config: operations (especially un-typing/backspacing) to be far more useful.
//config:
//config:config FEATURE_VI_UNDO_QUEUE_MAX
//config: int "Maximum undo character queue size"
//config: default 256
@@ -354,7 +357,7 @@ struct globals {
#if ENABLE_FEATURE_VI_USE_SIGNALS
sigjmp_buf restart; // catch_sig()
#endif
struct termios term_orig; // remember what the cooked mode was
struct termios term_orig, term_vi; // remember what the cooked mode was
#if ENABLE_FEATURE_VI_COLON
char *initial_cmds[3]; // currently 2 entries, NULL terminated
#endif
@@ -462,6 +465,7 @@ struct globals {
#define context_end (G.context_end )
#define restart (G.restart )
#define term_orig (G.term_orig )
#define term_vi (G.term_vi )
#define initial_cmds (G.initial_cmds )
#define readbuffer (G.readbuffer )
#define scr_out_buf (G.scr_out_buf )
@@ -715,6 +719,14 @@ static int init_text_buffer(char *fn)
{
int rc;
flush_undo_data();
modified_count = 0;
last_modified_count = -1;
#if ENABLE_FEATURE_VI_YANKMARK
/* init the marks */
memset(mark, 0, sizeof(mark));
#endif
/* allocate/reallocate text buffer */
free(text);
text_size = 10240;
@@ -729,14 +741,6 @@ static int init_text_buffer(char *fn)
// file doesnt exist. Start empty buf with dummy line
char_insert(text, '\n', NO_UNDO);
}
flush_undo_data();
modified_count = 0;
last_modified_count = -1;
#if ENABLE_FEATURE_VI_YANKMARK
/* init the marks */
memset(mark, 0, sizeof(mark));
#endif
return rc;
}
@@ -1034,9 +1038,7 @@ static void colon(char *buf)
|| strncmp(p, "wn", cnt) == 0
|| (p[0] == 'x' && !p[1])
) {
if (modified_count != 0 || p[0] != 'x') {
cnt = file_write(current_filename, text, end - 1);
}
cnt = file_write(current_filename, text, end - 1);
if (cnt < 0) {
if (cnt == -1)
status_line_bold("Write error: %s", strerror(errno));
@@ -1047,9 +1049,8 @@ static void colon(char *buf)
current_filename,
count_lines(text, end - 1), cnt
);
if (p[0] == 'x'
|| p[1] == 'q' || p[1] == 'n'
|| p[1] == 'Q' || p[1] == 'N'
if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
|| p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
) {
editing = 0;
}
@@ -1460,7 +1461,7 @@ static void colon(char *buf)
}
#endif /* FEATURE_VI_SEARCH */
} else if (strncmp(cmd, "version", i) == 0) { // show software version
status_line(BB_VER);
status_line(BB_VER " " BB_BT);
} else if (strncmp(cmd, "write", i) == 0 // write text to file
|| strncmp(cmd, "wq", i) == 0
|| strncmp(cmd, "wn", i) == 0
@@ -1479,19 +1480,16 @@ static void colon(char *buf)
goto ret;
}
#endif
// how many lines in text[]?
li = count_lines(q, r);
size = r - q + 1;
//if (useforce) {
// if "fn" is not write-able, chmod u+w
// sprintf(syscmd, "chmod u+w %s", fn);
// system(syscmd);
// forced = TRUE;
//}
if (modified_count != 0 || cmd[0] != 'x') {
size = r - q + 1;
l = file_write(fn, q, r);
} else {
size = 0;
l = 0;
}
l = file_write(fn, q, r);
//if (useforce && forced) {
// chmod u-w
// sprintf(syscmd, "chmod u-w %s", fn);
@@ -1502,20 +1500,17 @@ static void colon(char *buf)
if (l == -1)
status_line_bold_errno(fn);
} else {
// how many lines written
li = count_lines(q, q + l - 1);
status_line("'%s' %dL, %dC", fn, li, l);
if (l == size) {
if (q == text && q + l == end) {
modified_count = 0;
last_modified_count = -1;
}
if (cmd[0] == 'x'
|| cmd[1] == 'q' || cmd[1] == 'n'
|| cmd[1] == 'Q' || cmd[1] == 'N'
) {
editing = 0;
}
if (q == text && r == end - 1 && l == size) {
modified_count = 0;
last_modified_count = -1;
}
if ((cmd[0] == 'x' || cmd[1] == 'q' || cmd[1] == 'n'
|| cmd[0] == 'X' || cmd[1] == 'Q' || cmd[1] == 'N'
)
&& l == size
) {
editing = 0;
}
}
#if ENABLE_FEATURE_VI_YANKMARK
@@ -2739,9 +2734,15 @@ static char *swap_context(char *p) // goto new context for '' command make this
//----- Set terminal attributes --------------------------------
static void rawmode(void)
{
// no TERMIOS_CLEAR_ISIG: leave ISIG on - allow signals
set_termios_to_raw(STDIN_FILENO, &term_orig, TERMIOS_RAW_CRNL);
erase_char = term_orig.c_cc[VERASE];
tcgetattr(0, &term_orig);
term_vi = term_orig;
term_vi.c_lflag &= (~ICANON & ~ECHO); // leave ISIG on - allow intr's
term_vi.c_iflag &= (~IXON & ~ICRNL);
term_vi.c_oflag &= (~ONLCR);
term_vi.c_cc[VMIN] = 1;
term_vi.c_cc[VTIME] = 0;
erase_char = term_vi.c_cc[VERASE];
tcsetattr_stdin_TCSANOW(&term_vi);
}
static void cookmode(void)
@@ -2816,15 +2817,8 @@ static int readit(void) // read (maybe cursor) key from stdin
int c;
fflush_all();
// Wait for input. TIMEOUT = -1 makes read_key wait even
// on nonblocking stdin.
// Note: read_key sets errno to 0 on success.
again:
c = read_key(STDIN_FILENO, readbuffer, /*timeout:*/ -1);
c = read_key(STDIN_FILENO, readbuffer, /*timeout off:*/ -2);
if (c == -1) { // EOF/error
if (errno == EAGAIN) // paranoia
goto again;
go_bottom_and_clear_to_eol();
cookmode(); // terminal to "cooked"
bb_error_msg_and_die("can't read user input");
+1 -1
View File
@@ -7,7 +7,7 @@
# Licensed under GPLv2, see file LICENSE in this source tree.
#
BASE="${1:-/usr/lib/modules}"
local BASE="${1:-/usr/lib/modules}"
find "$BASE" -name '*.ko.gz' | while read I ; do
N=`basename "$I" '.ko.gz'`
+1 -1
View File
@@ -14,7 +14,7 @@ env | sort
while sleep 1; test $cnt != 0; do
echo "Trying to reread partition table on $DEVNAME ($cnt)"
cnt=$((cnt-1))
: $((cnt--))
# If device node doesn't exist, it means the device was removed.
# Stop trying.
test -e "$DEVNAME" || { echo "$DEVNAME doesn't exist, aborting"; exit 1; }
+1 -8
View File
@@ -18,18 +18,11 @@ then
metric=0
for i in $router
do
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
# Only replace resolv.conf if we have at least one DNS server
# Only replace resolv.conf is we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
+2 -9
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# Sample udhcpc renew script
# Sample udhcpc bound script
RESOLV_CONF="/etc/udhcpc/resolv.conf"
@@ -18,18 +18,11 @@ then
metric=0
for i in $router
do
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
/sbin/ip route add $i dev $interface
fi
/sbin/route add default gw $i dev $interface metric $((metric++))
done
fi
# Only replace resolv.conf if we have at least one DNS server
# Only replace resolv.conf is we have at least one DNS server
if [ -n "$dns" ]
then
echo -n > $RESOLV_CONF
+2 -8
View File
@@ -29,14 +29,8 @@ case "$1" in
metric=0
for i in $router ; do
echo "Adding router $i"
if [ "$subnet" = "255.255.255.255" ]; then
# special case for /32 subnets:
# /32 instructs kernel to always use routing for all outgoing packets
# (they can never be sent to local subnet - there is no local subnet for /32).
# Used in datacenters, avoids the need for private ip-addresses between two hops.
ip route add $i dev $interface
fi
route add default gw $i dev $interface metric $((metric++))
route add default gw $i dev $interface metric $metric
: $(( metric += 1 ))
done
fi
+18 -25
View File
@@ -48,7 +48,7 @@ ps tells me they did put X, dbus, NM and udev into runsvdir-supervised tree:
654 ? 00:00:00 runsv
659 ? 00:00:00 udevd
Here is a link to Void Linux's wiki:
Here is a link to Vod Linux's wiki:
https://wiki.voidlinux.eu/Runit
@@ -98,10 +98,10 @@ It is not required that a specific clone should be used. Let evolution work.
daemon: any long running background program. Common examples are sshd, getty,
ntpd, dhcp client...
service: daemon controlled by a service monitor.
service: same as "daemon"
service directory: a directory with an executable file (script) named "run"
which (usually) execs some daemon, possibly after some preparatory steps.
which (usually) execs daemon (possibly after some preparatory steps).
It should start it not as a child or daemonized process, but by exec'ing it
(inheriting the same PID and the place in the process tree).
@@ -116,7 +116,7 @@ whose directories disappeared.
supervisor: a tool which monitors one service directory.
It runs "run" script as its child. It restarts it if it dies.
It can be instructed to start/stop/signal its child.
It can be instructed to start/top/signal its child.
In daemontools package, it is called "supervise". In runit, it is called
"runsv". In s6, it is called "s6-supervise".
@@ -150,9 +150,7 @@ The less distros diverge, the easier users' lives are.
System-wide service dirs reside in a distro-specific location.
The recommended location is /var/service. (However, since it is not
a mandatory location, avoid depending on it in your run scripts.
Void Linux wanted to have it somewhere in /run/*, and they solved this
by making /var/service a symlink).
a mandatory location, avoid depending on it in your run scripts).
The install location for service dirs is /etc/rc:
when e.g. ntpd daemon is installed, it creates the /etc/rc/ntpd
@@ -184,14 +182,10 @@ of bad things may happen. This may be worked around by various
heuristics in service monitor which give new service a few seconds
of "grace time" to be fully populated; but this is not yet
implemented in any of three packages.
This also may be worked around by creating a .dotdir (a directory
whose name starts with a dot), populating it, and then renaming;
but packaging tools usually do not have an option to do this
automatically - additional install scripting in packages will be needed.
Daemons' output file descriptors are handled somewhat awkwardly
by various daemontools implementations. For example, for runit tools,
daemons' stdout goes to wherever runsvdir's stdout was directed;
daemons' stdout goes to wherever runsdir's stdout was directied;
stderr goes to runsvdir, which in turn "rotates" it on its command line
(which is visible in ps output).
@@ -242,12 +236,12 @@ there is no guarantee in which order commands are sent to them.
If DIR has no slash and is not "." or "..", it is assumed to be
relative to the system-wide service directory.
[Currently, "svc" exists only in daemontools and in busybox.
This proposal asks developers of other daemontools implementations
to add "svc" command to their projects]
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
The "svstat DIR1 DIR2..." prints one human-readable line for each directory,
saying whether supervise is successfully running in that directory,
and reporting the status information maintained by supervise.
Other tools with different names and APIs may exist; however
for portability scripts should use the above tools.
@@ -256,28 +250,27 @@ To this end, first create and populate a new /etc/rc/DIR.
Then "activate" it by running ??????? - this copies (or symlinks,
depending on the distro) its files to the "live" service directory,
wherever it is located on this distro.
whereever it is located on this distro.
Removal of the service should be done as follows:
svc -d DIR [DIR/log], then remove the service directory:
this makes service monitor SIGTERM per-directory supervisors
(if they exist in the implementation).
svc -d DIR [DIR/log], then remove the service directory
(this makes service monitor SIGTERM per-directory supervisors
(if they exist in the implementation))
Implementation details
Top-level service monitor program name is not standardized
[svscan, runsvdir, s6-svscan ...] - it does not need to be,
as far as daemon packagers are concerned.
Top-level service monitor program name is not standardized.
[svscan, runsvdir, s6-svscan ...]
It may run one per-directory supervisor, or two supervisors
(one for DIR/ and one for DIR/log/); for memory-constrained systems
an implementation is possible which itself controls all services, without
intermediate supervisors.
[runsvdir runs one "runsv DIR" per DIR, runsv handles DIR/log/ if that exists]
[svscan runs a pair of "supervise DIR" and "supervise DIR/log"]
[svscan runs a pair of "superwise DIR" and "superwise DIR/log"]
Directories are remembered by device+inode numbers, not names. Renaming a directory
Directores are remembered by device+inode numbers, not names. Renaming a directory
does not affect the running service (unless it is renamed to a .dotdir).
Removal (or .dotdiring) of a directory sends SIGTERM to any running services.
+1 -1
View File
@@ -21,7 +21,7 @@
# ntpsrv=10.34.32.125 10.34.255.7
#
# renew: lease is renewed. Environment is similar to "bound".
# The IP address does not change, however, the other DHCP parameters,
# The IP address does not change, however, the other DHCP paramaters,
# such as the default gateway, subnet mask, and dns server may change.
#
# nak: udhcpc received a NAK message.
+1 -1
View File
@@ -30,7 +30,7 @@ test x"$router" != x"" || exec env - sleep "$ping_time"
failcnt=0
while true; do
ping $ping_opts "$router" && exec env - sleep "$ping_time"
failcnt=$((failcnt+1))
: $((failcnt++))
msg "Failed to ping $router, fail count:$failcnt"
test $failcnt -ge $max_fail && break
env - sleep "$retry_time"
+15 -1
View File
@@ -89,6 +89,8 @@
//config: bool "Enable -perm: permissions matching"
//config: default y
//config: depends on FIND
//config: help
//config: Enable searching based on file permissions.
//config:
//config:config FEATURE_FIND_TYPE
//config: bool "Enable -type: file type matching (file/dir/link/...)"
@@ -102,11 +104,15 @@
//config: bool "Enable -xdev: 'stay in filesystem'"
//config: default y
//config: depends on FIND
//config: help
//config: This option allows find to restrict searches to a single filesystem.
//config:
//config:config FEATURE_FIND_MAXDEPTH
//config: bool "Enable -mindepth N and -maxdepth N"
//config: default y
//config: depends on FIND
//config: help
//config: This option enables -mindepth N and -maxdepth N option.
//config:
//config:config FEATURE_FIND_NEWER
//config: bool "Enable -newer: compare file modification times"
@@ -120,6 +126,8 @@
//config: bool "Enable -inum: inode number matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -inum' option for searching by inode number.
//config:
//config:config FEATURE_FIND_EXEC
//config: bool "Enable -exec: execute commands"
@@ -143,11 +151,15 @@
//config: bool "Enable -user: username/uid matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -user' option for searching by username or uid.
//config:
//config:config FEATURE_FIND_GROUP
//config: bool "Enable -group: group/gid matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -group' option for searching by group name or gid.
//config:
//config:config FEATURE_FIND_NOT
//config: bool "Enable the 'not' (!) operator"
@@ -176,13 +188,15 @@
//config: bool "Enable -size: file size matching"
//config: default y
//config: depends on FIND
//config: help
//config: Support the 'find -size' option for searching by file size.
//config:
//config:config FEATURE_FIND_PRUNE
//config: bool "Enable -prune: exclude subdirectories"
//config: default y
//config: depends on FIND
//config: help
//config: If the file is a directory, don't descend into it. Useful for
//config: If the file is a directory, dont descend into it. Useful for
//config: exclusion .svn and CVS directories.
//config:
//config:config FEATURE_FIND_DELETE
+3 -4
View File
@@ -39,14 +39,13 @@
//config:config FEATURE_GREP_CONTEXT
//config: bool "Enable before and after context flags (-A, -B and -C)"
//config: default y
//config: depends on GREP || EGREP || FGREP
//config: depends on GREP || EGREP
//config: help
//config: Print the specified number of leading (-B) and/or trailing (-A)
//config: context surrounding our matching lines.
//config: Print the specified number of context lines (-C).
//applet:IF_GREP(APPLET(grep, BB_DIR_BIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_EGREP(APPLET_ODDNAME(egrep, grep, BB_DIR_BIN, BB_SUID_DROP, egrep))
//applet:IF_FGREP(APPLET_ODDNAME(fgrep, grep, BB_DIR_BIN, BB_SUID_DROP, fgrep))
@@ -515,7 +514,7 @@ static int grep_file(FILE *file)
if (option_mask32 & OPT_o) {
if (FGREP_FLAG) {
/* -Fo just prints the pattern
* (unless -v: -Fov doesn't print anything at all) */
* (unless -v: -Fov doesnt print anything at all) */
if (found)
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
} else while (1) {
@@ -823,7 +822,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
grep_done: ;
} while (*argv && *++argv);
/* destroy all the elements in the pattern list */
/* destroy all the elments in the pattern list */
if (ENABLE_FEATURE_CLEAN_UP) {
while (pattern_head) {
llist_t *pattern_head_ptr = pattern_head;
+35 -142
View File
@@ -342,8 +342,6 @@ extern int *const bb_errno;
uint64_t bb_bswap_64(uint64_t x) FAST_FUNC;
#endif
unsigned long FAST_FUNC isqrt(unsigned long long N);
unsigned long long monotonic_ns(void) FAST_FUNC;
unsigned long long monotonic_us(void) FAST_FUNC;
unsigned long long monotonic_ms(void) FAST_FUNC;
@@ -357,27 +355,6 @@ extern char *skip_dev_pfx(const char *tty_name) FAST_FUNC;
extern char *strrstr(const char *haystack, const char *needle) FAST_FUNC;
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xrealloc(void *old, size_t size) FAST_FUNC;
/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
* at least v[idx] and v[idx+1], for all idx values.
* SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
* when all elements are used up. New elements are zeroed out.
* xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
* skipping an index is a bad bug - it may miss a realloc!
*/
#define xrealloc_vector(vector, shift, idx) \
xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
//TODO: supply a pointer to char[11] buffer (avoid statics)?
extern const char *bb_mode_string(mode_t mode) FAST_FUNC;
extern int is_directory(const char *name, int followLinks) FAST_FUNC;
@@ -716,56 +693,6 @@ struct hostent *xgethostbyname(const char *name) FAST_FUNC;
// + inet_common.c has additional IPv4-only stuff
#define TLS_MAX_MAC_SIZE 32
#define TLS_MAX_KEY_SIZE 32
struct tls_handshake_data; /* opaque */
typedef struct tls_state {
int ofd;
int ifd;
unsigned min_encrypted_len_on_read;
uint16_t cipher_id;
uint8_t encrypt_on_write;
unsigned MAC_size;
unsigned key_size;
uint8_t *outbuf;
int outbuf_size;
int inbuf_size;
int ofs_to_buffered;
int buffered_size;
uint8_t *inbuf;
struct tls_handshake_data *hsd;
// RFC 5246
// sequence number
// Each connection state contains a sequence number, which is
// maintained separately for read and write states. The sequence
// number MUST be set to zero whenever a connection state is made the
// active state. Sequence numbers are of type uint64 and may not
// exceed 2^64-1.
/*uint64_t read_seq64_be;*/
uint64_t write_seq64_be;
uint8_t *client_write_key;
uint8_t *server_write_key;
uint8_t client_write_MAC_key[TLS_MAX_MAC_SIZE];
uint8_t server_write_MAC_k__[TLS_MAX_MAC_SIZE];
uint8_t client_write_k__[TLS_MAX_KEY_SIZE];
uint8_t server_write_k__[TLS_MAX_KEY_SIZE];
} tls_state_t;
static inline tls_state_t *new_tls_state(void)
{
tls_state_t *tls = xzalloc(sizeof(*tls));
return tls;
}
void tls_handshake(tls_state_t *tls, const char *sni) FAST_FUNC;
void tls_run_copy_loop(tls_state_t *tls) FAST_FUNC;
void socket_want_pktinfo(int fd) FAST_FUNC;
ssize_t send_to_from(int fd, void *buf, size_t len, int flags,
const struct sockaddr *to,
@@ -778,8 +705,9 @@ ssize_t recv_from_to(int fd, void *buf, size_t len, int flags,
uint16_t inet_cksum(uint16_t *addr, int len) FAST_FUNC;
/* 0 if argv[0] is NULL: */
unsigned string_array_len(char **argv) FAST_FUNC;
char *xstrdup(const char *s) FAST_FUNC RETURNS_MALLOC;
char *xstrndup(const char *s, int n) FAST_FUNC RETURNS_MALLOC;
void *xmemdup(const void *s, int n) FAST_FUNC RETURNS_MALLOC;
void overlapping_strcpy(char *dst, const char *src) FAST_FUNC;
char *safe_strncpy(char *dst, const char *src, size_t size) FAST_FUNC;
char *strncpy_IFNAMSIZ(char *dst, const char *src) FAST_FUNC;
@@ -825,6 +753,24 @@ enum {
};
void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
void *malloc_or_warn(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xmalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xzalloc(size_t size) FAST_FUNC RETURNS_MALLOC;
void *xrealloc(void *old, size_t size) FAST_FUNC;
/* After v = xrealloc_vector(v, SHIFT, idx) it's ok to use
* at least v[idx] and v[idx+1], for all idx values.
* SHIFT specifies how many new elements are added (1:2, 2:4, ..., 8:256...)
* when all elements are used up. New elements are zeroed out.
* xrealloc_vector(v, SHIFT, idx) *MUST* be called with consecutive IDXs -
* skipping an index is a bad bug - it may miss a realloc!
*/
#define xrealloc_vector(vector, shift, idx) \
xrealloc_vector_helper((vector), (sizeof((vector)[0]) << 8) + (shift), (idx))
void* xrealloc_vector_helper(void *vector, unsigned sizeof_and_shift, int idx) FAST_FUNC;
extern ssize_t safe_read(int fd, void *buf, size_t count) FAST_FUNC;
extern ssize_t nonblock_immune_read(int fd, void *buf, size_t count) FAST_FUNC;
// NB: will return short read on error, not -1,
@@ -1097,19 +1043,10 @@ pid_t wait_any_nohang(int *wstat) FAST_FUNC;
*/
int wait4pid(pid_t pid) FAST_FUNC;
int wait_for_exitstatus(pid_t pid) FAST_FUNC;
/************************************************************************/
/* spawn_and_wait/run_nofork_applet/run_applet_no_and_exit need to work */
/* carefully together to reinit some global state while not disturbing */
/* other. Be careful if you change them. Consult docs/nofork_noexec.txt */
/************************************************************************/
/* Same as wait4pid(spawn(argv)), but with NOFORK/NOEXEC if configured: */
int spawn_and_wait(char **argv) FAST_FUNC;
/* Does NOT check that applet is NOFORK, just blindly runs it */
int run_nofork_applet(int applet_no, char **argv) FAST_FUNC;
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
extern void run_applet_no_and_exit(int a, const char *name, char **argv) NORETURN FAST_FUNC;
#endif
/* Helpers for daemonization.
*
@@ -1178,26 +1115,6 @@ extern const char *applet_long_options;
#endif
extern uint32_t option_mask32;
extern uint32_t getopt32(char **argv, const char *applet_opts, ...) FAST_FUNC;
/* BSD-derived getopt() functions require that optind be set to 1 in
* order to reset getopt() state. This used to be generally accepted
* way of resetting getopt(). However, glibc's getopt()
* has additional getopt() state beyond optind (specifically, glibc
* extensions such as '+' and '-' at the start of the string), and requires
* that optind be set to zero to reset its state. BSD-derived versions
* of getopt() misbehaved if optind is set to 0 in order to reset getopt(),
* and glibc's getopt() used to coredump if optind is set 1 in order
* to reset getopt().
* Then BSD introduced additional variable "optreset" which should be
* set to 1 in order to reset getopt(). Sigh. Standards, anyone?
*
* By ~2008, OpenBSD 3.4 was changed to survive glibc-like optind = 0
* (to interpret it as if optreset was set).
*/
#ifdef __GLIBC__
#define GETOPT_RESET() (optind = 0)
#else /* BSD style */
#define GETOPT_RESET() (optind = 1)
#endif
/* Having next pointer as a first member allows easy creation
@@ -1269,7 +1186,7 @@ extern void bb_logenv_override(void) FAST_FUNC;
/* Applets which are useful from another applets */
int bb_cat(char** argv) FAST_FUNC;
int bb_cat(char** argv);
/* If shell needs them, they exist even if not enabled as applets */
int echo_main(int argc, char** argv) IF_ECHO(MAIN_EXTERNALLY_VISIBLE);
int printf_main(int argc, char **argv) IF_PRINTF(MAIN_EXTERNALLY_VISIBLE);
@@ -1295,16 +1212,6 @@ int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC;
#endif
struct number_state {
unsigned width;
unsigned start;
unsigned inc;
const char *sep;
const char *empty_str;
smallint all, nonempty;
};
void print_numbered_lines(struct number_state *ns, const char *filename) FAST_FUNC;
/* Networking */
/* This structure defines protocol families and their handlers. */
@@ -1346,8 +1253,13 @@ const struct hwtype *get_hwtype(const char *name) FAST_FUNC;
const struct hwtype *get_hwntype(int type) FAST_FUNC;
extern int fstype_matches(const char *fstype, const char *comma_list) FAST_FUNC;
#ifndef BUILD_INDIVIDUAL
extern int find_applet_by_name(const char *name) FAST_FUNC;
extern void run_applet_no_and_exit(int a, char **argv) NORETURN FAST_FUNC;
#endif
#ifdef HAVE_MNTENT_H
extern int match_fstype(const struct mntent *mt, const char *fstypes) FAST_FUNC;
extern struct mntent *find_mount_point(const char *name, int subdir_too) FAST_FUNC;
#endif
extern void erase_mtab(const char * name) FAST_FUNC;
@@ -1363,15 +1275,10 @@ extern int get_linux_version_code(void) FAST_FUNC;
extern char *query_loop(const char *device) FAST_FUNC;
extern int del_loop(const char *device) FAST_FUNC;
/*
* If *devname is not NULL, use that name, otherwise try to find free one,
/* If *devname is not NULL, use that name, otherwise try to find free one,
* malloc and return it in *devname.
* return value is the opened fd to the loop device, or < on error
*/
extern int set_loop(char **devname, const char *file, unsigned long long offset, unsigned flags) FAST_FUNC;
/* These constants match linux/loop.h (without BB_ prefix): */
#define BB_LO_FLAGS_READ_ONLY 1
#define BB_LO_FLAGS_AUTOCLEAR 4
* return value: 1: read-only loopdev was setup, 0: rw, < 0: error */
extern int set_loop(char **devname, const char *file, unsigned long long offset, int ro) FAST_FUNC;
/* Like bb_ask below, but asks on stdin with no timeout. */
char *bb_ask_stdin(const char * prompt) FAST_FUNC;
@@ -1483,12 +1390,6 @@ extern void selinux_or_die(void) FAST_FUNC;
#define SETUP_ENV_NO_CHDIR (1 << 4)
void setup_environment(const char *shell, int flags, const struct passwd *pw) FAST_FUNC;
void nuke_str(char *str) FAST_FUNC;
#if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM
int is_tty_secure(const char *short_tty) FAST_FUNC;
#else
static ALWAYS_INLINE int is_tty_secure(const char *short_tty UNUSED_PARAM) { return 1; }
#endif
#define CHECKPASS_PW_HAS_EMPTY_PASSWORD 2
int check_password(const struct passwd *pw, const char *plaintext) FAST_FUNC;
int ask_and_check_password_extended(const struct passwd *pw, int timeout, const char *prompt) FAST_FUNC;
int ask_and_check_password(const struct passwd *pw) FAST_FUNC;
@@ -1537,10 +1438,6 @@ int get_terminal_width_height(int fd, unsigned *width, unsigned *height) FAST_FU
int get_terminal_width(int fd) FAST_FUNC;
int tcsetattr_stdin_TCSANOW(const struct termios *tp) FAST_FUNC;
#define TERMIOS_CLEAR_ISIG (1 << 0)
#define TERMIOS_RAW_CRNL (1 << 1)
#define TERMIOS_RAW_INPUT (1 << 2)
int set_termios_to_raw(int fd, struct termios *oldterm, int flags) FAST_FUNC;
/* NB: "unsigned request" is crucial! "int request" will break some arches! */
int ioctl_or_perror(int fd, unsigned request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5))) FAST_FUNC;
@@ -1852,23 +1749,19 @@ typedef struct sha3_ctx_t {
} sha3_ctx_t;
void md5_begin(md5_ctx_t *ctx) FAST_FUNC;
void md5_hash(md5_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
#define sha1_hash md5_hash
unsigned sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha256_begin(sha256_ctx_t *ctx) FAST_FUNC;
#define sha256_hash md5_hash
#define sha256_end sha1_end
void sha512_begin(sha512_ctx_t *ctx) FAST_FUNC;
void sha512_hash(sha512_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
unsigned sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
void sha3_begin(sha3_ctx_t *ctx) FAST_FUNC;
void sha3_hash(sha3_ctx_t *ctx, const void *buffer, size_t len) FAST_FUNC;
unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
/* TLS benefits from knowing that sha1 and sha256 share these. Give them "agnostic" names too */
typedef struct md5_ctx_t md5sha_ctx_t;
#define md5sha_hash md5_hash
#define sha_end sha1_end
void sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC;
extern uint32_t *global_crc32_table;
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
+5 -10
View File
@@ -108,18 +108,13 @@
* and/or smaller by using modified ABI. It is usually only needed
* on non-static, busybox internal functions. Recent versions of gcc
* optimize statics automatically. FAST_FUNC on static is required
* only if you need to match a function pointer's type.
* FAST_FUNC may not work well with -flto so allow user to disable this.
* (-DFAST_FUNC= )
*/
#ifndef FAST_FUNC
# if __GNUC_PREREQ(3,0) && defined(i386)
* only if you need to match a function pointer's type */
#if __GNUC_PREREQ(3,0) && defined(i386) /* || defined(__x86_64__)? */
/* stdcall makes callee to pop arguments from stack, not caller */
# define FAST_FUNC __attribute__((regparm(3),stdcall))
# define FAST_FUNC __attribute__((regparm(3),stdcall))
/* #elif ... - add your favorite arch today! */
# else
# define FAST_FUNC
# endif
#else
# define FAST_FUNC
#endif
/* Make all declarations hidden (-fvisibility flag only affects definitions) */
-8
View File
@@ -14,14 +14,6 @@
#define NOUSAGE_STR "\b"
#if !ENABLE_USE_BB_CRYPT || ENABLE_USE_BB_CRYPT_SHA
# define CRYPT_METHODS_HELP_STR "des,md5,sha256/512" \
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#else
# define CRYPT_METHODS_HELP_STR "des,md5" \
" (default "CONFIG_FEATURE_DEFAULT_PASSWD_ALGO")"
#endif
INSERT
#define busybox_notes_usage \
+1 -2
View File
@@ -46,9 +46,8 @@
//config: locating telinit executable.
//applet:IF_HALT(APPLET(halt, BB_DIR_SBIN, BB_SUID_DROP))
// APPLET_ODDNAME:name main location suid_type help
//applet:IF_POWEROFF(APPLET_ODDNAME(poweroff, halt, BB_DIR_SBIN, BB_SUID_DROP, poweroff))
//applet:IF_REBOOT( APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
//applet:IF_REBOOT(APPLET_ODDNAME(reboot, halt, BB_DIR_SBIN, BB_SUID_DROP, reboot))
//kbuild:lib-$(CONFIG_HALT) += halt.o
//kbuild:lib-$(CONFIG_POWEROFF) += halt.o
+26 -28
View File
@@ -17,7 +17,7 @@
//config: init is the first program run when the system boots.
//config:
//config:config LINUXRC
//config: bool "linuxrc: support running init from initrd (not initramfs)"
//config: bool "Support running init from within an initrd (not initramfs)"
//config: default y
//config: select FEATURE_SYSLOG
//config: help
@@ -73,15 +73,13 @@
//config: bool "Enable init to write to syslog"
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: If selected, some init messages are sent to syslog.
//config: Otherwise, they are sent to VT #5 if linux virtual tty is detected
//config: (if not, no separate logging is done).
//config:
//config:config FEATURE_INIT_QUIET
//config: bool "Be quiet on boot (no 'init started:' message)"
//config:config FEATURE_EXTRA_QUIET
//config: bool "Be _extra_ quiet on boot"
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: Prevent init from logging some messages to the console during boot.
//config:
//config:config FEATURE_INIT_COREDUMPS
//config: bool "Support dumping core for child processes (debugging only)"
@@ -106,13 +104,13 @@
//config: sets TERM to "vt102" if one is found.
//config:
//config:config FEATURE_INIT_MODIFY_CMDLINE
//config: bool "Clear init's command line"
//config: bool "Modify the command-line to \"init\""
//config: default y
//config: depends on INIT || LINUXRC
//config: help
//config: When launched as PID 1 and after parsing its arguments, init
//config: wipes all the arguments but argv[0] and rewrites argv[0] to
//config: contain only "init", so that its command line appears solely as
//config: contain only "init", so that its command-line appears solely as
//config: "init" in tools such as ps.
//config: If this option is set to Y, init will keep its original behavior,
//config: otherwise, all the arguments including argv[0] will be preserved,
@@ -216,9 +214,7 @@ struct init_action {
static struct init_action *init_action_list = NULL;
#if !ENABLE_FEATURE_INIT_SYSLOG
static const char *log_console = VC_5;
#endif
enum {
L_LOG = 0x1,
@@ -257,16 +253,17 @@ static void message(int where, const char *fmt, ...)
msg[l++] = '\n';
msg[l] = '\0';
#else
msg[l++] = '\n';
msg[l] = '\0';
if (where & L_LOG) {
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
{
static int log_fd = -1;
msg[l++] = '\n';
msg[l] = '\0';
/* Take full control of the log tty, and never close it.
* It's mine, all mine! Muhahahaha! */
if (log_fd < 0) {
log_fd = STDERR_FILENO;
if (log_console) {
if (!log_console) {
log_fd = STDERR_FILENO;
} else {
log_fd = device_open(log_console, O_WRONLY | O_NONBLOCK | O_NOCTTY);
if (log_fd < 0) {
bb_error_msg("can't log to %s", log_console);
@@ -276,9 +273,11 @@ static void message(int where, const char *fmt, ...)
}
}
}
full_write(log_fd, msg, l);
if (log_fd == STDERR_FILENO)
return; /* don't print dup messages */
if (where & L_LOG) {
full_write(log_fd, msg, l);
if (log_fd == STDERR_FILENO)
return; /* don't print dup messages */
}
}
#endif
@@ -328,9 +327,8 @@ static void console_init(void)
* if TERM is set to linux (the default) */
if (!s || strcmp(s, "linux") == 0)
putenv((char*)"TERM=vt102");
# if !ENABLE_FEATURE_INIT_SYSLOG
log_console = NULL;
# endif
if (!ENABLE_FEATURE_INIT_SYSLOG)
log_console = NULL;
} else
#endif
if (!s)
@@ -545,8 +543,8 @@ static pid_t run(const struct init_action *a)
}
/* Log the process name and args */
message(L_LOG, "starting pid %u, tty '%s': '%s'",
(int)getpid(), a->terminal, a->command);
message(L_LOG, "starting pid %d, tty '%s': '%s'",
getpid(), a->terminal, a->command);
/* Now run it. The new program will take over this PID,
* so nothing further in init.c should be run. */
@@ -761,7 +759,7 @@ static void run_shutdown_and_kill_processes(void)
/* Send signals to every process _except_ pid 1 */
kill(-1, SIGTERM);
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
message(L_CONSOLE | L_LOG, "Sent SIG%s to all processes", "TERM");
sync();
sleep(1);
@@ -1100,7 +1098,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
if (argv[1])
xsetenv("RUNLEVEL", argv[1]);
#if !ENABLE_FEATURE_INIT_QUIET
#if !ENABLE_FEATURE_EXTRA_QUIET
/* Hello world */
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
#endif
View File
File renamed without changes.
+16 -1
View File
@@ -70,13 +70,24 @@ config FEATURE_FAST_TOP
but code size is slightly bigger.
config FEATURE_ETC_NETWORKS
bool "Support /etc/networks"
bool "Support for /etc/networks"
default n
help
Enable support for network names in /etc/networks. This is
a rarely used feature which allows you to use names
instead of IP/mask pairs in route command.
config FEATURE_USE_TERMIOS
bool "Use termios to manipulate the screen"
default y
depends on MORE || TOP || POWERTOP
help
This option allows utilities such as 'more' and 'top' to determine
the size of the screen. If you leave this disabled, your utilities
that display things on the screen will be especially primitive and
will be unable to determine the current screen size, and will be
unable to move the cursor.
config FEATURE_EDITING
bool "Command line editing"
default y
@@ -136,11 +147,15 @@ config FEATURE_TAB_COMPLETION
bool "Tab completion"
default y
depends on FEATURE_EDITING
help
Enable tab completion.
config FEATURE_USERNAME_COMPLETION
bool "Username completion"
default y
depends on FEATURE_TAB_COMPLETION
help
Enable username completion.
config FEATURE_EDITING_FANCY_PROMPT
bool "Fancy shell prompts"
Loaded 100 of 351 files, more files were not shown because too many files have changed in this diff. Show more