Compare commits
344
Commits
1_26_2
...
1_27_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b400d9b2b | ||
|
|
81e26c4b8e | ||
|
|
0b16a67959 | ||
|
|
4989d05174 | ||
|
|
21e5d0f841 | ||
|
|
cf792a58ab | ||
|
|
0a53eadea5 | ||
|
|
25f07f5898 | ||
|
|
6bb89e1622 | ||
|
|
310bcec4dc | ||
|
|
8fd69c7bdb | ||
|
|
56a361bec1 | ||
|
|
6f13dd1d65 | ||
|
|
3df48bdde9 | ||
|
|
1f684bcde4 | ||
|
|
2cb72bb8de | ||
|
|
87d8ae94a2 | ||
|
|
a3de7190a5 | ||
|
|
f807b8e96e | ||
|
|
2f6dc07d8f | ||
|
|
54916641be | ||
|
|
80cb8796f8 | ||
|
|
ee67c9a60a | ||
|
|
8965e5089e | ||
|
|
e916d48e5a | ||
|
|
442d522f0b | ||
|
|
ceaffde511 | ||
|
|
7fdb764e2e | ||
|
|
4ee824f6ba | ||
|
|
48c803a206 | ||
|
|
e9aba3e7ea | ||
|
|
ba4fbca8a8 | ||
|
|
ae2b9f286c | ||
|
|
470bebe672 | ||
|
|
f56ddf2e4c | ||
|
|
9f4b4226a4 | ||
|
|
234b82ca19 | ||
|
|
4add757929 | ||
|
|
1c013fae28 | ||
|
|
5d72ae53c9 | ||
|
|
45100b8d07 | ||
|
|
62d1e98fbd | ||
|
|
2f24d30d01 | ||
|
|
978307f8a1 | ||
|
|
192dce4b84 | ||
|
|
6683d1cbb4 | ||
|
|
2599937c4e | ||
|
|
13d72c3fd9 | ||
|
|
f547041940 | ||
|
|
0c63299b84 | ||
|
|
bcb5764822 | ||
|
|
79c0d7332a | ||
|
|
ed820ccda1 | ||
|
|
741bfa9a72 | ||
|
|
c5d16e92c1 | ||
|
|
0cc9b1843d | ||
|
|
a1a3b595e1 | ||
|
|
5fe5be210c | ||
|
|
854174f7dd | ||
|
|
9c7ee1439a | ||
|
|
10ad622dc2 | ||
|
|
d85352b4ff | ||
|
|
8352b717ce | ||
|
|
44c0ab4102 | ||
|
|
107159ef1c | ||
|
|
933dcf1c8a | ||
|
|
021d50405b | ||
|
|
a3de0b3b86 | ||
|
|
335681ca8e | ||
|
|
517a82c5b6 | ||
|
|
c054822027 | ||
|
|
6c149f4d9a | ||
|
|
e139ae307e | ||
|
|
352ddd3d21 | ||
|
|
835ad3a984 | ||
|
|
c5496d3585 | ||
|
|
e31ca2e9b2 | ||
|
|
d9eb40c185 | ||
|
|
0cecbe7d5d | ||
|
|
783d57af7b | ||
|
|
ac47a00e2e | ||
|
|
1bc0bd13b5 | ||
|
|
67918b32ab | ||
|
|
b9512fa6b3 | ||
|
|
a976aaab0b | ||
|
|
8a134ec680 | ||
|
|
10673c44f1 | ||
|
|
cc1f8ba489 | ||
|
|
ad5394d591 | ||
|
|
dd3a395053 | ||
|
|
4908c79a01 | ||
|
|
f428f1dc6c | ||
|
|
12dc4fbf18 | ||
|
|
bef1713217 | ||
|
|
c6476dca54 | ||
|
|
c804d4ec5c | ||
|
|
7e5f2f3b51 | ||
|
|
1d232fd440 | ||
|
|
c1b5b2a190 | ||
|
|
ee7f75d94f | ||
|
|
87ae0fe095 | ||
|
|
0f7f1ae094 | ||
|
|
2f59bf39e2 | ||
|
|
42776708f2 | ||
|
|
7121bb8023 | ||
|
|
4eaa0f7729 | ||
|
|
eb76abb4f7 | ||
|
|
826bdcd51c | ||
|
|
d5342a1ad1 | ||
|
|
1140bf39ab | ||
|
|
2d4823b65b | ||
|
|
a7386bb35b | ||
|
|
4f0b540d08 | ||
|
|
0d6e3ad663 | ||
|
|
803c85a207 | ||
|
|
9c192e7f94 | ||
|
|
19578b4edf | ||
|
|
e7ac7abf06 | ||
|
|
d88f94a5df | ||
|
|
5d561ef634 | ||
|
|
229d3c467d | ||
|
|
636c3b627c | ||
|
|
6e99f1cb45 | ||
|
|
8808f7fc2e | ||
|
|
257734855c | ||
|
|
ab03061615 | ||
|
|
ed898ed2dd | ||
|
|
64d58aa806 | ||
|
|
e09f5e3045 | ||
|
|
8f3bf4f0d3 | ||
|
|
e3b65ab43d | ||
|
|
876c121ccb | ||
|
|
f4a670a911 | ||
|
|
f1db95abfb | ||
|
|
d2383f57cd | ||
|
|
dba0dc1999 | ||
|
|
a98db793cf | ||
|
|
ab518eea9c | ||
|
|
018804204f | ||
|
|
e88608eae2 | ||
|
|
02a2a278f6 | ||
|
|
74c2215086 | ||
|
|
7c67f1e9ab | ||
|
|
94dcfd8cc0 | ||
|
|
52a515d187 | ||
|
|
dc207f6696 | ||
|
|
5b3b468ec0 | ||
|
|
0ec4d08ea3 | ||
|
|
c39ee04705 | ||
|
|
af316aabf2 | ||
|
|
c393b1e919 | ||
|
|
c2b18583a3 | ||
|
|
415cc42b6a | ||
|
|
4ae658f077 | ||
|
|
8cc1ab3c11 | ||
|
|
8762512fdb | ||
|
|
c31b54fd81 | ||
|
|
5b05d9db29 | ||
|
|
5f7c82b32f | ||
|
|
b6871c1965 | ||
|
|
b1d6a2c624 | ||
|
|
264cb01540 | ||
|
|
fdfd716a85 | ||
|
|
dc7637d0aa | ||
|
|
b5b21126ca | ||
|
|
d6ace66973 | ||
|
|
ca659f84b2 | ||
|
|
065e988e7a | ||
|
|
67f6db6b27 | ||
|
|
35b54a3c24 | ||
|
|
eba7fe6bb9 | ||
|
|
86663910ba | ||
|
|
b181ca7552 | ||
|
|
ef0e76cc27 | ||
|
|
205d48e948 | ||
|
|
b4b12bf234 | ||
|
|
4d417709b0 | ||
|
|
786c9dc0c1 | ||
|
|
9967c9949e | ||
|
|
06f20bf675 | ||
|
|
7dd906a388 | ||
|
|
62a9b18547 | ||
|
|
cb8e84e65a | ||
|
|
b13b618335 | ||
|
|
8a2657cbf5 | ||
|
|
0f4364775f | ||
|
|
2181fb4af8 | ||
|
|
dff9fefd50 | ||
|
|
bca4ea8b68 | ||
|
|
89193f985b | ||
|
|
1500b3a50d | ||
|
|
49ecee098d | ||
|
|
9a64c3337c | ||
|
|
ccc1699e3e | ||
|
|
92c6898e10 | ||
|
|
4cde4cca65 | ||
|
|
96d9c5bdbd | ||
|
|
51b01fda30 | ||
|
|
a1cbaca1ba | ||
|
|
2c3131d88e | ||
|
|
5d43ddc59b | ||
|
|
b60686cc2a | ||
|
|
f5bd6f631c | ||
|
|
11540a8da4 | ||
|
|
7a18b9502a | ||
|
|
b5bf1913d3 | ||
|
|
9492da7e63 | ||
|
|
9a647c326a | ||
|
|
e1f90d13fa | ||
|
|
f580baf94a | ||
|
|
194b2ebd2a | ||
|
|
12389889c0 | ||
|
|
8908c1d4f5 | ||
|
|
f3d705f41b | ||
|
|
bbc7bee966 | ||
|
|
f6e20724d4 | ||
|
|
dd2577f21a | ||
|
|
0af5265180 | ||
|
|
54b927d78b | ||
|
|
3916139ac4 | ||
|
|
9731ca7611 | ||
|
|
38972a8df1 | ||
|
|
e7863f394e | ||
|
|
6e511393f9 | ||
|
|
179e88bec9 | ||
|
|
19e695ebad | ||
|
|
a0aae9f714 | ||
|
|
abbf17abcc | ||
|
|
f7806f9d8f | ||
|
|
432f1ae2ff | ||
|
|
6b1b004845 | ||
|
|
1bfc4b85a7 | ||
|
|
704c606f48 | ||
|
|
cccf8e735d | ||
|
|
a9e1866806 | ||
|
|
b5dfc3dfd6 | ||
|
|
b7e9ae6e9f | ||
|
|
c8ba23bcec | ||
|
|
5d1662ea1c | ||
|
|
e69d78c038 | ||
|
|
fe0588df3b | ||
|
|
e2cb3b990f | ||
|
|
9a6897a48a | ||
|
|
4e08a123b0 | ||
|
|
936e83e694 | ||
|
|
6c73aaff38 | ||
|
|
16e7f697f8 | ||
|
|
b8935d00b0 | ||
|
|
3f8ecd933a | ||
|
|
c5540d61f6 | ||
|
|
f78ad0938b | ||
|
|
11d0096516 | ||
|
|
2a17d1fc9b | ||
|
|
b1003f7019 | ||
|
|
ceff6b0ea9 | ||
|
|
a6f8651911 | ||
|
|
098b713c7b | ||
|
|
4c179373e0 | ||
|
|
ed15dde60a | ||
|
|
6c1f348fa7 | ||
|
|
01ccdd1d3c | ||
|
|
8944c67b1f | ||
|
|
027d3ab57d | ||
|
|
7d4aec0c3e | ||
|
|
a8a075acfe | ||
|
|
0fd9fb4244 | ||
|
|
c5891fe1af | ||
|
|
80f806cac9 | ||
|
|
a1184af5f8 | ||
|
|
f35ad3bd12 | ||
|
|
2b4c258e74 | ||
|
|
265062d59d | ||
|
|
f560422fa0 | ||
|
|
f10f7a21d4 | ||
|
|
61a91af63d | ||
|
|
1cc6804f69 | ||
|
|
53487a8d22 | ||
|
|
e7b54d0fcc | ||
|
|
590402bb55 | ||
|
|
3989e5adf4 | ||
|
|
8c1d857d25 | ||
|
|
6b4f4b5284 | ||
|
|
2a0867a5ed | ||
|
|
6bf52b615d | ||
|
|
80172e4622 | ||
|
|
b130f9f758 | ||
|
|
fb87d93d1e | ||
|
|
2b1559056c | ||
|
|
4e4f88e569 | ||
|
|
cc2fd5a986 | ||
|
|
5362cc4b8c | ||
|
|
fd68f1e80d | ||
|
|
442a414d66 | ||
|
|
41ade05cac | ||
|
|
4471969db2 | ||
|
|
6ec76d8719 | ||
|
|
d5933b1125 | ||
|
|
10d5ece64a | ||
|
|
7a85c60e7e | ||
|
|
1125d7d680 | ||
|
|
d5b5c2fa15 | ||
|
|
0ef478f01b | ||
|
|
4d06b31453 | ||
|
|
d5e7ff0292 | ||
|
|
a474728e82 | ||
|
|
0ffac1cc22 | ||
|
|
86584e134e | ||
|
|
fe93624fb6 | ||
|
|
6cd0294725 | ||
|
|
b62ea34afe | ||
|
|
e6add210b2 | ||
|
|
ecba2944d5 | ||
|
|
e3c4db8b39 | ||
|
|
9c083f599a | ||
|
|
9529115c4c | ||
|
|
c6137ba510 | ||
|
|
c6725b0af6 | ||
|
|
d3720828ea | ||
|
|
f1d76b64a0 | ||
|
|
b05bcaf29c | ||
|
|
ea7d2f6ec0 | ||
|
|
bddbeb82bf | ||
|
|
7890035452 | ||
|
|
1f71014fd6 | ||
|
|
96f1d6b70c | ||
|
|
7d5c881bd0 | ||
|
|
0b8835861b | ||
|
|
04c1a2a2c4 | ||
|
|
3bf4d69250 | ||
|
|
100aea8486 | ||
|
|
a1cd0d9849 | ||
|
|
ce3a98a222 | ||
|
|
4ea0ebdd42 | ||
|
|
1afa494fd1 | ||
|
|
10c01a711f | ||
|
|
9cc3d3ab21 | ||
|
|
7c5dea399b | ||
|
|
5d27cb3640 | ||
|
|
6704746c69 | ||
|
|
4acd393eba | ||
|
|
326edc3e37 | ||
|
|
2166952ec3 | ||
|
|
3a4cdf45f9 | ||
|
|
b5b1d2c5a8 |
No files matched your search
@@ -178,3 +178,6 @@ 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
|
||||
@@ -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,6 +33,19 @@ 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
|
||||
@@ -50,17 +63,6 @@ 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
|
||||
@@ -124,14 +126,14 @@ config INSTALL_NO_USR
|
||||
never to /usr/bin or /usr/sbin.
|
||||
|
||||
config PAM
|
||||
bool "Support for PAM (Pluggable Authentication Modules)"
|
||||
bool "Support 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 for --long-options"
|
||||
bool "Support --long-options"
|
||||
default y
|
||||
help
|
||||
Enable this if you want busybox applets to use the gnu --long-option
|
||||
@@ -198,7 +200,7 @@ config PID_FILE_PATH
|
||||
specify a pidfile path.
|
||||
|
||||
config FEATURE_SUID
|
||||
bool "Support for SUID/SGID handling"
|
||||
bool "Support SUID/SGID handling"
|
||||
default y
|
||||
help
|
||||
With this option you can install the busybox binary belonging
|
||||
@@ -338,6 +340,17 @@ 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
|
||||
@@ -611,6 +624,8 @@ 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
|
||||
@@ -625,7 +640,7 @@ config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
help
|
||||
Selecting this will add -Werror to gcc command line.
|
||||
This adds -Werror to gcc command line.
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 26
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 27
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
|
||||
@@ -36,6 +36,9 @@ 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
|
||||
|
||||
@@ -8,32 +8,22 @@ 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
@@ -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 for long filenames (not needed for debs)"
|
||||
//config: bool "Support long filenames (not needed for debs)"
|
||||
//config: default y
|
||||
//config: depends on AR
|
||||
//config: help
|
||||
|
||||
+78
-48
@@ -7,21 +7,31 @@
|
||||
#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
|
||||
//kbuild:lib-$(CONFIG_UNLZOP) += bbunzip.o
|
||||
/* bzip2_main() too: */
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
/* gzip_main() too: */
|
||||
//kbuild:lib-$(CONFIG_GZIP) += bbunzip.o
|
||||
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
OPT_STDOUT = 1 << 0,
|
||||
OPT_FORCE = 1 << 1,
|
||||
/* only some decompressors: */
|
||||
OPT_VERBOSE = 1 << 2,
|
||||
OPT_QUIET = 1 << 3,
|
||||
OPT_DECOMPRESS = 1 << 4,
|
||||
OPT_TEST = 1 << 5,
|
||||
SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION,
|
||||
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,
|
||||
};
|
||||
|
||||
static
|
||||
@@ -123,7 +133,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
xstate.signature_skipped = 0;
|
||||
/*xstate.signature_skipped = 0; - already is */
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
xstate.dst_fd = STDOUT_FILENO;
|
||||
status = unpacker(&xstate);
|
||||
@@ -178,8 +188,11 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
/* Delete _source_ file */
|
||||
del = filename;
|
||||
if (option_mask32 & OPT_KEEP) /* ... unless -k */
|
||||
del = NULL;
|
||||
}
|
||||
xunlink(del);
|
||||
if (del)
|
||||
xunlink(del);
|
||||
free_name:
|
||||
if (new_name != filename)
|
||||
free(new_name);
|
||||
@@ -193,7 +206,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
#if ENABLE_UNCOMPRESS \
|
||||
|| ENABLE_BUNZIP2 || ENABLE_BZCAT \
|
||||
|| ENABLE_FEATURE_BZIP2_DECOMPRESS \
|
||||
|| ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
|
||||
|| ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
|
||||
static
|
||||
@@ -236,7 +249,16 @@ 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");
|
||||
@@ -269,11 +291,12 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*/
|
||||
//usage:#define gunzip_trivial_usage
|
||||
//usage: "[-cft] [FILE]..."
|
||||
//usage: "[-cfkt] [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
|
||||
@@ -291,6 +314,7 @@ 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
|
||||
@@ -299,6 +323,7 @@ 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:
|
||||
@@ -306,14 +331,11 @@ 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))
|
||||
//kbuild:lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_ZCAT) += bbunzip.o
|
||||
#if ENABLE_GUNZIP || ENABLE_ZCAT
|
||||
#if ENABLE_FEATURE_GZIP_DECOMPRESS
|
||||
static
|
||||
char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
{
|
||||
@@ -369,7 +391,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
applet_long_options = gunzip_longopts;
|
||||
#endif
|
||||
getopt32(argv, "cfvqdtn");
|
||||
getopt32(argv, "cfkvqdtn");
|
||||
argv += optind;
|
||||
|
||||
/* If called as zcat...
|
||||
@@ -381,7 +403,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
#endif
|
||||
#endif /* FEATURE_GZIP_DECOMPRESS */
|
||||
|
||||
|
||||
/*
|
||||
@@ -391,11 +413,12 @@ 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: "[-cf] [FILE]..."
|
||||
//usage: "[-cfk] [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"
|
||||
@@ -404,6 +427,7 @@ 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
|
||||
@@ -417,18 +441,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))
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BZCAT) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2 || ENABLE_BZCAT
|
||||
#if ENABLE_FEATURE_BZIP2_DECOMPRESS || 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, "cfvqdt");
|
||||
getopt32(argv, "cfkvqdt");
|
||||
argv += optind;
|
||||
if (ENABLE_BZCAT && applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
@@ -447,44 +471,26 @@ 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: "[-cf] [FILE]..."
|
||||
//usage: "[-cfk] [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 [-cf] [FILE]..."
|
||||
//usage: "-d [-cfk] [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"
|
||||
@@ -518,7 +524,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 unlzma for speed"
|
||||
//config: bool "Optimize for speed"
|
||||
//config: default n
|
||||
//config: depends on UNLZMA || LZCAT || LZMA
|
||||
//config: help
|
||||
@@ -526,8 +532,9 @@ 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
|
||||
@@ -535,7 +542,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, "cfvqdt");
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
@@ -551,6 +558,28 @@ 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
|
||||
@@ -571,8 +600,9 @@ 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
|
||||
@@ -580,7 +610,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, "cfvqdt");
|
||||
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
|
||||
+19
-6
@@ -19,6 +19,15 @@
|
||||
//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
|
||||
@@ -28,9 +37,13 @@
|
||||
//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"
|
||||
@@ -184,13 +197,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, "cfv" IF_BUNZIP2("dt") "123456789qzs");
|
||||
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
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
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 5;
|
||||
opt >>= 6;
|
||||
#else
|
||||
opt >>= 3;
|
||||
opt >>= 4;
|
||||
#endif
|
||||
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
@@ -201,6 +214,6 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
option_mask32 &= 0x7; /* ignore all except -cfv */
|
||||
option_mask32 &= 0xf; /* ignore all except -cfkv */
|
||||
return bbunpack(argv, compressStream, append_ext, "bz2");
|
||||
}
|
||||
+2
-2
@@ -29,7 +29,7 @@
|
||||
//config: should probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_CPIO_O
|
||||
//config: bool "Support for archive creation"
|
||||
//config: bool "Support 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 for passthrough mode"
|
||||
//config: bool "Support passthrough mode"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CPIO_O
|
||||
//config: help
|
||||
|
||||
+14
-18
@@ -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 isnt placed on a new line.
|
||||
* - the first value for the confflile: field isn't 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.
|
||||
*
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg"
|
||||
//config: default n
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg is a medium-level tool to install, build, remove and manage
|
||||
@@ -110,7 +110,7 @@ typedef struct common_node_s {
|
||||
edge_t **edge;
|
||||
} common_node_t;
|
||||
|
||||
/* Currently it doesnt store packages that have state-status of not-installed
|
||||
/* Currently it doesn't 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 DOESNT add the key to the hashtable
|
||||
/* this DOESN'T 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 isnt already in there */
|
||||
/* Get the versions hash number, adding it if the number isn't 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 isnt already in there */
|
||||
/* Get the versions hash number, adding it if the number isn't 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 ':' isnt
|
||||
/* TODO: Name might still have trailing spaces if ':' isn't
|
||||
* 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 doesnt handle the status field */
|
||||
/* fill_package_struct doesn't 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 isnt exactly the same as old status */
|
||||
/* New status isn't 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 wasnt handle above, do it now*/
|
||||
/* If the package from the status file wasn't 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 doesnt exist, maybe we are starting from scratch */
|
||||
* file doesn't 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 dependendcies */
|
||||
/* Check dependentcies */
|
||||
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 doesnt exist is isnt fatal */
|
||||
/* If the file doesn't exist it isn't 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 isnt changed to "ok" until the package control info
|
||||
/* reinstreq isn't 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,10 +1938,6 @@ 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;
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default n
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
//config: dpkg-deb unpacks and provides information about Debian archives.
|
||||
|
||||
+25
-16
@@ -48,11 +48,9 @@ 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 gzip speed (0:small,slow - 2:fast,big)"
|
||||
//config: int "Trade memory for speed (0:small,slow - 2:fast,big)"
|
||||
//config: default 0
|
||||
//config: range 0 2
|
||||
//config: depends on GZIP
|
||||
@@ -72,22 +70,33 @@ 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: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
|
||||
//usage: "[-cfk" IF_FEATURE_GZIP_DECOMPRESS("dt") 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_GUNZIP(
|
||||
//usage: IF_FEATURE_GZIP_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"
|
||||
//usage:
|
||||
//usage:#define gzip_example_usage
|
||||
//usage: "$ ls -la /tmp/busybox*\n"
|
||||
@@ -267,7 +276,7 @@ enum {
|
||||
* input file length plus MIN_LOOKAHEAD.
|
||||
*/
|
||||
|
||||
#ifndef ENABLE_FEATURE_GZIP_LEVELS
|
||||
#if !ENABLE_FEATURE_GZIP_LEVELS
|
||||
|
||||
max_chain_length = 4096,
|
||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||
@@ -306,7 +315,7 @@ enum {
|
||||
|
||||
struct globals {
|
||||
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
#if ENABLE_FEATURE_GZIP_LEVELS
|
||||
unsigned max_chain_length;
|
||||
unsigned max_lazy_match;
|
||||
unsigned good_match;
|
||||
@@ -2154,7 +2163,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_GUNZIP
|
||||
#if ENABLE_FEATURE_GZIP_DECOMPRESS
|
||||
"decompress\0" No_argument "d"
|
||||
"uncompress\0" No_argument "d"
|
||||
"test\0" No_argument "t"
|
||||
@@ -2181,14 +2190,14 @@ static const char gzip_longopts[] ALIGN1 =
|
||||
*/
|
||||
|
||||
int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
#if ENABLE_GUNZIP
|
||||
#if ENABLE_FEATURE_GZIP_DECOMPRESS
|
||||
int gzip_main(int argc, char **argv)
|
||||
#else
|
||||
int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
{
|
||||
unsigned opt;
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
#if ENABLE_FEATURE_GZIP_LEVELS
|
||||
static const struct {
|
||||
uint8_t good;
|
||||
uint8_t chain_shift;
|
||||
@@ -2211,13 +2220,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, "cfv" IF_GUNZIP("dt") "qn123456789");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
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
|
||||
return gunzip_main(argc, argv);
|
||||
#endif
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
opt >>= ENABLE_GUNZIP ? 7 : 5; /* drop cfv[dt]qn bits */
|
||||
#if ENABLE_FEATURE_GZIP_LEVELS
|
||||
opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[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] */
|
||||
@@ -2226,7 +2235,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 &= 0x7; /* retain only -cfv */
|
||||
option_mask32 &= 0xf; /* retain only -cfkv */
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
|
||||
@@ -51,16 +51,19 @@ 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
|
||||
lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_BZCAT) += open_transformer.o decompress_bunzip2.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_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_GUNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_ZCAT) += open_transformer.o decompress_gunzip.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_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
|
||||
|
||||
@@ -127,8 +127,9 @@ 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 "
|
||||
"from %s to %s", "hard",
|
||||
"%s to %s", "hard",
|
||||
dst_name,
|
||||
hard_link);
|
||||
}
|
||||
@@ -181,8 +182,9 @@ 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 "
|
||||
"from %s to %s", "sym",
|
||||
"%s to %s", "sym",
|
||||
dst_name,
|
||||
file_header->link_target);
|
||||
}
|
||||
|
||||
@@ -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 & ((1 << bit_count) - 1);
|
||||
bits = bd->inbufBits & ((1U << 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, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
|
||||
i, j, runPos, symCount, symTotal, nSelectors, byteCount[256];
|
||||
int runCnt = runCnt; /* for compiler */
|
||||
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
|
||||
uint32_t *dbuf;
|
||||
unsigned origPtr;
|
||||
unsigned origPtr, t;
|
||||
|
||||
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[]. Concurently, initialize temp[] and limit[]. */
|
||||
/* Calculate permute[]. Concurrently, initialize temp[] and limit[]. */
|
||||
pp = 0;
|
||||
for (i = minLen; i <= maxLen; i++) {
|
||||
int k;
|
||||
|
||||
@@ -278,9 +278,10 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
|
||||
if (state >= LZMA_NUM_LIT_STATES) {
|
||||
int match_byte;
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
uint32_t pos;
|
||||
|
||||
while (pos >= header.dict_size)
|
||||
pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
match_byte = buffer[pos];
|
||||
do {
|
||||
@@ -336,9 +337,11 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
);
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
uint32_t pos;
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
while (pos >= header.dict_size)
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
goto one_byte1;
|
||||
@@ -429,10 +432,25 @@ 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;
|
||||
while (pos >= header.dict_size)
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
|
||||
@@ -448,6 +466,9 @@ 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...
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 splitted in three
|
||||
* Decode one bit. In some versions, this function has been split 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-splitted version results in nicer looking code too.
|
||||
* on x86). Using a non-split 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,
|
||||
|
||||
+37
-19
@@ -33,13 +33,13 @@
|
||||
//config:
|
||||
//config:config UNLZOP
|
||||
//config: bool "unlzop"
|
||||
//config: default y
|
||||
//config: default n # INCOMPAT: upstream lzop does not provide such tool
|
||||
//config: help
|
||||
//config: Lzop decompresion.
|
||||
//config:
|
||||
//config:config LZOPCAT
|
||||
//config: bool "lzopcat"
|
||||
//config: default y
|
||||
//config: default n # INCOMPAT: upstream lzop does not provide such tool
|
||||
//config: help
|
||||
//config: Alias to "unlzop -c".
|
||||
//config:
|
||||
@@ -53,19 +53,22 @@
|
||||
//config: and take up 3.2K of code.
|
||||
|
||||
//applet:IF_LZOP(APPLET(lzop, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_UNLZOP(APPLET_ODDNAME(unlzop, lzop, BB_DIR_USR_BIN, BB_SUID_DROP, unlzop))
|
||||
// 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_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: "[-cfvd123456789CF] [FILE]..."
|
||||
//usage: "[-cfUvd123456789CF] [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"
|
||||
@@ -77,10 +80,12 @@
|
||||
//usage: "\n -F Don't verify checksum"
|
||||
//usage:
|
||||
//usage:#define unlzop_trivial_usage
|
||||
//usage: "[-cfvF] [FILE]..."
|
||||
//usage: "[-cfkvF] [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"
|
||||
|
||||
@@ -471,27 +476,33 @@ struct globals {
|
||||
//#define LZOP_VERSION_STRING "1.01"
|
||||
//#define LZOP_VERSION_DATE "Apr 27th 2003"
|
||||
|
||||
#define OPTION_STRING "cfvqdt123456789CF"
|
||||
// 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"
|
||||
|
||||
/* Note: must be kept in sync with archival/bbunzip.c */
|
||||
enum {
|
||||
OPT_STDOUT = (1 << 0),
|
||||
OPT_FORCE = (1 << 1),
|
||||
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_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_7 = (1 << 13),
|
||||
OPT_8 = (1 << 14),
|
||||
OPT_C = (1 << 15),
|
||||
OPT_F = (1 << 16),
|
||||
OPT_9 = (1 << 15),
|
||||
OPT_C = (1 << 16),
|
||||
OPT_F = (1 << 17),
|
||||
OPT_k = (1 << 18),
|
||||
OPT_789 = OPT_7 | OPT_8 | OPT_9
|
||||
};
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -1124,6 +1135,13 @@ 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);
|
||||
|
||||
+29
-35
@@ -49,13 +49,15 @@
|
||||
//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 archive creation"
|
||||
//config: bool "Enable -c (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"
|
||||
@@ -74,7 +76,7 @@
|
||||
//config: a list of files to include or exclude from an archive.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
//config: bool "Support for old tar header format"
|
||||
//config: bool "Support old tar header format"
|
||||
//config: default y
|
||||
//config: depends on TAR || DPKG
|
||||
//config: help
|
||||
@@ -93,22 +95,12 @@
|
||||
//config: tarballs still exist.
|
||||
//config:
|
||||
//config:config FEATURE_TAR_GNU_EXTENSIONS
|
||||
//config: bool "Support for GNU tar extensions (long filenames)"
|
||||
//config: bool "Support 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 for writing to an external program"
|
||||
//config: bool "Support writing to an external program (--to-command)"
|
||||
//config: default y
|
||||
//config: depends on TAR && FEATURE_TAR_LONG_OPTIONS
|
||||
//config: help
|
||||
@@ -121,20 +113,17 @@
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
//config: Enables use of user and group names in tar. This affects contents
|
||||
//config: Enable 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) option"
|
||||
//config: bool "Enable -m (do not preserve time) GNU 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 for extracting SELinux labels"
|
||||
//config: bool "Support extracting SELinux labels"
|
||||
//config: default n
|
||||
//config: depends on TAR && SELINUX
|
||||
//config: help
|
||||
@@ -540,8 +529,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 occurance of a given dev/inode as a file while
|
||||
* treating any additional occurances as hard links. This is done
|
||||
* Treat the first occurrence of a given dev/inode as a file while
|
||||
* treating any additional occurrences as hard links. This is done
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
@@ -1227,21 +1216,26 @@ 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(xformer = unpack_Z_stream;)
|
||||
if (opt & OPT_COMPRESS) {
|
||||
USE_FOR_MMU(IF_FEATURE_SEAMLESS_Z(xformer = unpack_Z_stream;))
|
||||
USE_FOR_NOMMU(xformer_prog = "uncompress";)
|
||||
if (opt & OPT_GZIP)
|
||||
USE_FOR_MMU(xformer = unpack_gz_stream;)
|
||||
}
|
||||
if (opt & OPT_GZIP) {
|
||||
USE_FOR_MMU(IF_FEATURE_SEAMLESS_GZ(xformer = unpack_gz_stream;))
|
||||
USE_FOR_NOMMU(xformer_prog = "gunzip";)
|
||||
if (opt & OPT_BZIP2)
|
||||
USE_FOR_MMU(xformer = unpack_bz2_stream;)
|
||||
}
|
||||
if (opt & OPT_BZIP2) {
|
||||
USE_FOR_MMU(IF_FEATURE_SEAMLESS_BZ2(xformer = unpack_bz2_stream;))
|
||||
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
|
||||
if (opt & OPT_LZMA)
|
||||
USE_FOR_MMU(xformer = unpack_lzma_stream;)
|
||||
}
|
||||
if (opt & OPT_LZMA) {
|
||||
USE_FOR_MMU(IF_FEATURE_SEAMLESS_LZMA(xformer = unpack_lzma_stream;))
|
||||
USE_FOR_NOMMU(xformer_prog = "unlzma";)
|
||||
if (opt & OPT_XZ)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
}
|
||||
if (opt & OPT_XZ) {
|
||||
USE_FOR_MMU(IF_FEATURE_SEAMLESS_XZ(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 */
|
||||
|
||||
+396
-304
@@ -16,7 +16,6 @@
|
||||
* TODO
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip"
|
||||
//config: default y
|
||||
@@ -24,8 +23,34 @@
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
//config: commonly found on DOS/WIN systems. The default behavior
|
||||
//config: (with no options) is to extract the archive into the
|
||||
//config: current directory. Use the `-d' option to extract to a
|
||||
//config: directory of your choice.
|
||||
//config: current directory.
|
||||
//config:
|
||||
//config:config FEATURE_UNZIP_CDF
|
||||
//config: bool "Read and use Central Directory data"
|
||||
//config: default y
|
||||
//config: depends on UNZIP
|
||||
//config: help
|
||||
//config: If you know that you only need to deal with simple
|
||||
//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
|
||||
@@ -54,8 +79,8 @@
|
||||
enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* central directory's file header */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* "end of central directory" record */
|
||||
ZIP_CDF_MAGIC = 0x504b0102, /* CDF item */
|
||||
ZIP_CDE_MAGIC = 0x504b0506, /* End of CDF */
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
@@ -80,30 +105,21 @@ typedef union {
|
||||
uint32_t ucmpsize PACKED; /* 18-21 */
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
} formatted PACKED;
|
||||
/* filename follows (not NUL terminated) */
|
||||
/* extra field follows */
|
||||
/* data follows */
|
||||
} fmt PACKED;
|
||||
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
|
||||
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
struct BUG_zip_header_must_be_26_bytes {
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2
|
||||
== ZIP_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_ZIP(zip_header) do { \
|
||||
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
|
||||
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
|
||||
(zip_header).formatted.modtime = SWAP_LE16((zip_header).formatted.modtime ); \
|
||||
(zip_header).formatted.moddate = SWAP_LE16((zip_header).formatted.moddate ); \
|
||||
(zip_header).formatted.crc32 = SWAP_LE32((zip_header).formatted.crc32 ); \
|
||||
(zip_header).formatted.cmpsize = SWAP_LE32((zip_header).formatted.cmpsize ); \
|
||||
(zip_header).formatted.ucmpsize = SWAP_LE32((zip_header).formatted.ucmpsize ); \
|
||||
(zip_header).formatted.filename_len = SWAP_LE16((zip_header).formatted.filename_len); \
|
||||
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
|
||||
} while (0)
|
||||
#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 ); \
|
||||
(zip).fmt.filename_len = SWAP_LE16((zip).fmt.filename_len); \
|
||||
(zip).fmt.extra_len = SWAP_LE16((zip).fmt.extra_len ); \
|
||||
}} while (0)
|
||||
|
||||
#define CDF_HEADER_LEN 42
|
||||
|
||||
@@ -115,44 +131,44 @@ typedef union {
|
||||
uint16_t version_needed; /* 2-3 */
|
||||
uint16_t cdf_flags; /* 4-5 */
|
||||
uint16_t method; /* 6-7 */
|
||||
uint16_t mtime; /* 8-9 */
|
||||
uint16_t mdate; /* 10-11 */
|
||||
uint16_t modtime; /* 8-9 */
|
||||
uint16_t moddate; /* 10-11 */
|
||||
uint32_t crc32; /* 12-15 */
|
||||
uint32_t cmpsize; /* 16-19 */
|
||||
uint32_t ucmpsize; /* 20-23 */
|
||||
uint16_t file_name_length; /* 24-25 */
|
||||
uint16_t extra_field_length; /* 26-27 */
|
||||
uint16_t filename_len; /* 24-25 */
|
||||
uint16_t extra_len; /* 26-27 */
|
||||
uint16_t file_comment_length; /* 28-29 */
|
||||
uint16_t disk_number_start; /* 30-31 */
|
||||
uint16_t internal_file_attributes; /* 32-33 */
|
||||
uint32_t external_file_attributes PACKED; /* 34-37 */
|
||||
uint16_t internal_attributes; /* 32-33 */
|
||||
uint32_t external_attributes PACKED; /* 34-37 */
|
||||
uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
|
||||
} formatted PACKED;
|
||||
/* filename follows (not NUL terminated) */
|
||||
/* extra field follows */
|
||||
/* file comment follows */
|
||||
} fmt PACKED;
|
||||
} cdf_header_t;
|
||||
|
||||
struct BUG_cdf_header_must_be_42_bytes {
|
||||
char BUG_cdf_header_must_be_42_bytes[
|
||||
offsetof(cdf_header_t, formatted.relative_offset_of_local_header) + 4
|
||||
== CDF_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
#define FIX_ENDIANNESS_CDF(cdf) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
|
||||
(cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
|
||||
}} while (0)
|
||||
|
||||
#define FIX_ENDIANNESS_CDF(cdf_header) do { \
|
||||
(cdf_header).formatted.crc32 = SWAP_LE32((cdf_header).formatted.crc32 ); \
|
||||
(cdf_header).formatted.cmpsize = SWAP_LE32((cdf_header).formatted.cmpsize ); \
|
||||
(cdf_header).formatted.ucmpsize = SWAP_LE32((cdf_header).formatted.ucmpsize ); \
|
||||
(cdf_header).formatted.file_name_length = SWAP_LE16((cdf_header).formatted.file_name_length); \
|
||||
(cdf_header).formatted.extra_field_length = SWAP_LE16((cdf_header).formatted.extra_field_length); \
|
||||
(cdf_header).formatted.file_comment_length = SWAP_LE16((cdf_header).formatted.file_comment_length); \
|
||||
IF_DESKTOP( \
|
||||
(cdf_header).formatted.version_made_by = SWAP_LE16((cdf_header).formatted.version_made_by); \
|
||||
(cdf_header).formatted.external_file_attributes = SWAP_LE32((cdf_header).formatted.external_file_attributes); \
|
||||
) \
|
||||
} while (0)
|
||||
|
||||
#define CDE_HEADER_LEN 16
|
||||
#define CDE_LEN 16
|
||||
|
||||
typedef union {
|
||||
uint8_t raw[CDE_HEADER_LEN];
|
||||
uint8_t raw[CDE_LEN];
|
||||
struct {
|
||||
/* uint32_t signature; 50 4b 05 06 */
|
||||
uint16_t this_disk_no;
|
||||
@@ -161,25 +177,43 @@ typedef union {
|
||||
uint16_t cdf_entries_total;
|
||||
uint32_t cdf_size;
|
||||
uint32_t cdf_offset;
|
||||
/* uint16_t file_comment_length; */
|
||||
/* .ZIP file comment (variable size) */
|
||||
} formatted PACKED;
|
||||
} cde_header_t;
|
||||
/* uint16_t archive_comment_length; */
|
||||
/* archive comment follows */
|
||||
} fmt PACKED;
|
||||
} cde_t;
|
||||
|
||||
struct BUG_cde_header_must_be_16_bytes {
|
||||
char BUG_cde_header_must_be_16_bytes[
|
||||
sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
|
||||
#define FIX_ENDIANNESS_CDE(cde) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cde).fmt.cdf_offset = SWAP_LE32((cde).fmt.cdf_offset); \
|
||||
}} while (0)
|
||||
|
||||
struct BUG {
|
||||
/* Check the offset of the last element, not the length. This leniency
|
||||
* allows for poor packing, whereby the overall struct may be too long,
|
||||
* even though the elements are all in the right place.
|
||||
*/
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, fmt.extra_len) + 2
|
||||
== ZIP_HEADER_LEN ? 1 : -1];
|
||||
char BUG_cdf_header_must_be_42_bytes[
|
||||
offsetof(cdf_header_t, fmt.relative_offset_of_local_header) + 4
|
||||
== CDF_HEADER_LEN ? 1 : -1];
|
||||
char BUG_cde_must_be_16_bytes[
|
||||
sizeof(cde_t) == CDE_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_CDE(cde_header) do { \
|
||||
(cde_header).formatted.cdf_offset = SWAP_LE32((cde_header).formatted.cdf_offset); \
|
||||
} while (0)
|
||||
|
||||
enum { zip_fd = 3 };
|
||||
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
|
||||
#if !ENABLE_FEATURE_UNZIP_CDF
|
||||
|
||||
# define find_cdf_offset() BAD_CDF_OFFSET
|
||||
|
||||
#else
|
||||
/* Seen in the wild:
|
||||
* Self-extracting PRO2K3XP_32.exe contains 19078464 byte zip archive,
|
||||
* where CDE was nearly 48 kbytes before EOF.
|
||||
@@ -188,30 +222,31 @@ enum { zip_fd = 3 };
|
||||
* To make extraction work, bumped PEEK_FROM_END from 16k to 64k.
|
||||
*/
|
||||
#define PEEK_FROM_END (64*1024)
|
||||
|
||||
/* This value means that we failed to find CDF */
|
||||
#define BAD_CDF_OFFSET ((uint32_t)0xffffffff)
|
||||
|
||||
/* NB: does not preserve file position! */
|
||||
static uint32_t find_cdf_offset(void)
|
||||
{
|
||||
cde_header_t cde_header;
|
||||
cde_t cde;
|
||||
unsigned char *buf;
|
||||
unsigned char *p;
|
||||
off_t end;
|
||||
unsigned char *buf = xzalloc(PEEK_FROM_END);
|
||||
uint32_t found;
|
||||
|
||||
end = xlseek(zip_fd, 0, SEEK_END);
|
||||
end = lseek(zip_fd, 0, SEEK_END);
|
||||
if (end == (off_t) -1)
|
||||
return BAD_CDF_OFFSET;
|
||||
|
||||
end -= PEEK_FROM_END;
|
||||
if (end < 0)
|
||||
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);
|
||||
|
||||
found = BAD_CDF_OFFSET;
|
||||
p = buf;
|
||||
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
|
||||
while (p <= buf + PEEK_FROM_END - CDE_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
p++;
|
||||
continue;
|
||||
@@ -223,19 +258,19 @@ static uint32_t find_cdf_offset(void)
|
||||
if (*++p != 6)
|
||||
continue;
|
||||
/* we found CDE! */
|
||||
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde_header);
|
||||
memcpy(cde.raw, p + 1, CDE_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde);
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
* where cdf_offset points past EOF - ??
|
||||
* This check ignores such CDEs:
|
||||
*/
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf)) {
|
||||
found = cde_header.formatted.cdf_offset;
|
||||
if (cde.fmt.cdf_offset < end + (p - buf)) {
|
||||
found = cde.fmt.cdf_offset;
|
||||
dbg("Possible cdf_offset:0x%x at 0x%"OFF_FMT"x",
|
||||
(unsigned)found, end + (p-3 - buf));
|
||||
dbg(" cdf_offset+cdf_size:0x%x",
|
||||
(unsigned)(found + SWAP_LE32(cde_header.formatted.cdf_size)));
|
||||
(unsigned)(found + SWAP_LE32(cde.fmt.cdf_size)));
|
||||
/*
|
||||
* We do not "break" here because only the last CDE is valid.
|
||||
* I've seen a .zip archive which contained a .zip file,
|
||||
@@ -249,33 +284,36 @@ static uint32_t find_cdf_offset(void)
|
||||
return found;
|
||||
};
|
||||
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf)
|
||||
{
|
||||
off_t org;
|
||||
uint32_t magic;
|
||||
|
||||
org = xlseek(zip_fd, 0, SEEK_CUR);
|
||||
if (cdf_offset == BAD_CDF_OFFSET)
|
||||
return cdf_offset;
|
||||
|
||||
if (!cdf_offset)
|
||||
cdf_offset = find_cdf_offset();
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
|
||||
xlseek(zip_fd, cdf_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cdf_ptr->raw, CDF_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDF(*cdf_ptr);
|
||||
dbg(" file_name_length:%u extra_field_length:%u file_comment_length:%u",
|
||||
(unsigned)cdf_ptr->formatted.file_name_length,
|
||||
(unsigned)cdf_ptr->formatted.extra_field_length,
|
||||
(unsigned)cdf_ptr->formatted.file_comment_length
|
||||
);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf_ptr->formatted.file_name_length
|
||||
+ cdf_ptr->formatted.extra_field_length
|
||||
+ cdf_ptr->formatted.file_comment_length;
|
||||
dbg("Reading CDF at 0x%x", (unsigned)cdf_offset);
|
||||
xlseek(zip_fd, cdf_offset, SEEK_SET);
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* Central Directory End? Assume CDF has ended.
|
||||
* (more correct method is to use cde.cdf_entries_total counter)
|
||||
*/
|
||||
if (magic == ZIP_CDE_MAGIC) {
|
||||
dbg("got ZIP_CDE_MAGIC");
|
||||
return 0; /* EOF */
|
||||
}
|
||||
xread(zip_fd, cdf->raw, CDF_HEADER_LEN);
|
||||
|
||||
FIX_ENDIANNESS_CDF(*cdf);
|
||||
dbg(" filename_len:%u extra_len:%u file_comment_length:%u",
|
||||
(unsigned)cdf->fmt.filename_len,
|
||||
(unsigned)cdf->fmt.extra_len,
|
||||
(unsigned)cdf->fmt.file_comment_length
|
||||
);
|
||||
cdf_offset += 4 + CDF_HEADER_LEN
|
||||
+ cdf->fmt.filename_len
|
||||
+ cdf->fmt.extra_len
|
||||
+ cdf->fmt.file_comment_length;
|
||||
|
||||
dbg("Returning file position to 0x%"OFF_FMT"x", org);
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cdf_offset;
|
||||
};
|
||||
#endif
|
||||
@@ -297,32 +335,66 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
free(name);
|
||||
}
|
||||
|
||||
static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
static void unzip_extract(zip_header_t *zip, int dst_fd)
|
||||
{
|
||||
if (zip_header->formatted.method == 0) {
|
||||
transformer_state_t xstate;
|
||||
|
||||
if (zip->fmt.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
off_t size = zip_header->formatted.ucmpsize;
|
||||
off_t size = zip->fmt.ucmpsize;
|
||||
if (size)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
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) {
|
||||
/* Method 8 - inflate */
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.bytes_in = zip_header->formatted.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_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
if (zip->fmt.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,15 +411,12 @@ int unzip_main(int argc, char **argv)
|
||||
{
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
smallint quiet = 0;
|
||||
IF_NOT_DESKTOP(const) smallint verbose = 0;
|
||||
IF_NOT_FEATURE_UNZIP_CDF(const) smallint verbose = 0;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
smallint x_opt_seen;
|
||||
#if ENABLE_DESKTOP
|
||||
uint32_t cdf_offset;
|
||||
#endif
|
||||
unsigned long total_usize;
|
||||
unsigned long total_size;
|
||||
unsigned total_entries;
|
||||
@@ -430,7 +499,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'v': /* Verbose list */
|
||||
IF_DESKTOP(verbose++;)
|
||||
IF_FEATURE_UNZIP_CDF(verbose++;)
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
@@ -545,91 +614,114 @@ int unzip_main(int argc, char **argv)
|
||||
total_usize = 0;
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
#if ENABLE_DESKTOP
|
||||
cdf_offset = 0;
|
||||
#endif
|
||||
cdf_offset = find_cdf_offset(); /* try to seek to the end, find CDE and CDF start */
|
||||
while (1) {
|
||||
uint32_t magic;
|
||||
zip_header_t zip;
|
||||
mode_t dir_mode = 0777;
|
||||
#if ENABLE_DESKTOP
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
mode_t file_mode = 0666;
|
||||
#endif
|
||||
|
||||
/* Check magic number */
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* Central directory? It's at the end, so exit */
|
||||
if (magic == ZIP_CDF_MAGIC) {
|
||||
dbg("got ZIP_CDF_MAGIC");
|
||||
break;
|
||||
}
|
||||
#if ENABLE_DESKTOP
|
||||
/* Data descriptor? It was a streaming file, go on */
|
||||
if (magic == ZIP_DD_MAGIC) {
|
||||
dbg("got ZIP_DD_MAGIC");
|
||||
/* skip over duplicate crc32, cmpsize and ucmpsize */
|
||||
unzip_skip(3 * 4);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
|
||||
dbg("got ZIP_FILEHEADER_MAGIC");
|
||||
|
||||
/* Read the file header */
|
||||
xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip_header);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
|
||||
}
|
||||
#if !ENABLE_DESKTOP
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0009)) {
|
||||
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
|
||||
}
|
||||
#else
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0001)) {
|
||||
/* 0x0001 - encrypted */
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
}
|
||||
|
||||
if (cdf_offset != BAD_CDF_OFFSET) {
|
||||
cdf_header_t cdf_header;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf_header);
|
||||
/*
|
||||
* Note: cdf_offset can become BAD_CDF_OFFSET after the above call.
|
||||
if (!ENABLE_FEATURE_UNZIP_CDF || cdf_offset == BAD_CDF_OFFSET) {
|
||||
/* Normally happens when input is unseekable.
|
||||
*
|
||||
* Valid ZIP file has Central Directory at the end
|
||||
* with central directory file headers (CDFs).
|
||||
* After it, there is a Central Directory End structure.
|
||||
* CDFs identify what files are in the ZIP and where
|
||||
* they are located. This allows ZIP readers to load
|
||||
* the list of files without reading the entire ZIP archive.
|
||||
* ZIP files may be appended to, only files specified in
|
||||
* the CD are valid. Scanning for local file headers is
|
||||
* not a correct algorithm.
|
||||
*
|
||||
* We try to do the above, and resort to "linear" reading
|
||||
* of ZIP file only if seek failed or CDE wasn't found.
|
||||
*/
|
||||
if (zip_header.formatted.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory. See unzip_doc.txt
|
||||
*/
|
||||
zip_header.formatted.crc32 = cdf_header.formatted.crc32;
|
||||
zip_header.formatted.cmpsize = cdf_header.formatted.cmpsize;
|
||||
zip_header.formatted.ucmpsize = cdf_header.formatted.ucmpsize;
|
||||
uint32_t magic;
|
||||
|
||||
/* Check magic number */
|
||||
xread(zip_fd, &magic, 4);
|
||||
/* CDF item? Assume there are no more files, exit */
|
||||
if (magic == ZIP_CDF_MAGIC) {
|
||||
dbg("got ZIP_CDF_MAGIC");
|
||||
break;
|
||||
}
|
||||
if ((cdf_header.formatted.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf_header.formatted.external_file_attributes >> 16);
|
||||
/* Data descriptor? It was a streaming file, go on */
|
||||
if (magic == ZIP_DD_MAGIC) {
|
||||
dbg("got ZIP_DD_MAGIC");
|
||||
/* skip over duplicate crc32, cmpsize and ucmpsize */
|
||||
unzip_skip(3 * 4);
|
||||
continue;
|
||||
}
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
|
||||
dbg("got ZIP_FILEHEADER_MAGIC");
|
||||
|
||||
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 (cdf_offset == BAD_CDF_OFFSET
|
||||
&& (zip_header.formatted.zip_flags & SWAP_LE16(0x0008))
|
||||
) {
|
||||
/* If it's a streaming zip, we _require_ CDF */
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
else {
|
||||
/* cdf_offset is valid (and we know the file is seekable) */
|
||||
cdf_header_t cdf;
|
||||
cdf_offset = read_next_cdf(cdf_offset, &cdf);
|
||||
if (cdf_offset == 0) /* EOF? */
|
||||
break;
|
||||
# if 1
|
||||
xlseek(zip_fd,
|
||||
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4,
|
||||
SEEK_SET);
|
||||
xread(zip_fd, zip.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip);
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0008)) {
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory.
|
||||
*/
|
||||
zip.fmt.crc32 = cdf.fmt.crc32;
|
||||
zip.fmt.cmpsize = cdf.fmt.cmpsize;
|
||||
zip.fmt.ucmpsize = cdf.fmt.ucmpsize;
|
||||
}
|
||||
# else
|
||||
/* CDF has the same data as local header, no need to read the latter...
|
||||
* ...not really. An archive was seen with cdf.extra_len == 6 but
|
||||
* zip.extra_len == 0.
|
||||
*/
|
||||
memcpy(&zip.fmt.version,
|
||||
&cdf.fmt.version_needed, ZIP_HEADER_LEN);
|
||||
xlseek(zip_fd,
|
||||
SWAP_LE32(cdf.fmt.relative_offset_of_local_header) + 4 + ZIP_HEADER_LEN,
|
||||
SEEK_SET);
|
||||
# endif
|
||||
if ((cdf.fmt.version_made_by >> 8) == 3) {
|
||||
/* This archive is created on Unix */
|
||||
dir_mode = file_mode = (cdf.fmt.external_attributes >> 16);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (zip.fmt.zip_flags & SWAP_LE16(0x0001)) {
|
||||
/* 0x0001 - encrypted */
|
||||
bb_error_msg_and_die("zip flag %s is not supported",
|
||||
"1 (encryption)");
|
||||
}
|
||||
dbg("File cmpsize:0x%x extra_len:0x%x ucmpsize:0x%x",
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)zip_header.formatted.extra_len,
|
||||
(unsigned)zip_header.formatted.ucmpsize
|
||||
(unsigned)zip.fmt.cmpsize,
|
||||
(unsigned)zip.fmt.extra_len,
|
||||
(unsigned)zip.fmt.ucmpsize
|
||||
);
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
|
||||
dst_fn = xzalloc(zip.fmt.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip.fmt.filename_len);
|
||||
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
unzip_skip(zip.fmt.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
@@ -638,129 +730,129 @@ int unzip_main(int argc, char **argv)
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
|| (zaccept && !find_list_entry(zaccept, dst_fn))
|
||||
) { /* Skip entry */
|
||||
i = 'n';
|
||||
} else {
|
||||
if (listing) {
|
||||
/* List entry */
|
||||
char dtbuf[sizeof("mm-dd-yyyy hh:mm")];
|
||||
sprintf(dtbuf, "%02u-%02u-%04u %02u:%02u",
|
||||
(zip_header.formatted.moddate >> 5) & 0xf, // mm: 0x01e0
|
||||
(zip_header.formatted.moddate) & 0x1f, // dd: 0x001f
|
||||
(zip_header.formatted.moddate >> 9) + 1980, // yy: 0xfe00
|
||||
(zip_header.formatted.modtime >> 11), // hh: 0xf800
|
||||
(zip_header.formatted.modtime >> 5) & 0x3f // mm: 0x07e0
|
||||
// seconds/2 are not shown, encoded in ----------- 0x001f
|
||||
);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// "--------- ---------- ----- ----"
|
||||
printf( "%9u " "%s " "%s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
dtbuf,
|
||||
dst_fn);
|
||||
} else {
|
||||
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
|
||||
if ((int32_t)percents < 0)
|
||||
percents = 0; /* happens if ucmpsize < cmpsize */
|
||||
percents = percents * 100;
|
||||
if (zip_header.formatted.ucmpsize)
|
||||
percents /= zip_header.formatted.ucmpsize;
|
||||
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
printf( "%8u %s" "%9u%4u%% " "%s " "%08x " "%s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
zip_header.formatted.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
|
||||
*/
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)percents,
|
||||
dtbuf,
|
||||
zip_header.formatted.crc32,
|
||||
dst_fn);
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
}
|
||||
total_usize += zip_header.formatted.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 {
|
||||
/* Extract file */
|
||||
check_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);
|
||||
}
|
||||
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 skip_cmpsize;
|
||||
}
|
||||
|
||||
switch (i) {
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
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);
|
||||
}
|
||||
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]) {
|
||||
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_DESKTOP
|
||||
#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
|
||||
case -1: /* Unzip */
|
||||
do_extract:
|
||||
if (!quiet) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
: */ " inflating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_extract(&zip_header, dst_fd);
|
||||
unzip_extract(&zip, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
@@ -769,9 +861,9 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
case 'N':
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
unzip_skip(zip_header.formatted.cmpsize);
|
||||
case 'n': /* Skip entry data */
|
||||
skip_cmpsize:
|
||||
unzip_skip(zip.fmt.cmpsize);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
@@ -784,7 +876,7 @@ int unzip_main(int argc, char **argv)
|
||||
goto check_file;
|
||||
|
||||
default:
|
||||
printf("error: invalid response [%c]\n", (char)i);
|
||||
printf("error: invalid response [%c]\n", (char)key_buf[0]);
|
||||
goto check_file;
|
||||
}
|
||||
|
||||
|
||||
@@ -265,11 +265,6 @@ 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
|
||||
#
|
||||
@@ -387,7 +382,7 @@ CONFIG_FEATURE_KILL_REMOVED=y
|
||||
CONFIG_FEATURE_KILL_DELAY=1
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_HALT=y
|
||||
@@ -457,15 +452,12 @@ 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"
|
||||
|
||||
@@ -524,7 +516,6 @@ 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
|
||||
@@ -879,9 +870,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
|
||||
@@ -277,7 +277,6 @@ 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
|
||||
|
||||
@@ -392,7 +391,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_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
# CONFIG_HALT is not set
|
||||
@@ -527,7 +526,6 @@ 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
|
||||
@@ -873,9 +871,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
|
||||
@@ -276,11 +276,6 @@ 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
|
||||
#
|
||||
@@ -404,7 +399,7 @@ CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_DELAY=0
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_HALT=y
|
||||
@@ -472,15 +467,12 @@ 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"
|
||||
|
||||
@@ -540,7 +532,6 @@ 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
|
||||
@@ -893,9 +884,9 @@ CONFIG_ASH_BASH_COMPAT=y
|
||||
CONFIG_ASH_JOB_CONTROL=y
|
||||
CONFIG_ASH_ALIAS=y
|
||||
CONFIG_ASH_GETOPTS=y
|
||||
CONFIG_ASH_BUILTIN_ECHO=y
|
||||
CONFIG_ASH_BUILTIN_PRINTF=y
|
||||
CONFIG_ASH_BUILTIN_TEST=y
|
||||
CONFIG_ASH_ECHO=y
|
||||
CONFIG_ASH_PRINTF=y
|
||||
CONFIG_ASH_TEST=y
|
||||
CONFIG_ASH_CMDCMD=y
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
|
||||
|
||||
@@ -94,7 +94,6 @@ 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
|
||||
@@ -289,11 +288,6 @@ 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
|
||||
#
|
||||
@@ -422,7 +416,7 @@ CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_DELAY=0
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
@@ -493,15 +487,12 @@ 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"
|
||||
|
||||
@@ -936,9 +927,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
|
||||
@@ -174,7 +174,6 @@ 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
|
||||
@@ -390,11 +389,6 @@ 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
|
||||
#
|
||||
@@ -529,7 +523,7 @@ CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_DELAY=0
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
@@ -603,15 +597,12 @@ 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"
|
||||
|
||||
@@ -1081,9 +1072,9 @@ CONFIG_ASH_BASH_COMPAT=y
|
||||
CONFIG_ASH_JOB_CONTROL=y
|
||||
CONFIG_ASH_ALIAS=y
|
||||
CONFIG_ASH_GETOPTS=y
|
||||
CONFIG_ASH_BUILTIN_ECHO=y
|
||||
CONFIG_ASH_BUILTIN_PRINTF=y
|
||||
CONFIG_ASH_BUILTIN_TEST=y
|
||||
CONFIG_ASH_ECHO=y
|
||||
CONFIG_ASH_PRINTF=y
|
||||
CONFIG_ASH_TEST=y
|
||||
CONFIG_ASH_HELP=y
|
||||
CONFIG_ASH_CMDCMD=y
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
|
||||
@@ -112,7 +112,6 @@ 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
|
||||
@@ -312,11 +311,6 @@ 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
|
||||
#
|
||||
@@ -445,7 +439,7 @@ CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_DELAY=0
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
@@ -517,15 +511,12 @@ 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"
|
||||
|
||||
@@ -968,9 +959,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
|
||||
@@ -102,7 +102,6 @@ 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
|
||||
@@ -316,11 +315,6 @@ 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
|
||||
#
|
||||
@@ -455,7 +449,7 @@ CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_DELAY=0
|
||||
CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
@@ -528,15 +522,12 @@ 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"
|
||||
|
||||
@@ -996,9 +987,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_HELP is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
|
||||
@@ -94,7 +94,6 @@ 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
|
||||
@@ -289,11 +288,6 @@ 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
|
||||
#
|
||||
@@ -422,7 +416,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_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
CONFIG_INIT_TERMINAL_TYPE=""
|
||||
@@ -936,9 +930,9 @@ CONFIG_ASH_BASH_COMPAT=y
|
||||
CONFIG_ASH_JOB_CONTROL=y
|
||||
CONFIG_ASH_ALIAS=y
|
||||
CONFIG_ASH_GETOPTS=y
|
||||
CONFIG_ASH_BUILTIN_ECHO=y
|
||||
CONFIG_ASH_BUILTIN_PRINTF=y
|
||||
CONFIG_ASH_BUILTIN_TEST=y
|
||||
CONFIG_ASH_ECHO=y
|
||||
CONFIG_ASH_PRINTF=y
|
||||
CONFIG_ASH_TEST=y
|
||||
CONFIG_ASH_CMDCMD=y
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
CONFIG_ASH_OPTIMIZE_FOR_SIZE=y
|
||||
|
||||
@@ -93,7 +93,6 @@ 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
|
||||
@@ -287,11 +286,6 @@ 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
|
||||
#
|
||||
@@ -419,7 +413,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_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
CONFIG_INIT_TERMINAL_TYPE=""
|
||||
@@ -912,9 +906,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_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_ECHO is not set
|
||||
# CONFIG_ASH_PRINTF is not set
|
||||
# CONFIG_ASH_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
|
||||
@@ -42,18 +42,14 @@
|
||||
//config: depends on LOADFONT || SETFONT
|
||||
//config:
|
||||
//config:config FEATURE_LOADFONT_PSF2
|
||||
//config: bool "Support for PSF2 console fonts"
|
||||
//config: bool "Support 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 for old (raw) console fonts"
|
||||
//config: bool "Support 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))
|
||||
|
||||
@@ -56,6 +56,8 @@ 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
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
//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))
|
||||
|
||||
|
||||
+1
-15
@@ -27,25 +27,11 @@ 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 for human readable output (example 13k, 23M, 235G)"
|
||||
bool "Support human readable output (example 13k, 23M, 235G)"
|
||||
default y
|
||||
depends on DF || DU || LS
|
||||
help
|
||||
|
||||
@@ -10,12 +10,9 @@ lib-y:=
|
||||
|
||||
INSERT
|
||||
|
||||
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 adduser
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_HUSH) += echo.o # used by hush
|
||||
lib-$(CONFIG_FTPD) += ls.o # used by ftpd
|
||||
lib-$(CONFIG_ASH_BUILTIN_PRINTF) += printf.o
|
||||
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_FTPD) += ls.o # used by ftpd
|
||||
+134
-22
@@ -12,56 +12,168 @@
|
||||
//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_NOFORK(cat, cat, BB_DIR_BIN, BB_SUID_DROP, cat))
|
||||
//applet:IF_CAT(APPLET(cat, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//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: "[FILE]..."
|
||||
//usage: "[-nb"IF_FEATURE_CATV("vteA")"] [FILE]..."
|
||||
//usage:#define cat_full_usage "\n\n"
|
||||
//usage: "Concatenate FILEs and print them to stdout"
|
||||
//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:
|
||||
//usage:#define cat_example_usage
|
||||
//usage: "$ cat /proc/uptime\n"
|
||||
//usage: "110716.72 17.67"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
|
||||
int bb_cat(char **argv)
|
||||
#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)
|
||||
{
|
||||
int fd;
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
|
||||
if (!*argv)
|
||||
argv = (char**) &bb_argv_dash;
|
||||
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
|
||||
|
||||
/* 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) {
|
||||
/* 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;
|
||||
if (fd < 0) {
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
retval = EXIT_FAILURE;
|
||||
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);
|
||||
} while (*++argv);
|
||||
|
||||
return retval;
|
||||
fflush_stdout_and_exit(retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cat_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "u");
|
||||
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");
|
||||
argv += optind;
|
||||
return bb_cat(argv);
|
||||
|
||||
#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);
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -17,8 +17,6 @@
|
||||
//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
@@ -17,9 +17,9 @@
|
||||
//kbuild:lib-$(CONFIG_CKSUM) += cksum.o
|
||||
|
||||
//usage:#define cksum_trivial_usage
|
||||
//usage: "FILES..."
|
||||
//usage: "FILE..."
|
||||
//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
@@ -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 for cp"
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on CP && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable long options for cp.
|
||||
//config: Enable long options.
|
||||
//config: Also add support for --parents option.
|
||||
|
||||
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
|
||||
|
||||
+9
-10
@@ -41,7 +41,7 @@
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for writing a certain number of bytes in and out,
|
||||
//config: Enable 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: Enables support for status=noxfer/none option.
|
||||
//config: Enable support for status=noxfer/none option.
|
||||
|
||||
//applet:IF_DD(APPLET_NOEXEC(dd, dd, BB_DIR_BIN, BB_SUID_DROP, dd))
|
||||
|
||||
@@ -133,9 +133,8 @@ enum {
|
||||
/* end of input flags */
|
||||
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 7,
|
||||
FLAG_STATUS = 1 << 8,
|
||||
FLAG_STATUS_NONE = 1 << 9,
|
||||
FLAG_STATUS_NOXFER = 1 << 10,
|
||||
FLAG_STATUS_NONE = 1 << 8,
|
||||
FLAG_STATUS_NOXFER = 1 << 9,
|
||||
};
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
@@ -396,7 +395,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 << n;
|
||||
G.flags |= FLAG_STATUS_NONE << n;
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
@@ -532,11 +531,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) {
|
||||
|
||||
+3
-5
@@ -29,11 +29,9 @@
|
||||
//config: default y
|
||||
//config: depends on DF
|
||||
//config: help
|
||||
//config: This option enables -a, -i and -B.
|
||||
//config:
|
||||
//config: -a Show all filesystems
|
||||
//config: -i Inodes
|
||||
//config: -B <SIZE> Blocksize
|
||||
//config: -a Show all filesystems
|
||||
//config: -i Inodes
|
||||
//config: -B <SIZE> Blocksize
|
||||
|
||||
//applet:IF_DF(APPLET(df, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* dos2unix for BusyBox
|
||||
*
|
||||
* dos2unix '\n' convertor 0.5.0
|
||||
* dos2unix '\n' converter 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.
|
||||
|
||||
+5
-4
@@ -26,16 +26,17 @@
|
||||
//config:
|
||||
//config:# this entry also appears in shell/Config.in, next to the echo builtin
|
||||
//config:config FEATURE_FANCY_ECHO
|
||||
//config: bool "Enable echo options (-n and -e)"
|
||||
//config: bool "Enable -n and -e options"
|
||||
//config: default y
|
||||
//config: depends on ECHO || ASH_BUILTIN_ECHO || HUSH
|
||||
//config: help
|
||||
//config: This adds options (-n and -e) to echo.
|
||||
//config: depends on ECHO || ASH_ECHO || HUSH_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 */
|
||||
|
||||
|
||||
@@ -35,8 +35,6 @@
|
||||
//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))
|
||||
|
||||
|
||||
+5
-8
@@ -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,8 +30,6 @@
|
||||
//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"
|
||||
@@ -43,10 +41,9 @@
|
||||
//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
|
||||
@@ -58,7 +55,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"
|
||||
@@ -72,7 +69,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"
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
+1
-3
@@ -14,11 +14,9 @@
|
||||
//config: from files.
|
||||
//config:
|
||||
//config:config FEATURE_FANCY_HEAD
|
||||
//config: bool "Enable head options (-c, -q, and -v)"
|
||||
//config: bool "Enable -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))
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
//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))
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
+241
-319
@@ -37,22 +37,21 @@
|
||||
//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: help
|
||||
//config: Enable the ls option (-R).
|
||||
//config:
|
||||
//config:config FEATURE_LS_WIDTH
|
||||
//config: bool "Enable -w WIDTH and window size autodetection"
|
||||
//config: default y
|
||||
//config: depends on LS
|
||||
//config:
|
||||
//config:config FEATURE_LS_SORTFILES
|
||||
//config: bool "Sort the file names"
|
||||
@@ -102,18 +101,17 @@
|
||||
//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("kKZ") "]"
|
||||
//usage: IF_FEATURE_AUTOWIDTH(" [-w WIDTH]") " [FILE]..."
|
||||
//usage: IF_SELINUX("kZ") "]"
|
||||
//usage: IF_FEATURE_LS_WIDTH(" [-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"
|
||||
////usage: "\n -C List by columns" - don't show, this is a default anyway
|
||||
//usage: "\n -x List by lines"
|
||||
//usage: "\n -d List directory entries instead of contents"
|
||||
//usage: IF_FEATURE_LS_FOLLOWLINKS(
|
||||
@@ -132,29 +130,34 @@
|
||||
//usage: "\n -n List numeric UIDs and GIDs instead of names"
|
||||
//usage: "\n -s List allocated blocks"
|
||||
//usage: IF_FEATURE_LS_TIMESTAMPS(
|
||||
//usage: "\n -e List full date and time"
|
||||
//usage: "\n -lc List ctime"
|
||||
//usage: "\n -lu List atime"
|
||||
//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 List sizes in human readable format (1K 243M 2G)"
|
||||
//usage: "\n -h Human readable sizes (1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_LS_SORTFILES(
|
||||
//usage: "\n -r Sort in reverse order"
|
||||
//usage: IF_LONG_OPTS(
|
||||
//usage: "\n --group-directories-first"
|
||||
//usage: )
|
||||
//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 -c With -l: sort by ctime"
|
||||
//usage: "\n -t With -l: sort by mtime"
|
||||
//usage: "\n -u With -l: sort by atime"
|
||||
//usage: "\n -t Sort by mtime"
|
||||
//usage: "\n -tc Sort by ctime"
|
||||
//usage: "\n -tu 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_AUTOWIDTH(
|
||||
//usage: "\n -w N Assume the terminal is N columns wide"
|
||||
//usage: IF_FEATURE_LS_WIDTH(
|
||||
//usage: "\n -w N Format N columns wide"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_LS_COLOR(
|
||||
//usage: "\n --color[={always,never,auto}] Control coloring"
|
||||
@@ -189,187 +192,90 @@ 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,
|
||||
};
|
||||
|
||||
/* -Cadil1 Std options, busybox always supports */
|
||||
/* -Cadi1l Std options, busybox always supports */
|
||||
/* -gnsxA Std options, busybox always supports */
|
||||
/* -Q GNU option, busybox always supports */
|
||||
/* -k SELinux option, busybox always supports (ignores if !SELinux) */
|
||||
/* Std has -k which means "show sizes in kbytes" */
|
||||
/* -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 */
|
||||
/* -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) */
|
||||
/* -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) */
|
||||
/* -Z SELinux mandated option, busybox optionally supports */
|
||||
static const char ls_options[] ALIGN1 =
|
||||
"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 */;
|
||||
"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 */
|
||||
;
|
||||
enum {
|
||||
//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_C = (1 << 0),
|
||||
OPT_a = (1 << 1),
|
||||
OPT_d = (1 << 2),
|
||||
OPT_i = (1 << 3),
|
||||
OPT_1 = (1 << 4),
|
||||
OPT_l = (1 << 5),
|
||||
OPT_g = (1 << 6),
|
||||
//OPT_n = (1 << 7),
|
||||
//OPT_s = (1 << 8),
|
||||
//OPT_x = (1 << 9),
|
||||
OPT_Q = (1 << 10),
|
||||
//OPT_A = (1 << 11),
|
||||
//OPT_k = (1 << 12),
|
||||
OPT_n = (1 << 7),
|
||||
OPT_s = (1 << 8),
|
||||
OPT_x = (1 << 9),
|
||||
OPT_A = (1 << 10),
|
||||
//OPT_k = (1 << 11),
|
||||
|
||||
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_F = 12,
|
||||
OPTBIT_p, /* 13 */
|
||||
OPTBIT_R = OPTBIT_F + 2 * ENABLE_FEATURE_LS_FILETYPES,
|
||||
OPTBIT_K = OPTBIT_R + 1 * ENABLE_FEATURE_LS_RECURSIVE,
|
||||
OPTBIT_Z, /* 25 */
|
||||
OPTBIT_L = OPTBIT_K + 2 * ENABLE_SELINUX,
|
||||
OPTBIT_H, /* 27 */
|
||||
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_h = OPTBIT_L + 2 * ENABLE_FEATURE_LS_FOLLOWLINKS,
|
||||
OPTBIT_T = OPTBIT_h + 1 * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPTBIT_w, /* 30 */
|
||||
OPTBIT_color = OPTBIT_T + 2 * ENABLE_FEATURE_AUTOWIDTH,
|
||||
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 */
|
||||
|
||||
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_AUTOWIDTH,
|
||||
OPT_w = (1 << OPTBIT_w) * ENABLE_FEATURE_AUTOWIDTH,
|
||||
OPT_color = (1 << OPTBIT_color) * ENABLE_FEATURE_LS_COLOR,
|
||||
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,
|
||||
};
|
||||
|
||||
/* 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
|
||||
*/
|
||||
@@ -399,9 +305,7 @@ 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_atime;
|
||||
time_t dn_mtime;
|
||||
time_t dn_ctime;
|
||||
time_t dn_time;
|
||||
#endif
|
||||
ino_t dn_ino;
|
||||
blkcnt_t dn_blocks;
|
||||
@@ -422,8 +326,8 @@ struct globals {
|
||||
# define G_show_color 0
|
||||
#endif
|
||||
smallint exit_code;
|
||||
unsigned all_fmt;
|
||||
#if ENABLE_FEATURE_AUTOWIDTH
|
||||
smallint show_dirname;
|
||||
#if ENABLE_FEATURE_LS_WIDTH
|
||||
unsigned terminal_width;
|
||||
# define G_terminal_width (G.terminal_width)
|
||||
#else
|
||||
@@ -439,7 +343,7 @@ struct globals {
|
||||
setup_common_bufsiz(); \
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
IF_FEATURE_AUTOWIDTH(G_terminal_width = TERMINAL_WIDTH;) \
|
||||
IF_FEATURE_LS_WIDTH(G_terminal_width = TERMINAL_WIDTH;) \
|
||||
IF_FEATURE_LS_TIMESTAMPS(time(&G.current_time_t);) \
|
||||
} while (0)
|
||||
|
||||
@@ -496,11 +400,12 @@ static char bold(mode_t mode)
|
||||
#if ENABLE_FEATURE_LS_FILETYPES
|
||||
static char append_char(mode_t mode)
|
||||
{
|
||||
if (!(G.all_fmt & LIST_FILETYPE))
|
||||
if (!(option_mask32 & (OPT_F|OPT_p)))
|
||||
return '\0';
|
||||
|
||||
if (S_ISDIR(mode))
|
||||
return '/';
|
||||
if (!(G.all_fmt & LIST_CLASSIFY))
|
||||
if (!(option_mask32 & OPT_F))
|
||||
return '\0';
|
||||
if (S_ISREG(mode) && (mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
|
||||
return '*';
|
||||
@@ -531,8 +436,8 @@ static unsigned calc_name_len(const char *name)
|
||||
}
|
||||
|
||||
/* Return the number of used columns.
|
||||
* Note that only STYLE_COLUMNAR uses return value.
|
||||
* STYLE_SINGLE and STYLE_LONG don't care.
|
||||
* Note that only columnar output uses return value.
|
||||
* -l and -1 modes 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
|
||||
@@ -565,13 +470,14 @@ static unsigned print_name(const char *name)
|
||||
}
|
||||
|
||||
/* Return the number of used columns.
|
||||
* Note that only STYLE_COLUMNAR uses return value,
|
||||
* STYLE_SINGLE and STYLE_LONG don't care.
|
||||
* Note that only columnar output uses return value,
|
||||
* -l and -1 modes 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;
|
||||
@@ -580,50 +486,61 @@ 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 (G.all_fmt & LIST_SYMLINK)
|
||||
if (opt & OPT_l)
|
||||
if (S_ISLNK(dn->dn_mode))
|
||||
lpath = xmalloc_readlink_or_warn(dn->fullname);
|
||||
|
||||
if (G.all_fmt & LIST_INO)
|
||||
if (opt & OPT_i) /* show inode# */
|
||||
column += printf("%7llu ", (long long) dn->dn_ino);
|
||||
//TODO: -h should affect -s too:
|
||||
if (G.all_fmt & LIST_BLOCKS)
|
||||
if (opt & OPT_s) /* show allocated blocks */
|
||||
column += printf("%6"OFF_FMT"u ", (off_t) (dn->dn_blocks >> 1));
|
||||
if (G.all_fmt & LIST_MODEBITS)
|
||||
if (opt & OPT_l) {
|
||||
/* long listing: show mode */
|
||||
column += printf("%-10s ", (char *) bb_mode_string(dn->dn_mode));
|
||||
if (G.all_fmt & LIST_NLINKS)
|
||||
/* long listing: show number of links */
|
||||
column += printf("%4lu ", (long) dn->dn_nlink);
|
||||
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);
|
||||
}
|
||||
/* 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 ENABLE_FEATURE_LS_USERNAME
|
||||
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));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (G.all_fmt & LIST_SIZE) {
|
||||
#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 (S_ISBLK(dn->dn_mode) || S_ISCHR(dn->dn_mode)) {
|
||||
column += printf("%4u, %3u ",
|
||||
dn->dn_rdev_maj,
|
||||
dn->dn_rdev_min);
|
||||
} else {
|
||||
if (option_mask32 & OPT_h) {
|
||||
if (opt & 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)
|
||||
@@ -632,25 +549,22 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
column += printf("%9"OFF_FMT"u ", dn->dn_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
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:
|
||||
/* long listing: show {m,c,a}time */
|
||||
if (opt & OPT_full_time) { /* --full-time */
|
||||
/* coreutils 8.4 ls --full-time prints:
|
||||
* 2009-07-13 17:49:27.000000000 +0200
|
||||
* we don't show fractional seconds.
|
||||
*/
|
||||
column += printf("%.24s ", filetime);
|
||||
} else { /* LIST_DATE_TIME */
|
||||
/* G.current_time_t ~== time(NULL) */
|
||||
time_t age = G.current_time_t - *ttime;
|
||||
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;
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* less than 6 months old */
|
||||
/* "mmm dd hh:mm " */
|
||||
@@ -663,14 +577,8 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
}
|
||||
#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) {
|
||||
@@ -689,7 +597,9 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
if (lpath) {
|
||||
printf(" -> ");
|
||||
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
|
||||
if ((G.all_fmt & LIST_FILETYPE) || G_show_color) {
|
||||
if ((opt & (OPT_F|OPT_p))
|
||||
|| G_show_color
|
||||
) {
|
||||
mode_t mode = dn->dn_mode_stat;
|
||||
if (!mode)
|
||||
if (stat(dn->fullname, &statbuf) == 0)
|
||||
@@ -711,7 +621,7 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_LS_FILETYPES
|
||||
if (G.all_fmt & LIST_FILETYPE) {
|
||||
if (opt & (OPT_F|OPT_p)) {
|
||||
if (append) {
|
||||
putchar(append);
|
||||
column++;
|
||||
@@ -727,9 +637,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 STYLE_COLUMNAR */
|
||||
unsigned column_width = 0; /* used only by coulmnal output */
|
||||
|
||||
if (G.all_fmt & STYLE_LONG) { /* STYLE_LONG or STYLE_SINGLE */
|
||||
if (option_mask32 & (OPT_l|OPT_1)) {
|
||||
ncols = 1;
|
||||
} else {
|
||||
/* find the longest file name, use that as the column width */
|
||||
@@ -738,10 +648,11 @@ static void display_files(struct dnode **dn, unsigned nfiles)
|
||||
if (column_width < len)
|
||||
column_width = len;
|
||||
}
|
||||
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);
|
||||
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 */
|
||||
;
|
||||
ncols = (unsigned)G_terminal_width / column_width;
|
||||
}
|
||||
|
||||
@@ -759,7 +670,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 (G.all_fmt & DISP_ROWS)
|
||||
if (option_mask32 & OPT_x)
|
||||
i = (row * ncols) + nc; /* display across row */
|
||||
else
|
||||
i = (nc * nrows) + row; /* display by column */
|
||||
@@ -792,7 +703,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 (is_selinux_enabled()) {
|
||||
if (option_mask32 & OPT_Z) {
|
||||
getfilecon(fullname, &cur->sid);
|
||||
}
|
||||
#endif
|
||||
@@ -805,7 +716,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 (is_selinux_enabled()) {
|
||||
if (option_mask32 & OPT_Z) {
|
||||
lgetfilecon(fullname, &cur->sid);
|
||||
}
|
||||
#endif
|
||||
@@ -822,9 +733,11 @@ 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_atime = statbuf.st_atime ;
|
||||
cur->dn_mtime = statbuf.st_mtime ;
|
||||
cur->dn_ctime = statbuf.st_ctime ;
|
||||
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;
|
||||
#endif
|
||||
cur->dn_ino = statbuf.st_ino ;
|
||||
cur->dn_blocks = statbuf.st_blocks;
|
||||
@@ -938,33 +851,30 @@ static int sortcmp(const void *a, const void *b)
|
||||
{
|
||||
struct dnode *d1 = *(struct dnode **)a;
|
||||
struct dnode *d2 = *(struct dnode **)b;
|
||||
unsigned sort_opts = G.all_fmt & SORT_MASK;
|
||||
unsigned opt = option_mask32;
|
||||
off_t dif;
|
||||
|
||||
dif = 0; /* assume SORT_NAME */
|
||||
dif = 0; /* assume sort by name */
|
||||
// TODO: use pre-initialized function pointer
|
||||
// instead of branch forest
|
||||
if (sort_opts == SORT_SIZE) {
|
||||
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 */
|
||||
dif = (d2->dn_size - d1->dn_size);
|
||||
} else
|
||||
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);
|
||||
if (opt & OPT_t) { /* sort by time */
|
||||
dif = (d2->dn_time - d1->dn_time);
|
||||
} else
|
||||
#if defined(HAVE_STRVERSCMP) && HAVE_STRVERSCMP == 1
|
||||
if (sort_opts == SORT_VERSION) {
|
||||
if (opt & OPT_v) { /* sort by version */
|
||||
dif = strverscmp(d1->name, d2->name);
|
||||
} else
|
||||
#endif
|
||||
if (sort_opts == SORT_EXT) {
|
||||
if (opt & OPT_X) { /* sort by extension */
|
||||
dif = strcmp(strchrnul(d1->name, '.'), strchrnul(d2->name, '.'));
|
||||
}
|
||||
if (dif == 0) {
|
||||
@@ -973,18 +883,17 @@ static int sortcmp(const void *a, const void *b)
|
||||
dif = strcoll(d1->name, d2->name);
|
||||
else
|
||||
dif = strcmp(d1->name, d2->name);
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
} 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) */
|
||||
dif = 1 | (int)((uoff_t)dif >> BITS_TO_SHIFT);
|
||||
}
|
||||
}
|
||||
|
||||
return (G.all_fmt & SORT_REVERSE) ? -(int)dif : (int)dif;
|
||||
maybe_invert_and_ret:
|
||||
return (opt & OPT_r) ? -(int)dif : (int)dif;
|
||||
}
|
||||
|
||||
static void dnsort(struct dnode **dn, int size)
|
||||
@@ -1023,13 +932,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 ((!entry->d_name[1] || (entry->d_name[1] == '.' && !entry->d_name[2]))
|
||||
&& !(G.all_fmt & DISP_DOT)
|
||||
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]))
|
||||
) {
|
||||
continue;
|
||||
continue; /* if only -A, skip . and .. but show other dotfiles */
|
||||
}
|
||||
if (!(G.all_fmt & DISP_HIDDEN))
|
||||
continue;
|
||||
}
|
||||
fullname = concat_path_file(path, entry->d_name);
|
||||
cur = my_stat(fullname, bb_basename(fullname), 0);
|
||||
@@ -1097,7 +1006,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
struct dnode **subdnp;
|
||||
|
||||
for (; *dn; dn++) {
|
||||
if (G.all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
|
||||
if (G.show_dirname || (option_mask32 & OPT_R)) {
|
||||
if (!first)
|
||||
bb_putchar('\n');
|
||||
first = 0;
|
||||
@@ -1105,15 +1014,16 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
}
|
||||
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if ((G.all_fmt & STYLE_MASK) == STYLE_LONG || (G.all_fmt & LIST_BLOCKS))
|
||||
if (option_mask32 & (OPT_s|OPT_l)) {
|
||||
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
|
||||
&& (G.all_fmt & DISP_RECURSIVE)
|
||||
&& (option_mask32 & OPT_R)
|
||||
) {
|
||||
struct dnode **dnd;
|
||||
unsigned dndirs;
|
||||
@@ -1135,7 +1045,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;
|
||||
@@ -1157,23 +1067,25 @@ 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_SORTFILES)
|
||||
G.all_fmt = SORT_NAME;
|
||||
|
||||
#if ENABLE_FEATURE_AUTOWIDTH
|
||||
#if ENABLE_FEATURE_LS_WIDTH
|
||||
/* obtain the terminal width */
|
||||
G_terminal_width = get_terminal_width(STDIN_FILENO);
|
||||
/* go one less... */
|
||||
@@ -1181,10 +1093,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
/* process options */
|
||||
IF_FEATURE_LS_COLOR(applet_long_options = ls_longopts;)
|
||||
IF_LONG_OPTS(applet_long_options = ls_longopts;)
|
||||
opt_complementary =
|
||||
/* -e implies -l */
|
||||
IF_FEATURE_LS_TIMESTAMPS("el")
|
||||
/* -n and -g imply -l */
|
||||
"nl:gl"
|
||||
/* --full-time implies -l */
|
||||
IF_FEATURE_LS_TIMESTAMPS(IF_LONG_OPTS(":\xff""l"))
|
||||
/* http://pubs.opengroup.org/onlinepubs/9699919799/utilities/ls.html:
|
||||
* in some pairs of opts, only last one takes effect:
|
||||
*/
|
||||
@@ -1196,25 +1110,28 @@ 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_AUTOWIDTH(":w+");
|
||||
IF_FEATURE_LS_WIDTH(":w+");
|
||||
opt = getopt32(argv, ls_options
|
||||
IF_FEATURE_AUTOWIDTH(, NULL, &G_terminal_width)
|
||||
IF_FEATURE_LS_WIDTH(, /*-T*/ NULL, /*-w*/ &G_terminal_width)
|
||||
IF_FEATURE_LS_COLOR(, &color_opt)
|
||||
);
|
||||
for (i = 0; opt_flags[i] != (1U << 31); i++) {
|
||||
if (opt & (1 << i)) {
|
||||
uint32_t flags = opt_flags[i];
|
||||
#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
|
||||
|
||||
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;
|
||||
}
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & OPT_Z) {
|
||||
if (!is_selinux_enabled())
|
||||
option_mask32 &= ~OPT_Z;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_LS_COLOR
|
||||
/* set G_show_color = 1/0 */
|
||||
@@ -1242,27 +1159,35 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
/* sort out which command line options take precedence */
|
||||
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 (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 ((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 (!(G.all_fmt & STYLE_MASK))
|
||||
G.all_fmt |= (isatty(STDOUT_FILENO) ? STYLE_COLUMNAR : STYLE_SINGLE);
|
||||
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;
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
if (!argv[0])
|
||||
*--argv = (char*)".";
|
||||
|
||||
if (argv[1])
|
||||
G.all_fmt |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
G.show_dirname = 1; /* 2 or more items? label directories */
|
||||
|
||||
/* stuff the command line file names into a dnode array */
|
||||
dn = NULL;
|
||||
@@ -1270,10 +1195,7 @@ 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: */
|
||||
!((G.all_fmt & STYLE_MASK) == STYLE_LONG
|
||||
|| (G.all_fmt & LIST_BLOCKS)
|
||||
|| (option_mask32 & OPT_F)
|
||||
)
|
||||
!(option_mask32 & (OPT_l|OPT_s|OPT_F))
|
||||
/* ... or if -H: */
|
||||
|| (option_mask32 & OPT_H)
|
||||
/* ... or if -L, but my_stat always follows links if -L */
|
||||
@@ -1302,7 +1224,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
break;
|
||||
}
|
||||
|
||||
if (G.all_fmt & DISP_NOLIST) {
|
||||
if (option_mask32 & OPT_d) {
|
||||
sort_and_display_files(dnp, nfiles);
|
||||
} else {
|
||||
dnd = splitdnarray(dnp, SPLIT_DIR);
|
||||
|
||||
@@ -45,7 +45,6 @@
|
||||
//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))
|
||||
@@ -167,7 +166,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);
|
||||
void FAST_FUNC (*final)(void*, void*);
|
||||
unsigned FAST_FUNC (*final)(void*, void*);
|
||||
char hash_algo;
|
||||
|
||||
src_fd = open_or_warn_stdin(filename);
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
//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))
|
||||
|
||||
|
||||
File renamed without changes.
@@ -21,8 +21,6 @@
|
||||
//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
@@ -0,0 +1,101 @@
|
||||
/* 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);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/* 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);
|
||||
}
|
||||
+4
-1
@@ -49,6 +49,9 @@
|
||||
|
||||
//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"
|
||||
@@ -417,7 +420,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_BUILTIN_PRINTF
|
||||
if (ENABLE_ASH_PRINTF
|
||||
&& applet_name[0] != 'p'
|
||||
) {
|
||||
bb_error_msg("usage: printf FORMAT [ARGUMENT...]");
|
||||
|
||||
+3
-2
@@ -16,7 +16,8 @@
|
||||
//config: help
|
||||
//config: rm is used to remove files or directories.
|
||||
|
||||
//applet:IF_RM(APPLET_NOFORK(rm, rm, BB_DIR_BIN, BB_SUID_DROP, rm))
|
||||
//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 */
|
||||
|
||||
//kbuild:lib-$(CONFIG_RM) += rm.o
|
||||
|
||||
@@ -36,7 +37,7 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
int rm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
+3
-2
@@ -12,7 +12,8 @@
|
||||
//config: help
|
||||
//config: print a sequence of numbers
|
||||
|
||||
//applet:IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
|
||||
//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 */
|
||||
|
||||
//kbuild:lib-$(CONFIG_SEQ) += seq.o
|
||||
|
||||
@@ -26,7 +27,7 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
int seq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int seq_main(int argc, char **argv)
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/* 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
@@ -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;
|
||||
r %= i + 1;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
+3
-4
@@ -26,13 +26,12 @@
|
||||
//config: from files.
|
||||
//config:
|
||||
//config:config FEATURE_FANCY_TAIL
|
||||
//config: bool "Enable extra tail options (-q, -s, -v, and -F)"
|
||||
//config: bool "Enable -q, -s, -v, and -F options"
|
||||
//config: default y
|
||||
//config: depends on TAIL
|
||||
//config: help
|
||||
//config: The options (-q, -s, -v and -F) are provided by GNU tail, but
|
||||
//config: are not specific in the SUSv3 standard.
|
||||
//config:
|
||||
//config: These options are provided by GNU tail, but
|
||||
//config: are not specific in the SUSv3 standard:
|
||||
//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
|
||||
|
||||
+8
-7
@@ -42,19 +42,20 @@
|
||||
//config:config FEATURE_TEST_64
|
||||
//config: bool "Extend test to 64 bit"
|
||||
//config: default y
|
||||
//config: depends on TEST || TEST1 || TEST2 || ASH_BUILTIN_TEST || HUSH
|
||||
//config: depends on TEST || TEST1 || TEST2 || ASH_TEST || HUSH_TEST
|
||||
//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_BUILTIN_TEST) += test.o test_ptr_hack.o
|
||||
//kbuild:lib-$(CONFIG_HUSH) += 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
|
||||
|
||||
/* "test --help" is special-cased to ignore --help */
|
||||
//usage:#define test_trivial_usage NOUSAGE_STR
|
||||
@@ -841,7 +842,7 @@ int test_main(int argc, char **argv)
|
||||
const char *arg0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_BUILTIN_TEST || ENABLE_HUSH)
|
||||
if ((ENABLE_TEST1 || ENABLE_TEST2 || ENABLE_ASH_TEST || ENABLE_HUSH_TEST)
|
||||
&& (arg0[0] == '[')
|
||||
) {
|
||||
--argc;
|
||||
|
||||
File renamed without changes.
+1
-1
@@ -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 0
|
||||
#if ENABLE_FEDORA_COMPAT
|
||||
/* Fedora does something like this */
|
||||
strcpy(uname_info.processor, uname_info.name.machine);
|
||||
strcpy(uname_info.platform, uname_info.name.machine);
|
||||
|
||||
+9
-2
@@ -26,6 +26,7 @@
|
||||
//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"
|
||||
@@ -54,12 +55,13 @@ 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:+", &skip_fields, &skip_chars, &max_chars);
|
||||
opt = getopt32(argv, "cduf:+s:+w:+i", &skip_fields, &skip_chars, &max_chars);
|
||||
argv += optind;
|
||||
|
||||
input_filename = argv[0];
|
||||
@@ -106,7 +108,12 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
|
||||
++cur_compare;
|
||||
}
|
||||
|
||||
if (!old_line || strncmp(old_compare, cur_compare, max_chars)) {
|
||||
if (!old_line)
|
||||
break;
|
||||
if ((opt & OPT_i)
|
||||
? strncasecmp(old_compare, cur_compare, max_chars)
|
||||
: strncmp(old_compare, cur_compare, max_chars)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,13 @@ 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;
|
||||
|
||||
@@ -47,10 +47,16 @@ 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, and stray trailing spaces */
|
||||
/* 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.
|
||||
*/
|
||||
str_len = line_len;
|
||||
while (--str_len >= 0 && isspace(line[str_len]))
|
||||
while (--str_len >= 0
|
||||
&& (line[str_len] == '\n' || line[str_len] == '\r')
|
||||
) {
|
||||
line[str_len] = '\0';
|
||||
}
|
||||
|
||||
if (strcmp(line, "end") == 0) {
|
||||
return; /* the only non-error exit */
|
||||
@@ -65,7 +71,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
@@ -40,11 +40,11 @@
|
||||
//config: in specified files.
|
||||
//config:
|
||||
//config:config FEATURE_WC_LARGE
|
||||
//config: bool "Support very large files in wc"
|
||||
//config: bool "Support very large counts"
|
||||
//config: default y
|
||||
//config: depends on WC
|
||||
//config: help
|
||||
//config: Use "unsigned long long" in wc for counter variables.
|
||||
//config: Use "unsigned long long" for counter variables.
|
||||
|
||||
//applet:IF_WC(APPLET(wc, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
|
||||
+47
-5
@@ -23,6 +23,14 @@
|
||||
//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
|
||||
@@ -30,11 +38,14 @@
|
||||
//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_WHO(APPLET(who, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
//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))
|
||||
|
||||
//kbuild:lib-$(CONFIG_USERS) += who.o
|
||||
//kbuild:lib-$(CONFIG_WHO) += who.o
|
||||
//kbuild:lib-$(CONFIG_W) += 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'. */
|
||||
|
||||
@@ -43,6 +54,31 @@
|
||||
//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"
|
||||
@@ -73,14 +109,17 @@ 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_users ? "" : "aH");
|
||||
if (opt & 2) // -H
|
||||
opt = getopt32(argv, do_who ? "aH" : "");
|
||||
if ((opt & 2) || do_w) /* -H or we are w */
|
||||
puts("USER\t\tTTY\t\tIDLE\tTIME\t\t HOST");
|
||||
|
||||
setutxent();
|
||||
@@ -114,6 +153,9 @@ 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
|
||||
);
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@
|
||||
//config: yes is used to repeatedly output a specific string, or
|
||||
//config: the default string `y'.
|
||||
|
||||
//applet:IF_YES(APPLET_NOFORK(yes, yes, BB_DIR_USR_BIN, BB_SUID_DROP, yes))
|
||||
//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 */
|
||||
|
||||
//kbuild:lib-$(CONFIG_YES) += yes.o
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@
|
||||
//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"
|
||||
|
||||
@@ -64,22 +64,19 @@ 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))
|
||||
|
||||
|
||||
+37
-7
@@ -33,6 +33,7 @@ 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.
|
||||
* ...
|
||||
@@ -51,6 +52,9 @@ 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.
|
||||
@@ -81,18 +85,44 @@ 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
|
||||
applet tables will contain NOFORK/NOEXEC bits
|
||||
if command's name matches some applet name;
|
||||
spawn_and_wait(argv) will do NOFORK/NOEXEC tricks
|
||||
|
||||
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
|
||||
//TODO: the above two things probably should have separate options?
|
||||
|
||||
FEATURE_SH_NOFORK (needs FEATURE_PREFER_APPLETS=y)
|
||||
FEATURE_SH_STANDALONE
|
||||
shells will try to exec /proc/self/exe if command's name matches
|
||||
some applet name; shells will do NOEXEC trick on NOEXEC applets
|
||||
|
||||
//TODO: split (same as for PREFER_APPLETS)
|
||||
|
||||
FEATURE_SH_NOFORK
|
||||
shells will do NOFORK trick on NOFORK applets
|
||||
@@ -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, paste, pathchk, pax, pr, qalter, qdel, qhold, qmove,
|
||||
mailx, newgrp, nl, pathchk, pax, pr, qalter, qdel, qhold, qmove,
|
||||
qmsg, qrerun, qrls, qselect, qsig, qstat, qsub, tabs, talk, tput,
|
||||
tsort, unlink, uucp, uustat, uux
|
||||
|
||||
@@ -469,6 +469,12 @@ 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
@@ -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 (childs) they spawned.
|
||||
processes are waiting for other processes (children) 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
|
||||
immediatly, but the calling shell isn't told about the non-normal exit
|
||||
immediately, 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 happend automatically, but of you catch
|
||||
you don't catch SIGINT, this happened 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 desireable to exit the right way, even if you don't
|
||||
<P>It is always desirable 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, childs must do what?</th>
|
||||
<th>To behave properly, children must do what?</th>
|
||||
</tr>
|
||||
|
||||
<tr valign=top align=left>
|
||||
|
||||
@@ -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 uesd, not once
|
||||
and complex "define" are evaluated each time they used, not once
|
||||
at declarations like enums. Also, the preprocessor does _no_ type checking
|
||||
whatsoever, making it much more error prone.
|
||||
|
||||
|
||||
+1
-1
@@ -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", "BB_BT")");
|
||||
puts("fsck (busybox "BB_VER")");
|
||||
|
||||
/* Even plain "fsck /dev/hda1" needs fstab to get fs type,
|
||||
* so we are scanning it anyway */
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ config FEATURE_ALLOW_EXEC
|
||||
default y
|
||||
depends on VI || AWK
|
||||
help
|
||||
Enables vi and awk features which allows user to execute
|
||||
Enables vi and awk features which allow user to execute
|
||||
shell commands (using system() C call).
|
||||
|
||||
endmenu
|
||||
+21
-18
@@ -88,8 +88,6 @@
|
||||
//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"
|
||||
@@ -297,17 +295,6 @@ 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);
|
||||
@@ -728,9 +715,19 @@ static int diffreg(char *file[2])
|
||||
fp[0] = stdin;
|
||||
fp[1] = stdin;
|
||||
for (i = 0; i < 2; i++) {
|
||||
int fd = open_or_warn_stdin(file[i]);
|
||||
if (fd == -1)
|
||||
goto out;
|
||||
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);
|
||||
}
|
||||
}
|
||||
/* Our diff implementation is using seek.
|
||||
* When we meet non-seekable file, we must make a temp copy.
|
||||
*/
|
||||
@@ -991,17 +988,23 @@ 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
|
||||
} else if (option_mask32 & FLAG(N)) {
|
||||
if (stat(file[i], &stb[i]))
|
||||
xstat("/dev/null", &stb[i]);
|
||||
} 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
@@ -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 shouldnt ever equal NULL */
|
||||
/* endstr shouldn't 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 exension) */
|
||||
/* Ignore case (gnu extension) */
|
||||
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 wasnt a single-letter command that takes no arguments
|
||||
/* if it wasn't 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 dont check
|
||||
* the last char in replace string. Thus we don't check
|
||||
* for replace[i] == NUL. (counterexample anyone?) */
|
||||
/* if we find a backslash escaped character, print the character */
|
||||
pipe_putc(replace[i]);
|
||||
|
||||
+62
-56
@@ -30,7 +30,7 @@
|
||||
//config: you may wish to use something else.
|
||||
//config:
|
||||
//config:config FEATURE_VI_MAX_LEN
|
||||
//config: int "Maximum screen width in vi"
|
||||
//config: int "Maximum screen width"
|
||||
//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 vi to display 8-bit chars (otherwise shows dots)"
|
||||
//config: bool "Allow 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 for vi. This does not
|
||||
//config: Enable a limited set of colon commands. This does not
|
||||
//config: provide an "ex" mode.
|
||||
//config:
|
||||
//config:config FEATURE_VI_YANKMARK
|
||||
@@ -61,16 +61,14 @@
|
||||
//config: default y
|
||||
//config: depends on VI
|
||||
//config: help
|
||||
//config: This will enable you to use yank and put, as well as mark in
|
||||
//config: busybox vi.
|
||||
//config: This will enable you to use yank and put, as well as mark.
|
||||
//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 in
|
||||
//config: busybox vi.
|
||||
//config: Select this if you wish to be able to do search and replace.
|
||||
//config:
|
||||
//config:config FEATURE_VI_REGEX_SEARCH
|
||||
//config: bool "Enable regex in search and replace"
|
||||
@@ -84,16 +82,15 @@
|
||||
//config: default y
|
||||
//config: depends on VI
|
||||
//config: help
|
||||
//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: 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:
|
||||
//config:config FEATURE_VI_DOT_CMD
|
||||
//config: bool "Remember previous cmd and \".\" cmd"
|
||||
//config: default y
|
||||
//config: depends on VI
|
||||
//config: help
|
||||
//config: Make busybox vi remember the last command and be able to repeat it.
|
||||
//config: Make 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"
|
||||
@@ -104,25 +101,23 @@
|
||||
//config: open a file in read-only mode.
|
||||
//config:
|
||||
//config:config FEATURE_VI_SETOPTS
|
||||
//config: bool "Enable set-able options, ai ic showmatch"
|
||||
//config: bool "Enable settable 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 for :set"
|
||||
//config: bool "Support :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: Make busybox vi behave nicely with terminals that get resized.
|
||||
//config: 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"
|
||||
@@ -133,15 +128,16 @@
|
||||
//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:
|
||||
//config: This is not clean but helps a lot on serial lines and such.
|
||||
//config:
|
||||
//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
|
||||
@@ -152,6 +148,7 @@
|
||||
//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
|
||||
@@ -357,7 +354,7 @@ struct globals {
|
||||
#if ENABLE_FEATURE_VI_USE_SIGNALS
|
||||
sigjmp_buf restart; // catch_sig()
|
||||
#endif
|
||||
struct termios term_orig, term_vi; // remember what the cooked mode was
|
||||
struct termios term_orig; // remember what the cooked mode was
|
||||
#if ENABLE_FEATURE_VI_COLON
|
||||
char *initial_cmds[3]; // currently 2 entries, NULL terminated
|
||||
#endif
|
||||
@@ -465,7 +462,6 @@ 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 )
|
||||
@@ -719,14 +715,6 @@ 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;
|
||||
@@ -741,6 +729,14 @@ 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;
|
||||
}
|
||||
|
||||
@@ -1038,7 +1034,9 @@ static void colon(char *buf)
|
||||
|| strncmp(p, "wn", cnt) == 0
|
||||
|| (p[0] == 'x' && !p[1])
|
||||
) {
|
||||
cnt = file_write(current_filename, text, end - 1);
|
||||
if (modified_count != 0 || p[0] != 'x') {
|
||||
cnt = file_write(current_filename, text, end - 1);
|
||||
}
|
||||
if (cnt < 0) {
|
||||
if (cnt == -1)
|
||||
status_line_bold("Write error: %s", strerror(errno));
|
||||
@@ -1049,8 +1047,9 @@ static void colon(char *buf)
|
||||
current_filename,
|
||||
count_lines(text, end - 1), cnt
|
||||
);
|
||||
if (p[0] == 'x' || p[1] == 'q' || p[1] == 'n'
|
||||
|| p[0] == 'X' || p[1] == 'Q' || p[1] == 'N'
|
||||
if (p[0] == 'x'
|
||||
|| p[1] == 'q' || p[1] == 'n'
|
||||
|| p[1] == 'Q' || p[1] == 'N'
|
||||
) {
|
||||
editing = 0;
|
||||
}
|
||||
@@ -1461,7 +1460,7 @@ static void colon(char *buf)
|
||||
}
|
||||
#endif /* FEATURE_VI_SEARCH */
|
||||
} else if (strncmp(cmd, "version", i) == 0) { // show software version
|
||||
status_line(BB_VER " " BB_BT);
|
||||
status_line(BB_VER);
|
||||
} else if (strncmp(cmd, "write", i) == 0 // write text to file
|
||||
|| strncmp(cmd, "wq", i) == 0
|
||||
|| strncmp(cmd, "wn", i) == 0
|
||||
@@ -1480,16 +1479,19 @@ 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;
|
||||
//}
|
||||
l = file_write(fn, q, r);
|
||||
if (modified_count != 0 || cmd[0] != 'x') {
|
||||
size = r - q + 1;
|
||||
l = file_write(fn, q, r);
|
||||
} else {
|
||||
size = 0;
|
||||
l = 0;
|
||||
}
|
||||
//if (useforce && forced) {
|
||||
// chmod u-w
|
||||
// sprintf(syscmd, "chmod u-w %s", fn);
|
||||
@@ -1500,17 +1502,20 @@ 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 (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 (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 ENABLE_FEATURE_VI_YANKMARK
|
||||
@@ -2734,15 +2739,9 @@ static char *swap_context(char *p) // goto new context for '' command make this
|
||||
//----- Set terminal attributes --------------------------------
|
||||
static void rawmode(void)
|
||||
{
|
||||
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);
|
||||
// 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];
|
||||
}
|
||||
|
||||
static void cookmode(void)
|
||||
@@ -2817,8 +2816,15 @@ static int readit(void) // read (maybe cursor) key from stdin
|
||||
int c;
|
||||
|
||||
fflush_all();
|
||||
c = read_key(STDIN_FILENO, readbuffer, /*timeout off:*/ -2);
|
||||
|
||||
// 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);
|
||||
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
@@ -7,7 +7,7 @@
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
#
|
||||
|
||||
local BASE="${1:-/usr/lib/modules}"
|
||||
BASE="${1:-/usr/lib/modules}"
|
||||
|
||||
find "$BASE" -name '*.ko.gz' | while read I ; do
|
||||
N=`basename "$I" '.ko.gz'`
|
||||
|
||||
@@ -14,7 +14,7 @@ env | sort
|
||||
|
||||
while sleep 1; test $cnt != 0; do
|
||||
echo "Trying to reread partition table on $DEVNAME ($cnt)"
|
||||
: $((cnt--))
|
||||
cnt=$((cnt-1))
|
||||
# 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; }
|
||||
|
||||
@@ -18,11 +18,18 @@ 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 is we have at least one DNS server
|
||||
# Only replace resolv.conf if we have at least one DNS server
|
||||
if [ -n "$dns" ]
|
||||
then
|
||||
echo -n > $RESOLV_CONF
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
# Sample udhcpc bound script
|
||||
# Sample udhcpc renew script
|
||||
|
||||
RESOLV_CONF="/etc/udhcpc/resolv.conf"
|
||||
|
||||
@@ -18,11 +18,18 @@ 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 is we have at least one DNS server
|
||||
# Only replace resolv.conf if we have at least one DNS server
|
||||
if [ -n "$dns" ]
|
||||
then
|
||||
echo -n > $RESOLV_CONF
|
||||
|
||||
@@ -29,8 +29,14 @@ case "$1" in
|
||||
metric=0
|
||||
for i in $router ; do
|
||||
echo "Adding router $i"
|
||||
route add default gw $i dev $interface metric $metric
|
||||
: $(( metric += 1 ))
|
||||
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++))
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
@@ -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 Vod Linux's wiki:
|
||||
Here is a link to Void 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: same as "daemon"
|
||||
service: daemon controlled by a service monitor.
|
||||
|
||||
service directory: a directory with an executable file (script) named "run"
|
||||
which (usually) execs daemon (possibly after some preparatory steps).
|
||||
which (usually) execs some 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/top/signal its child.
|
||||
It can be instructed to start/stop/signal its child.
|
||||
In daemontools package, it is called "supervise". In runit, it is called
|
||||
"runsv". In s6, it is called "s6-supervise".
|
||||
|
||||
@@ -150,7 +150,9 @@ 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).
|
||||
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).
|
||||
|
||||
The install location for service dirs is /etc/rc:
|
||||
when e.g. ntpd daemon is installed, it creates the /etc/rc/ntpd
|
||||
@@ -182,10 +184,14 @@ 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 runsdir's stdout was directied;
|
||||
daemons' stdout goes to wherever runsvdir's stdout was directed;
|
||||
stderr goes to runsvdir, which in turn "rotates" it on its command line
|
||||
(which is visible in ps output).
|
||||
|
||||
@@ -236,11 +242,11 @@ 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.
|
||||
|
||||
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
|
||||
[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 "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.
|
||||
The "svok DIR" tool exits 0 if service is running, and nonzero if not.
|
||||
|
||||
Other tools with different names and APIs may exist; however
|
||||
for portability scripts should use the above tools.
|
||||
@@ -250,27 +256,28 @@ 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,
|
||||
whereever it is located on this distro.
|
||||
wherever 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 ...]
|
||||
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.
|
||||
|
||||
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 "superwise DIR" and "superwise DIR/log"]
|
||||
[svscan runs a pair of "supervise DIR" and "supervise DIR/log"]
|
||||
|
||||
Directores are remembered by device+inode numbers, not names. Renaming a directory
|
||||
Directories 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.
|
||||
|
||||
@@ -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 paramaters,
|
||||
# The IP address does not change, however, the other DHCP parameters,
|
||||
# such as the default gateway, subnet mask, and dns server may change.
|
||||
#
|
||||
# nak: udhcpc received a NAK message.
|
||||
|
||||
@@ -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=$((failcnt+1))
|
||||
msg "Failed to ping $router, fail count:$failcnt"
|
||||
test $failcnt -ge $max_fail && break
|
||||
env - sleep "$retry_time"
|
||||
|
||||
+1
-15
@@ -89,8 +89,6 @@
|
||||
//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/...)"
|
||||
@@ -104,15 +102,11 @@
|
||||
//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"
|
||||
@@ -126,8 +120,6 @@
|
||||
//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"
|
||||
@@ -151,15 +143,11 @@
|
||||
//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"
|
||||
@@ -188,15 +176,13 @@
|
||||
//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, dont descend into it. Useful for
|
||||
//config: If the file is a directory, don't descend into it. Useful for
|
||||
//config: exclusion .svn and CVS directories.
|
||||
//config:
|
||||
//config:config FEATURE_FIND_DELETE
|
||||
|
||||
+4
-3
@@ -39,13 +39,14 @@
|
||||
//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
|
||||
//config: depends on GREP || EGREP || FGREP
|
||||
//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))
|
||||
|
||||
@@ -514,7 +515,7 @@ static int grep_file(FILE *file)
|
||||
if (option_mask32 & OPT_o) {
|
||||
if (FGREP_FLAG) {
|
||||
/* -Fo just prints the pattern
|
||||
* (unless -v: -Fov doesnt print anything at all) */
|
||||
* (unless -v: -Fov doesn't print anything at all) */
|
||||
if (found)
|
||||
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
|
||||
} else while (1) {
|
||||
@@ -822,7 +823,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
|
||||
grep_done: ;
|
||||
} while (*argv && *++argv);
|
||||
|
||||
/* destroy all the elments in the pattern list */
|
||||
/* destroy all the elements in the pattern list */
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
while (pattern_head) {
|
||||
llist_t *pattern_head_ptr = pattern_head;
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
# enabling it. Run it after applets.h is generated.
|
||||
|
||||
# CONFIG_applet names
|
||||
grep ^IF_ applets.h | grep -v IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
|
||||
| grep -v MODPROBE_SMALL \
|
||||
| sed 's/BB_SYSCTL/SYSCTL/' \
|
||||
| sed 's/TEST1/[/' \
|
||||
| sed 's/TEST2/[[/' \
|
||||
grep ^IF_ applets.h | grep -v ^IF_FEATURE_ | sed 's/IF_\([A-Z0-9._-]*\)(.*/\1/' \
|
||||
| sort | uniq \
|
||||
>applets_APP1
|
||||
|
||||
@@ -17,8 +13,11 @@ grep ^IF_ applets.h | sed -e's/ //g' -e's/.*(\([a-z[][^,]*\),.*/\1/' \
|
||||
| grep -v '^bash$' \
|
||||
| grep -v '^sh$' \
|
||||
| tr a-z A-Z \
|
||||
| sed 's/^SYSCTL$/BB_SYSCTL/' \
|
||||
| sed 's/^\[\[$/TEST1/' \
|
||||
| sed 's/^\[$/TEST2/' \
|
||||
| sort | uniq \
|
||||
>applets_APP2
|
||||
|
||||
diff -u applets_APP1 applets_APP2 >applets_APP.diff
|
||||
rm applets_APP1 applets_APP2
|
||||
#rm applets_APP1 applets_APP2
|
||||
+142
-35
@@ -342,6 +342,8 @@ 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;
|
||||
@@ -355,6 +357,27 @@ 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;
|
||||
@@ -693,6 +716,56 @@ 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,
|
||||
@@ -705,9 +778,8 @@ 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;
|
||||
|
||||
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;
|
||||
/* 0 if argv[0] is NULL: */
|
||||
unsigned string_array_len(char **argv) FAST_FUNC;
|
||||
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;
|
||||
@@ -753,24 +825,6 @@ 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,
|
||||
@@ -1043,10 +1097,19 @@ 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.
|
||||
*
|
||||
@@ -1115,6 +1178,26 @@ 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
|
||||
@@ -1186,7 +1269,7 @@ extern void bb_logenv_override(void) FAST_FUNC;
|
||||
|
||||
|
||||
/* Applets which are useful from another applets */
|
||||
int bb_cat(char** argv);
|
||||
int bb_cat(char** argv) FAST_FUNC;
|
||||
/* 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);
|
||||
@@ -1212,6 +1295,16 @@ 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. */
|
||||
@@ -1253,13 +1346,8 @@ const struct hwtype *get_hwtype(const char *name) FAST_FUNC;
|
||||
const struct hwtype *get_hwntype(int type) 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
|
||||
|
||||
extern int fstype_matches(const char *fstype, const char *comma_list) FAST_FUNC;
|
||||
#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;
|
||||
@@ -1275,10 +1363,15 @@ 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: 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;
|
||||
* 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
|
||||
|
||||
/* Like bb_ask below, but asks on stdin with no timeout. */
|
||||
char *bb_ask_stdin(const char * prompt) FAST_FUNC;
|
||||
@@ -1390,6 +1483,12 @@ 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;
|
||||
@@ -1438,6 +1537,10 @@ 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;
|
||||
@@ -1749,19 +1852,23 @@ 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;
|
||||
void md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
|
||||
unsigned md5_end(md5_ctx_t *ctx, void *resbuf) FAST_FUNC;
|
||||
void sha1_begin(sha1_ctx_t *ctx) FAST_FUNC;
|
||||
#define sha1_hash md5_hash
|
||||
void sha1_end(sha1_ctx_t *ctx, void *resbuf) FAST_FUNC;
|
||||
unsigned 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;
|
||||
void sha512_end(sha512_ctx_t *ctx, void *resbuf) FAST_FUNC;
|
||||
unsigned 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;
|
||||
void sha3_end(sha3_ctx_t *ctx, void *resbuf) 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
|
||||
|
||||
extern uint32_t *global_crc32_table;
|
||||
uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC;
|
||||
|
||||
+10
-5
@@ -108,13 +108,18 @@
|
||||
* 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 */
|
||||
#if __GNUC_PREREQ(3,0) && defined(i386) /* || defined(__x86_64__)? */
|
||||
* 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)
|
||||
/* 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
|
||||
# else
|
||||
# define FAST_FUNC
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Make all declarations hidden (-fvisibility flag only affects definitions) */
|
||||
|
||||
@@ -14,6 +14,14 @@
|
||||
|
||||
#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 \
|
||||
|
||||
+2
-1
@@ -46,8 +46,9 @@
|
||||
//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
|
||||
|
||||
+29
-27
@@ -17,7 +17,7 @@
|
||||
//config: init is the first program run when the system boots.
|
||||
//config:
|
||||
//config:config LINUXRC
|
||||
//config: bool "Support running init from within an initrd (not initramfs)"
|
||||
//config: bool "linuxrc: support running init from initrd (not initramfs)"
|
||||
//config: default y
|
||||
//config: select FEATURE_SYSLOG
|
||||
//config: help
|
||||
@@ -73,17 +73,19 @@
|
||||
//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_EXTRA_QUIET
|
||||
//config: bool "Be _extra_ quiet on boot"
|
||||
//config:config FEATURE_INIT_QUIET
|
||||
//config: bool "Be quiet on boot (no 'init started:' message)"
|
||||
//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)"
|
||||
//config: default y
|
||||
//config: default n # not Y because this is a debug option
|
||||
//config: depends on INIT || LINUXRC
|
||||
//config: help
|
||||
//config: If this option is enabled and the file /.init_enable_core
|
||||
@@ -104,13 +106,13 @@
|
||||
//config: sets TERM to "vt102" if one is found.
|
||||
//config:
|
||||
//config:config FEATURE_INIT_MODIFY_CMDLINE
|
||||
//config: bool "Modify the command-line to \"init\""
|
||||
//config: bool "Clear init's command line"
|
||||
//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,
|
||||
@@ -214,7 +216,9 @@ 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,
|
||||
@@ -253,17 +257,16 @@ static void message(int where, const char *fmt, ...)
|
||||
msg[l++] = '\n';
|
||||
msg[l] = '\0';
|
||||
#else
|
||||
{
|
||||
static int log_fd = -1;
|
||||
|
||||
msg[l++] = '\n';
|
||||
msg[l] = '\0';
|
||||
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;
|
||||
|
||||
if (log_fd < 0) {
|
||||
if (!log_console) {
|
||||
log_fd = STDERR_FILENO;
|
||||
} else {
|
||||
log_fd = STDERR_FILENO;
|
||||
if (log_console) {
|
||||
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);
|
||||
@@ -273,11 +276,9 @@ static void message(int where, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (where & L_LOG) {
|
||||
full_write(log_fd, msg, l);
|
||||
if (log_fd == STDERR_FILENO)
|
||||
return; /* don't print dup messages */
|
||||
}
|
||||
full_write(log_fd, msg, l);
|
||||
if (log_fd == STDERR_FILENO)
|
||||
return; /* don't print dup messages */
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -327,8 +328,9 @@ 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;
|
||||
# if !ENABLE_FEATURE_INIT_SYSLOG
|
||||
log_console = NULL;
|
||||
# endif
|
||||
} else
|
||||
#endif
|
||||
if (!s)
|
||||
@@ -543,8 +545,8 @@ static pid_t run(const struct init_action *a)
|
||||
}
|
||||
|
||||
/* Log the process name and args */
|
||||
message(L_LOG, "starting pid %d, tty '%s': '%s'",
|
||||
getpid(), a->terminal, a->command);
|
||||
message(L_LOG, "starting pid %u, tty '%s': '%s'",
|
||||
(int)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. */
|
||||
@@ -759,7 +761,7 @@ static void run_shutdown_and_kill_processes(void)
|
||||
|
||||
/* Send signals to every process _except_ pid 1 */
|
||||
kill(-1, SIGTERM);
|
||||
message(L_CONSOLE | L_LOG, "Sent SIG%s to all processes", "TERM");
|
||||
message(L_CONSOLE, "Sent SIG%s to all processes", "TERM");
|
||||
sync();
|
||||
sleep(1);
|
||||
|
||||
@@ -1098,7 +1100,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[1])
|
||||
xsetenv("RUNLEVEL", argv[1]);
|
||||
|
||||
#if !ENABLE_FEATURE_EXTRA_QUIET
|
||||
#if !ENABLE_FEATURE_INIT_QUIET
|
||||
/* Hello world */
|
||||
message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
|
||||
#endif
|
||||
|
||||
Loaded 100 of 370 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user