Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28dd64a0e1 | ||
|
|
5698ff9323 | ||
|
|
d9e0c438e1 |
No files matched your search
-15
@@ -35,18 +35,3 @@ Config.in
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
|
||||
#
|
||||
# testing output
|
||||
#
|
||||
/busybox.links
|
||||
/runtest-tempdir-links
|
||||
/testsuite/echo-ne
|
||||
|
||||
#
|
||||
# cscope output
|
||||
#
|
||||
cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
@@ -116,21 +116,9 @@ config FEATURE_COMPRESS_USAGE
|
||||
and have very little memory, this might not be a win. Otherwise,
|
||||
you probably want this.
|
||||
|
||||
config BUSYBOX
|
||||
bool "Include busybox applet"
|
||||
default y
|
||||
help
|
||||
The busybox applet provides general help regarding busybox and
|
||||
allows the included applets to be listed. It's also required
|
||||
if applet links are to be installed at runtime.
|
||||
|
||||
If you can live without these features disabling this will save
|
||||
some space.
|
||||
|
||||
config FEATURE_INSTALLER
|
||||
bool "Support --install [-s] to install applet links at runtime"
|
||||
default y
|
||||
depends on BUSYBOX
|
||||
help
|
||||
Enable 'busybox --install [-s]' support. This will allow you to use
|
||||
busybox at runtime to create hard links or symlinks for all the
|
||||
@@ -269,26 +257,6 @@ config UNICODE_PRESERVE_BROKEN
|
||||
at shell prompt will list file named 0xff (single char name
|
||||
with char value 255), not file named '?'.
|
||||
|
||||
config PAM
|
||||
bool "Support for PAM (Pluggable Authentication Modules)"
|
||||
default n
|
||||
help
|
||||
Use PAM in some busybox applets (currently login and httpd) instead
|
||||
of direct access to password database.
|
||||
|
||||
config FEATURE_USE_SENDFILE
|
||||
bool "Use sendfile system call"
|
||||
default y
|
||||
select PLATFORM_LINUX
|
||||
help
|
||||
When enabled, busybox will use the kernel sendfile() function
|
||||
instead of read/write loops to copy data between file descriptors
|
||||
(for example, cp command does this a lot).
|
||||
If sendfile() doesn't work, copying code falls back to read/write
|
||||
loop. sendfile() was originally implemented for faster I/O
|
||||
from files to sockets, but since Linux 2.6.33 it was extended
|
||||
to work for many more file types.
|
||||
|
||||
config LONG_OPTS
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
@@ -448,7 +416,10 @@ config SELINUX
|
||||
the option of compiling in SELinux applets.
|
||||
|
||||
If you do not have a complete SELinux userland installed, this stuff
|
||||
will not compile. Specifially, libselinux 1.28 or better is
|
||||
will not compile. Go visit
|
||||
http://www.nsa.gov/selinux/index.html
|
||||
to download the necessary stuff to allow busybox to compile with
|
||||
this option enabled. Specifially, libselinux 1.28 or better is
|
||||
directly required by busybox. If the installation is located in a
|
||||
non-standard directory, provide it by invoking make as follows:
|
||||
CFLAGS=-I<libselinux-include-path> \
|
||||
@@ -700,24 +671,6 @@ config DEBUG_PESSIMIZE
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
config DEBUG_SANITIZE
|
||||
bool "Enable runtime sanitizers (ASAN/LSAN/USAN/etc...)"
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to enable runtime sanitizers. These help
|
||||
catch bad memory accesses (e.g. buffer overflows), but will make
|
||||
the executable larger and slow down runtime a bit.
|
||||
|
||||
If you aren't developing/testing busybox, say N here.
|
||||
|
||||
config UNIT_TEST
|
||||
bool "Build unit tests"
|
||||
default n
|
||||
help
|
||||
Say Y here if you want to build unit tests (both the framework and
|
||||
test cases) as a Busybox applet. This results in bigger code, so you
|
||||
probably don't want this option in production builds.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
default n
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 25
|
||||
PATCHLEVEL = 22
|
||||
SUBLEVEL = 1
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
@@ -552,7 +552,7 @@ export INSTALL_PATH ?= /boot
|
||||
#
|
||||
# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
|
||||
# relocations required by build roots. This is not defined in the
|
||||
# makefile but the argument can be passed to make if needed.
|
||||
# makefile but the arguement can be passed to make if needed.
|
||||
#
|
||||
|
||||
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
|
||||
@@ -610,8 +610,7 @@ quiet_cmd_busybox__ ?= LINK $@
|
||||
"$(LDFLAGS) $(EXTRA_LDFLAGS)" \
|
||||
"$(core-y)" \
|
||||
"$(libs-y)" \
|
||||
"$(LDLIBS)" \
|
||||
&& $(srctree)/scripts/generate_BUFSIZ.sh --post include/common_bufsiz.h
|
||||
"$(LDLIBS)"
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
@@ -845,15 +844,12 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
|
||||
# Split autoconf.h into include/linux/config/*
|
||||
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
|
||||
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs include/bbconfigopts.h include/bbconfigopts_bz2.h
|
||||
quiet_cmd_gen_common_bufsiz = GEN include/common_bufsiz.h
|
||||
cmd_gen_common_bufsiz = $(srctree)/scripts/generate_BUFSIZ.sh include/common_bufsiz.h
|
||||
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
|
||||
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
|
||||
#bbox# piggybacked generation of few .h files
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h
|
||||
$(call cmd,split_autoconf)
|
||||
$(call cmd,gen_bbconfigopts)
|
||||
$(call cmd,gen_common_bufsiz)
|
||||
@touch $@
|
||||
|
||||
# Generate some files
|
||||
@@ -969,7 +965,6 @@ CLEAN_FILES += busybox busybox_unstripped* busybox.links \
|
||||
MRPROPER_DIRS += include/config include2
|
||||
MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
include/NUM_APPLETS.h \
|
||||
include/common_bufsiz.h \
|
||||
include/autoconf.h \
|
||||
include/bbconfigopts.h \
|
||||
include/bbconfigopts_bz2.h \
|
||||
@@ -1170,7 +1165,24 @@ endif
|
||||
ALLSOURCE_ARCHS := $(ARCH)
|
||||
|
||||
define all-sources
|
||||
( find -regex '.*\.[ch]$$' )
|
||||
( find $(__srctree) $(RCS_FIND_IGNORE) \
|
||||
\( -name include -o -name arch \) -prune -o \
|
||||
-name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLSOURCE_ARCHS) ; do \
|
||||
find $(__srctree)arch/$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
find $(__srctree)include $(RCS_FIND_IGNORE) \
|
||||
\( -name config -o -name 'asm-*' \) -prune \
|
||||
-o -name '*.[chS]' -print; \
|
||||
for ARCH in $(ALLINCLUDE_ARCHS) ; do \
|
||||
find $(__srctree)include/asm-$${ARCH} $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print; \
|
||||
done ; \
|
||||
find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \
|
||||
-name '*.[chS]' -print )
|
||||
endef
|
||||
|
||||
quiet_cmd_cscope-file = FILELST cscope.files
|
||||
|
||||
@@ -28,10 +28,6 @@ ifeq ($(CONFIG_INSTALL_SH_APPLET_SCRIPT_WRAPPER),y)
|
||||
INSTALL_OPTS:= --scriptwrapper
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_FEATURE_INDIVIDUAL),y)
|
||||
INSTALL_OPTS:= --binaries
|
||||
LIBBUSYBOX_SONAME:= 0_lib/libbusybox.so.$(BB_VER)
|
||||
endif
|
||||
install: $(srctree)/applets/install.sh busybox busybox.links
|
||||
$(Q)DO_INSTALL_LIBS="$(strip $(LIBBUSYBOX_SONAME) $(DO_INSTALL_LIBS))" \
|
||||
$(SHELL) $< $(CONFIG_PREFIX) $(INSTALL_OPTS)
|
||||
@@ -59,11 +55,7 @@ endif
|
||||
# (cp -pPR is POSIX-compliant (cp -dpR or cp -a would not be))
|
||||
.PHONY: check
|
||||
.PHONY: test
|
||||
ifeq ($(CONFIG_UNIT_TEST),y)
|
||||
UNIT_CMD = ./busybox unit
|
||||
endif
|
||||
check test: busybox busybox.links
|
||||
$(UNIT_CMD)
|
||||
test -d $(objtree)/testsuite || cp -pPR $(srctree)/testsuite $(objtree)
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite \
|
||||
$(SHELL) -c "cd $(objtree)/testsuite && $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)"
|
||||
|
||||
+9
-21
@@ -56,9 +56,6 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
|
||||
# Defeat .eh_frame bloat (gcc 4.6.3 x86-32 defconfig: 20% smaller busybox binary):
|
||||
CFLAGS += $(call cc-option,-fno-unwind-tables,)
|
||||
CFLAGS += $(call cc-option,-fno-asynchronous-unwind-tables,)
|
||||
# No automatic printf->puts,putchar conversions
|
||||
# (try disabling this and comparing assembly, it's instructive)
|
||||
CFLAGS += $(call cc-option,-fno-builtin-printf,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
@@ -75,11 +72,6 @@ else
|
||||
CFLAGS += $(call cc-option,-Os,$(call cc-option,-O2,))
|
||||
endif
|
||||
endif
|
||||
ifeq ($(CONFIG_DEBUG_SANITIZE),y)
|
||||
CFLAGS += $(call cc-option,-fsanitize=address,)
|
||||
CFLAGS += $(call cc-option,-fsanitize=leak,)
|
||||
CFLAGS += $(call cc-option,-fsanitize=undefined,)
|
||||
endif
|
||||
|
||||
# If arch/$(ARCH)/Makefile did not override it (with, say, -fPIC)...
|
||||
ARCH_FPIC ?= -fpic
|
||||
@@ -134,19 +126,15 @@ else
|
||||
LDLIBS += m
|
||||
endif
|
||||
|
||||
# libpam may use libpthread, libdl and/or libaudit.
|
||||
# On some platforms that requires an explicit -lpthread, -ldl, -laudit.
|
||||
# However, on *other platforms* it fails when some of those flags
|
||||
# given needlessly. On some systems, crypt needs pthread.
|
||||
#
|
||||
# I even had a system where a runtime test for pthread
|
||||
# (similar to CRYPT_AVAILABLE test above) was not reliable.
|
||||
#
|
||||
# Do not propagate this mess by adding libraries to CONFIG_PAM/CRYPT_AVAILABLE blocks.
|
||||
# Add libraries you need to CONFIG_EXTRA_LDLIBS instead.
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
LDLIBS += pam pam_misc
|
||||
# libpam uses libpthread, so for static builds busybox must be linked to
|
||||
# libpthread. On some platforms that requires an explicit -lpthread, so
|
||||
# it should be in LDLIBS. For non-static builds, scripts/trylink will
|
||||
# take care of removing -lpthread if possible. (Not bothering to check
|
||||
# CONFIG_STATIC because even in a non-static build it could be that the
|
||||
# only libpam available is libpam.a, so -lpthread could still be
|
||||
# needed.)
|
||||
LDLIBS += pam pam_misc pthread
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
@@ -175,7 +163,7 @@ SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_LDFLAGS),)
|
||||
LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
EXTRA_LDFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_LDFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
|
||||
@@ -21,6 +21,10 @@ help:
|
||||
@echo ' defconfig - set .config to largest generic configuration'
|
||||
@echo ' menuconfig - interactive curses-based configurator'
|
||||
@echo ' oldconfig - resolve any unresolved symbols in .config'
|
||||
@echo ' hosttools - build sed for the host.'
|
||||
@echo ' You can use these commands if the commands on the host'
|
||||
@echo ' is unusable. Afterwards use it like:'
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@$(if $(boards), \
|
||||
$(foreach b, $(boards), \
|
||||
printf " %-21s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
|
||||
|
||||
@@ -185,7 +185,7 @@ Supported hardware:
|
||||
Under 2.4 Linux kernels, kernel module loading was implemented in a
|
||||
platform-specific manner. Busybox's insmod utility has been reported to
|
||||
work under ARM, CRIS, H8/300, x86, ia64, x86_64, m68k, MIPS, PowerPC, S390,
|
||||
SH3/4/5, Sparc, and v850e. Anything else probably won't work.
|
||||
SH3/4/5, Sparc, v850e, and x86_64. Anything else probably won't work.
|
||||
|
||||
The module loading mechanism for the 2.6 kernel is much more generic, and
|
||||
we believe 2.6.x kernel module loading support should work on all
|
||||
|
||||
@@ -258,3 +258,5 @@ vdprintf() -> similar sized functionality
|
||||
|
||||
* more support for advanced linux 2.6.x features, see: iotop
|
||||
most likely there is more
|
||||
|
||||
* even more support for statistics: mpstat, iostat, powertop....
|
||||
+25
-85
@@ -14,7 +14,6 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#undef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
|
||||
@@ -41,6 +40,8 @@ struct bb_applet {
|
||||
|
||||
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
|
||||
|
||||
static int offset[NUM_APPLETS];
|
||||
|
||||
static int cmp_name(const void *a, const void *b)
|
||||
{
|
||||
const struct bb_applet *aa = a;
|
||||
@@ -48,42 +49,26 @@ static int cmp_name(const void *a, const void *b)
|
||||
return strcmp(aa->name, bb->name);
|
||||
}
|
||||
|
||||
static int str_isalnum_(const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
if (!isalnum(*s) && *s != '_')
|
||||
return 0;
|
||||
s++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
// In find_applet_by_name(), before linear search, narrow it down
|
||||
// by looking at N "equidistant" names. With ~350 applets:
|
||||
// KNOWN_APPNAME_OFFSETS cycles
|
||||
// 0 9057
|
||||
// 2 4604 + ~100 bytes of code
|
||||
// 4 2407 + 4 bytes
|
||||
// 8 1342 + 8 bytes
|
||||
// 16 908 + 16 bytes
|
||||
// 32 884 + 32 bytes
|
||||
// With 8, int16_t applet_nameofs[] table has 7 elements.
|
||||
int KNOWN_APPNAME_OFFSETS = 8;
|
||||
// With 128 applets we do two linear searches, with 1..7 strcmp's in the first one
|
||||
// and 1..16 strcmp's in the second. With 256 apps, second search does 1..32 strcmp's.
|
||||
if (NUM_APPLETS < 128)
|
||||
KNOWN_APPNAME_OFFSETS = 4;
|
||||
if (NUM_APPLETS < 32)
|
||||
KNOWN_APPNAME_OFFSETS = 0;
|
||||
int i;
|
||||
int ofs;
|
||||
// unsigned MAX_APPLET_NAME_LEN = 1;
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
offset[i] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
/* We reuse 4 high-order bits of offset array for other purposes,
|
||||
* so if they are indeed needed, refuse to proceed */
|
||||
if (ofs > 0xfff)
|
||||
return 1;
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
@@ -98,27 +83,7 @@ int main(int argc, char **argv)
|
||||
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
|
||||
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
|
||||
}
|
||||
|
||||
printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
|
||||
if (KNOWN_APPNAME_OFFSETS > 0) {
|
||||
int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
|
||||
for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
|
||||
index[i] = i * NUM_APPLETS / KNOWN_APPNAME_OFFSETS;
|
||||
ofs = 0;
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
for (j = 0; j < KNOWN_APPNAME_OFFSETS; j++)
|
||||
if (i == index[j])
|
||||
offset[j] = ofs;
|
||||
ofs += strlen(applets[i].name) + 1;
|
||||
}
|
||||
/* If the list of names is too long refuse to proceed */
|
||||
if (ofs > 0xffff)
|
||||
return 1;
|
||||
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
|
||||
for (i = 1; i < KNOWN_APPNAME_OFFSETS; i++)
|
||||
printf("%d,\n", offset[i]);
|
||||
printf("};\n\n");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
//printf("#ifndef SKIP_definitions\n");
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
@@ -129,12 +94,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
printf(";\n\n");
|
||||
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
if (str_isalnum_(applets[i].name))
|
||||
printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
@@ -143,39 +102,20 @@ int main(int argc, char **argv)
|
||||
printf("};\n");
|
||||
printf("#endif\n\n");
|
||||
|
||||
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
#if ENABLE_FEATURE_PREFER_APPLETS
|
||||
printf("const uint8_t applet_flags[] ALIGN1 = {\n");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].nofork + (applets[i].noexec << 1);
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 2;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 4;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= (applets[i].nofork + (applets[i].noexec << 1)) << 6;
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
printf("};\n\n");
|
||||
+ (applets[i].nofork << 12)
|
||||
+ (applets[i].noexec << 13)
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
printf("const uint8_t applet_suid[] ALIGN1 = {\n");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].need_suid; /* 2 bits */
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 2;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 4;
|
||||
if (++i < NUM_APPLETS)
|
||||
v |= applets[i].need_suid << 6;
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
+ (applets[i].need_suid << 14) /* 2 bits */
|
||||
#endif
|
||||
);
|
||||
}
|
||||
printf("};\n\n");
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
|
||||
|
||||
+2
-24
@@ -5,26 +5,19 @@ export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--scriptwrapper]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
sharedlib_dir="0_lib"
|
||||
|
||||
linkopts=""
|
||||
scriptwrapper="n"
|
||||
binaries="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
case "$2" in
|
||||
--hardlinks) linkopts="-f";;
|
||||
--symlinks) linkopts="-fs";;
|
||||
--binaries) binaries="y";;
|
||||
--scriptwrapper) scriptwrapper="y";swrapall="y";;
|
||||
--sw-sh-hard) scriptwrapper="y";linkopts="-f";;
|
||||
--sw-sh-sym) scriptwrapper="y";linkopts="-fs";;
|
||||
@@ -47,9 +40,8 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
for i in $DO_INSTALL_LIBS; do
|
||||
rm -f "$prefix/$libdir/$i" || exit 1
|
||||
if [ -f "$i" ]; then
|
||||
echo " Installing $i to the target at $prefix/$libdir/"
|
||||
cp -pPR "$i" "$prefix/$libdir/" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/`basename $i`" || exit 1
|
||||
chmod 0644 "$prefix/$libdir/$i" || exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -76,7 +68,6 @@ install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
||||
|
||||
for i in $h; do
|
||||
appdir=`dirname "$i"`
|
||||
app=`basename "$i"`
|
||||
mkdir -p "$prefix/$appdir" || exit 1
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
@@ -87,19 +78,6 @@ for i in $h; do
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ "$binaries" = "y" ]; then
|
||||
# Copy the binary over rather
|
||||
if [ -e $sharedlib_dir/$app ]; then
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR $sharedlib_dir/$app $prefix/$i || exit 1
|
||||
else
|
||||
echo " $prefix/$i already exists"
|
||||
fi
|
||||
else
|
||||
echo "Error: Could not find $sharedlib_dir/$app"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
|
||||
@@ -20,7 +20,6 @@ exec >"$target.$$"
|
||||
|
||||
echo '#define UNPACKED_USAGE "" \'
|
||||
"$loc/usage" | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
@@ -28,13 +27,6 @@ echo '#define UNPACKED_USAGE "" \'
|
||||
-e 's/^/"/' \
|
||||
-e 's/$/" \\/'
|
||||
echo ''
|
||||
# "grep -v '^ '" is for toybox's od bug: od -b prints some extra lines:
|
||||
#0000000 010 000 010 000 133 055 144 146 135 040 133 055 143 040 103 117
|
||||
# 000010 000010 026533 063144 020135 026533 020143 047503
|
||||
#0000020 116 106 104 111 122 135 040 133 055 154 040 114 117 107 106 111
|
||||
# 043116 044504 056522 055440 066055 046040 043517 044506
|
||||
#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 PACKED_USAGE \'
|
||||
## Breaks on big-endian systems!
|
||||
@@ -48,7 +40,6 @@ echo '#define PACKED_USAGE \'
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/$/ \\/'
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -b \
|
||||
| grep -v '^ ' \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ config FEATURE_SEAMLESS_GZ
|
||||
|
||||
config FEATURE_SEAMLESS_Z
|
||||
bool "tar, rpm, modprobe etc understand .Z data"
|
||||
default n # it is ancient
|
||||
default n
|
||||
help
|
||||
Make tar, rpm, modprobe etc understand .Z data.
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
|
||||
libs-y += libarchive/
|
||||
libs-y += libarchive/
|
||||
|
||||
lib-y:=
|
||||
|
||||
|
||||
+13
-3
@@ -22,13 +22,23 @@
|
||||
//config: default n # needs to be improved to be able to replace binutils ar
|
||||
//config: help
|
||||
//config: ar is an archival utility program used to create, modify, and
|
||||
//config: extract contents from archives. In practice, it is used exclusively
|
||||
//config: for object module archives used by compilers.
|
||||
//config: extract contents from archives. An archive is a single file holding
|
||||
//config: a collection of other files in a structure that makes it possible to
|
||||
//config: retrieve the original individual files (called archive members).
|
||||
//config: The original files' contents, mode (permissions), timestamp, owner,
|
||||
//config: and group are preserved in the archive, and can be restored on
|
||||
//config: extraction.
|
||||
//config:
|
||||
//config: The stored filename is limited to 15 characters. (for more information
|
||||
//config: see long filename support).
|
||||
//config: ar has 60 bytes of overheads for every stored file.
|
||||
//config:
|
||||
//config: This implementation of ar can extract archives, it cannot create or
|
||||
//config: modify them.
|
||||
//config: On an x86 system, the ar applet adds about 1K.
|
||||
//config:
|
||||
//config: Unless you have a specific application which requires ar, you should
|
||||
//config: probably say N here: most compilers come with their own ar utility.
|
||||
//config: probably say N here.
|
||||
//config:
|
||||
//config:config FEATURE_AR_LONG_FILENAMES
|
||||
//config: bool "Support for long filenames (not needed for debs)"
|
||||
|
||||
+40
-39
@@ -39,7 +39,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
|
||||
}
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_state_t *xstate),
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
|
||||
char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
|
||||
const char *expected_ext
|
||||
)
|
||||
@@ -48,7 +48,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
IF_DESKTOP(long long) int status = 0;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
transformer_state_t xstate;
|
||||
transformer_aux_data_t aux;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -72,8 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
goto err;
|
||||
} else {
|
||||
/* "clever zcat" with FILE */
|
||||
/* fail_if_not_compressed because zcat refuses uncompressed input */
|
||||
int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
|
||||
int fd = open_zipped(filename);
|
||||
if (fd < 0)
|
||||
goto err_name;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
@@ -81,7 +80,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
} else
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -120,11 +119,9 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
xstate.signature_skipped = 0;
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
xstate.dst_fd = STDOUT_FILENO;
|
||||
status = unpacker(&xstate);
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = 1;
|
||||
status = unpacker(&aux);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
} else {
|
||||
@@ -143,10 +140,10 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
unsigned new_name_len;
|
||||
|
||||
/* TODO: restore other things? */
|
||||
if (xstate.mtime != 0) {
|
||||
if (aux.mtime != 0) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = xstate.mtime;
|
||||
times[1].tv_sec = times[0].tv_sec = aux.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
@@ -220,7 +217,7 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
|
||||
//config:config UNCOMPRESS
|
||||
//config: bool "uncompress"
|
||||
//config: default n # ancient
|
||||
//config: default n
|
||||
//config: help
|
||||
//config: uncompress is used to decompress archives created by compress.
|
||||
//config: Not much used anymore, replaced by gzip/gunzip.
|
||||
@@ -228,13 +225,18 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
|
||||
//applet:IF_UNCOMPRESS(APPLET(uncompress, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//kbuild:lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
#if ENABLE_UNCOMPRESS
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, unpack_Z_stream, make_new_name_generic, "Z");
|
||||
return bbunpack(argv, unpack_uncompress, make_new_name_generic, "Z");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -290,13 +292,6 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//config: gunzip is used to decompress archives created by gzip.
|
||||
//config: You can use the `-t' option to test the integrity of
|
||||
//config: an archive, without decompressing it.
|
||||
//config:
|
||||
//config:config FEATURE_GUNZIP_LONG_OPTIONS
|
||||
//config: bool "Enable long options"
|
||||
//config: default y
|
||||
//config: depends on GUNZIP && LONG_OPTS
|
||||
//config: help
|
||||
//config: Enable use of long options.
|
||||
|
||||
//applet:IF_GUNZIP(APPLET(gunzip, BB_DIR_BIN, BB_SUID_DROP))
|
||||
//applet:IF_GUNZIP(APPLET_ODDNAME(zcat, gunzip, BB_DIR_BIN, BB_SUID_DROP, zcat))
|
||||
@@ -328,17 +323,11 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
static const char gunzip_longopts[] ALIGN1 =
|
||||
"stdout\0" No_argument "c"
|
||||
"to-stdout\0" No_argument "c"
|
||||
"force\0" No_argument "f"
|
||||
"test\0" No_argument "t"
|
||||
"no-name\0" No_argument "n"
|
||||
;
|
||||
#endif
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -355,9 +344,6 @@ static const char gunzip_longopts[] ALIGN1 =
|
||||
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
#if ENABLE_FEATURE_GUNZIP_LONG_OPTIONS
|
||||
applet_long_options = gunzip_longopts;
|
||||
#endif
|
||||
getopt32(argv, "cfvqdtn");
|
||||
argv += optind;
|
||||
|
||||
@@ -368,7 +354,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -408,6 +394,11 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//kbuild:lib-$(CONFIG_BZIP2) += bbunzip.o
|
||||
//kbuild:lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
#if ENABLE_BUNZIP2
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -416,7 +407,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (applet_name[2] == 'c') /* bzcat */
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
return bbunpack(argv, unpack_bunzip2, make_new_name_generic, "bz2");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -502,6 +493,11 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_LZMA(APPLET_ODDNAME(lzma, unlzma, BB_DIR_USR_BIN, BB_SUID_DROP, lzma))
|
||||
//kbuild:lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
#if ENABLE_UNLZMA
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -516,7 +512,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
return bbunpack(argv, unpack_unlzma, make_new_name_generic, "lzma");
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -540,6 +536,11 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
//applet:IF_XZ(APPLET_ODDNAME(xz, unxz, BB_DIR_USR_BIN, BB_SUID_DROP, xz))
|
||||
//kbuild:lib-$(CONFIG_UNXZ) += bbunzip.o
|
||||
#if ENABLE_UNXZ
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
|
||||
{
|
||||
return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
@@ -554,6 +555,6 @@ int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
return bbunpack(argv, unpack_unxz, make_new_name_generic, "xz");
|
||||
}
|
||||
#endif
|
||||
+1
-1
@@ -127,7 +127,7 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
|
||||
+11
-39
@@ -11,7 +11,6 @@
|
||||
* Only supports new ASCII and CRC formats
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
//config:config CPIO
|
||||
@@ -47,7 +46,7 @@
|
||||
//kbuild:lib-$(CONFIG_CPIO) += cpio.o
|
||||
|
||||
//usage:#define cpio_trivial_usage
|
||||
//usage: "[-dmvu] [-F FILE] [-R USER[:GRP]]" IF_FEATURE_CPIO_O(" [-H newc]")
|
||||
//usage: "[-dmvu] [-F FILE]" IF_FEATURE_CPIO_O(" [-H newc]")
|
||||
//usage: " [-ti"IF_FEATURE_CPIO_O("o")"]" IF_FEATURE_CPIO_P(" [-p DIR]")
|
||||
//usage: " [EXTR_FILE]..."
|
||||
//usage:#define cpio_full_usage "\n\n"
|
||||
@@ -66,13 +65,11 @@
|
||||
//usage: IF_FEATURE_CPIO_P(
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: "\n -d Make leading directories"
|
||||
//usage: "\n -m Preserve mtime"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -u Overwrite"
|
||||
//usage: "\n -F FILE Input (-t,-i,-p) or output (-o) file"
|
||||
//usage: "\n -R USER[:GRP] Set owner of created files"
|
||||
//usage: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -H newc Archive format"
|
||||
//usage: )
|
||||
@@ -132,7 +129,7 @@
|
||||
-I FILE File to use instead of standard input
|
||||
-L, --dereference Dereference symbolic links (copy the files
|
||||
that they point to instead of copying the links)
|
||||
-R, --owner=[USER][:.][GRP] Set owner of created files
|
||||
-R, --owner=[USER][:.][GROUP] Set owner of created files
|
||||
|
||||
Options valid in --extract and --pass-through modes:
|
||||
-d, --make-directories Create leading directories where needed
|
||||
@@ -152,8 +149,7 @@ enum {
|
||||
OPT_PRESERVE_MTIME = (1 << 6),
|
||||
OPT_DEREF = (1 << 7),
|
||||
OPT_FILE = (1 << 8),
|
||||
OPT_OWNER = (1 << 9),
|
||||
OPTBIT_OWNER = 9,
|
||||
OPTBIT_FILE = 8,
|
||||
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
|
||||
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
|
||||
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
|
||||
@@ -166,18 +162,7 @@ enum {
|
||||
OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
|
||||
};
|
||||
|
||||
#define OPTION_STR "it0uvdmLF:R:"
|
||||
|
||||
struct globals {
|
||||
struct bb_uidgid_t owner_ugid;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
void BUG_cpio_globals_too_big(void);
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
G.owner_ugid.uid = -1L; \
|
||||
G.owner_ugid.gid = -1L; \
|
||||
} while (0)
|
||||
#define OPTION_STR "it0uvdmLF:"
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
static off_t cpio_pad4(off_t size)
|
||||
@@ -195,6 +180,7 @@ static off_t cpio_pad4(off_t size)
|
||||
* It's ok to exit instead of return. */
|
||||
static NOINLINE int cpio_o(void)
|
||||
{
|
||||
static const char trailer[] ALIGN1 = "TRAILER!!!";
|
||||
struct name_s {
|
||||
struct name_s *next;
|
||||
char name[1];
|
||||
@@ -236,11 +222,6 @@ static NOINLINE int cpio_o(void)
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
|
||||
if (G.owner_ugid.uid != (uid_t)-1L)
|
||||
st.st_uid = G.owner_ugid.uid;
|
||||
if (G.owner_ugid.gid != (gid_t)-1L)
|
||||
st.st_gid = G.owner_ugid.gid;
|
||||
|
||||
if (!(S_ISLNK(st.st_mode) || S_ISREG(st.st_mode)))
|
||||
st.st_size = 0; /* paranoia */
|
||||
|
||||
@@ -275,6 +256,7 @@ static NOINLINE int cpio_o(void)
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
|
||||
} else { /* line == NULL: EOF */
|
||||
next_link:
|
||||
if (links) {
|
||||
@@ -293,7 +275,7 @@ static NOINLINE int cpio_o(void)
|
||||
} else {
|
||||
/* If no (more) hardlinks to output,
|
||||
* output "trailer" entry */
|
||||
name = cpio_TRAILER;
|
||||
name = trailer;
|
||||
/* st.st_size == 0 is a must, but for uniformity
|
||||
* in the output, we zero out everything */
|
||||
memset(&st, 0, sizeof(st));
|
||||
@@ -341,7 +323,7 @@ static NOINLINE int cpio_o(void)
|
||||
}
|
||||
|
||||
if (!line) {
|
||||
if (name != cpio_TRAILER)
|
||||
if (name != trailer)
|
||||
goto next_link;
|
||||
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
|
||||
return EXIT_SUCCESS;
|
||||
@@ -357,7 +339,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename;
|
||||
char *cpio_owner;
|
||||
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
unsigned opt;
|
||||
|
||||
@@ -372,14 +353,12 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
"pass-through\0" No_argument "p"
|
||||
#endif
|
||||
#endif
|
||||
"owner\0" Required_argument "R"
|
||||
"verbose\0" No_argument "v"
|
||||
"quiet\0" No_argument "\xff"
|
||||
"to-stdout\0" No_argument "\xfe"
|
||||
;
|
||||
#endif
|
||||
|
||||
INIT_G();
|
||||
archive_handle = init_handle();
|
||||
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
|
||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||
@@ -390,21 +369,14 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* -L makes sense only with -o or -p */
|
||||
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
opt = getopt32(argv, OPTION_STR, &cpio_filename, &cpio_owner);
|
||||
#else
|
||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"),
|
||||
&cpio_filename, &cpio_owner, &cpio_fmt);
|
||||
#endif
|
||||
opt = getopt32(argv, OPTION_STR, &cpio_filename);
|
||||
argv += optind;
|
||||
if (opt & OPT_OWNER) { /* -R */
|
||||
parse_chown_usergroup_or_die(&G.owner_ugid, cpio_owner);
|
||||
archive_handle->cpio__owner = G.owner_ugid;
|
||||
}
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
if (opt & OPT_FILE) { /* -F */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
|
||||
argv += optind;
|
||||
if ((opt & (OPT_FILE|OPT_CREATE)) == OPT_FILE) { /* -F without -o */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
|
||||
+4
-15
@@ -1151,13 +1151,13 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
|
||||
if (result && number_of_alternatives == 0) {
|
||||
if (root_of_alternatives)
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, which %s",
|
||||
"package %s %sdepends on %s, "
|
||||
"which cannot be satisfied",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[root_of_alternatives->name],
|
||||
"cannot be satisfied");
|
||||
name_hashtable[root_of_alternatives->name]);
|
||||
bb_error_msg_and_die(
|
||||
"package %s %sdepends on %s, which %s",
|
||||
"package %s %sdepends on %s, which %s\n",
|
||||
name_hashtable[package_node->name],
|
||||
package_edge->type == EDGE_PRE_DEPENDS ? "pre-" : "",
|
||||
name_hashtable[package_edge->name],
|
||||
@@ -1472,16 +1472,12 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
@@ -1496,19 +1492,12 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
tar_handle->src_fd = ar_handle->src_fd;
|
||||
|
||||
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
|
||||
@@ -70,8 +70,6 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar");
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
@@ -84,10 +82,6 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_XZ
|
||||
llist_add_to(&ar_archive->accept, (char*)"data.tar.xz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.xz");
|
||||
#endif
|
||||
|
||||
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
|
||||
+25
-113
@@ -62,30 +62,15 @@ aa: 85.1% -- replaced with aa.gz
|
||||
//config: 1: larger buffers, larger hash-tables
|
||||
//config: 2: larger buffers, largest hash-tables
|
||||
//config: Larger models may give slightly better compression
|
||||
//config:
|
||||
//config:config FEATURE_GZIP_LEVELS
|
||||
//config: bool "Enable compression levels"
|
||||
//config: default n
|
||||
//config: depends on GZIP
|
||||
//config: help
|
||||
//config: Enable support for compression levels 4-9. The default level
|
||||
//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.
|
||||
|
||||
//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: "[-cfd] [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: "\n -d Decompress"
|
||||
//usage: )
|
||||
//usage: "\n -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
//usage:
|
||||
@@ -267,8 +252,6 @@ enum {
|
||||
* input file length plus MIN_LOOKAHEAD.
|
||||
*/
|
||||
|
||||
#ifndef ENABLE_FEATURE_GZIP_LEVELS
|
||||
|
||||
max_chain_length = 4096,
|
||||
/* To speed up deflation, hash chains are never searched beyond this length.
|
||||
* A higher limit improves compression ratio but degrades the speed.
|
||||
@@ -300,23 +283,11 @@ enum {
|
||||
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
|
||||
* meaning.
|
||||
*/
|
||||
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
|
||||
};
|
||||
|
||||
|
||||
struct globals {
|
||||
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
unsigned max_chain_length;
|
||||
unsigned max_lazy_match;
|
||||
unsigned good_match;
|
||||
unsigned nice_match;
|
||||
#define max_chain_length (G1.max_chain_length)
|
||||
#define max_lazy_match (G1.max_lazy_match)
|
||||
#define good_match (G1.good_match)
|
||||
#define nice_match (G1.nice_match)
|
||||
#endif
|
||||
|
||||
lng block_start;
|
||||
|
||||
/* window position at the beginning of the current output block. Gets
|
||||
@@ -446,46 +417,19 @@ static void flush_outbuf(void)
|
||||
#define put_8bit(c) \
|
||||
do { \
|
||||
G1.outbuf[G1.outcnt++] = (c); \
|
||||
if (G1.outcnt == OUTBUFSIZ) \
|
||||
flush_outbuf(); \
|
||||
if (G1.outcnt == OUTBUFSIZ) flush_outbuf(); \
|
||||
} while (0)
|
||||
|
||||
/* Output a 16 bit value, lsb first */
|
||||
static void put_16bit(ush w)
|
||||
{
|
||||
/* GCC 4.2.1 won't optimize out redundant loads of G1.outcnt
|
||||
* (probably because of fear of aliasing with G1.outbuf[]
|
||||
* stores), do it explicitly:
|
||||
*/
|
||||
unsigned outcnt = G1.outcnt;
|
||||
uch *dst = &G1.outbuf[outcnt];
|
||||
|
||||
#if BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
ush *dst16 = (void*) dst;
|
||||
*dst16 = w; /* unalinged LSB 16-bit store */
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
if (G1.outcnt < OUTBUFSIZ - 2) {
|
||||
G1.outbuf[G1.outcnt++] = w;
|
||||
G1.outbuf[G1.outcnt++] = w >> 8;
|
||||
} else {
|
||||
put_8bit(w);
|
||||
put_8bit(w >> 8);
|
||||
}
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
#else
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
dst[1] = w;
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Slowpath: we will need to do flush_outbuf() */
|
||||
G1.outcnt = ++outcnt;
|
||||
if (outcnt == OUTBUFSIZ)
|
||||
flush_outbuf();
|
||||
put_8bit(w);
|
||||
}
|
||||
|
||||
static void put_32bit(ulg n)
|
||||
@@ -1374,6 +1318,7 @@ static void build_tree(tree_desc * desc)
|
||||
/* and insert the new node in the heap */
|
||||
G2.heap[SMALLEST] = node++;
|
||||
pqdownheap(tree, SMALLEST);
|
||||
|
||||
} while (G2.heap_len >= 2);
|
||||
|
||||
G2.heap[--G2.heap_max] = G2.heap[SMALLEST];
|
||||
@@ -1721,6 +1666,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 0); /* without header */
|
||||
G2.compressed_len = stored_len << 3;
|
||||
|
||||
} else if (stored_len + 4 <= opt_lenb && buf != NULL) {
|
||||
/* 4: two words for the lengths */
|
||||
/* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
|
||||
@@ -1734,6 +1680,7 @@ static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
G2.compressed_len += (stored_len + 4) << 3;
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 1); /* with header */
|
||||
|
||||
} else if (static_lenb == opt_lenb) {
|
||||
send_bits((STATIC_TREES << 1) + eof, 3);
|
||||
compress_block((ct_data *) G2.static_ltree, (ct_data *) G2.static_dtree);
|
||||
@@ -2060,7 +2007,7 @@ static void ct_init(void)
|
||||
* IN assertions: the input and output buffers are cleared.
|
||||
*/
|
||||
|
||||
static void zip(void)
|
||||
static void zip(ulg time_stamp)
|
||||
{
|
||||
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
|
||||
|
||||
@@ -2071,7 +2018,7 @@ static void zip(void)
|
||||
/* compression method: 8 (DEFLATED) */
|
||||
/* general flags: 0 */
|
||||
put_32bit(0x00088b1f);
|
||||
put_32bit(0); /* Unix timestamp */
|
||||
put_32bit(time_stamp);
|
||||
|
||||
/* Write deflated file to zip file */
|
||||
G1.crc = ~0;
|
||||
@@ -2095,8 +2042,10 @@ static void zip(void)
|
||||
|
||||
/* ======================================================================== */
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
/* Clear input and output buffers */
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
@@ -2128,23 +2077,9 @@ IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED
|
||||
G2.bl_desc.max_length = MAX_BL_BITS;
|
||||
//G2.bl_desc.max_code = 0;
|
||||
|
||||
#if 0
|
||||
/* Saving of timestamp is disabled. Why?
|
||||
* - it is not Y2038-safe.
|
||||
* - some people want deterministic results
|
||||
* (normally they'd use -n, but our -n is a nop).
|
||||
* - it's bloat.
|
||||
* Per RFC 1952, gzfile.time=0 is "no timestamp".
|
||||
* If users will demand this to be reinstated,
|
||||
* implement -n "don't save timestamp".
|
||||
*/
|
||||
struct stat s;
|
||||
s.st_ctime = 0;
|
||||
fstat(STDIN_FILENO, &s);
|
||||
zip(s.st_ctime);
|
||||
#else
|
||||
zip();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2162,7 +2097,6 @@ static const char gzip_longopts[] ALIGN1 =
|
||||
"quiet\0" No_argument "q"
|
||||
"fast\0" No_argument "1"
|
||||
"best\0" No_argument "9"
|
||||
"no-name\0" No_argument "n"
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -2188,45 +2122,24 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
{
|
||||
unsigned opt;
|
||||
#ifdef ENABLE_FEATURE_GZIP_LEVELS
|
||||
static const struct {
|
||||
uint8_t good;
|
||||
uint8_t chain_shift;
|
||||
uint8_t lazy2;
|
||||
uint8_t nice2;
|
||||
} gzip_level_config[6] = {
|
||||
{4, 4, 4/2, 16/2}, /* Level 4 */
|
||||
{8, 5, 16/2, 32/2}, /* Level 5 */
|
||||
{8, 7, 16/2, 128/2}, /* Level 6 */
|
||||
{8, 8, 32/2, 128/2}, /* Level 7 */
|
||||
{32, 10, 128/2, 258/2}, /* Level 8 */
|
||||
{32, 12, 258/2, 258/2}, /* Level 9 */
|
||||
};
|
||||
#endif
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
applet_long_options = gzip_longopts;
|
||||
#endif
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "qn123456789");
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x18) // -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 (opt == 0)
|
||||
opt = 1 << 6; /* default: 6 */
|
||||
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
|
||||
max_chain_length = 1 << gzip_level_config[opt].chain_shift;
|
||||
good_match = gzip_level_config[opt].good;
|
||||
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 &= 0x7; /* ignore -q, -0..9 */
|
||||
//if (opt & 0x1) // -c
|
||||
//if (opt & 0x2) // -f
|
||||
//if (opt & 0x4) // -v
|
||||
argv += optind;
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
@@ -2238,6 +2151,5 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Initialize the CRC32 table */
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, pack_gzip, append_ext, "gz");
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
# Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
|
||||
lib-y:= common.o
|
||||
lib-y:=
|
||||
|
||||
COMMON_FILES:= \
|
||||
\
|
||||
@@ -30,13 +30,11 @@ COMMON_FILES:= \
|
||||
DPKG_FILES:= \
|
||||
unpack_ar_archive.o \
|
||||
filter_accept_list_reassign.o \
|
||||
unsafe_prefix.o \
|
||||
get_header_ar.o \
|
||||
get_header_tar.o \
|
||||
get_header_tar_gz.o \
|
||||
get_header_tar_bz2.o \
|
||||
get_header_tar_lzma.o \
|
||||
get_header_tar_xz.o \
|
||||
|
||||
INSERT
|
||||
|
||||
@@ -45,7 +43,7 @@ lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o
|
||||
lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
@@ -54,7 +52,7 @@ lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.
|
||||
lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_GUNZIP) += 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_UNZIP) += open_transformer.o decompress_gunzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
|
||||
|
||||
|
||||
@@ -385,6 +385,7 @@ void sendMTFValues(EState* s)
|
||||
cost[0] = cost01 & 0xffff; cost[1] = cost01 >> 16;
|
||||
cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16;
|
||||
cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16;
|
||||
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char cpio_TRAILER[] ALIGN1 = "TRAILER!!!";
|
||||
@@ -11,12 +11,6 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
int dst_fd;
|
||||
int res;
|
||||
char *hard_link;
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
char *dst_name;
|
||||
#else
|
||||
# define dst_name (file_header->name)
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_SELINUX
|
||||
char *sctx = archive_handle->tar__sctx[PAX_NEXT_FILE];
|
||||
@@ -29,49 +23,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Hard links are encoded as regular files of size 0
|
||||
* with a nonempty link field */
|
||||
hard_link = NULL;
|
||||
if (S_ISREG(file_header->mode) && file_header->size == 0)
|
||||
hard_link = file_header->link_target;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
dst_name = file_header->name;
|
||||
if (archive_handle->tar__strip_components) {
|
||||
unsigned n = archive_handle->tar__strip_components;
|
||||
do {
|
||||
dst_name = strchr(dst_name, '/');
|
||||
if (!dst_name || dst_name[1] == '\0') {
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
dst_name++;
|
||||
/*
|
||||
* Link target is shortened only for hardlinks:
|
||||
* softlinks restored unchanged.
|
||||
*/
|
||||
if (hard_link) {
|
||||
// GNU tar 1.26 does not check that we reached end of link name:
|
||||
// if "dir/hardlink" is hardlinked to "file",
|
||||
// tar xvf a.tar --strip-components=1 says:
|
||||
// tar: hardlink: Cannot hard link to '': No such file or directory
|
||||
// and continues processing. We silently skip such entries.
|
||||
hard_link = strchr(hard_link, '/');
|
||||
if (!hard_link || hard_link[1] == '\0') {
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
hard_link++;
|
||||
}
|
||||
} while (--n != 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *slash = strrchr(dst_name, '/');
|
||||
char *slash = strrchr(file_header->name, '/');
|
||||
if (slash) {
|
||||
*slash = '\0';
|
||||
bb_make_directory(dst_name, -1, FILEUTILS_RECUR);
|
||||
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
|
||||
*slash = '/';
|
||||
}
|
||||
}
|
||||
@@ -79,7 +35,12 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
|
||||
/* Remove the entry if it exists */
|
||||
if (!S_ISDIR(file_header->mode)) {
|
||||
if (hard_link) {
|
||||
/* Is it hardlink?
|
||||
* We encode hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode)
|
||||
&& file_header->link_target
|
||||
&& file_header->size == 0
|
||||
) {
|
||||
/* Ugly special case:
|
||||
* tar cf t.tar hardlink1 hardlink2 hardlink1
|
||||
* results in this tarball structure:
|
||||
@@ -87,22 +48,22 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
* hardlink2 -> hardlink1
|
||||
* hardlink1 -> hardlink1 <== !!!
|
||||
*/
|
||||
if (strcmp(hard_link, dst_name) == 0)
|
||||
if (strcmp(file_header->link_target, file_header->name) == 0)
|
||||
goto ret;
|
||||
}
|
||||
/* Proceed with deleting */
|
||||
if (unlink(dst_name) == -1
|
||||
if (unlink(file_header->name) == -1
|
||||
&& errno != ENOENT
|
||||
) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
dst_name);
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat existing_sb;
|
||||
if (lstat(dst_name, &existing_sb) == -1) {
|
||||
if (lstat(file_header->name, &existing_sb) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat old file");
|
||||
}
|
||||
@@ -112,25 +73,30 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
&& !S_ISDIR(file_header->mode)
|
||||
) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", dst_name);
|
||||
"same age file exists", file_header->name);
|
||||
}
|
||||
data_skip(archive_handle);
|
||||
goto ret;
|
||||
}
|
||||
else if ((unlink(dst_name) == -1) && (errno != EISDIR)) {
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
dst_name);
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
res = link(hard_link, dst_name);
|
||||
if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
/* Handle hard links separately
|
||||
* We encode hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode)
|
||||
&& file_header->link_target
|
||||
&& file_header->size == 0
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("can't create %slink "
|
||||
"from %s to %s", "hard",
|
||||
dst_name,
|
||||
hard_link);
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
|
||||
goto ret;
|
||||
@@ -140,17 +106,17 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
char *dst_nameN;
|
||||
char *dst_name;
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_nameN = dst_name;
|
||||
dst_name = file_header->name;
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME)
|
||||
/* rpm-style temp file name */
|
||||
dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid());
|
||||
dst_name = xasprintf("%s;%x", dst_name, (int)getpid());
|
||||
#endif
|
||||
dst_fd = xopen3(dst_nameN,
|
||||
dst_fd = xopen3(dst_name,
|
||||
flags,
|
||||
file_header->mode
|
||||
);
|
||||
@@ -158,32 +124,32 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
close(dst_fd);
|
||||
#ifdef ARCHIVE_REPLACE_VIA_RENAME
|
||||
if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) {
|
||||
xrename(dst_nameN, dst_name);
|
||||
free(dst_nameN);
|
||||
xrename(dst_name, file_header->name);
|
||||
free(dst_name);
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(dst_name, file_header->mode);
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", dst_name);
|
||||
bb_perror_msg("can't make dir %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
//TODO: what if file_header->link_target == NULL (say, corrupted tarball?)
|
||||
res = symlink(file_header->link_target, dst_name);
|
||||
if (res != 0
|
||||
res = symlink(file_header->link_target, file_header->name);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't create %slink "
|
||||
"from %s to %s", "sym",
|
||||
dst_name,
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
}
|
||||
break;
|
||||
@@ -191,11 +157,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
case S_IFBLK:
|
||||
case S_IFCHR:
|
||||
case S_IFIFO:
|
||||
res = mknod(dst_name, file_header->mode, file_header->device);
|
||||
res = mknod(file_header->name, file_header->mode, file_header->device);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't create node %s", dst_name);
|
||||
bb_perror_msg("can't create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -220,20 +186,20 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
#endif
|
||||
/* GNU tar 1.15.1 uses chown, not lchown */
|
||||
chown(dst_name, uid, gid);
|
||||
chown(file_header->name, uid, gid);
|
||||
}
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
|
||||
chmod(dst_name, file_header->mode);
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
|
||||
struct timeval t[2];
|
||||
|
||||
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
|
||||
t[1].tv_usec = t[0].tv_usec = 0;
|
||||
utimes(dst_name, t);
|
||||
utimes(file_header->name, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -112,12 +112,13 @@ void FAST_FUNC data_extract_to_command(archive_handle_t *archive_handle)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, p[1], -file_header->size);
|
||||
close(p[1]);
|
||||
|
||||
status = wait_for_exitstatus(pid);
|
||||
if (safe_waitpid(pid, &status, 0) == -1)
|
||||
bb_perror_msg_and_die("waitpid");
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status))
|
||||
bb_error_msg_and_die("'%s' returned status %d",
|
||||
archive_handle->tar__to_command, WEXITSTATUS(status));
|
||||
if (WIFSIGNALED(status))
|
||||
bb_error_msg_and_die("'%s' terminated by signal %d",
|
||||
bb_error_msg_and_die("'%s' terminated on signal %d",
|
||||
archive_handle->tar__to_command, WTERMSIG(status));
|
||||
|
||||
if (!BB_MMU) {
|
||||
|
||||
@@ -731,7 +731,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream(transformer_state_t *xstate)
|
||||
unpack_bz2_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
bunzip_data *bd;
|
||||
@@ -739,14 +739,14 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
int i;
|
||||
unsigned len;
|
||||
|
||||
if (check_signature16(xstate, BZIP2_MAGIC))
|
||||
if (check_signature16(aux, src_fd, BZIP2_MAGIC))
|
||||
return -1;
|
||||
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -756,7 +756,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
i = IOBUF_SIZE - i; /* number of bytes produced */
|
||||
if (i == 0) /* EOF? */
|
||||
break;
|
||||
if (i != transformer_write(xstate, outbuf, i)) {
|
||||
if (i != full_write(dst_fd, outbuf, i)) {
|
||||
bb_error_msg("short write");
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
goto release_mem;
|
||||
}
|
||||
@@ -789,7 +790,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
len = bd->inbufCount - bd->inbufPos;
|
||||
memcpy(outbuf, &bd->inbuf[bd->inbufPos], len);
|
||||
if (len < 2) {
|
||||
if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
if (safe_read(src_fd, outbuf + len, 2 - len) != 2 - len)
|
||||
break;
|
||||
len = 2;
|
||||
}
|
||||
|
||||
@@ -305,11 +305,11 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
unsigned i; /* counter, current code */
|
||||
unsigned j; /* counter */
|
||||
int k; /* number of bits in current code */
|
||||
const unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
unsigned *p; /* pointer into c[], b[], or v[] */
|
||||
huft_t *q; /* points to current table */
|
||||
huft_t r; /* table entry for structure assignment */
|
||||
huft_t *u[BMAX]; /* table stack */
|
||||
unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */
|
||||
unsigned v[N_MAX]; /* values in order of bit length */
|
||||
int ws[BMAX + 1]; /* bits decoded stack */
|
||||
int w; /* bits decoded */
|
||||
unsigned x[BMAX + 1]; /* bit offsets, then code stack */
|
||||
@@ -324,7 +324,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* Generate counts for each bit length */
|
||||
memset(c, 0, sizeof(c));
|
||||
p = b;
|
||||
p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */
|
||||
i = n;
|
||||
do {
|
||||
c[*p]++; /* assume all entries <= BMAX */
|
||||
@@ -364,12 +364,8 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
*xp++ = j;
|
||||
}
|
||||
|
||||
/* Make a table of values in order of bit lengths.
|
||||
* To detect bad input, unused v[i]'s are set to invalid value UINT_MAX.
|
||||
* In particular, last v[i] is never filled and must not be accessed.
|
||||
*/
|
||||
memset(v, 0xff, sizeof(v));
|
||||
p = b;
|
||||
/* Make a table of values in order of bit lengths */
|
||||
p = (unsigned *) b;
|
||||
i = 0;
|
||||
do {
|
||||
j = *p++;
|
||||
@@ -436,9 +432,7 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
|
||||
/* set up table entry in r */
|
||||
r.b = (unsigned char) (k - w);
|
||||
if (/*p >= v + n || -- redundant, caught by the second check: */
|
||||
*p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/
|
||||
) {
|
||||
if (p >= v + n) {
|
||||
r.e = 99; /* out of values--invalid code */
|
||||
} else if (*p < s) {
|
||||
r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */
|
||||
@@ -523,9 +517,8 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
if (e == 99)
|
||||
abort_unzip(PASS_STATE_ONLY);;
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -561,9 +554,8 @@ static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
e = t->e;
|
||||
if (e > 16)
|
||||
do {
|
||||
if (e == 99) {
|
||||
if (e == 99)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bb >>= t->b;
|
||||
k -= t->b;
|
||||
e -= 16;
|
||||
@@ -829,9 +821,8 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
|
||||
b_dynamic >>= 4;
|
||||
k_dynamic -= 4;
|
||||
if (nl > 286 || nd > 30) {
|
||||
if (nl > 286 || nd > 30)
|
||||
abort_unzip(PASS_STATE_ONLY); /* bad lengths */
|
||||
}
|
||||
|
||||
/* read in bit-length-code lengths */
|
||||
for (j = 0; j < nb; j++) {
|
||||
@@ -912,14 +903,12 @@ static int inflate_block(STATE_PARAM smallint *e)
|
||||
bl = lbits;
|
||||
|
||||
i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl);
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
bd = dbits;
|
||||
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd);
|
||||
if (i != 0) {
|
||||
if (i != 0)
|
||||
abort_unzip(PASS_STATE_ONLY);
|
||||
}
|
||||
|
||||
/* set up data for inflate_codes() */
|
||||
inflate_codes_setup(PASS_STATE bl, bd);
|
||||
@@ -982,7 +971,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
|
||||
|
||||
/* Called from unpack_gz_stream() and inflate_unzip() */
|
||||
static IF_DESKTOP(long long) int
|
||||
inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n = 0;
|
||||
ssize_t nwrote;
|
||||
@@ -991,7 +980,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
gunzip_window = xmalloc(GUNZIP_WSIZE);
|
||||
gunzip_outbuf_count = 0;
|
||||
gunzip_bytes_out = 0;
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = in;
|
||||
|
||||
/* (re) initialize state */
|
||||
method = -1;
|
||||
@@ -1007,15 +996,15 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
error_msg = "corrupted data";
|
||||
if (setjmp(error_jmp)) {
|
||||
/* Error from deep inside zip machinery */
|
||||
bb_error_msg(error_msg);
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
int r = inflate_get_next_window(PASS_STATE_ONLY);
|
||||
nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote == (ssize_t)-1) {
|
||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||
if (nwrote != (ssize_t)gunzip_outbuf_count) {
|
||||
bb_perror_msg("write");
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
@@ -1045,22 +1034,22 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
/* For unzip */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
inflate_unzip(transformer_state_t *xstate)
|
||||
inflate_unzip(transformer_aux_data_t *aux, int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
ALLOC_STATE;
|
||||
|
||||
to_read = xstate->bytes_in;
|
||||
to_read = aux->bytes_in;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer_offset = 4;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE in, out);
|
||||
free(bytebuffer);
|
||||
|
||||
xstate->crc32 = gunzip_crc;
|
||||
xstate->bytes_out = gunzip_bytes_out;
|
||||
aux->crc32 = gunzip_crc;
|
||||
aux->bytes_out = gunzip_bytes_out;
|
||||
DEALLOC_STATE;
|
||||
return n;
|
||||
}
|
||||
@@ -1118,7 +1107,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
static int check_header_gzip(STATE_PARAM transformer_aux_data_t *aux)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -1130,8 +1119,9 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
uint8_t os_flags_UNUSED;
|
||||
} PACKED formatted;
|
||||
} header;
|
||||
|
||||
BUILD_BUG_ON(sizeof(header) != 8);
|
||||
struct BUG_header {
|
||||
char BUG_header[sizeof(header) == 8 ? 1 : -1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Rewind bytebuffer. We use the beginning because the header has 8
|
||||
@@ -1179,7 +1169,8 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
}
|
||||
|
||||
xstate->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
if (aux)
|
||||
aux->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
@@ -1191,27 +1182,27 @@ static int check_header_gzip(STATE_PARAM transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(transformer_state_t *xstate)
|
||||
unpack_gz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
uint32_t v32;
|
||||
IF_DESKTOP(long long) int total, n;
|
||||
DECLARE_STATE;
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_Z
|
||||
if (check_signature16(xstate, GZIP_MAGIC))
|
||||
if (check_signature16(aux, src_fd, GZIP_MAGIC))
|
||||
return -1;
|
||||
#else
|
||||
if (!xstate->signature_skipped) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2) {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
return -1;
|
||||
}
|
||||
if (magic2 == COMPRESS_MAGIC) {
|
||||
xstate->signature_skipped = 2;
|
||||
return unpack_Z_stream(xstate);
|
||||
aux->check_signature = 0;
|
||||
return unpack_Z_stream(aux, src_fd, dst_fd);
|
||||
}
|
||||
if (magic2 != GZIP_MAGIC)
|
||||
goto bad_magic;
|
||||
@@ -1224,16 +1215,16 @@ unpack_gz_stream(transformer_state_t *xstate)
|
||||
to_read = -1;
|
||||
// bytebuffer_max = 0x8000;
|
||||
bytebuffer = xmalloc(bytebuffer_max);
|
||||
gunzip_src_fd = xstate->src_fd;
|
||||
gunzip_src_fd = src_fd;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE xstate)) {
|
||||
if (!check_header_gzip(PASS_STATE aux)) {
|
||||
bb_error_msg("corrupted data");
|
||||
total = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
n = inflate_unzip_internal(PASS_STATE xstate);
|
||||
n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);
|
||||
if (n < 0) {
|
||||
total = -1;
|
||||
goto ret;
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
*/
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_Z_stream(transformer_state_t *xstate)
|
||||
unpack_Z_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
IF_DESKTOP(long long) int retval = -1;
|
||||
@@ -102,7 +102,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
if (check_signature16(xstate, COMPRESS_MAGIC))
|
||||
if (check_signature16(aux, src_fd, COMPRESS_MAGIC))
|
||||
return -1;
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
@@ -114,7 +114,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(xstate->src_fd, inbuf, 1) != 1) {
|
||||
if (full_read(src_fd, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
@@ -166,7 +166,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ);
|
||||
rsize = safe_read(src_fd, inbuf + insize, IBUFSIZ);
|
||||
if (rsize < 0)
|
||||
bb_error_msg_and_die(bb_msg_read_error);
|
||||
insize += rsize;
|
||||
@@ -274,7 +274,7 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
@@ -297,10 +297,11 @@ unpack_Z_stream(transformer_state_t *xstate)
|
||||
/* Remember previous code. */
|
||||
oldcode = incode;
|
||||
}
|
||||
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
xtransformer_write(xstate, outbuf, outpos);
|
||||
xwrite(dst_fd, outbuf, outpos);
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ enum {
|
||||
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_lzma_stream(transformer_state_t *xstate)
|
||||
unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
@@ -214,6 +214,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint16_t *p;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
@@ -223,7 +225,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
@@ -237,9 +239,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
/* Example values from linux-3.3.4.tar.lzma:
|
||||
* dict_size: 64M, dst_size: 2^64-1
|
||||
*/
|
||||
header.dict_size = SWAP_LE32(header.dict_size);
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
@@ -248,17 +247,13 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
{
|
||||
int num_probs;
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
}
|
||||
|
||||
rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
@@ -306,7 +301,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
@@ -315,7 +310,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
goto one_byte2;
|
||||
#endif
|
||||
} else {
|
||||
int num_bits;
|
||||
int offset;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
@@ -440,22 +434,19 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
/* FIXME: ...........^^^^^
|
||||
* shouldn't it be "global_pos + buffer_pos < header.dst_size"?
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
IF_NOT_DESKTOP(int total_written = 0; /* success */)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
|
||||
#include "unxz/xz_dec_stream.c"
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_xz_stream(transformer_state_t *xstate)
|
||||
unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
{
|
||||
enum xz_ret xz_result;
|
||||
struct xz_buf iobuf;
|
||||
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
iobuf.out = membuf + BUFSIZ;
|
||||
iobuf.out_size = BUFSIZ;
|
||||
|
||||
if (!xstate || xstate->signature_skipped) {
|
||||
if (!aux || aux->check_signature == 0) {
|
||||
/* Preload XZ file signature */
|
||||
strcpy((char*)membuf, HEADER_MAGIC);
|
||||
iobuf.in_size = HEADER_MAGIC_SIZE;
|
||||
@@ -67,7 +67,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
xz_result = X_OK;
|
||||
while (1) {
|
||||
if (iobuf.in_pos == iobuf.in_size) {
|
||||
int rd = safe_read(xstate->src_fd, membuf, BUFSIZ);
|
||||
int rd = safe_read(src_fd, membuf, BUFSIZ);
|
||||
if (rd < 0) {
|
||||
bb_error_msg(bb_msg_read_error);
|
||||
total = -1;
|
||||
@@ -104,7 +104,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
||||
// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
||||
if (iobuf.out_pos) {
|
||||
xtransformer_write(xstate, iobuf.out, iobuf.out_pos);
|
||||
xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
||||
IF_DESKTOP(total += iobuf.out_pos;)
|
||||
iobuf.out_pos = 0;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,6 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
name_ptr++;
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
if (strcmp(name_ptr, "tar") == 0) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
@@ -50,12 +46,6 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& strcmp(name_ptr, "xz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_xz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -37,7 +37,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
archive_handle->offset += 110;
|
||||
|
||||
if (!is_prefixed_with(&cpio_header[0], "07070")
|
||||
if (strncmp(&cpio_header[0], "07070", 5) != 0
|
||||
|| (cpio_header[5] != '1' && cpio_header[5] != '2')
|
||||
) {
|
||||
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
|
||||
@@ -52,11 +52,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
&major, &minor, &namesize) != 10)
|
||||
bb_error_msg_and_die("damaged cpio file");
|
||||
file_header->mode = mode;
|
||||
/* "cpio -R USER:GRP" support: */
|
||||
if (archive_handle->cpio__owner.uid != (uid_t)-1L)
|
||||
uid = archive_handle->cpio__owner.uid;
|
||||
if (archive_handle->cpio__owner.gid != (gid_t)-1L)
|
||||
gid = archive_handle->cpio__owner.gid;
|
||||
file_header->uid = uid;
|
||||
file_header->gid = gid;
|
||||
file_header->mtime = mtime;
|
||||
@@ -80,7 +75,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
/* Update offset amount and skip padding before file contents */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
if (strcmp(file_header->name, cpio_TRAILER) == 0) {
|
||||
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
|
||||
/* Always round up. ">> 9" divides by 512 */
|
||||
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
|
||||
goto create_hardlinks;
|
||||
|
||||
@@ -17,6 +17,36 @@
|
||||
typedef uint32_t aliased_uint32_t FIX_ALIASING;
|
||||
typedef off_t aliased_off_t FIX_ALIASING;
|
||||
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (strncmp(cp, "/../"+1, 3) == 0) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
@@ -60,21 +90,13 @@ static unsigned long long getOctal(char *str, int len)
|
||||
}
|
||||
#define GET_OCTAL(a) getOctal((a), sizeof(a))
|
||||
|
||||
#define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX)
|
||||
#if !TAR_EXTD
|
||||
#define process_pax_hdr(archive_handle, sz, global) \
|
||||
process_pax_hdr(archive_handle, sz)
|
||||
#endif
|
||||
/* "global" is 0 or 1 */
|
||||
static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
|
||||
{
|
||||
#if !TAR_EXTD
|
||||
unsigned blk_sz = (sz + 511) & (~511);
|
||||
seek_by_read(archive_handle->src_fd, blk_sz);
|
||||
#else
|
||||
unsigned blk_sz = (sz + 511) & (~511);
|
||||
char *buf, *p;
|
||||
unsigned blk_sz;
|
||||
|
||||
blk_sz = (sz + 511) & (~511);
|
||||
p = buf = xmalloc(blk_sz + 1);
|
||||
xread(archive_handle->src_fd, buf, blk_sz);
|
||||
archive_handle->offset += blk_sz;
|
||||
@@ -93,9 +115,7 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
*/
|
||||
p += len;
|
||||
sz -= len;
|
||||
if (
|
||||
/** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */
|
||||
(int)(sz|len) < 0 /* this works */
|
||||
if ((int)sz < 0
|
||||
|| len == 0
|
||||
|| errno != EINVAL
|
||||
|| *end != ' '
|
||||
@@ -112,31 +132,30 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
|
||||
p[-1] = '\0';
|
||||
value = end + 1;
|
||||
|
||||
# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (!global && is_prefixed_with(value, "path=")) {
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {
|
||||
value += sizeof("path=") - 1;
|
||||
free(archive_handle->tar__longname);
|
||||
archive_handle->tar__longname = xstrdup(value);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
# if ENABLE_FEATURE_TAR_SELINUX
|
||||
#if ENABLE_FEATURE_TAR_SELINUX
|
||||
/* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
|
||||
* This is what Red Hat's patched version of tar uses.
|
||||
*/
|
||||
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
|
||||
if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
|
||||
# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
|
||||
if (strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {
|
||||
value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
|
||||
free(archive_handle->tar__sctx[global]);
|
||||
archive_handle->tar__sctx[global] = xstrdup(value);
|
||||
continue;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
free(buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
@@ -211,7 +230,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
if (!is_prefixed_with(tar.magic, "ustar")
|
||||
if (strncmp(tar.magic, "ustar", 5) != 0
|
||||
&& (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
|
||||
) {
|
||||
@@ -222,7 +241,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
* or not first block (false positive, it's not .gz/.bz2!) */
|
||||
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
|
||||
goto err;
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
|
||||
if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0)
|
||||
err:
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
archive_handle->offset = 0;
|
||||
@@ -359,14 +378,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
case '6':
|
||||
file_header->mode |= S_IFIFO;
|
||||
goto size0;
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
/* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */
|
||||
case 'L':
|
||||
/* free: paranoia: tar with several consecutive longnames */
|
||||
free(p_longname);
|
||||
@@ -386,17 +398,18 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
archive_handle->offset += file_header->size;
|
||||
/* return get_header_tar(archive_handle); */
|
||||
goto again;
|
||||
/*
|
||||
* case 'S': // Sparse file
|
||||
* Was seen in the wild. Not supported (yet?).
|
||||
* See https://www.gnu.org/software/tar/manual/html_section/tar_92.html
|
||||
* for the format. (An "Old GNU Format" was seen, not PAX formats).
|
||||
*/
|
||||
// case 'D': /* GNU dump dir */
|
||||
// case 'M': /* Continuation of multi volume archive */
|
||||
// case 'N': /* Old GNU for names > 100 characters */
|
||||
// case 'V': /* Volume header */
|
||||
case 'D': /* GNU dump dir */
|
||||
case 'M': /* Continuation of multi volume archive */
|
||||
case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'S': /* Sparse file */
|
||||
case 'V': /* Volume header */
|
||||
#endif
|
||||
case 'g': /* pax global header */
|
||||
case 'x': { /* pax extended header */
|
||||
if ((uoff_t)file_header->size > 0xfffff) /* paranoia */
|
||||
goto skip_ext_hdr;
|
||||
process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g'));
|
||||
goto again_after_align;
|
||||
}
|
||||
skip_ext_hdr:
|
||||
{
|
||||
@@ -427,7 +440,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* Everything up to and including last ".." component is stripped */
|
||||
overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name));
|
||||
//TODO: do the same for file_header->link_target?
|
||||
|
||||
/* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if it's a directory */
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -11,7 +11,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -14,7 +14,7 @@ char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
char FAST_FUNC get_header_tar_xz(archive_handle_t *archive_handle)
|
||||
{
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
fork_transformer_with_sig(archive_handle->src_fd, unpack_xz_stream, "unxz");
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
/* Can only do one file at a time */
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -71,6 +71,7 @@ typedef struct {
|
||||
uint8_t *out;
|
||||
|
||||
unsigned r1_lit;
|
||||
|
||||
} lzo1x_999_t;
|
||||
|
||||
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
|
||||
|
||||
@@ -6,65 +6,27 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
|
||||
void FAST_FUNC init_transformer_aux_data(transformer_aux_data_t *aux)
|
||||
{
|
||||
memset(xstate, 0, sizeof(*xstate));
|
||||
memset(aux, 0, sizeof(*aux));
|
||||
}
|
||||
|
||||
int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
|
||||
int FAST_FUNC check_signature16(transformer_aux_data_t *aux, int src_fd, unsigned magic16)
|
||||
{
|
||||
if (!xstate->signature_skipped) {
|
||||
if (aux && aux->check_signature) {
|
||||
uint16_t magic2;
|
||||
if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
if (full_read(src_fd, &magic2, 2) != 2 || magic2 != magic16) {
|
||||
bb_error_msg("invalid magic");
|
||||
#if 0 /* possible future extension */
|
||||
if (aux->check_signature > 1)
|
||||
xfunc_die();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
xstate->signature_skipped = 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote;
|
||||
|
||||
if (xstate->mem_output_size_max != 0) {
|
||||
size_t pos = xstate->mem_output_size;
|
||||
size_t size;
|
||||
|
||||
size = (xstate->mem_output_size += bufsize);
|
||||
if (size > xstate->mem_output_size_max) {
|
||||
free(xstate->mem_output_buf);
|
||||
xstate->mem_output_buf = NULL;
|
||||
bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max);
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1);
|
||||
memcpy(xstate->mem_output_buf + pos, buf, bufsize);
|
||||
xstate->mem_output_buf[size] = '\0';
|
||||
nwrote = bufsize;
|
||||
} else {
|
||||
nwrote = full_write(xstate->dst_fd, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
bb_perror_msg("write");
|
||||
nwrote = -1;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
ret:
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize)
|
||||
{
|
||||
ssize_t nwrote = transformer_write(xstate, buf, bufsize);
|
||||
if (nwrote != (ssize_t)bufsize) {
|
||||
xfunc_die();
|
||||
}
|
||||
return nwrote;
|
||||
}
|
||||
|
||||
void check_errors_in_children(int signo)
|
||||
{
|
||||
int status;
|
||||
@@ -98,12 +60,12 @@ void check_errors_in_children(int signo)
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
#if BB_MMU
|
||||
void FAST_FUNC fork_transformer(int fd,
|
||||
int signature_skipped,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
|
||||
void FAST_FUNC open_transformer(int fd,
|
||||
int check_signature,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
||||
)
|
||||
#else
|
||||
void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
void FAST_FUNC open_transformer(int fd, const char *transform_prog)
|
||||
#endif
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
@@ -118,12 +80,10 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
#if BB_MMU
|
||||
{
|
||||
IF_DESKTOP(long long) int r;
|
||||
transformer_state_t xstate;
|
||||
init_transformer_state(&xstate);
|
||||
xstate.signature_skipped = signature_skipped;
|
||||
xstate.src_fd = fd;
|
||||
xstate.dst_fd = fd_pipe.wr;
|
||||
r = transformer(&xstate);
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.check_signature = check_signature;
|
||||
r = transformer(&aux, fd, fd_pipe.wr);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe.wr); /* send EOF */
|
||||
close(fd);
|
||||
@@ -158,18 +118,16 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed)
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
|
||||
{
|
||||
union {
|
||||
uint8_t b[4];
|
||||
uint16_t b16[2];
|
||||
uint32_t b32[1];
|
||||
} magic;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->signature_skipped = 2;
|
||||
int offset = -2;
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
/* .gz and .bz2 both have 2-byte signature, and their
|
||||
* unpack_XXX_stream wants this header skipped. */
|
||||
@@ -177,177 +135,85 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& magic.b16[0] == GZIP_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_gz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_Z
|
||||
&& magic.b16[0] == COMPRESS_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_Z_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";)
|
||||
USE_FOR_MMU(xformer = unpack_gz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "gunzip";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& magic.b16[0] == BZIP2_MAGIC
|
||||
) {
|
||||
xstate->xformer = unpack_bz2_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
|
||||
USE_FOR_MMU(xformer = unpack_bz2_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "bunzip2";)
|
||||
goto found_magic;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_XZ
|
||||
&& magic.b16[0] == XZ_MAGIC1
|
||||
) {
|
||||
xstate->signature_skipped = 6;
|
||||
offset = -6;
|
||||
xread(fd, magic.b32, sizeof(magic.b32[0]));
|
||||
if (magic.b32[0] == XZ_MAGIC2) {
|
||||
xstate->xformer = unpack_xz_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unxz";)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
goto found_magic;
|
||||
}
|
||||
}
|
||||
|
||||
/* No known magic seen */
|
||||
if (fail_if_not_compressed)
|
||||
if (fail_if_not_detected)
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
IF_FEATURE_SEAMLESS_XZ("/xz")
|
||||
" magic");
|
||||
|
||||
/* Some callers expect this function to "consume" fd
|
||||
* even if data is not compressed. In this case,
|
||||
* we return a state with trivial transformer.
|
||||
*/
|
||||
// USE_FOR_MMU(xstate->xformer = copy_stream;)
|
||||
// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
return 1;
|
||||
|
||||
found_magic:
|
||||
return xstate;
|
||||
}
|
||||
|
||||
/* Used by e.g. rpm which gives us a fd without filename,
|
||||
* thus we can't guess the format from filename's extension.
|
||||
*/
|
||||
int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
|
||||
{
|
||||
transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
if (!xstate || !xstate->xformer) {
|
||||
free(xstate);
|
||||
return 1;
|
||||
}
|
||||
|
||||
# if BB_MMU
|
||||
fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
|
||||
open_transformer_with_no_sig(fd, xformer);
|
||||
# else
|
||||
/* NOMMU version of fork_transformer execs
|
||||
/* NOMMU version of open_transformer execs
|
||||
* an external unzipper that wants
|
||||
* file position at the start of the file.
|
||||
*/
|
||||
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
|
||||
* file position at the start of the file */
|
||||
xlseek(fd, offset, SEEK_CUR);
|
||||
open_transformer_with_sig(fd, xformer, xformer_prog);
|
||||
# endif
|
||||
free(xstate);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed)
|
||||
int FAST_FUNC open_zipped(const char *fname)
|
||||
{
|
||||
transformer_state_t *xstate;
|
||||
int fd;
|
||||
|
||||
fd = open(fname, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
return fd;
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";)
|
||||
return xstate;
|
||||
open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
xstate = setup_transformer_on_fd(fd, fail_if_not_compressed);
|
||||
|
||||
return xstate;
|
||||
}
|
||||
|
||||
int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
|
||||
{
|
||||
int fd;
|
||||
transformer_state_t *xstate;
|
||||
|
||||
xstate = open_transformer(fname, fail_if_not_compressed);
|
||||
if (!xstate)
|
||||
return -1;
|
||||
|
||||
fd = xstate->src_fd;
|
||||
# if BB_MMU
|
||||
if (xstate->xformer) {
|
||||
fork_transformer_with_no_sig(fd, xstate->xformer);
|
||||
} else {
|
||||
/* the file is not compressed */
|
||||
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
if ((ENABLE_FEATURE_SEAMLESS_GZ)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
|| (ENABLE_FEATURE_SEAMLESS_XZ)
|
||||
) {
|
||||
setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
|
||||
}
|
||||
# else
|
||||
/* NOMMU can't avoid the seek :( */
|
||||
xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
if (xstate->xformer) {
|
||||
fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
|
||||
} /* else: the file is not compressed */
|
||||
# endif
|
||||
|
||||
free(xstate);
|
||||
return fd;
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
|
||||
void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p)
|
||||
{
|
||||
# if 1
|
||||
transformer_state_t *xstate;
|
||||
char *image;
|
||||
|
||||
xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0);
|
||||
if (!xstate) /* file open error */
|
||||
return NULL;
|
||||
|
||||
image = NULL;
|
||||
if (xstate->xformer) {
|
||||
/* In-memory decompression */
|
||||
xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095);
|
||||
xstate->xformer(xstate);
|
||||
if (xstate->mem_output_buf) {
|
||||
image = xstate->mem_output_buf;
|
||||
if (maxsz_p)
|
||||
*maxsz_p = xstate->mem_output_size;
|
||||
}
|
||||
} else {
|
||||
/* File is not compressed */
|
||||
//FIXME: avoid seek
|
||||
xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
|
||||
xstate->signature_skipped = 0;
|
||||
image = xmalloc_read(xstate->src_fd, maxsz_p);
|
||||
}
|
||||
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(xstate->src_fd);
|
||||
free(xstate);
|
||||
return image;
|
||||
# else
|
||||
/* This version forks a subprocess - much more expensive */
|
||||
int fd;
|
||||
char *image;
|
||||
|
||||
fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
|
||||
fd = open_zipped(fname);
|
||||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
@@ -355,8 +221,6 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
|
||||
if (!image)
|
||||
bb_perror_msg("read error from '%s'", fname);
|
||||
close(fd);
|
||||
return image;
|
||||
# endif
|
||||
}
|
||||
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
return image;
|
||||
}
|
||||
@@ -12,7 +12,7 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
char magic[7];
|
||||
|
||||
xread(ar_archive->src_fd, magic, AR_MAGIC_LEN);
|
||||
if (!is_prefixed_with(magic, AR_MAGIC)) {
|
||||
if (strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {
|
||||
bb_error_msg_and_die("invalid ar magic");
|
||||
}
|
||||
ar_archive->offset += AR_MAGIC_LEN;
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
const char* FAST_FUNC strip_unsafe_prefix(const char *str)
|
||||
{
|
||||
const char *cp = str;
|
||||
while (1) {
|
||||
char *cp2;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (is_prefixed_with(cp, "/../"+1)) {
|
||||
cp += 3;
|
||||
continue;
|
||||
}
|
||||
cp2 = strstr(cp, "/../");
|
||||
if (!cp2)
|
||||
break;
|
||||
cp = cp2 + 4;
|
||||
}
|
||||
if (cp != str) {
|
||||
static smallint warned = 0;
|
||||
if (!warned) {
|
||||
warned = 1;
|
||||
bb_error_msg("removing leading '%.*s' from member names",
|
||||
(int)(cp - str), str);
|
||||
}
|
||||
}
|
||||
return cp;
|
||||
}
|
||||
@@ -995,8 +995,10 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
s->lzma2.need_props = false;
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_PROPERTIES;
|
||||
|
||||
} else if (s->lzma2.need_props) {
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
} else {
|
||||
s->lzma2.next_sequence
|
||||
= SEQ_LZMA_PREPARE;
|
||||
@@ -1078,6 +1080,7 @@ XZ_EXTERN NOINLINE enum xz_ret XZ_FUNC xz_dec_lzma2_run(
|
||||
|
||||
rc_reset(&s->rc);
|
||||
s->lzma2.sequence = SEQ_CONTROL;
|
||||
|
||||
} else if (b->out_pos == b->out_size
|
||||
|| (b->in_pos == b->in_size
|
||||
&& s->temp.size
|
||||
|
||||
@@ -353,6 +353,7 @@ static enum xz_ret XZ_FUNC crc32_validate(struct xz_dec *s, struct xz_buf *b)
|
||||
return XZ_DATA_ERROR;
|
||||
|
||||
s->pos += 8;
|
||||
|
||||
} while (s->pos < 32);
|
||||
|
||||
s->crc32 = 0;
|
||||
@@ -752,6 +753,7 @@ XZ_EXTERN enum xz_ret XZ_FUNC xz_dec_run(struct xz_dec *s, struct xz_buf *b)
|
||||
b->in_pos = in_start;
|
||||
b->out_pos = out_start;
|
||||
}
|
||||
|
||||
} else if (ret == XZ_OK && in_start == b->in_pos
|
||||
&& out_start == b->out_pos) {
|
||||
if (s->allow_buf_error)
|
||||
|
||||
+12
-11
@@ -71,7 +71,6 @@
|
||||
//usage: "\n -F Don't store or verify checksum"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
#include "liblzo_interface.h"
|
||||
|
||||
@@ -444,8 +443,8 @@ struct globals {
|
||||
chksum_t chksum_in;
|
||||
chksum_t chksum_out;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
//#define G (*ptr_to_globals)
|
||||
//#define INIT_G() do {
|
||||
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
@@ -641,7 +640,7 @@ static int lzo_get_method(header_t *h)
|
||||
/**********************************************************************/
|
||||
// compress a file
|
||||
/**********************************************************************/
|
||||
static NOINLINE int lzo_compress(const header_t *h)
|
||||
static NOINLINE smallint lzo_compress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r = 0; /* LZO_E_OK */
|
||||
@@ -651,6 +650,7 @@ static NOINLINE int lzo_compress(const header_t *h)
|
||||
uint32_t d_adler32 = ADLER32_INIT_VALUE;
|
||||
uint32_t d_crc32 = CRC32_INIT_VALUE;
|
||||
int l;
|
||||
smallint ok = 1;
|
||||
uint8_t *wrk_mem = NULL;
|
||||
|
||||
if (h->method == M_LZO1X_1)
|
||||
@@ -732,7 +732,7 @@ static NOINLINE int lzo_compress(const header_t *h)
|
||||
free(wrk_mem);
|
||||
free(b1);
|
||||
free(b2);
|
||||
return 1;
|
||||
return ok;
|
||||
}
|
||||
|
||||
static FAST_FUNC void lzo_check(
|
||||
@@ -753,7 +753,7 @@ static FAST_FUNC void lzo_check(
|
||||
/**********************************************************************/
|
||||
// decompress a file
|
||||
/**********************************************************************/
|
||||
static NOINLINE int lzo_decompress(const header_t *h)
|
||||
static NOINLINE smallint lzo_decompress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r;
|
||||
@@ -761,6 +761,7 @@ static NOINLINE int lzo_decompress(const header_t *h)
|
||||
uint32_t c_adler32 = ADLER32_INIT_VALUE;
|
||||
uint32_t d_adler32 = ADLER32_INIT_VALUE;
|
||||
uint32_t c_crc32 = CRC32_INIT_VALUE, d_crc32 = CRC32_INIT_VALUE;
|
||||
smallint ok = 1;
|
||||
uint8_t *b1;
|
||||
uint32_t mcs_block_size = MAX_COMPRESSED_SIZE(block_size);
|
||||
uint8_t *b2 = NULL;
|
||||
@@ -864,7 +865,7 @@ static NOINLINE int lzo_decompress(const header_t *h)
|
||||
}
|
||||
|
||||
free(b2);
|
||||
return 1;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -896,7 +897,7 @@ static NOINLINE int lzo_decompress(const header_t *h)
|
||||
* chksum_out
|
||||
* The rest is identical.
|
||||
*/
|
||||
static const unsigned char lzop_magic[9] ALIGN1 = {
|
||||
static const unsigned char lzop_magic[9] = {
|
||||
0x89, 0x4c, 0x5a, 0x4f, 0x00, 0x0d, 0x0a, 0x1a, 0x0a
|
||||
};
|
||||
|
||||
@@ -1049,7 +1050,7 @@ static void lzo_set_method(header_t *h)
|
||||
h->level = level;
|
||||
}
|
||||
|
||||
static int do_lzo_compress(void)
|
||||
static smallint do_lzo_compress(void)
|
||||
{
|
||||
header_t header;
|
||||
|
||||
@@ -1077,7 +1078,7 @@ static int do_lzo_compress(void)
|
||||
/**********************************************************************/
|
||||
// decompress
|
||||
/**********************************************************************/
|
||||
static int do_lzo_decompress(void)
|
||||
static smallint do_lzo_decompress(void)
|
||||
{
|
||||
header_t header;
|
||||
|
||||
@@ -1098,7 +1099,7 @@ static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_e
|
||||
return xasprintf("%s.lzo", filename);
|
||||
}
|
||||
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate UNUSED_PARAM)
|
||||
static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_aux_data_t *aux UNUSED_PARAM)
|
||||
{
|
||||
if (option_mask32 & OPT_DECOMPRESS)
|
||||
return do_lzo_decompress();
|
||||
|
||||
+3
-4
@@ -29,7 +29,6 @@
|
||||
//usage: "\n -qpc List config files"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
#include "rpm.h"
|
||||
|
||||
@@ -94,8 +93,8 @@ struct globals {
|
||||
rpm_index **mytags;
|
||||
int tagcount;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
|
||||
static void extract_cpio(int fd, const char *source_rpm)
|
||||
{
|
||||
@@ -123,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1);
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
/* This works, but doesn't report uncompress errors (they happen in child) */
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
|
||||
setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1);
|
||||
if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
|
||||
|
||||
+60
-114
@@ -146,23 +146,25 @@
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "bb_archive.h"
|
||||
/* FIXME: Stop using this non-standard feature */
|
||||
#ifndef FNM_LEADING_DIR
|
||||
# define FNM_LEADING_DIR 0
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
# define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
|
||||
#else
|
||||
# define DBG(...) ((void)0)
|
||||
#endif
|
||||
#define DBG_OPTION_PARSING 0
|
||||
|
||||
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
|
||||
#define DBG(...) ((void)0)
|
||||
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
|
||||
|
||||
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
@@ -619,12 +621,21 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
# endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
# define WAIT_FOR_CHILD 0
|
||||
@@ -638,6 +649,11 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
# endif
|
||||
|
||||
gzipPid = xvfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
@@ -653,7 +669,7 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(gzip, gzip, "-f", (char *)0);
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0);
|
||||
vfork_exec_errno = errno;
|
||||
_exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -676,21 +692,16 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", gzip);
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
}
|
||||
}
|
||||
#endif /* SEAMLESS_COMPRESSION */
|
||||
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
|
||||
|
||||
#if !SEAMLESS_COMPRESSION
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#endif
|
||||
/* gcc 4.2.1 inlines it, making code bigger */
|
||||
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, const char *gzip)
|
||||
const llist_t *exclude, int gzip)
|
||||
{
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
@@ -703,7 +714,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
* can avoid including the tarball into itself.... */
|
||||
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
#endif
|
||||
@@ -738,7 +749,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
#if SEAMLESS_COMPRESSION
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip) {
|
||||
int status;
|
||||
if (safe_waitpid(-1, &status, 0) == -1)
|
||||
@@ -750,9 +761,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
#endif
|
||||
return errorFlag;
|
||||
}
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
# define writeTarFile(...) 0
|
||||
#endif
|
||||
#else
|
||||
int writeTarFile(int tar_fd, int verboseFlag,
|
||||
int recurseFlags, const llist_t *include,
|
||||
const llist_t *exclude, int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -860,7 +873,6 @@ enum {
|
||||
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
OPTBIT_STRIP_COMPONENTS,
|
||||
OPTBIT_NORECURSION,
|
||||
IF_FEATURE_TAR_TO_COMMAND(OPTBIT_2COMMAND ,)
|
||||
OPTBIT_NUMERIC_OWNER,
|
||||
@@ -885,13 +897,12 @@ enum {
|
||||
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
|
||||
OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
|
||||
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
|
||||
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
|
||||
OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
|
||||
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
|
||||
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
|
||||
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
|
||||
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
|
||||
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
|
||||
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
|
||||
OPT_NORECURSION = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NORECURSION )) + 0, // no-recursion
|
||||
OPT_2COMMAND = IF_FEATURE_TAR_TO_COMMAND( (1 << OPTBIT_2COMMAND )) + 0, // to-command
|
||||
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
|
||||
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
|
||||
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
|
||||
|
||||
OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
|
||||
};
|
||||
@@ -935,7 +946,6 @@ static const char tar_longopts[] ALIGN1 =
|
||||
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
|
||||
"touch\0" No_argument "m"
|
||||
# endif
|
||||
"strip-components\0" Required_argument "\xf9"
|
||||
"no-recursion\0" No_argument "\xfa"
|
||||
# if ENABLE_FEATURE_TAR_TO_COMMAND
|
||||
"to-command\0" Required_argument "\xfb"
|
||||
@@ -965,7 +975,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
llist_t *excludes = NULL;
|
||||
#endif
|
||||
INIT_G();
|
||||
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
@@ -982,28 +991,15 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
"tt:vv:" // count -t,-v
|
||||
IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
"\xff::" // --exclude=PATTERN is a list
|
||||
"\xff::" // cumulative lists for --exclude
|
||||
#endif
|
||||
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
|
||||
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
|
||||
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
":\xf9+" // --strip-components=NUM
|
||||
#endif
|
||||
;
|
||||
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
applet_long_options = tar_longopts;
|
||||
#endif
|
||||
#if ENABLE_DESKTOP
|
||||
/* Lie to buildroot when it starts asking stupid questions. */
|
||||
if (argv[1] && strcmp(argv[1], "--version") == 0) {
|
||||
// Output of 'tar --version' examples:
|
||||
// tar (GNU tar) 1.15.1
|
||||
// tar (GNU tar) 1.25
|
||||
// bsdtar 2.8.3 - libarchive 2.8.3
|
||||
puts("tar (busybox) " BB_VER);
|
||||
return 0;
|
||||
}
|
||||
if (argv[1] && argv[1][0] != '-') {
|
||||
/* Compat:
|
||||
* 1st argument without dash handles options with parameters
|
||||
@@ -1040,14 +1036,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_FEATURE_SEAMLESS_XZ( "J" )
|
||||
IF_FEATURE_SEAMLESS_Z( "Z" )
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
|
||||
IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
, &tar_handle->tar__strip_components // --strip-components
|
||||
#endif
|
||||
IF_FEATURE_TAR_TO_COMMAND(, &(tar_handle->tar__to_command)) // --to-command
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
, &excludes // --exclude
|
||||
@@ -1055,49 +1047,11 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
);
|
||||
#if DBG_OPTION_PARSING
|
||||
bb_error_msg("opt: 0x%08x", opt);
|
||||
# define showopt(o) bb_error_msg("opt & %s(%x): %x", #o, o, opt & o);
|
||||
showopt(OPT_TEST );
|
||||
showopt(OPT_EXTRACT );
|
||||
showopt(OPT_BASEDIR );
|
||||
showopt(OPT_TARNAME );
|
||||
showopt(OPT_2STDOUT );
|
||||
showopt(OPT_NOPRESERVE_OWNER);
|
||||
showopt(OPT_P );
|
||||
showopt(OPT_VERBOSE );
|
||||
showopt(OPT_KEEP_OLD );
|
||||
showopt(OPT_CREATE );
|
||||
showopt(OPT_DEREFERENCE );
|
||||
showopt(OPT_BZIP2 );
|
||||
showopt(OPT_LZMA );
|
||||
showopt(OPT_INCLUDE_FROM );
|
||||
showopt(OPT_EXCLUDE_FROM );
|
||||
showopt(OPT_GZIP );
|
||||
showopt(OPT_XZ );
|
||||
showopt(OPT_COMPRESS );
|
||||
showopt(OPT_NOPRESERVE_TIME );
|
||||
showopt(OPT_STRIP_COMPONENTS);
|
||||
showopt(OPT_NORECURSION );
|
||||
showopt(OPT_2COMMAND );
|
||||
showopt(OPT_NUMERIC_OWNER );
|
||||
showopt(OPT_NOPRESERVE_PERM );
|
||||
showopt(OPT_OVERWRITE );
|
||||
showopt(OPT_ANY_COMPRESS );
|
||||
bb_error_msg("base_dir:'%s'", base_dir);
|
||||
bb_error_msg("tar_filename:'%s'", tar_filename);
|
||||
bb_error_msg("verboseFlag:%d", verboseFlag);
|
||||
bb_error_msg("tar_handle->tar__to_command:'%s'", tar_handle->tar__to_command);
|
||||
bb_error_msg("tar_handle->tar__strip_components:%u", tar_handle->tar__strip_components);
|
||||
return 0;
|
||||
# undef showopt
|
||||
#endif
|
||||
//bb_error_msg("opt:%08x", opt);
|
||||
argv += optind;
|
||||
|
||||
if (verboseFlag)
|
||||
tar_handle->action_header = header_verbose_list;
|
||||
if (verboseFlag == 1)
|
||||
tar_handle->action_header = header_list;
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
if (verboseFlag == 1) tar_handle->action_header = header_list;
|
||||
|
||||
if (opt & OPT_EXTRACT)
|
||||
tar_handle->action_data = data_extract_all;
|
||||
@@ -1183,7 +1137,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
tar_handle->src_fd = open_zipped(tar_filename);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
@@ -1195,26 +1149,19 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
//if (SEAMLESS_COMPRESSION || OPT_COMPRESS)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
# if SEAMLESS_COMPRESSION
|
||||
const char *zipMode = NULL;
|
||||
if (opt & OPT_COMPRESS)
|
||||
zipMode = "compress";
|
||||
if (opt & OPT_GZIP)
|
||||
zipMode = "gzip";
|
||||
if (opt & OPT_BZIP2)
|
||||
zipMode = "bzip2";
|
||||
if (opt & OPT_LZMA)
|
||||
zipMode = "lzma";
|
||||
if (opt & OPT_XZ)
|
||||
zipMode = "xz";
|
||||
# endif
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
|
||||
zipMode = 2;
|
||||
#endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag,
|
||||
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
|
||||
@@ -1222,10 +1169,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (opt & OPT_ANY_COMPRESS) {
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
|
||||
USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);)
|
||||
USE_FOR_NOMMU(const char *xformer_prog;)
|
||||
|
||||
if (opt & OPT_COMPRESS)
|
||||
@@ -1244,7 +1190,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
USE_FOR_MMU(xformer = unpack_xz_stream;)
|
||||
USE_FOR_NOMMU(xformer_prog = "unxz";)
|
||||
|
||||
fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
|
||||
/* Can't lseek over pipes */
|
||||
tar_handle->seek = seek_by_read;
|
||||
/*tar_handle->offset = 0; - already is */
|
||||
|
||||
+61
-128
@@ -45,12 +45,6 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#else
|
||||
# define dbg(...) ((void)0)
|
||||
#endif
|
||||
|
||||
enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
@@ -199,17 +193,15 @@ static uint32_t find_cdf_offset(void)
|
||||
unsigned char *p;
|
||||
off_t end;
|
||||
unsigned char *buf = xzalloc(PEEK_FROM_END);
|
||||
uint32_t found;
|
||||
|
||||
end = xlseek(zip_fd, 0, SEEK_END);
|
||||
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);
|
||||
full_read(zip_fd, buf, PEEK_FROM_END);
|
||||
|
||||
found = BAD_CDF_OFFSET;
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
p = buf;
|
||||
while (p <= buf + PEEK_FROM_END - CDE_HEADER_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
@@ -228,25 +220,14 @@ static uint32_t find_cdf_offset(void)
|
||||
/*
|
||||
* I've seen .ZIP files with seemingly valid CDEs
|
||||
* where cdf_offset points past EOF - ??
|
||||
* This check ignores such CDEs:
|
||||
* Ignore such CDEs:
|
||||
*/
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf)) {
|
||||
found = cde_header.formatted.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)));
|
||||
/*
|
||||
* We do not "break" here because only the last CDE is valid.
|
||||
* I've seen a .zip archive which contained a .zip file,
|
||||
* uncompressed, and taking the first CDE was using
|
||||
* the CDE inside that file!
|
||||
*/
|
||||
}
|
||||
if (cde_header.formatted.cdf_offset < end + (p - buf))
|
||||
break;
|
||||
cde_header.formatted.cdf_offset = BAD_CDF_OFFSET;
|
||||
}
|
||||
free(buf);
|
||||
dbg("Found cdf_offset:0x%x", (unsigned)found);
|
||||
return found;
|
||||
return cde_header.formatted.cdf_offset;
|
||||
};
|
||||
|
||||
static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
@@ -259,22 +240,15 @@ static uint32_t read_next_cdf(uint32_t cdf_offset, cdf_header_t *cdf_ptr)
|
||||
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("Returning file position to 0x%"OFF_FMT"x", org);
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cdf_offset;
|
||||
};
|
||||
@@ -306,19 +280,17 @@ static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
} else {
|
||||
/* 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)
|
||||
transformer_aux_data_t aux;
|
||||
init_transformer_aux_data(&aux);
|
||||
aux.bytes_in = zip_header->formatted.cmpsize;
|
||||
if (inflate_unzip(&aux, zip_fd, dst_fd) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (xstate.crc32 ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (aux.crc32 ^ 0xffffffffL)) {
|
||||
bb_error_msg_and_die("crc error");
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != xstate.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != aux.bytes_out) {
|
||||
/* Don't die. Who knows, maybe len calculation
|
||||
* was botched somewhere. After all, crc matched! */
|
||||
bb_error_msg("bad length");
|
||||
@@ -487,7 +459,7 @@ int unzip_main(int argc, char **argv)
|
||||
if (overwrite == O_PROMPT)
|
||||
overwrite = O_NEVER;
|
||||
} else {
|
||||
static const char extn[][5] ALIGN1 = { ".zip", ".ZIP" };
|
||||
static const char extn[][5] = { ".zip", ".ZIP" };
|
||||
char *ext = src_fn + strlen(src_fn);
|
||||
int src_fd;
|
||||
|
||||
@@ -514,11 +486,11 @@ int unzip_main(int argc, char **argv)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing) {
|
||||
puts(verbose ?
|
||||
" Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
"-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
" Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
"-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
:
|
||||
" Length Date Time Name\n"
|
||||
"--------- ---------- ----- ----"
|
||||
" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -558,14 +530,11 @@ int unzip_main(int argc, char **argv)
|
||||
/* 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");
|
||||
if (magic == 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;
|
||||
@@ -573,7 +542,6 @@ int unzip_main(int argc, char **argv)
|
||||
#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);
|
||||
@@ -617,11 +585,6 @@ int unzip_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
}
|
||||
#endif
|
||||
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
|
||||
);
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
@@ -631,72 +594,52 @@ int unzip_main(int argc, char **argv)
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
|
||||
/* Guard against "/abspath", "/../" and similar attacks */
|
||||
overlapping_strcpy(dst_fn, strip_unsafe_prefix(dst_fn));
|
||||
|
||||
/* Filter zip entries */
|
||||
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
|
||||
);
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// "--------- ---------- ----- ----"
|
||||
printf( "%9u " "%s " "%s\n",
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
dtbuf,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
} 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",
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %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,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
zip_header.formatted.crc32,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
}
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) {
|
||||
/* Extracting to STDOUT */
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
} else if (last_char_is(dst_fn, '/')) {
|
||||
/* Extract directory */
|
||||
} 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);
|
||||
@@ -710,26 +653,22 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
} else {
|
||||
if (!S_ISDIR(stat_buf.st_mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
dst_fn, "directory");
|
||||
bb_error_msg_and_die("'%s' exists but is not directory", dst_fn);
|
||||
}
|
||||
}
|
||||
i = 'n';
|
||||
} else {
|
||||
/* Extract file */
|
||||
|
||||
} else { /* Extract file */
|
||||
check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
/* File does not exist */
|
||||
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 */
|
||||
} else { /* File already exists */
|
||||
if (overwrite == O_NEVER) {
|
||||
i = 'n';
|
||||
} else if (S_ISREG(stat_buf.st_mode)) {
|
||||
/* File is regular file */
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == O_ALWAYS) {
|
||||
i = 'y';
|
||||
} else {
|
||||
@@ -737,10 +676,8 @@ int unzip_main(int argc, char **argv)
|
||||
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");
|
||||
} else { /* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not regular file", dst_fn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -793,25 +730,21 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
if (listing && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// "--------- ---------- ----- ----"
|
||||
printf( " --------%21s" "-------\n"
|
||||
"%9lu%21s" "%u files\n",
|
||||
"",
|
||||
total_usize, "", total_entries);
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( " -------- -------\n"
|
||||
"%9lu" " %u files\n",
|
||||
total_usize, total_entries);
|
||||
} else {
|
||||
unsigned long percents = total_usize - total_size;
|
||||
if ((long)percents < 0)
|
||||
percents = 0; /* happens if usize < size */
|
||||
percents = percents * 100;
|
||||
if (total_usize)
|
||||
percents /= total_usize;
|
||||
// " Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ---- ---------- ----- -------- ----"
|
||||
printf( "-------- ------- ----%28s" "----\n"
|
||||
"%8lu" "%17lu%4u%%%28s" "%u files\n",
|
||||
"",
|
||||
total_usize, total_size, (unsigned)percents, "",
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "-------- ------- --- -------\n"
|
||||
"%8lu" "%17lu%4u%% %u files\n",
|
||||
total_usize, total_size, (unsigned)percents,
|
||||
total_entries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_HALT=y
|
||||
# CONFIG_FEATURE_CALL_TELINIT is not set
|
||||
CONFIG_TELINIT_PATH=""
|
||||
|
||||
@@ -395,7 +395,7 @@ CONFIG_FEATURE_KILL_DELAY=0
|
||||
# CONFIG_FEATURE_INIT_SYSLOG is not set
|
||||
# CONFIG_FEATURE_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
# CONFIG_FEATURE_INITRD is not set
|
||||
# CONFIG_HALT is not set
|
||||
# CONFIG_FEATURE_CALL_TELINIT is not set
|
||||
CONFIG_TELINIT_PATH=""
|
||||
|
||||
@@ -407,7 +407,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_HALT=y
|
||||
# CONFIG_FEATURE_CALL_TELINIT is not set
|
||||
CONFIG_TELINIT_PATH=""
|
||||
|
||||
@@ -89,6 +89,7 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
# CONFIG_FEATURE_SYSTEMD is not set
|
||||
# CONFIG_FEATURE_RTMINMAX is not set
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
@@ -425,7 +426,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
CONFIG_MESG=y
|
||||
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -107,6 +107,7 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
# CONFIG_FEATURE_SYSTEMD is not set
|
||||
# CONFIG_FEATURE_RTMINMAX is not set
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
@@ -448,7 +449,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
CONFIG_MESG=y
|
||||
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
|
||||
+73
-115
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.24.0.git
|
||||
# Fri Sep 18 20:39:29 2015
|
||||
# Busybox version: 1.21.0.git
|
||||
# Mon May 28 21:51:18 2012
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -36,15 +36,12 @@ CONFIG_LAST_SUPPORTED_WCHAR=0
|
||||
# CONFIG_UNICODE_BIDI_SUPPORT is not set
|
||||
# CONFIG_UNICODE_NEUTRAL_TABLE is not set
|
||||
# CONFIG_UNICODE_PRESERVE_BROKEN is not set
|
||||
# CONFIG_PAM is not set
|
||||
CONFIG_FEATURE_USE_SENDFILE=y
|
||||
CONFIG_LONG_OPTS=y
|
||||
# CONFIG_FEATURE_DEVPTS is not set
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
# CONFIG_FEATURE_UTMP is not set
|
||||
# CONFIG_FEATURE_WTMP is not set
|
||||
# CONFIG_FEATURE_PIDFILE is not set
|
||||
CONFIG_PID_FILE_PATH=""
|
||||
# CONFIG_FEATURE_SUID is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
@@ -66,7 +63,7 @@ CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_LFS is not set
|
||||
CONFIG_CROSS_COMPILER_PREFIX="arm-linux-androideabi-"
|
||||
CONFIG_SYSROOT="/opt/android-ndk/platforms/android-9/arch-arm"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers -fuse-ld=bfd"
|
||||
CONFIG_EXTRA_CFLAGS="-DANDROID -D__ANDROID__ -DSK_RELEASE -nostdlib -march=armv7-a -msoft-float -mfloat-abi=softfp -mfpu=neon -mthumb -mthumb-interwork -fpic -fno-short-enums -fgcse-after-reload -frename-registers"
|
||||
CONFIG_EXTRA_LDFLAGS="-Xlinker -z -Xlinker muldefs -nostdlib -Bdynamic -Xlinker -dynamic-linker -Xlinker /system/bin/linker -Xlinker -z -Xlinker nocopyreloc -Xlinker --no-undefined ${SYSROOT}/usr/lib/crtbegin_dynamic.o ${SYSROOT}/usr/lib/crtend_android.o"
|
||||
CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
|
||||
@@ -75,7 +72,6 @@ CONFIG_EXTRA_LDLIBS="dl m c gcc"
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
# CONFIG_DEBUG_PESSIMIZE is not set
|
||||
# CONFIG_UNIT_TEST is not set
|
||||
# CONFIG_WERROR is not set
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
@@ -96,10 +92,10 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
# CONFIG_FEATURE_SYSTEMD is not set
|
||||
# CONFIG_FEATURE_RTMINMAX is not set
|
||||
CONFIG_PASSWORD_MINLEN=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
|
||||
@@ -137,14 +133,7 @@ CONFIG_FEATURE_SEAMLESS_Z=y
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_FEATURE_AR_CREATE=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
@@ -152,14 +141,14 @@ CONFIG_FEATURE_CPIO_P=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_GZIP=y
|
||||
# CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
|
||||
CONFIG_GZIP_FAST=0
|
||||
# CONFIG_FEATURE_GZIP_LEVELS is not set
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
CONFIG_FEATURE_TAR_AUTODETECT=y
|
||||
@@ -172,6 +161,12 @@ CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
# CONFIG_FEATURE_TAR_SELINUX is not set
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_LZMA=y
|
||||
CONFIG_UNXZ=y
|
||||
CONFIG_XZ=y
|
||||
CONFIG_UNZIP=y
|
||||
|
||||
#
|
||||
@@ -183,27 +178,16 @@ CONFIG_CAT=y
|
||||
# CONFIG_FEATURE_DATE_ISOFMT is not set
|
||||
# CONFIG_FEATURE_DATE_NANO is not set
|
||||
# CONFIG_FEATURE_DATE_COMPAT is not set
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_FEATURE_DD_STATUS=y
|
||||
# CONFIG_HOSTID is not set
|
||||
# CONFIG_ID is not set
|
||||
# CONFIG_GROUPS is not set
|
||||
CONFIG_SHUF=y
|
||||
CONFIG_SYNC=y
|
||||
# CONFIG_FEATURE_SYNC_FANCY is not set
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
# CONFIG_FEATURE_TOUCH_NODEREF is not set
|
||||
CONFIG_FEATURE_TOUCH_SUSV3=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUNCATE=y
|
||||
CONFIG_UNLINK=y
|
||||
CONFIG_BASE64=y
|
||||
# CONFIG_WHO is not set
|
||||
# CONFIG_USERS is not set
|
||||
@@ -219,6 +203,10 @@ CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
# CONFIG_FEATURE_CP_LONG_OPTIONS is not set
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
# CONFIG_DF is not set
|
||||
# CONFIG_FEATURE_DF_FANCY is not set
|
||||
CONFIG_DIRNAME=y
|
||||
@@ -275,7 +263,6 @@ CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SHA3SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_FEATURE_FLOAT_SLEEP=y
|
||||
@@ -287,6 +274,7 @@ CONFIG_FEATURE_SPLIT_FANCY=y
|
||||
# CONFIG_FEATURE_STAT_FORMAT is not set
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
@@ -295,7 +283,6 @@ CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
|
||||
CONFIG_TRUE=y
|
||||
# CONFIG_TTY is not set
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNAME_OSNAME="GNU/Linux"
|
||||
CONFIG_UNEXPAND=y
|
||||
# CONFIG_FEATURE_UNEXPAND_LONG_OPTIONS is not set
|
||||
CONFIG_UNIQ=y
|
||||
@@ -307,11 +294,6 @@ CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_YES=y
|
||||
|
||||
#
|
||||
# Common options
|
||||
#
|
||||
CONFIG_FEATURE_VERBOSE=y
|
||||
|
||||
#
|
||||
# Common options for cp and mv
|
||||
#
|
||||
@@ -328,7 +310,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -374,16 +356,7 @@ CONFIG_WHICH=y
|
||||
#
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_FEATURE_AWK_GNU_EXTENSIONS=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_MAX_LEN=4096
|
||||
CONFIG_FEATURE_VI_8BIT=y
|
||||
@@ -398,9 +371,14 @@ CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_ASK_TERMINAL=y
|
||||
CONFIG_FEATURE_VI_UNDO=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE=y
|
||||
CONFIG_FEATURE_VI_UNDO_QUEUE_MAX=256
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
# CONFIG_FEATURE_DIFF_LONG_OPTIONS is not set
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
@@ -417,7 +395,6 @@ CONFIG_FEATURE_FIND_MAXDEPTH=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
CONFIG_FEATURE_FIND_EXEC_PLUS=y
|
||||
CONFIG_FEATURE_FIND_USER=y
|
||||
CONFIG_FEATURE_FIND_GROUP=y
|
||||
CONFIG_FEATURE_FIND_NOT=y
|
||||
@@ -439,7 +416,6 @@ CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_REPL_STR=y
|
||||
|
||||
#
|
||||
# Init Utilities
|
||||
@@ -458,7 +434,7 @@ CONFIG_FEATURE_INIT_SCTTY=y
|
||||
CONFIG_FEATURE_INIT_SYSLOG=y
|
||||
CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_LINUXRC=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_INIT_TERMINAL_TYPE="linux"
|
||||
CONFIG_MESG=y
|
||||
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
@@ -471,12 +447,11 @@ CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
# CONFIG_FEATURE_SHADOWPASSWDS is not set
|
||||
# CONFIG_USE_BB_PWD_GRP is not set
|
||||
# CONFIG_USE_BB_SHADOW is not set
|
||||
CONFIG_USE_BB_CRYPT=y
|
||||
CONFIG_USE_BB_CRYPT_SHA=y
|
||||
# CONFIG_USE_BB_CRYPT is not set
|
||||
# CONFIG_USE_BB_CRYPT_SHA is not set
|
||||
# CONFIG_ADDUSER is not set
|
||||
# CONFIG_FEATURE_ADDUSER_LONG_OPTIONS is not set
|
||||
# CONFIG_FEATURE_CHECK_NAMES is not set
|
||||
CONFIG_LAST_ID=0
|
||||
CONFIG_FIRST_SYSTEM_ID=0
|
||||
CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_ADDGROUP is not set
|
||||
@@ -488,6 +463,7 @@ CONFIG_LAST_SYSTEM_ID=0
|
||||
# CONFIG_GETTY is not set
|
||||
# CONFIG_LOGIN is not set
|
||||
# CONFIG_LOGIN_SESSION_AS_CHILD is not set
|
||||
# CONFIG_PAM is not set
|
||||
# CONFIG_LOGIN_SCRIPTS is not set
|
||||
# CONFIG_FEATURE_NOLOGIN is not set
|
||||
# CONFIG_FEATURE_SECURETTY is not set
|
||||
@@ -545,26 +521,13 @@ CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
|
||||
# Linux System Utilities
|
||||
#
|
||||
CONFIG_BLOCKDEV=y
|
||||
CONFIG_FATATTR=y
|
||||
CONFIG_FSTRIM=y
|
||||
# CONFIG_MDEV is not set
|
||||
# CONFIG_FEATURE_MDEV_CONF is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME is not set
|
||||
# CONFIG_FEATURE_MDEV_RENAME_REGEXP is not set
|
||||
# CONFIG_FEATURE_MDEV_EXEC is not set
|
||||
# CONFIG_FEATURE_MDEV_LOAD_FIRMWARE is not set
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_FEATURE_MOUNT_OTHERTAB is not set
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_REV=y
|
||||
CONFIG_UEVENT=y
|
||||
# CONFIG_ACPID is not set
|
||||
# CONFIG_FEATURE_ACPID_COMPAT is not set
|
||||
CONFIG_BLKID=y
|
||||
@@ -610,6 +573,15 @@ CONFIG_LSUSB=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_UUID=y
|
||||
CONFIG_MORE=y
|
||||
# CONFIG_MOUNT is not set
|
||||
# CONFIG_FEATURE_MOUNT_FAKE is not set
|
||||
# CONFIG_FEATURE_MOUNT_VERBOSE is not set
|
||||
# CONFIG_FEATURE_MOUNT_HELPERS is not set
|
||||
# CONFIG_FEATURE_MOUNT_LABEL is not set
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_CIFS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FLAGS is not set
|
||||
# CONFIG_FEATURE_MOUNT_FSTAB is not set
|
||||
# CONFIG_PIVOT_ROOT is not set
|
||||
# CONFIG_RDATE is not set
|
||||
CONFIG_RDEV=y
|
||||
@@ -619,7 +591,6 @@ CONFIG_SCRIPT=y
|
||||
CONFIG_SCRIPTREPLAY=y
|
||||
# CONFIG_SETARCH is not set
|
||||
# CONFIG_SWAPONOFF is not set
|
||||
# CONFIG_FEATURE_SWAPON_DISCARD is not set
|
||||
# CONFIG_FEATURE_SWAPON_PRI is not set
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
# CONFIG_UMOUNT is not set
|
||||
@@ -632,45 +603,32 @@ CONFIG_VOLUMEID=y
|
||||
#
|
||||
# Filesystem/Volume identification
|
||||
#
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXFAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_F2FS=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ISO9660=y
|
||||
CONFIG_FEATURE_VOLUMEID_JFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NILFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SQUASHFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_XFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_NTFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ISO9660=y
|
||||
CONFIG_FEATURE_VOLUMEID_UDF=y
|
||||
CONFIG_FEATURE_VOLUMEID_LUKS=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXSWAP=y
|
||||
CONFIG_FEATURE_VOLUMEID_CRAMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_ROMFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_SYSV=y
|
||||
CONFIG_FEATURE_VOLUMEID_OCFS2=y
|
||||
CONFIG_FEATURE_VOLUMEID_LINUXRAID=y
|
||||
|
||||
#
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
# CONFIG_CONSPY is not set
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_I2CGET=y
|
||||
CONFIG_I2CSET=y
|
||||
CONFIG_I2CDUMP=y
|
||||
CONFIG_I2CDETECT=y
|
||||
CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
CONFIG_FEATURE_LESS_BRACKETS=y
|
||||
CONFIG_FEATURE_LESS_FLAGS=y
|
||||
CONFIG_FEATURE_LESS_TRUNCATE=y
|
||||
CONFIG_FEATURE_LESS_MARKS=y
|
||||
CONFIG_FEATURE_LESS_REGEXP=y
|
||||
CONFIG_FEATURE_LESS_WINCH=y
|
||||
@@ -679,17 +637,13 @@ CONFIG_FEATURE_LESS_DASHCMD=y
|
||||
CONFIG_FEATURE_LESS_LINENUMS=y
|
||||
# CONFIG_NANDWRITE is not set
|
||||
CONFIG_NANDDUMP=y
|
||||
# CONFIG_RFKILL is not set
|
||||
CONFIG_SETSERIAL=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
# CONFIG_UBIATTACH is not set
|
||||
# CONFIG_UBIDETACH is not set
|
||||
# CONFIG_UBIMKVOL is not set
|
||||
# CONFIG_UBIRMVOL is not set
|
||||
# CONFIG_UBIRSVOL is not set
|
||||
# CONFIG_UBIUPDATEVOL is not set
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_ADJTIMEX is not set
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_FEATURE_COMPRESS_BBCONFIG=y
|
||||
@@ -705,6 +659,10 @@ CONFIG_FEATURE_CHAT_SEND_ESCAPES=y
|
||||
CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
CONFIG_FEATURE_DC_LIBM=y
|
||||
@@ -742,14 +700,18 @@ CONFIG_MAN=y
|
||||
# CONFIG_MT is not set
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
# CONFIG_READAHEAD is not set
|
||||
# CONFIG_RFKILL is not set
|
||||
# CONFIG_RUNLEVEL is not set
|
||||
CONFIG_RX=y
|
||||
CONFIG_SETSID=y
|
||||
CONFIG_STRINGS=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
# CONFIG_WALL is not set
|
||||
# CONFIG_WATCHDOG is not set
|
||||
|
||||
#
|
||||
@@ -781,13 +743,13 @@ CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FEATURE_FTP_AUTHENTICATION=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
# CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS is not set
|
||||
# CONFIG_HOSTNAME is not set
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
@@ -844,7 +806,6 @@ CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
# CONFIG_NSLOOKUP is not set
|
||||
# CONFIG_NTPD is not set
|
||||
# CONFIG_FEATURE_NTPD_SERVER is not set
|
||||
# CONFIG_FEATURE_NTPD_CONF is not set
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
# CONFIG_SLATTACH is not set
|
||||
@@ -882,7 +843,6 @@ CONFIG_FEATURE_TUNCTL_UG=y
|
||||
CONFIG_DHCPD_LEASES_FILE=""
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
CONFIG_FEATURE_UDHCP_RFC3397=y
|
||||
@@ -929,13 +889,6 @@ CONFIG_POWERTOP=y
|
||||
CONFIG_PSTREE=y
|
||||
CONFIG_PWDX=y
|
||||
CONFIG_SMEMCAP=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_UPTIME=y
|
||||
# CONFIG_FEATURE_UPTIME_UTMP_SUPPORT is not set
|
||||
CONFIG_FREE=y
|
||||
@@ -956,6 +909,13 @@ CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
|
||||
# CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS is not set
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
@@ -1001,7 +961,6 @@ CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
# CONFIG_ASH_BUILTIN_TEST is not set
|
||||
# CONFIG_ASH_HELP is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
@@ -1051,7 +1010,6 @@ CONFIG_FEATURE_SYSLOGD_READ_BUFFER_SIZE=0
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=0
|
||||
# CONFIG_LOGREAD is not set
|
||||
# CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING is not set
|
||||
# CONFIG_FEATURE_KMSG_SYSLOG is not set
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_FEATURE_KLOGD_KLOGCTL=y
|
||||
# CONFIG_LOGGER is not set
|
||||
@@ -89,6 +89,7 @@ CONFIG_PREFIX="./_install"
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
# CONFIG_FEATURE_SYSTEMD is not set
|
||||
CONFIG_FEATURE_RTMINMAX=y
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SMALL=1
|
||||
@@ -425,7 +426,7 @@ CONFIG_FEATURE_KILL_DELAY=0
|
||||
# CONFIG_FEATURE_INIT_SYSLOG is not set
|
||||
# CONFIG_FEATURE_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
# CONFIG_FEATURE_INITRD is not set
|
||||
CONFIG_INIT_TERMINAL_TYPE=""
|
||||
CONFIG_MESG=y
|
||||
CONFIG_FEATURE_MESG_ENABLE_ONLY_GROUP=y
|
||||
|
||||
@@ -422,7 +422,7 @@ CONFIG_FEATURE_KILL_DELAY=0
|
||||
# CONFIG_FEATURE_INIT_SYSLOG is not set
|
||||
# CONFIG_FEATURE_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_LINUXRC is not set
|
||||
# CONFIG_FEATURE_INITRD is not set
|
||||
CONFIG_INIT_TERMINAL_TYPE=""
|
||||
# CONFIG_MESG is not set
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
//usage: "$ dumpkmap > keymap\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
@@ -38,7 +37,6 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
#define flags bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
|
||||
/* When user accidentally runs "dumpkmap FILE"
|
||||
* instead of "dumpkmap >FILE", we'd dump binary stuff to tty.
|
||||
|
||||
@@ -10,9 +10,8 @@
|
||||
//usage:#define loadkmap_trivial_usage
|
||||
//usage: "< keymap"
|
||||
//usage:#define loadkmap_full_usage "\n\n"
|
||||
//usage: "Load a binary keyboard translation table from stdin"
|
||||
////usage: "\n"
|
||||
////usage: "\n -C TTY Affect TTY instead of /dev/tty"
|
||||
//usage: "Load a binary keyboard translation table from stdin\n"
|
||||
/* //usage: "\n -C TTY Affect TTY instead of /dev/tty" */
|
||||
//usage:
|
||||
//usage:#define loadkmap_example_usage
|
||||
//usage: "$ loadkmap < /etc/i18n/lang-keymap\n"
|
||||
@@ -57,7 +56,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
if (!is_prefixed_with(flags, BINARY_KEYMAP_MAGIC))
|
||||
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
|
||||
bb_error_msg_and_die("not a valid binary keymap");
|
||||
|
||||
xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
|
||||
|
||||
@@ -14,12 +14,10 @@
|
||||
//usage: "Resize the screen"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
#define ESC "\033"
|
||||
|
||||
#define old_termios_p ((struct termios*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define old_termios_p ((struct termios*)&bb_common_bufsiz1)
|
||||
|
||||
static void
|
||||
onintr(int sig UNUSED_PARAM)
|
||||
@@ -35,8 +33,6 @@ int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
struct winsize w = { 0, 0, 0, 0 };
|
||||
int ret;
|
||||
|
||||
INIT_G();
|
||||
|
||||
/* We use _stderr_ in order to make resize usable
|
||||
* in shell backticks (those redirect stdout away from tty).
|
||||
* NB: other versions of resize open "/dev/tty"
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
*/
|
||||
|
||||
//usage:#define setlogcons_trivial_usage
|
||||
//usage: "[N]"
|
||||
//usage: "N"
|
||||
//usage:#define setlogcons_full_usage "\n\n"
|
||||
//usage: "Redirect the kernel output to console N. Default:0 (current console)"
|
||||
//usage: "Redirect the kernel output to console N (0 for current)"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (04 /*CTRL-D*/ == c)
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
// we assume a PC keyboard
|
||||
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
|
||||
|
||||
+62
-21
@@ -11,7 +11,7 @@ config CAL
|
||||
bool "cal"
|
||||
default y
|
||||
help
|
||||
cal is used to display a monthly calendar.
|
||||
cal is used to display a monthly calender.
|
||||
|
||||
config CATV
|
||||
bool "catv"
|
||||
@@ -87,6 +87,44 @@ config CUT
|
||||
cut is used to print selected parts of lines from
|
||||
each file to stdout.
|
||||
|
||||
config DD
|
||||
bool "dd"
|
||||
default y
|
||||
help
|
||||
dd copies a file (from standard input to standard output,
|
||||
by default) using specific input and output blocksizes,
|
||||
while optionally performing conversions on it.
|
||||
|
||||
config FEATURE_DD_SIGNAL_HANDLING
|
||||
bool "Enable DD signal handling for status reporting"
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null&
|
||||
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in
|
||||
10899206+0 records out
|
||||
|
||||
config FEATURE_DD_THIRD_STATUS_LINE
|
||||
bool "Enable the third status line upon signal"
|
||||
default y
|
||||
depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
help
|
||||
Displays a coreutils-like third status line with transferred bytes,
|
||||
elapsed time and speed.
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
Enables support for writing a certain number of bytes in and out,
|
||||
at a time, and performing conversions on the data stream.
|
||||
|
||||
config DF
|
||||
bool "df"
|
||||
default y
|
||||
@@ -543,6 +581,22 @@ config FEATURE_SPLIT_FANCY
|
||||
Supports additional suffixes 'b' for 512 bytes,
|
||||
'g' for 1GiB for the -b option.
|
||||
|
||||
config STAT
|
||||
bool "stat"
|
||||
default y
|
||||
select PLATFORM_LINUX # statfs()
|
||||
help
|
||||
display file or filesystem status.
|
||||
|
||||
config FEATURE_STAT_FORMAT
|
||||
bool "Enable custom formats (-c)"
|
||||
default y
|
||||
depends on STAT
|
||||
help
|
||||
Without this, stat will not support the '-c format' option where
|
||||
users can pass a custom format string for output. This adds about
|
||||
7k to a nonstatic build on amd64.
|
||||
|
||||
config STTY
|
||||
bool "stty"
|
||||
default y
|
||||
@@ -555,6 +609,12 @@ config SUM
|
||||
help
|
||||
checksum and count the blocks in a file
|
||||
|
||||
config SYNC
|
||||
bool "sync"
|
||||
default y
|
||||
help
|
||||
sync is used to flush filesystem buffers.
|
||||
|
||||
config TAC
|
||||
bool "tac"
|
||||
default y
|
||||
@@ -573,13 +633,12 @@ config FEATURE_FANCY_TAIL
|
||||
default y
|
||||
depends on TAIL
|
||||
help
|
||||
The options (-q, -s, -v and -F) are provided by GNU tail, but
|
||||
The options (-q, -s, and -v) are provided by GNU tail, but
|
||||
are not specific in the SUSv3 standard.
|
||||
|
||||
-q Never output headers giving file names
|
||||
-s SEC Wait SEC seconds between reads with -f
|
||||
-v Always output headers giving file names
|
||||
-F Same as -f, but keep retrying
|
||||
|
||||
config TEE
|
||||
bool "tee"
|
||||
@@ -614,14 +673,6 @@ config UNAME
|
||||
help
|
||||
uname is used to print system information.
|
||||
|
||||
config UNAME_OSNAME
|
||||
string "Operating system name"
|
||||
default "GNU/Linux"
|
||||
depends on UNAME
|
||||
help
|
||||
Sets the operating system name reported by uname -o. The
|
||||
default is "GNU/Linux".
|
||||
|
||||
config UNEXPAND
|
||||
bool "unexpand"
|
||||
default y
|
||||
@@ -687,16 +738,6 @@ config YES
|
||||
yes is used to repeatedly output a specific string, or
|
||||
the default string `y'.
|
||||
|
||||
comment "Common options"
|
||||
|
||||
config FEATURE_VERBOSE
|
||||
bool "Support verbose options (usually -v) for various applets"
|
||||
default y
|
||||
help
|
||||
Enable cp -v, rm -v and similar messages.
|
||||
Also enables long option (--verbose) if it exists.
|
||||
Without this option, -v is accepted but ignored.
|
||||
|
||||
comment "Common options for cp and mv"
|
||||
depends on CP || MV
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ lib-$(CONFIG_SORT) += sort.o
|
||||
lib-$(CONFIG_STAT) += stat.o
|
||||
lib-$(CONFIG_STTY) += stty.o
|
||||
lib-$(CONFIG_SUM) += sum.o
|
||||
lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAC) += tac.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
//usage:#define basename_trivial_usage
|
||||
//usage: "FILE [SUFFIX]"
|
||||
//usage:#define basename_full_usage "\n\n"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE"
|
||||
//usage: "Strip directory path and .SUFFIX from FILE\n"
|
||||
//usage:
|
||||
//usage:#define basename_example_usage
|
||||
//usage: "$ basename /usr/local/bin/foo\n"
|
||||
|
||||
+9
-14
@@ -19,17 +19,6 @@
|
||||
//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)
|
||||
@@ -37,6 +26,14 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
unsigned opts;
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
typedef char BUG_const_mismatch[
|
||||
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
|
||||
? 1 : -1
|
||||
];
|
||||
|
||||
opts = getopt32(argv, "etv");
|
||||
argv += optind;
|
||||
#if 0 /* These consts match, we can just pass "opts" to visible() */
|
||||
@@ -49,9 +46,6 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* 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) {
|
||||
@@ -61,6 +55,7 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
|
||||
for (;;) {
|
||||
int i, res;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
res = read(fd, read_buf, COMMON_BUFSIZE);
|
||||
if (res < 0)
|
||||
retval = EXIT_FAILURE;
|
||||
|
||||
+2
-2
@@ -69,9 +69,9 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
|
||||
if (S_ISLNK(statbuf->st_mode))
|
||||
return TRUE;
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
newmode = bb_parse_mode((char *)param, statbuf->st_mode);
|
||||
if (newmode == (mode_t)-1)
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
bb_error_msg_and_die("invalid mode '%s'", (char *)param);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
|
||||
+7
-3
@@ -11,15 +11,15 @@
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
//usage:#define chown_trivial_usage
|
||||
//usage: "[-Rh"IF_DESKTOP("LHPcvf")"]... USER[:[GRP]] FILE..."
|
||||
//usage: "[-RhLHP"IF_DESKTOP("cvf")"]... OWNER[<.|:>[GROUP]] FILE..."
|
||||
//usage:#define chown_full_usage "\n\n"
|
||||
//usage: "Change the owner and/or group of each FILE to USER and/or GRP\n"
|
||||
//usage: "Change the owner and/or group of each FILE to OWNER and/or GROUP\n"
|
||||
//usage: "\n -R Recurse"
|
||||
//usage: "\n -h Affect symlinks instead of symlink targets"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -L Traverse all symlinks to directories"
|
||||
//usage: "\n -H Traverse symlinks on command line only"
|
||||
//usage: "\n -P Don't traverse symlinks (default)"
|
||||
//usage: IF_DESKTOP(
|
||||
//usage: "\n -c List changed files"
|
||||
//usage: "\n -v List all files"
|
||||
//usage: "\n -f Hide errors"
|
||||
@@ -112,6 +112,10 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
int opt, flags;
|
||||
struct param_t param;
|
||||
|
||||
/* Just -1 might not work: uid_t may be unsigned long */
|
||||
param.ugid.uid = -1L;
|
||||
param.ugid.gid = -1L;
|
||||
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
applet_long_options = chown_longopts;
|
||||
#endif
|
||||
|
||||
+1
-3
@@ -13,7 +13,6 @@
|
||||
//usage: "Calculate the CRC32 checksums of FILES"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
@@ -33,7 +32,6 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
argv++;
|
||||
#endif
|
||||
|
||||
setup_common_bufsiz();
|
||||
do {
|
||||
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
|
||||
|
||||
@@ -45,7 +43,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
length = 0;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
|
||||
while ((bytes_read = safe_read(fd, read_buf, sizeof(read_buf))) > 0) {
|
||||
length += bytes_read;
|
||||
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
|
||||
}
|
||||
|
||||
+13
-18
@@ -31,7 +31,6 @@
|
||||
//usage: "\n -f Overwrite"
|
||||
//usage: "\n -i Prompt before overwrite"
|
||||
//usage: "\n -l,-s Create (sym)links"
|
||||
//usage: "\n -u Copy only newer files"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
@@ -50,10 +49,12 @@ int cp_main(int argc, char **argv)
|
||||
int flags;
|
||||
int status;
|
||||
enum {
|
||||
FILEUTILS_CP_OPTNUM = sizeof(FILEUTILS_CP_OPTSTR)-1,
|
||||
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
|
||||
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
|
||||
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
|
||||
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
|
||||
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
|
||||
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -75,12 +76,11 @@ int cp_main(int argc, char **argv)
|
||||
"recursive\0" No_argument "R"
|
||||
"symbolic-link\0" No_argument "s"
|
||||
"verbose\0" No_argument "v"
|
||||
"update\0" No_argument "u"
|
||||
"remove-destination\0" No_argument "\xff"
|
||||
"parents\0" No_argument "\xfe"
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR);
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
* -f, --force
|
||||
@@ -95,11 +95,6 @@ int cp_main(int argc, char **argv)
|
||||
* -d same as --no-dereference --preserve=links
|
||||
* -p same as --preserve=mode,ownership,timestamps
|
||||
* -c same as --preserve=context
|
||||
* -u, --update
|
||||
* copy only when the SOURCE file is newer than the destination
|
||||
* file or when the destination file is missing
|
||||
* --remove-destination
|
||||
* remove each existing destination file before attempting to open
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* NOT SUPPORTED IN BBOX:
|
||||
@@ -112,6 +107,8 @@ int cp_main(int argc, char **argv)
|
||||
* preserve attributes (default: mode,ownership,timestamps),
|
||||
* if possible additional attributes: security context,links,all
|
||||
* --no-preserve=ATTR_LIST
|
||||
* --remove-destination
|
||||
* remove each existing destination file before attempting to open
|
||||
* --sparse=WHEN
|
||||
* control creation of sparse files
|
||||
* --strip-trailing-slashes
|
||||
@@ -122,6 +119,9 @@ int cp_main(int argc, char **argv)
|
||||
* copy all SOURCE arguments into DIRECTORY
|
||||
* -T, --no-target-directory
|
||||
* treat DEST as a normal file
|
||||
* -u, --update
|
||||
* copy only when the SOURCE file is newer than the destination
|
||||
* file or when the destination file is missing
|
||||
* -x, --one-file-system
|
||||
* stay on this file system
|
||||
* -Z, --context=CONTEXT
|
||||
@@ -157,16 +157,11 @@ int cp_main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
//bb_error_msg("flags:%x FILEUTILS_RMDEST:%x OPT_parents:%x",
|
||||
// flags, FILEUTILS_RMDEST, OPT_parents);
|
||||
if (flags & OPT_parents) {
|
||||
if (!(d_flags & 2)) {
|
||||
bb_error_msg_and_die("with --parents, the destination must be a directory");
|
||||
}
|
||||
}
|
||||
if (flags & FILEUTILS_RMDEST) {
|
||||
flags |= FILEUTILS_FORCE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ...if neither is a directory... */
|
||||
|
||||
+2
-4
@@ -138,7 +138,6 @@
|
||||
//usage: "Wed Apr 12 18:52:41 MDT 2000\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#if ENABLE_FEATURE_DATE_NANO
|
||||
# include <sys/syscall.h>
|
||||
#endif
|
||||
@@ -369,17 +368,16 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
#define date_buf bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
if (*fmt_dt2str == '\0') {
|
||||
/* With no format string, just print a blank line */
|
||||
date_buf[0] = '\0';
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
if (is_prefixed_with(fmt_dt2str, "%f")) {
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
/* Generate output string */
|
||||
strftime(date_buf, COMMON_BUFSIZE, fmt_dt2str, &tm_time);
|
||||
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
|
||||
}
|
||||
puts(date_buf);
|
||||
|
||||
|
||||
+71
-157
@@ -8,54 +8,9 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config DD
|
||||
//config: bool "dd"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dd copies a file (from standard input to standard output,
|
||||
//config: by default) using specific input and output blocksizes,
|
||||
//config: while optionally performing conversions on it.
|
||||
//config:
|
||||
//config:config FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: bool "Enable signal handling for status reporting"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
//config: print to standard error the number of records read and written
|
||||
//config: so far, then to resume copying.
|
||||
//config:
|
||||
//config: $ dd if=/dev/zero of=/dev/null &
|
||||
//config: $ pid=$!; kill -USR1 $pid; sleep 1; kill $pid
|
||||
//config: 10899206+0 records in
|
||||
//config: 10899206+0 records out
|
||||
//config:
|
||||
//config:config FEATURE_DD_THIRD_STATUS_LINE
|
||||
//config: bool "Enable the third status line upon signal"
|
||||
//config: default y
|
||||
//config: depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
//config: help
|
||||
//config: Displays a coreutils-like third status line with transferred bytes,
|
||||
//config: elapsed time and speed.
|
||||
//config:
|
||||
//config:config FEATURE_DD_IBS_OBS
|
||||
//config: bool "Enable ibs, obs and conv options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for writing a certain number of bytes in and out,
|
||||
//config: at a time, and performing conversions on the data stream.
|
||||
//config:
|
||||
//config:config FEATURE_DD_STATUS
|
||||
//config: bool "Enable status display options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
//config: Enables support for status=noxfer/none option.
|
||||
|
||||
//usage:#define dd_trivial_usage
|
||||
//usage: "[if=FILE] [of=FILE] " IF_FEATURE_DD_IBS_OBS("[ibs=N] [obs=N] ") "[bs=N] [count=N] [skip=N]\n"
|
||||
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync] [iflag=skip_bytes]")
|
||||
//usage: " [seek=N]" IF_FEATURE_DD_IBS_OBS(" [conv=notrunc|noerror|sync|fsync]")
|
||||
//usage:#define dd_full_usage "\n\n"
|
||||
//usage: "Copy a file with converting and formatting\n"
|
||||
//usage: "\n if=FILE Read from FILE instead of stdin"
|
||||
@@ -76,14 +31,9 @@
|
||||
//usage: "\n conv=sync Pad blocks with zeros"
|
||||
//usage: "\n conv=fsync Physically write data out before finishing"
|
||||
//usage: "\n conv=swab Swap every pair of bytes"
|
||||
//usage: "\n iflag=skip_bytes skip=N is in bytes"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_DD_STATUS(
|
||||
//usage: "\n status=noxfer Suppress rate output"
|
||||
//usage: "\n status=none Suppress all output"
|
||||
//usage: )
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kB (1000), k (1024), MB, M, GB, G"
|
||||
//usage: "\nN may be suffixed by c (1), w (2), b (512), kD (1000), k (1024), MD, M, GD, G"
|
||||
//usage:
|
||||
//usage:#define dd_example_usage
|
||||
//usage: "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n"
|
||||
@@ -91,7 +41,6 @@
|
||||
//usage: "4+0 records out\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
@@ -101,40 +50,33 @@ enum {
|
||||
ofd = STDOUT_FILENO,
|
||||
};
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
{ "b", 512 },
|
||||
{ "kD", 1000 },
|
||||
{ "k", 1024 },
|
||||
{ "K", 1024 }, /* compat with coreutils dd */
|
||||
{ "MD", 1000000 },
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
unsigned long long total_bytes;
|
||||
unsigned long long begin_time_us;
|
||||
#endif
|
||||
int flags;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
} while (0)
|
||||
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
/* start of input flags */
|
||||
FLAG_IFLAG_SHIFT = 5,
|
||||
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* 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,
|
||||
};
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
{
|
||||
@@ -151,13 +93,6 @@ static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
G.out_full, G.out_part);
|
||||
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
# if ENABLE_FEATURE_DD_STATUS
|
||||
if (G.flags & FLAG_STATUS_NOXFER) /* status=noxfer active? */
|
||||
return;
|
||||
//TODO: should status=none make dd stop reacting to USR1 entirely?
|
||||
//So far we react to it (we print the stats),
|
||||
//status=none only suppresses final, non-USR1 generated status message.
|
||||
# endif
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
@@ -210,51 +145,30 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
# define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static int parse_comma_flags(char *val, const char *words, const char *error_in)
|
||||
{
|
||||
int flags = 0;
|
||||
while (1) {
|
||||
int n;
|
||||
char *arg;
|
||||
/* find ',', replace them with NUL so we can use val for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on val being non-null, else strchr would fault.
|
||||
*/
|
||||
arg = strchr(val, ',');
|
||||
if (arg)
|
||||
*arg = '\0';
|
||||
n = index_in_strings(words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg_to, val, error_in);
|
||||
flags |= (1 << n);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
*arg = ','; /* to preserve ps listing */
|
||||
val = arg + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
enum {
|
||||
/* Must be in the same order as OP_conv_XXX! */
|
||||
/* (see "flags |= (1 << what)" below) */
|
||||
FLAG_NOTRUNC = (1 << 0) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SYNC = (1 << 1) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_NOERROR = (1 << 2) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FSYNC = (1 << 3) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_SWAB = (1 << 4) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of conv flags */
|
||||
FLAG_TWOBUFS = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 6,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs\0""obs\0""conv\0""iflag\0"
|
||||
"ibs\0""obs\0""conv\0"
|
||||
#endif
|
||||
;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
static const char conv_words[] ALIGN1 =
|
||||
"notrunc\0""sync\0""noerror\0""fsync\0""swab\0";
|
||||
static const char iflag_words[] ALIGN1 =
|
||||
"skip_bytes\0";
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
static const char status_words[] ALIGN1 =
|
||||
"none\0""noxfer\0";
|
||||
#endif
|
||||
enum {
|
||||
OP_bs = 0,
|
||||
@@ -263,12 +177,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_skip,
|
||||
OP_if,
|
||||
OP_of,
|
||||
IF_FEATURE_DD_STATUS(OP_status,)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
OP_ibs,
|
||||
OP_obs,
|
||||
OP_conv,
|
||||
OP_iflag,
|
||||
/* Must be in the same order as FLAG_XXX! */
|
||||
OP_conv_notrunc = 0,
|
||||
OP_conv_sync,
|
||||
@@ -288,7 +200,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
//ibm from ASCII to alternate EBCDIC
|
||||
/* Partially implemented: */
|
||||
//swab swap every pair of input bytes: will abort on non-even reads
|
||||
OP_iflag_skip_bytes,
|
||||
#endif
|
||||
};
|
||||
smallint exitcode = EXIT_FAILURE;
|
||||
@@ -304,12 +215,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
size_t oc;
|
||||
ssize_t prev_read_size; /* for detecting swab failure */
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
@@ -345,39 +258,52 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (what == OP_ibs) {
|
||||
/* Must fit into positive ssize_t */
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
obs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
G.flags |= parse_comma_flags(val, conv_words, "conv");
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_iflag) {
|
||||
G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
|
||||
while (1) {
|
||||
int n;
|
||||
/* find ',', replace them with NUL so we can use val for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on val being non-null, else strchr would fault.
|
||||
*/
|
||||
arg = strchr(val, ',');
|
||||
if (arg)
|
||||
*arg = '\0';
|
||||
n = index_in_strings(conv_words, val);
|
||||
if (n < 0)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, val, "conv");
|
||||
flags |= (1 << n);
|
||||
if (!arg) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
/* *arg = ','; - to preserve ps listing? */
|
||||
val = arg + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
obs = ibs;
|
||||
/*continue;*/
|
||||
}
|
||||
/* These can be large: */
|
||||
if (what == OP_count) {
|
||||
G.flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_seek) {
|
||||
seek = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
seek = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_skip) {
|
||||
skip = XATOU_SFX(val, cwbkMG_suffixes);
|
||||
skip = XATOU_SFX(val, dd_suffixes);
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_if) {
|
||||
@@ -388,16 +314,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = val;
|
||||
/*continue;*/
|
||||
}
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
if (what == OP_status) {
|
||||
int n;
|
||||
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;
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
} /* end of "for (argv[i])" */
|
||||
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
@@ -405,7 +321,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
obuf = ibuf;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (ibs != obs) {
|
||||
G.flags |= FLAG_TWOBUFS;
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
#endif
|
||||
@@ -425,12 +341,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (outfile) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(G.flags & FLAG_NOTRUNC))
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(G.flags & FLAG_NOTRUNC)) {
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
@@ -446,10 +362,9 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
outfile = bb_msg_standard_output;
|
||||
}
|
||||
if (skip) {
|
||||
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
|
||||
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
|
||||
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
|
||||
do {
|
||||
ssize_t n = safe_read(ifd, ibuf, blocksz);
|
||||
ssize_t n = safe_read(ifd, ibuf, ibs);
|
||||
if (n < 0)
|
||||
goto die_infile;
|
||||
if (n == 0)
|
||||
@@ -462,7 +377,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
@@ -470,7 +385,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
break;
|
||||
if (n < 0) {
|
||||
/* "Bad block" */
|
||||
if (!(G.flags & FLAG_NOERROR))
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
bb_simple_perror_msg(infile);
|
||||
/* GNU dd with conv=noerror skips over bad blocks */
|
||||
@@ -479,7 +394,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if (G.flags & FLAG_SWAB) {
|
||||
if (flags & FLAG_SWAB) {
|
||||
uint16_t *p16;
|
||||
ssize_t n2;
|
||||
|
||||
@@ -504,12 +419,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (G.flags & FLAG_SYNC) {
|
||||
if (flags & FLAG_SYNC) {
|
||||
memset(ibuf + n, 0, ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
if (G.flags & FLAG_TWOBUFS) {
|
||||
if (flags & FLAG_TWOBUFS) {
|
||||
char *tmp = ibuf;
|
||||
while (n) {
|
||||
size_t d = obs - oc;
|
||||
@@ -531,7 +446,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto out_status;
|
||||
}
|
||||
|
||||
if (G.flags & FLAG_FSYNC) {
|
||||
if (flags & FLAG_FSYNC) {
|
||||
if (fsync(ofd) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
@@ -553,12 +468,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
out_status:
|
||||
if (!ENABLE_FEATURE_DD_STATUS || !(G.flags & FLAG_STATUS_NONE))
|
||||
dd_output_status(0);
|
||||
dd_output_status(0);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
free(obuf);
|
||||
if (G.flags & FLAG_TWOBUFS)
|
||||
if (flags & FLAG_TWOBUFS)
|
||||
free(ibuf);
|
||||
}
|
||||
|
||||
|
||||
+8
-28
@@ -25,7 +25,6 @@
|
||||
//usage:#define df_trivial_usage
|
||||
//usage: "[-Pk"
|
||||
//usage: IF_FEATURE_HUMAN_READABLE("mh")
|
||||
//usage: "T"
|
||||
//usage: IF_FEATURE_DF_FANCY("ai] [-B SIZE")
|
||||
//usage: "] [FILESYSTEM]..."
|
||||
//usage:#define df_full_usage "\n\n"
|
||||
@@ -36,7 +35,6 @@
|
||||
//usage: "\n -m 1M-byte blocks"
|
||||
//usage: "\n -h Human readable (e.g. 1K 243M 2G)"
|
||||
//usage: )
|
||||
//usage: "\n -T Print filesystem type"
|
||||
//usage: IF_FEATURE_DF_FANCY(
|
||||
//usage: "\n -a Show all filesystems"
|
||||
//usage: "\n -i Inodes"
|
||||
@@ -85,12 +83,11 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_FSTYPE = (1 << 2),
|
||||
OPT_ALL = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 5) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (4 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
@@ -102,7 +99,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kPT"
|
||||
opt = getopt32(argv, "kP"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
IF_FEATURE_DF_FANCY(, &chp));
|
||||
@@ -137,11 +134,8 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
}
|
||||
|
||||
printf("Filesystem %s%-15sUsed Available %s Mounted on\n",
|
||||
(opt & OPT_FSTYPE) ? "Type " : "",
|
||||
disp_units_hdr,
|
||||
(opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
printf("Filesystem %-15sUsed Available %s Mounted on\n",
|
||||
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
@@ -154,7 +148,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
const char *fs_type;
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -177,7 +170,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
device = mount_entry->mnt_fsname;
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
@@ -226,22 +218,10 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
|
||||
}
|
||||
free(uni_dev);
|
||||
if (opt & OPT_FSTYPE) {
|
||||
char *uni_type = unicode_conv_to_printable(&uni_stat, fs_type);
|
||||
if (uni_stat.unicode_width > 10 && !(opt & OPT_POSIX))
|
||||
printf(" %s\n%31s", uni_type, "");
|
||||
else
|
||||
printf(" %s%*s", uni_type, 10 - (int)uni_stat.unicode_width, "");
|
||||
free(uni_type);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
|
||||
printf("\n%-20s", "");
|
||||
if (opt & OPT_FSTYPE) {
|
||||
if (printf(" %-10s", fs_type) > 11 && !(opt & OPT_POSIX))
|
||||
printf("\n%-30s", "");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
|
||||
+9
-11
@@ -41,7 +41,7 @@ enum {
|
||||
static void convert(char *fn, int conv_type)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int ch;
|
||||
int i;
|
||||
char *temp_fn = temp_fn; /* for compiler */
|
||||
char *resolved_fn = resolved_fn;
|
||||
|
||||
@@ -49,30 +49,28 @@ static void convert(char *fn, int conv_type)
|
||||
out = stdout;
|
||||
if (fn != NULL) {
|
||||
struct stat st;
|
||||
int fd;
|
||||
|
||||
resolved_fn = xmalloc_follow_symlinks(fn);
|
||||
if (resolved_fn == NULL)
|
||||
bb_simple_perror_msg_and_die(fn);
|
||||
in = xfopen_for_read(resolved_fn);
|
||||
xfstat(fileno(in), &st, resolved_fn);
|
||||
fstat(fileno(in), &st);
|
||||
|
||||
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
|
||||
fd = xmkstemp(temp_fn);
|
||||
if (fchmod(fd, st.st_mode) == -1)
|
||||
i = xmkstemp(temp_fn);
|
||||
if (fchmod(i, st.st_mode) == -1)
|
||||
bb_simple_perror_msg_and_die(temp_fn);
|
||||
fchown(fd, st.st_uid, st.st_gid);
|
||||
|
||||
out = xfdopen_for_write(fd);
|
||||
out = xfdopen_for_write(i);
|
||||
}
|
||||
|
||||
while ((ch = fgetc(in)) != EOF) {
|
||||
if (ch == '\r')
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
if (i == '\r')
|
||||
continue;
|
||||
if (ch == '\n')
|
||||
if (i == '\n')
|
||||
if (conv_type == CT_UNIX2DOS)
|
||||
fputc('\r', out);
|
||||
fputc(ch, out);
|
||||
fputc(i, out);
|
||||
}
|
||||
|
||||
if (fn != NULL) {
|
||||
|
||||
+16
-26
@@ -58,7 +58,6 @@
|
||||
//usage: "2417 .\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
enum {
|
||||
OPT_a_files_too = (1 << 0),
|
||||
@@ -76,7 +75,7 @@ enum {
|
||||
|
||||
struct globals {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned long disp_unit;
|
||||
unsigned long disp_hr;
|
||||
#else
|
||||
unsigned disp_k;
|
||||
#endif
|
||||
@@ -86,31 +85,22 @@ struct globals {
|
||||
int du_depth;
|
||||
dev_t dir_dev;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
|
||||
|
||||
/* FIXME? coreutils' du rounds sizes up:
|
||||
* for example, 1025k file is shown as "2" by du -m.
|
||||
* We round to nearest.
|
||||
*/
|
||||
static void print(unsigned long long size, const char *filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
# if ENABLE_DESKTOP
|
||||
/* ~30 bytes of code for extra comtat:
|
||||
* coreutils' du rounds sizes up:
|
||||
* for example, 1025k file is shown as "2" by du -m.
|
||||
* We round to nearest if human-readable [too hard to fix],
|
||||
* else (fixed scale such as -m), we round up. To that end,
|
||||
* add yet another half of the unit before displaying:
|
||||
*/
|
||||
if (G.disp_unit)
|
||||
size += (G.disp_unit-1) / (unsigned)(512 * 2);
|
||||
# endif
|
||||
printf("%s\t%s\n",
|
||||
/* size x 512 / G.disp_unit.
|
||||
* If G.disp_unit == 0, show one fractional
|
||||
* and use suffixes
|
||||
*/
|
||||
make_human_readable_str(size, 512, G.disp_unit),
|
||||
/* size x 512 / G.disp_hr, show one fractional,
|
||||
* use suffixes if G.disp_hr == 0 */
|
||||
make_human_readable_str(size, 512, G.disp_hr),
|
||||
filename);
|
||||
#else
|
||||
if (G.disp_k) {
|
||||
@@ -209,10 +199,10 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
INIT_G();
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 1024;)
|
||||
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_unit = 512;)
|
||||
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
|
||||
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
G.disp_unit = 512;
|
||||
G.disp_hr = 512;
|
||||
#else
|
||||
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
|
||||
/* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
|
||||
@@ -230,13 +220,13 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
|
||||
argv += optind;
|
||||
if (opt & OPT_h_for_humans) {
|
||||
G.disp_unit = 0;
|
||||
G.disp_hr = 0;
|
||||
}
|
||||
if (opt & OPT_m_mbytes) {
|
||||
G.disp_unit = 1024*1024;
|
||||
G.disp_hr = 1024*1024;
|
||||
}
|
||||
if (opt & OPT_k_kbytes) {
|
||||
G.disp_unit = 1024;
|
||||
G.disp_hr = 1024;
|
||||
}
|
||||
#else
|
||||
opt_complementary = "H-L:L-H:s-d:d-s:d+";
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned buflen;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = 0, /* 0 -- disable escape sequences */
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
|
||||
|
||||
+2
-3
@@ -61,7 +61,6 @@
|
||||
//usage: "of characters matched or 0."
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "xregex.h"
|
||||
|
||||
#if ENABLE_EXPR_MATH_SUPPORT_64
|
||||
@@ -100,8 +99,8 @@ typedef struct valinfo VALUE;
|
||||
struct globals {
|
||||
char **args;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
|
||||
/* forward declarations */
|
||||
static VALUE *eval(void);
|
||||
|
||||
+5
-3
@@ -10,9 +10,11 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/000095399/utilities/false.html */
|
||||
|
||||
/* "false --help" is special-cased to ignore --help */
|
||||
//usage:#define false_trivial_usage NOUSAGE_STR
|
||||
//usage:#define false_full_usage ""
|
||||
//usage:#define false_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define false_full_usage "\n\n"
|
||||
//usage: "Return an exit code of FALSE (1)"
|
||||
//usage:
|
||||
//usage:#define false_example_usage
|
||||
//usage: "$ false\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
+19
-34
@@ -8,7 +8,7 @@
|
||||
|
||||
/* -v, -b, -c are ignored */
|
||||
//usage:#define install_trivial_usage
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [-t DIR] [SOURCE]... DEST"
|
||||
//usage: "[-cdDsp] [-o USER] [-g GRP] [-m MODE] [SOURCE]... DEST"
|
||||
//usage:#define install_full_usage "\n\n"
|
||||
//usage: "Copy files and set attributes\n"
|
||||
//usage: "\n -c Just copy (default)"
|
||||
@@ -19,7 +19,6 @@
|
||||
//usage: "\n -o USER Set ownership"
|
||||
//usage: "\n -g GRP Set group ownership"
|
||||
//usage: "\n -m MODE Set permissions"
|
||||
//usage: "\n -t DIR Install to DIR"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -Z Set security context"
|
||||
//usage: )
|
||||
@@ -29,16 +28,12 @@
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
static const char install_longopts[] ALIGN1 =
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
"directory\0" No_argument "d"
|
||||
"preserve-timestamps\0" No_argument "p"
|
||||
"strip\0" No_argument "s"
|
||||
"group\0" Required_argument "g"
|
||||
"mode\0" Required_argument "m"
|
||||
"owner\0" Required_argument "o"
|
||||
"target-directory\0" Required_argument "t"
|
||||
/* autofs build insists of using -b --suffix=.orig */
|
||||
/* TODO? (short option for --suffix is -S) */
|
||||
#if ENABLE_SELINUX
|
||||
@@ -94,11 +89,11 @@ int install_main(int argc, char **argv)
|
||||
const char *gid_str;
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
int mkdir_flags = FILEUTILS_RECUR;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int opts;
|
||||
int min_args = 1;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int isdir;
|
||||
int isdir = 0;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext;
|
||||
bool use_default_selinux_context = 1;
|
||||
@@ -114,22 +109,21 @@ int install_main(int argc, char **argv)
|
||||
OPT_GROUP = 1 << 7,
|
||||
OPT_MODE = 1 << 8,
|
||||
OPT_OWNER = 1 << 9,
|
||||
OPT_TARGET = 1 << 10,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 12,
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "t--d:d--t:s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:t:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str, &last
|
||||
IF_SELINUX(, &scontext));
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
@@ -147,11 +141,6 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_v) && FILEUTILS_VERBOSE) {
|
||||
mkdir_flags |= FILEUTILS_VERBOSE;
|
||||
copy_flags |= FILEUTILS_VERBOSE;
|
||||
}
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour,
|
||||
* BSD only preserves modification time */
|
||||
if (opts & OPT_PRESERVE_TIME) {
|
||||
@@ -159,41 +148,37 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
mode = 0755; /* GNU coreutils 6.10 compat */
|
||||
if (opts & OPT_MODE)
|
||||
mode = bb_parse_mode(mode_str, mode);
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
/* If -t DIR is in use, then isdir=true, last="DIR" */
|
||||
isdir = (opts & OPT_TARGET);
|
||||
if (!(opts & (OPT_TARGET|OPT_DIRECTORY))) {
|
||||
/* Neither -t DIR nor -d is in use */
|
||||
argc--;
|
||||
last = argv[argc];
|
||||
argv[argc] = NULL;
|
||||
last = argv[argc - 1];
|
||||
if (!(opts & OPT_DIRECTORY)) {
|
||||
argv[argc - 1] = NULL;
|
||||
min_args++;
|
||||
|
||||
/* coreutils install resolves link in this case, don't use lstat */
|
||||
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
if (argc < min_args)
|
||||
bb_show_usage();
|
||||
|
||||
while ((arg = *argv++) != NULL) {
|
||||
char *dest;
|
||||
|
||||
char *dest = last;
|
||||
if (opts & OPT_DIRECTORY) {
|
||||
dest = arg;
|
||||
/* GNU coreutils 6.9 does not set uid:gid
|
||||
* on intermediate created directories
|
||||
* (only on last one) */
|
||||
if (bb_make_directory(dest, 0755, mkdir_flags)) {
|
||||
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
} else {
|
||||
dest = last;
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
|
||||
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created. */
|
||||
free(ddir);
|
||||
|
||||
@@ -33,9 +33,7 @@ mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
|
||||
int opt;
|
||||
opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode = bb_parse_mode(smode, mode);
|
||||
if (mode != (mode_t)-1) /* if mode is valid */
|
||||
/* make future mknod/mkfifo set mode bits exactly */
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
umask(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ int ln_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
free(src_name);
|
||||
|
||||
} while ((++argv)[1]);
|
||||
|
||||
return status;
|
||||
|
||||
+16
-21
@@ -93,7 +93,6 @@
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
#include "unicode.h"
|
||||
|
||||
|
||||
@@ -366,9 +365,8 @@ struct globals {
|
||||
time_t current_time_t;
|
||||
#endif
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
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;) \
|
||||
@@ -568,12 +566,12 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
if (G.all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
|
||||
char *filetime;
|
||||
const time_t *ttime = &dn->dn_mtime;
|
||||
time_t ttime = dn->dn_mtime;
|
||||
if (G.all_fmt & TIME_ACCESS)
|
||||
ttime = &dn->dn_atime;
|
||||
ttime = dn->dn_atime;
|
||||
if (G.all_fmt & TIME_CHANGE)
|
||||
ttime = &dn->dn_ctime;
|
||||
filetime = ctime(ttime);
|
||||
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:
|
||||
@@ -582,16 +580,13 @@ static NOINLINE unsigned display_single(const struct dnode *dn)
|
||||
column += printf("%.24s ", filetime);
|
||||
} else { /* LIST_DATE_TIME */
|
||||
/* G.current_time_t ~== time(NULL) */
|
||||
time_t age = G.current_time_t - *ttime;
|
||||
time_t age = G.current_time_t - ttime;
|
||||
printf("%.6s ", filetime + 4); /* "Jun 30" */
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* less than 6 months old */
|
||||
/* "mmm dd hh:mm " */
|
||||
printf("%.12s ", filetime + 4);
|
||||
} else {
|
||||
/* "mmm dd yyyy " */
|
||||
/* "mmm dd yyyyy " after year 9999 :) */
|
||||
strchr(filetime + 20, '\n')[0] = ' ';
|
||||
printf("%.7s%6s", filetime + 4, filetime + 20);
|
||||
/* hh:mm if less than 6 months old */
|
||||
printf("%.5s ", filetime + 11);
|
||||
} else { /* year. buggy if year > 9999 ;) */
|
||||
printf(" %.4s ", filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
@@ -670,7 +665,7 @@ static void display_files(struct dnode **dn, unsigned nfiles)
|
||||
if (column_width < len)
|
||||
column_width = len;
|
||||
}
|
||||
column_width += 2 +
|
||||
column_width += 1 +
|
||||
IF_SELINUX( ((G.all_fmt & LIST_CONTEXT) ? 33 : 0) + )
|
||||
((G.all_fmt & LIST_INO) ? 8 : 0) +
|
||||
((G.all_fmt & LIST_BLOCKS) ? 5 : 0);
|
||||
@@ -698,8 +693,8 @@ static void display_files(struct dnode **dn, unsigned nfiles)
|
||||
if (i < nfiles) {
|
||||
if (column > 0) {
|
||||
nexttab -= column;
|
||||
printf("%*s", nexttab, "");
|
||||
column += nexttab;
|
||||
printf("%*s ", nexttab, "");
|
||||
column += nexttab + 1;
|
||||
}
|
||||
nexttab = column + column_width;
|
||||
column += display_single(dn[i]);
|
||||
@@ -1037,7 +1032,7 @@ 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 ((G.all_fmt & STYLE_MASK) == STYLE_LONG)
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
@@ -1107,7 +1102,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
#if ENABLE_FEATURE_AUTOWIDTH
|
||||
/* obtain the terminal width */
|
||||
G_terminal_width = get_terminal_width(STDIN_FILENO);
|
||||
get_terminal_width_height(STDIN_FILENO, &G_terminal_width, NULL);
|
||||
/* go one less... */
|
||||
G_terminal_width--;
|
||||
#endif
|
||||
|
||||
+4
-8
@@ -48,9 +48,7 @@ static const char mkdir_longopts[] ALIGN1 =
|
||||
#if ENABLE_SELINUX
|
||||
"context\0" Required_argument "Z"
|
||||
#endif
|
||||
#if ENABLE_FEATURE_VERBOSE
|
||||
"verbose\0" No_argument "v"
|
||||
#endif
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -69,20 +67,18 @@ int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_MKDIR_LONG_OPTIONS
|
||||
applet_long_options = mkdir_longopts;
|
||||
#endif
|
||||
opt = getopt32(argv, "m:pv" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
opt = getopt32(argv, "m:p" IF_SELINUX("Z:") "v", &smode IF_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
mode_t mmode = bb_parse_mode(smode, 0777);
|
||||
if (mmode == (mode_t)-1) {
|
||||
mode_t mmode = 0777;
|
||||
if (!bb_parse_mode(smode, &mmode)) {
|
||||
bb_error_msg_and_die("invalid mode '%s'", smode);
|
||||
}
|
||||
mode = mmode;
|
||||
}
|
||||
if (opt & 2)
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 4) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
#if ENABLE_SELINUX
|
||||
if (opt & 8) {
|
||||
if (opt & 4) {
|
||||
selinux_or_die();
|
||||
setfscreatecon_or_die(scontext);
|
||||
}
|
||||
|
||||
+1
-7
@@ -33,17 +33,13 @@ static const char mv_longopts[] ALIGN1 =
|
||||
"interactive\0" No_argument "i"
|
||||
"force\0" No_argument "f"
|
||||
"no-clobber\0" No_argument "n"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
#endif
|
||||
|
||||
#define OPT_FORCE (1 << 0)
|
||||
#define OPT_INTERACTIVE (1 << 1)
|
||||
#define OPT_NOCLOBBER (1 << 2)
|
||||
#define OPT_VERBOSE ((1 << 3) * ENABLE_FEATURE_VERBOSE)
|
||||
|
||||
|
||||
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mv_main(int argc, char **argv)
|
||||
@@ -62,6 +58,7 @@ int mv_main(int argc, char **argv)
|
||||
/* Need at least two arguments.
|
||||
* If more than one of -f, -i, -n is specified , only the final one
|
||||
* takes effect (it unsets previous options).
|
||||
* -v is accepted but ignored.
|
||||
*/
|
||||
opt_complementary = "-2:f-in:i-fn:n-fi";
|
||||
flags = getopt32(argv, "finv");
|
||||
@@ -151,9 +148,6 @@ int mv_main(int argc, char **argv)
|
||||
status = 1;
|
||||
}
|
||||
RET_0:
|
||||
if (flags & OPT_VERBOSE) {
|
||||
printf("'%s' -> '%s'\n", *argv, dest);
|
||||
}
|
||||
if (dest != last) {
|
||||
free((void *) dest);
|
||||
}
|
||||
|
||||
+114
-128
@@ -20,7 +20,6 @@
|
||||
|
||||
|
||||
/* #include "libbb.h" - done in od.c */
|
||||
#include "common_bufsiz.h"
|
||||
#define assert(a) ((void)0)
|
||||
|
||||
|
||||
@@ -67,7 +66,7 @@ enum {
|
||||
/* -S was -s and also had optional parameter */ \
|
||||
/* but in coreutils 6.3 it was renamed and now has */ \
|
||||
/* _mandatory_ parameter */ \
|
||||
&str_A, &str_N, &str_j, &lst_t, &str_S, &G.bytes_per_block)
|
||||
&str_A, &str_N, &str_j, &lst_t, &str_S, &bytes_per_block)
|
||||
|
||||
|
||||
/* Check for 0x7f is a coreutils 6.3 addition */
|
||||
@@ -175,53 +174,38 @@ struct ERR_width_bytes_has_bad_size {
|
||||
char ERR_width_bytes_has_bad_size[ARRAY_SIZE(width_bytes) == N_SIZE_SPECS ? 1 : -1];
|
||||
};
|
||||
|
||||
struct globals {
|
||||
smallint exit_code;
|
||||
static smallint exit_code;
|
||||
|
||||
unsigned string_min;
|
||||
static unsigned string_min;
|
||||
|
||||
/* An array of specs describing how to format each input block. */
|
||||
unsigned n_specs;
|
||||
struct tspec *spec;
|
||||
/* An array of specs describing how to format each input block. */
|
||||
static size_t n_specs;
|
||||
static struct tspec *spec;
|
||||
|
||||
/* Function that accepts an address and an optional following char,
|
||||
and prints the address and char to stdout. */
|
||||
void (*format_address)(off_t, char);
|
||||
|
||||
/* The difference between the old-style pseudo starting address and
|
||||
the number of bytes to skip. */
|
||||
/* Function that accepts an address and an optional following char,
|
||||
and prints the address and char to stdout. */
|
||||
static void (*format_address)(off_t, char);
|
||||
/* The difference between the old-style pseudo starting address and
|
||||
the number of bytes to skip. */
|
||||
#if ENABLE_LONG_OPTS
|
||||
off_t pseudo_offset;
|
||||
# define G_pseudo_offset G.pseudo_offset
|
||||
static off_t pseudo_offset;
|
||||
#else
|
||||
enum { pseudo_offset = 0 };
|
||||
#endif
|
||||
/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all
|
||||
input is formatted. */
|
||||
/* When zero, MAX_BYTES_TO_FORMAT and END_OFFSET are ignored, and all
|
||||
input is formatted. */
|
||||
|
||||
/* The number of input bytes formatted per output line. It must be
|
||||
a multiple of the least common multiple of the sizes associated with
|
||||
the specified output types. It should be as large as possible, but
|
||||
no larger than 16 -- unless specified with the -w option. */
|
||||
unsigned bytes_per_block; /* have to use unsigned, not size_t */
|
||||
/* The number of input bytes formatted per output line. It must be
|
||||
a multiple of the least common multiple of the sizes associated with
|
||||
the specified output types. It should be as large as possible, but
|
||||
no larger than 16 -- unless specified with the -w option. */
|
||||
static unsigned bytes_per_block = 32; /* have to use unsigned, not size_t */
|
||||
|
||||
/* A NULL-terminated list of the file-arguments from the command line. */
|
||||
const char *const *file_list;
|
||||
|
||||
/* The input stream associated with the current file. */
|
||||
FILE *in_stream;
|
||||
|
||||
bool not_first;
|
||||
bool prev_pair_equal;
|
||||
} FIX_ALIASING;
|
||||
#if !ENABLE_LONG_OPTS
|
||||
enum { G_pseudo_offset = 0 };
|
||||
#endif
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
|
||||
G.bytes_per_block = 32; \
|
||||
} while (0)
|
||||
/* A NULL-terminated list of the file-arguments from the command line. */
|
||||
static const char *const *file_list;
|
||||
|
||||
/* The input stream associated with the current file. */
|
||||
static FILE *in_stream;
|
||||
|
||||
#define MAX_INTEGRAL_TYPE_SIZE sizeof(ulonglong_t)
|
||||
static const unsigned char integral_type_size[MAX_INTEGRAL_TYPE_SIZE + 1] ALIGN1 = {
|
||||
@@ -403,11 +387,11 @@ print_named_ascii(size_t n_bytes, const char *block,
|
||||
" sp"
|
||||
};
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
// actually " x\0 xxx\0", but want to share string with print_ascii.
|
||||
// [12] because we take three 32bit stack slots anyway, and
|
||||
// gcc is too dumb to initialize with constant stores,
|
||||
// it copies initializer from rodata. Oh well.
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65410
|
||||
|
||||
while (n_bytes--) {
|
||||
unsigned masked_c = *(unsigned char *) block++;
|
||||
@@ -435,7 +419,7 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
const char *unused_fmt_string UNUSED_PARAM)
|
||||
{
|
||||
// buf[N] pos: 01234 56789
|
||||
char buf[12] = " x\0 xxx\0";
|
||||
char buf[12] = " x\0 0xx\0";
|
||||
|
||||
while (n_bytes--) {
|
||||
const char *s;
|
||||
@@ -471,9 +455,11 @@ print_ascii(size_t n_bytes, const char *block,
|
||||
case '\v':
|
||||
s = " \\v";
|
||||
break;
|
||||
default:
|
||||
buf[6] = (c >> 6 & 3) + '0';
|
||||
buf[7] = (c >> 3 & 7) + '0';
|
||||
case '\x7f':
|
||||
s = " 177";
|
||||
break;
|
||||
default: /* c is never larger than 040 */
|
||||
buf[7] = (c >> 3) + '0';
|
||||
buf[8] = (c & 7) + '0';
|
||||
s = buf + 5;
|
||||
}
|
||||
@@ -492,17 +478,17 @@ static void
|
||||
open_next_file(void)
|
||||
{
|
||||
while (1) {
|
||||
if (!*G.file_list)
|
||||
if (!*file_list)
|
||||
return;
|
||||
G.in_stream = fopen_or_warn_stdin(*G.file_list++);
|
||||
if (G.in_stream) {
|
||||
in_stream = fopen_or_warn_stdin(*file_list++);
|
||||
if (in_stream) {
|
||||
break;
|
||||
}
|
||||
G.exit_code = 1;
|
||||
exit_code = 1;
|
||||
}
|
||||
|
||||
if ((option_mask32 & (OPT_N|OPT_S)) == OPT_N)
|
||||
setbuf(G.in_stream, NULL);
|
||||
setbuf(in_stream, NULL);
|
||||
}
|
||||
|
||||
/* Test whether there have been errors on in_stream, and close it if
|
||||
@@ -515,16 +501,16 @@ open_next_file(void)
|
||||
static void
|
||||
check_and_close(void)
|
||||
{
|
||||
if (G.in_stream) {
|
||||
if (ferror(G.in_stream)) {
|
||||
bb_error_msg("%s: read error", (G.in_stream == stdin)
|
||||
if (in_stream) {
|
||||
if (ferror(in_stream)) {
|
||||
bb_error_msg("%s: read error", (in_stream == stdin)
|
||||
? bb_msg_standard_input
|
||||
: G.file_list[-1]
|
||||
: file_list[-1]
|
||||
);
|
||||
G.exit_code = 1;
|
||||
exit_code = 1;
|
||||
}
|
||||
fclose_if_not_stdin(G.in_stream);
|
||||
G.in_stream = NULL;
|
||||
fclose_if_not_stdin(in_stream);
|
||||
in_stream = NULL;
|
||||
}
|
||||
|
||||
if (ferror(stdout)) {
|
||||
@@ -760,9 +746,9 @@ decode_format_string(const char *s)
|
||||
|
||||
assert(s != next);
|
||||
s = next;
|
||||
G.spec = xrealloc_vector(G.spec, 4, G.n_specs);
|
||||
memcpy(&G.spec[G.n_specs], &tspec, sizeof(G.spec[0]));
|
||||
G.n_specs++;
|
||||
spec = xrealloc_vector(spec, 4, n_specs);
|
||||
memcpy(&spec[n_specs], &tspec, sizeof(spec[0]));
|
||||
n_specs++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -779,7 +765,7 @@ skip(off_t n_skip)
|
||||
if (n_skip == 0)
|
||||
return;
|
||||
|
||||
while (G.in_stream) { /* !EOF */
|
||||
while (in_stream) { /* !EOF */
|
||||
struct stat file_stats;
|
||||
|
||||
/* First try seeking. For large offsets, this extra work is
|
||||
@@ -797,15 +783,15 @@ skip(off_t n_skip)
|
||||
If the number of bytes left to skip is at least
|
||||
as large as the size of the current file, we can
|
||||
decrement n_skip and go on to the next file. */
|
||||
if (fstat(fileno(G.in_stream), &file_stats) == 0
|
||||
if (fstat(fileno(in_stream), &file_stats) == 0
|
||||
&& S_ISREG(file_stats.st_mode) && file_stats.st_size > 0
|
||||
) {
|
||||
if (file_stats.st_size < n_skip) {
|
||||
n_skip -= file_stats.st_size;
|
||||
/* take "check & close / open_next" route */
|
||||
} else {
|
||||
if (fseeko(G.in_stream, n_skip, SEEK_CUR) != 0)
|
||||
G.exit_code = 1;
|
||||
if (fseeko(in_stream, n_skip, SEEK_CUR) != 0)
|
||||
exit_code = 1;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -818,7 +804,7 @@ skip(off_t n_skip)
|
||||
while (n_skip > 0) {
|
||||
if (n_skip < n_bytes_to_read)
|
||||
n_bytes_to_read = n_skip;
|
||||
n_bytes_read = fread(buf, 1, n_bytes_to_read, G.in_stream);
|
||||
n_bytes_read = fread(buf, 1, n_bytes_to_read, in_stream);
|
||||
n_skip -= n_bytes_read;
|
||||
if (n_bytes_read != n_bytes_to_read)
|
||||
break; /* EOF on this file or error */
|
||||
@@ -871,7 +857,7 @@ static void
|
||||
format_address_label(off_t address, char c)
|
||||
{
|
||||
format_address_std(address, ' ');
|
||||
format_address_paren(address + G_pseudo_offset, c);
|
||||
format_address_paren(address + pseudo_offset, c);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -902,34 +888,36 @@ static void
|
||||
write_block(off_t current_offset, size_t n_bytes,
|
||||
const char *prev_block, const char *curr_block)
|
||||
{
|
||||
unsigned i;
|
||||
static char first = 1;
|
||||
static char prev_pair_equal = 0;
|
||||
size_t i;
|
||||
|
||||
if (!(option_mask32 & OPT_v)
|
||||
&& G.not_first
|
||||
&& n_bytes == G.bytes_per_block
|
||||
&& memcmp(prev_block, curr_block, G.bytes_per_block) == 0
|
||||
&& !first
|
||||
&& n_bytes == bytes_per_block
|
||||
&& memcmp(prev_block, curr_block, bytes_per_block) == 0
|
||||
) {
|
||||
if (G.prev_pair_equal) {
|
||||
if (prev_pair_equal) {
|
||||
/* The two preceding blocks were equal, and the current
|
||||
block is the same as the last one, so print nothing. */
|
||||
} else {
|
||||
puts("*");
|
||||
G.prev_pair_equal = 1;
|
||||
prev_pair_equal = 1;
|
||||
}
|
||||
} else {
|
||||
G.not_first = 1;
|
||||
G.prev_pair_equal = 0;
|
||||
for (i = 0; i < G.n_specs; i++) {
|
||||
first = 0;
|
||||
prev_pair_equal = 0;
|
||||
for (i = 0; i < n_specs; i++) {
|
||||
if (i == 0)
|
||||
G.format_address(current_offset, '\0');
|
||||
format_address(current_offset, '\0');
|
||||
else
|
||||
printf("%*s", address_pad_len_char - '0', "");
|
||||
(*G.spec[i].print_function) (n_bytes, curr_block, G.spec[i].fmt_string);
|
||||
if (G.spec[i].hexl_mode_trailer) {
|
||||
(*spec[i].print_function) (n_bytes, curr_block, spec[i].fmt_string);
|
||||
if (spec[i].hexl_mode_trailer) {
|
||||
/* space-pad out to full line width, then dump the trailer */
|
||||
unsigned datum_width = width_bytes[G.spec[i].size];
|
||||
unsigned blank_fields = (G.bytes_per_block - n_bytes) / datum_width;
|
||||
unsigned field_width = G.spec[i].field_width + 1;
|
||||
unsigned datum_width = width_bytes[spec[i].size];
|
||||
unsigned blank_fields = (bytes_per_block - n_bytes) / datum_width;
|
||||
unsigned field_width = spec[i].field_width + 1;
|
||||
printf("%*s", blank_fields * field_width, "");
|
||||
dump_hexl_mode_trailer(n_bytes, curr_block);
|
||||
}
|
||||
@@ -941,19 +929,19 @@ write_block(off_t current_offset, size_t n_bytes,
|
||||
static void
|
||||
read_block(size_t n, char *block, size_t *n_bytes_in_buffer)
|
||||
{
|
||||
assert(0 < n && n <= G.bytes_per_block);
|
||||
assert(0 < n && n <= bytes_per_block);
|
||||
|
||||
*n_bytes_in_buffer = 0;
|
||||
|
||||
if (n == 0)
|
||||
return;
|
||||
|
||||
while (G.in_stream != NULL) { /* EOF. */
|
||||
while (in_stream != NULL) { /* EOF. */
|
||||
size_t n_needed;
|
||||
size_t n_read;
|
||||
|
||||
n_needed = n - *n_bytes_in_buffer;
|
||||
n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, G.in_stream);
|
||||
n_read = fread(block + *n_bytes_in_buffer, 1, n_needed, in_stream);
|
||||
*n_bytes_in_buffer += n_read;
|
||||
if (n_read == n_needed)
|
||||
break;
|
||||
@@ -972,8 +960,8 @@ get_lcm(void)
|
||||
size_t i;
|
||||
int l_c_m = 1;
|
||||
|
||||
for (i = 0; i < G.n_specs; i++)
|
||||
l_c_m = lcm(l_c_m, width_bytes[(int) G.spec[i].size]);
|
||||
for (i = 0; i < n_specs; i++)
|
||||
l_c_m = lcm(l_c_m, width_bytes[(int) spec[i].size]);
|
||||
return l_c_m;
|
||||
}
|
||||
|
||||
@@ -994,8 +982,8 @@ dump(off_t current_offset, off_t end_offset)
|
||||
int idx;
|
||||
size_t n_bytes_read;
|
||||
|
||||
block[0] = xmalloc(2 * G.bytes_per_block);
|
||||
block[1] = block[0] + G.bytes_per_block;
|
||||
block[0] = xmalloc(2 * bytes_per_block);
|
||||
block[1] = block[0] + bytes_per_block;
|
||||
|
||||
idx = 0;
|
||||
if (option_mask32 & OPT_N) {
|
||||
@@ -1005,21 +993,21 @@ dump(off_t current_offset, off_t end_offset)
|
||||
n_bytes_read = 0;
|
||||
break;
|
||||
}
|
||||
n_needed = MIN(end_offset - current_offset, (off_t) G.bytes_per_block);
|
||||
n_needed = MIN(end_offset - current_offset, (off_t) bytes_per_block);
|
||||
read_block(n_needed, block[idx], &n_bytes_read);
|
||||
if (n_bytes_read < G.bytes_per_block)
|
||||
if (n_bytes_read < bytes_per_block)
|
||||
break;
|
||||
assert(n_bytes_read == G.bytes_per_block);
|
||||
assert(n_bytes_read == bytes_per_block);
|
||||
write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
|
||||
current_offset += n_bytes_read;
|
||||
idx ^= 1;
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
read_block(G.bytes_per_block, block[idx], &n_bytes_read);
|
||||
if (n_bytes_read < G.bytes_per_block)
|
||||
read_block(bytes_per_block, block[idx], &n_bytes_read);
|
||||
if (n_bytes_read < bytes_per_block)
|
||||
break;
|
||||
assert(n_bytes_read == G.bytes_per_block);
|
||||
assert(n_bytes_read == bytes_per_block);
|
||||
write_block(current_offset, n_bytes_read, block[idx ^ 1], block[idx]);
|
||||
current_offset += n_bytes_read;
|
||||
idx ^= 1;
|
||||
@@ -1042,7 +1030,7 @@ dump(off_t current_offset, off_t end_offset)
|
||||
current_offset += n_bytes_read;
|
||||
}
|
||||
|
||||
G.format_address(current_offset, '\n');
|
||||
format_address(current_offset, '\n');
|
||||
|
||||
if ((option_mask32 & OPT_N) && current_offset >= end_offset)
|
||||
check_and_close();
|
||||
@@ -1073,16 +1061,16 @@ dump(off_t current_offset, off_t end_offset)
|
||||
static void
|
||||
dump_strings(off_t address, off_t end_offset)
|
||||
{
|
||||
unsigned bufsize = MAX(100, G.string_min);
|
||||
unsigned bufsize = MAX(100, string_min);
|
||||
unsigned char *buf = xmalloc(bufsize);
|
||||
|
||||
while (1) {
|
||||
size_t i;
|
||||
int c;
|
||||
|
||||
/* See if the next 'G.string_min' chars are all printing chars. */
|
||||
/* See if the next 'string_min' chars are all printing chars. */
|
||||
tryline:
|
||||
if ((option_mask32 & OPT_N) && (end_offset - G.string_min <= address))
|
||||
if ((option_mask32 & OPT_N) && (end_offset - string_min <= address))
|
||||
break;
|
||||
i = 0;
|
||||
while (!(option_mask32 & OPT_N) || address < end_offset) {
|
||||
@@ -1091,8 +1079,8 @@ dump_strings(off_t address, off_t end_offset)
|
||||
buf = xrealloc(buf, bufsize);
|
||||
}
|
||||
|
||||
while (G.in_stream) { /* !EOF */
|
||||
c = fgetc(G.in_stream);
|
||||
while (in_stream) { /* !EOF */
|
||||
c = fgetc(in_stream);
|
||||
if (c != EOF)
|
||||
goto got_char;
|
||||
check_and_close();
|
||||
@@ -1109,12 +1097,12 @@ dump_strings(off_t address, off_t end_offset)
|
||||
buf[i++] = c; /* String continues; store it all. */
|
||||
}
|
||||
|
||||
if (i < G.string_min) /* Too short! */
|
||||
if (i < string_min) /* Too short! */
|
||||
goto tryline;
|
||||
|
||||
/* If we get here, the string is all printable and NUL-terminated */
|
||||
buf[i] = 0;
|
||||
G.format_address(address - i - 1, ' ');
|
||||
format_address(address - i - 1, ' ');
|
||||
|
||||
for (i = 0; (c = buf[i]); i++) {
|
||||
switch (c) {
|
||||
@@ -1132,7 +1120,7 @@ dump_strings(off_t address, off_t end_offset)
|
||||
}
|
||||
|
||||
/* We reach this point only if we search through
|
||||
(max_bytes_to_format - G.string_min) bytes before reaching EOF. */
|
||||
(max_bytes_to_format - string_min) bytes before reaching EOF. */
|
||||
check_and_close();
|
||||
ret:
|
||||
free(buf);
|
||||
@@ -1204,10 +1192,8 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* The maximum number of bytes that will be formatted. */
|
||||
off_t max_bytes_to_format = 0;
|
||||
|
||||
INIT_G();
|
||||
|
||||
/*G.spec = NULL; - already is */
|
||||
G.format_address = format_address_std;
|
||||
spec = NULL;
|
||||
format_address = format_address_std;
|
||||
address_base_char = 'o';
|
||||
address_pad_len_char = '7';
|
||||
|
||||
@@ -1233,7 +1219,7 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg_and_die("bad output address radix "
|
||||
"'%c' (must be [doxn])", str_A[0]);
|
||||
pos = p - doxn;
|
||||
if (pos == 3) G.format_address = format_address_none;
|
||||
if (pos == 3) format_address = format_address_none;
|
||||
address_base_char = doxn_address_base_char[pos];
|
||||
address_pad_len_char = doxn_address_pad_len_char[pos];
|
||||
}
|
||||
@@ -1256,11 +1242,11 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_x) decode_format_string("x2");
|
||||
if (opt & OPT_s) decode_format_string("d2");
|
||||
if (opt & OPT_S) {
|
||||
G.string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
|
||||
string_min = xstrtou_sfx(str_S, 0, bkm_suffixes);
|
||||
}
|
||||
|
||||
// Bloat:
|
||||
//if ((option_mask32 & OPT_S) && G.n_specs > 0)
|
||||
//if ((option_mask32 & OPT_S) && n_specs > 0)
|
||||
// bb_error_msg_and_die("no type may be specified when dumping strings");
|
||||
|
||||
/* If the --traditional option is used, there may be from
|
||||
@@ -1316,14 +1302,14 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (pseudo_start >= 0) {
|
||||
if (G.format_address == format_address_none) {
|
||||
if (format_address == format_address_none) {
|
||||
address_base_char = 'o';
|
||||
address_pad_len_char = '7';
|
||||
G.format_address = format_address_paren;
|
||||
format_address = format_address_paren;
|
||||
} else {
|
||||
G.format_address = format_address_label;
|
||||
format_address = format_address_label;
|
||||
}
|
||||
G_pseudo_offset = pseudo_start - n_bytes_to_skip;
|
||||
pseudo_offset = pseudo_start - n_bytes_to_skip;
|
||||
}
|
||||
}
|
||||
/* else: od --traditional (without args) */
|
||||
@@ -1336,45 +1322,45 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg_and_die("SKIP + SIZE is too large");
|
||||
}
|
||||
|
||||
if (G.n_specs == 0) {
|
||||
if (n_specs == 0) {
|
||||
decode_format_string("o2");
|
||||
/*G.n_specs = 1; - done by decode_format_string */
|
||||
/*n_specs = 1; - done by decode_format_string */
|
||||
}
|
||||
|
||||
/* If no files were listed on the command line,
|
||||
set the global pointer FILE_LIST so that it
|
||||
references the null-terminated list of one name: "-". */
|
||||
G.file_list = bb_argv_dash;
|
||||
file_list = bb_argv_dash;
|
||||
if (argv[0]) {
|
||||
/* Set the global pointer FILE_LIST so that it
|
||||
references the first file-argument on the command-line. */
|
||||
G.file_list = (char const *const *) argv;
|
||||
file_list = (char const *const *) argv;
|
||||
}
|
||||
|
||||
/* Open the first input file */
|
||||
open_next_file();
|
||||
/* Skip over any unwanted header bytes */
|
||||
skip(n_bytes_to_skip);
|
||||
if (!G.in_stream)
|
||||
if (!in_stream)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
/* Compute output block length */
|
||||
l_c_m = get_lcm();
|
||||
|
||||
if (opt & OPT_w) { /* -w: width */
|
||||
if (!G.bytes_per_block || G.bytes_per_block % l_c_m != 0) {
|
||||
if (!bytes_per_block || bytes_per_block % l_c_m != 0) {
|
||||
bb_error_msg("warning: invalid width %u; using %d instead",
|
||||
(unsigned)G.bytes_per_block, l_c_m);
|
||||
G.bytes_per_block = l_c_m;
|
||||
(unsigned)bytes_per_block, l_c_m);
|
||||
bytes_per_block = l_c_m;
|
||||
}
|
||||
} else {
|
||||
G.bytes_per_block = l_c_m;
|
||||
bytes_per_block = l_c_m;
|
||||
if (l_c_m < DEFAULT_BYTES_PER_BLOCK)
|
||||
G.bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m;
|
||||
bytes_per_block *= DEFAULT_BYTES_PER_BLOCK / l_c_m;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < G.n_specs; i++) {
|
||||
for (i = 0; i < n_specs; i++) {
|
||||
printf("%d: fmt=\"%s\" width=%d\n",
|
||||
i, spec[i].fmt_string, width_bytes[spec[i].size]);
|
||||
}
|
||||
@@ -1388,5 +1374,5 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (fclose(stdin))
|
||||
bb_perror_msg_and_die(bb_msg_standard_input);
|
||||
|
||||
return G.exit_code;
|
||||
return exit_code;
|
||||
}
|
||||
+3
-9
@@ -131,8 +131,8 @@ static double my_xstrtod(const char *arg)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Handles %b; return 1 if output is to be short-circuited by \c */
|
||||
static int print_esc_string(const char *str)
|
||||
/* Handles %b */
|
||||
static void print_esc_string(const char *str)
|
||||
{
|
||||
char c;
|
||||
while ((c = *str) != '\0') {
|
||||
@@ -145,9 +145,6 @@ static int print_esc_string(const char *str)
|
||||
str++;
|
||||
}
|
||||
}
|
||||
else if (*str == 'c') {
|
||||
return 1;
|
||||
}
|
||||
{
|
||||
/* optimization: don't force arg to be on-stack,
|
||||
* use another variable for that. */
|
||||
@@ -158,8 +155,6 @@ static int print_esc_string(const char *str)
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void print_direc(char *format, unsigned fmt_length,
|
||||
@@ -285,8 +280,7 @@ static char **print_formatted(char *f, char **argv, int *conv_err)
|
||||
}
|
||||
if (*f == 'b') {
|
||||
if (*argv) {
|
||||
if (print_esc_string(*argv))
|
||||
return saved_argv; /* causes main() to exit */
|
||||
print_esc_string(*argv);
|
||||
++argv;
|
||||
}
|
||||
break;
|
||||
|
||||
+1
-2
@@ -38,6 +38,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned opt;
|
||||
|
||||
opt_complementary = "f-i:i-f";
|
||||
/* -v (verbose) is ignored */
|
||||
opt = getopt32(argv, "fiRrv");
|
||||
argv += optind;
|
||||
if (opt & 1)
|
||||
@@ -46,8 +47,6 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FILEUTILS_INTERACTIVE;
|
||||
if (opt & (8|4))
|
||||
flags |= FILEUTILS_RECUR;
|
||||
if ((opt & 16) && FILEUTILS_VERBOSE)
|
||||
flags |= FILEUTILS_VERBOSE;
|
||||
|
||||
if (*argv != NULL) {
|
||||
do {
|
||||
|
||||
+2
-8
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
#define PARENTS (1 << 0)
|
||||
#define VERBOSE ((1 << 1) * ENABLE_FEATURE_VERBOSE)
|
||||
//efine VERBOSE (1 << 1) //accepted but ignored
|
||||
#define IGNORE_NON_EMPTY (1 << 2)
|
||||
|
||||
int rmdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -44,12 +44,10 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
static const char rmdir_longopts[] ALIGN1 =
|
||||
"parents\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
/* Debian etch: many packages fail to be purged or installed
|
||||
* because they desperately want this option: */
|
||||
"ignore-fail-on-non-empty\0" No_argument "\xff"
|
||||
IF_FEATURE_VERBOSE(
|
||||
"verbose\0" No_argument "v"
|
||||
)
|
||||
;
|
||||
applet_long_options = rmdir_longopts;
|
||||
#endif
|
||||
@@ -64,10 +62,6 @@ int rmdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
path = *argv;
|
||||
|
||||
while (1) {
|
||||
if (flags & VERBOSE) {
|
||||
printf("rmdir: removing directory, '%s'\n", path);
|
||||
}
|
||||
|
||||
if (rmdir(path) < 0) {
|
||||
#if ENABLE_FEATURE_RMDIR_LONG_OPTIONS
|
||||
if ((flags & IGNORE_NON_EMPTY) && errno == ENOTEMPTY)
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* shuf: Write a random permutation of the input lines to standard output.
|
||||
*
|
||||
* Copyright (C) 2014 by Bartosz Golaszewski <bartekgola@gmail.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
//config:config SHUF
|
||||
//config: bool "shuf"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Generate random permutations
|
||||
|
||||
//kbuild:lib-$(CONFIG_SHUF) += shuf.o
|
||||
//applet:IF_SHUF(APPLET_NOEXEC(shuf, shuf, BB_DIR_USR_BIN, BB_SUID_DROP, shuf))
|
||||
|
||||
//usage:#define shuf_trivial_usage
|
||||
//usage: "[-e|-i L-H] [-n NUM] [-o FILE] [-z] [FILE|ARG...]"
|
||||
//usage:#define shuf_full_usage "\n\n"
|
||||
//usage: "Randomly permute lines\n"
|
||||
//usage: "\n -e Treat ARGs as lines"
|
||||
//usage: "\n -i L-H Treat numbers L-H as lines"
|
||||
//usage: "\n -n NUM Output at most NUM lines"
|
||||
//usage: "\n -o FILE Write to FILE, not standard output"
|
||||
//usage: "\n -z End lines with zero byte, not newline"
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#define OPT_e (1 << 0)
|
||||
#define OPT_i (1 << 1)
|
||||
#define OPT_n (1 << 2)
|
||||
#define OPT_o (1 << 3)
|
||||
#define OPT_z (1 << 4)
|
||||
#define OPT_STR "ei:n:o:z"
|
||||
|
||||
/*
|
||||
* Use the Fisher-Yates shuffle algorithm on an array of lines.
|
||||
*/
|
||||
static void shuffle_lines(char **lines, unsigned numlines)
|
||||
{
|
||||
unsigned i;
|
||||
unsigned r;
|
||||
char *tmp;
|
||||
|
||||
srand(monotonic_us());
|
||||
|
||||
for (i = numlines-1; i > 0; i--) {
|
||||
r = rand();
|
||||
/* RAND_MAX can be as small as 32767 */
|
||||
if (i > RAND_MAX)
|
||||
r ^= rand() << 15;
|
||||
r %= i;
|
||||
tmp = lines[i];
|
||||
lines[i] = lines[r];
|
||||
lines[r] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
int shuf_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int shuf_main(int argc, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
char *opt_i_str, *opt_n_str, *opt_o_str;
|
||||
unsigned i;
|
||||
char **lines;
|
||||
unsigned numlines;
|
||||
char eol;
|
||||
|
||||
opt_complementary = "e--i:i--e"; /* mutually exclusive */
|
||||
opts = getopt32(argv, OPT_STR, &opt_i_str, &opt_n_str, &opt_o_str);
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
/* Prepare lines for shuffling - either: */
|
||||
if (opts & OPT_e) {
|
||||
/* make lines from command-line arguments */
|
||||
numlines = argc;
|
||||
lines = argv;
|
||||
} else
|
||||
if (opts & OPT_i) {
|
||||
/* create a range of numbers */
|
||||
char *dash;
|
||||
unsigned lo, hi;
|
||||
|
||||
dash = strchr(opt_i_str, '-');
|
||||
if (!dash) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
*dash = '\0';
|
||||
lo = xatou(opt_i_str);
|
||||
hi = xatou(dash + 1);
|
||||
*dash = '-';
|
||||
if (hi < lo) {
|
||||
bb_error_msg_and_die("bad range '%s'", opt_i_str);
|
||||
}
|
||||
|
||||
numlines = (hi+1) - lo;
|
||||
lines = xmalloc(numlines * sizeof(lines[0]));
|
||||
for (i = 0; i < numlines; i++) {
|
||||
lines[i] = (char*)(uintptr_t)lo;
|
||||
lo++;
|
||||
}
|
||||
} else {
|
||||
/* default - read lines from stdin or the input file */
|
||||
FILE *fp;
|
||||
|
||||
if (argc > 1)
|
||||
bb_show_usage();
|
||||
|
||||
fp = xfopen_stdin(argv[0] ? argv[0] : "-");
|
||||
lines = NULL;
|
||||
numlines = 0;
|
||||
for (;;) {
|
||||
char *line = xmalloc_fgetline(fp);
|
||||
if (!line)
|
||||
break;
|
||||
lines = xrealloc_vector(lines, 6, numlines);
|
||||
lines[numlines++] = line;
|
||||
}
|
||||
fclose_if_not_stdin(fp);
|
||||
}
|
||||
|
||||
if (numlines != 0)
|
||||
shuffle_lines(lines, numlines);
|
||||
|
||||
if (opts & OPT_o)
|
||||
xmove_fd(xopen(opt_o_str, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
|
||||
if (opts & OPT_n) {
|
||||
unsigned maxlines;
|
||||
maxlines = xatou(opt_n_str);
|
||||
if (numlines > maxlines)
|
||||
numlines = maxlines;
|
||||
}
|
||||
|
||||
eol = '\n';
|
||||
if (opts & OPT_z)
|
||||
eol = '\0';
|
||||
|
||||
for (i = 0; i < numlines; i++) {
|
||||
if (opts & OPT_i)
|
||||
printf("%u%c", (unsigned)(uintptr_t)lines[i], eol);
|
||||
else
|
||||
printf("%s%c", lines[i], eol);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+37
-63
@@ -14,25 +14,25 @@
|
||||
|
||||
//usage:#define sort_trivial_usage
|
||||
//usage: "[-nru"
|
||||
//usage: IF_FEATURE_SORT_BIG("gMcszbdfiokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
|
||||
//usage: IF_FEATURE_SORT_BIG("gMcszbdfimSTokt] [-o FILE] [-k start[.offset][opts][,end[.offset][opts]] [-t CHAR")
|
||||
//usage: "] [FILE]..."
|
||||
//usage:#define sort_full_usage "\n\n"
|
||||
//usage: "Sort lines of text\n"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
//usage: "\n -o FILE Output to FILE"
|
||||
//usage: "\n -c Check whether input is sorted"
|
||||
//usage: "\n -b Ignore leading blanks"
|
||||
//usage: "\n -f Ignore case"
|
||||
//usage: "\n -i Ignore unprintable characters"
|
||||
//usage: "\n -c Check whether input is sorted"
|
||||
//usage: "\n -d Dictionary order (blank or alphanumeric only)"
|
||||
//usage: "\n -f Ignore case"
|
||||
//usage: "\n -g General numerical sort"
|
||||
//usage: "\n -i Ignore unprintable characters"
|
||||
//usage: "\n -k Sort key"
|
||||
//usage: "\n -M Sort month"
|
||||
//usage: )
|
||||
//-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G)
|
||||
//usage: "\n -n Sort numbers"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
//usage: "\n -t CHAR Field separator"
|
||||
//usage: "\n -k N[,M] Sort by Nth field"
|
||||
//usage: "\n -o Output to file"
|
||||
//usage: "\n -k Sort by key"
|
||||
//usage: "\n -t CHAR Key separator"
|
||||
//usage: )
|
||||
//usage: "\n -r Reverse sort order"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
@@ -41,10 +41,7 @@
|
||||
//usage: "\n -u Suppress duplicate lines"
|
||||
//usage: IF_FEATURE_SORT_BIG(
|
||||
//usage: "\n -z Lines are terminated by NUL, not newline"
|
||||
////usage: "\n -m Ignored for GNU compatibility"
|
||||
////usage: "\n -S BUFSZ Ignored for GNU compatibility"
|
||||
////usage: "\n -T TMPDIR Ignored for GNU compatibility"
|
||||
//usage: )
|
||||
//usage: "\n -mST Ignored for GNU compatibility")
|
||||
//usage:
|
||||
//usage:#define sort_example_usage
|
||||
//usage: "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n"
|
||||
@@ -109,9 +106,7 @@ static struct sort_key {
|
||||
|
||||
static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
{
|
||||
int start = start; /* for compiler */
|
||||
int end;
|
||||
int len, j;
|
||||
int start = 0, end = 0, len, j;
|
||||
unsigned i;
|
||||
|
||||
/* Special case whole string, so we don't have to make a copy */
|
||||
@@ -128,15 +123,12 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
end = len;
|
||||
/* Loop through fields */
|
||||
else {
|
||||
unsigned char ch = 0;
|
||||
|
||||
end = 0;
|
||||
for (i = 1; i < key->range[2*j] + j; i++) {
|
||||
if (key_separator) {
|
||||
/* Skip body of key and separator */
|
||||
while ((ch = str[end]) != '\0') {
|
||||
end++;
|
||||
if (ch == key_separator)
|
||||
while (str[end]) {
|
||||
if (str[end++] == key_separator)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@@ -144,44 +136,34 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
while (isspace(str[end]))
|
||||
end++;
|
||||
/* Skip body of key */
|
||||
while (str[end] != '\0') {
|
||||
while (str[end]) {
|
||||
if (isspace(str[end]))
|
||||
break;
|
||||
end++;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Remove last delim: "abc:def:" => "abc:def" */
|
||||
if (j && ch) {
|
||||
//if (str[end-1] != key_separator)
|
||||
// bb_error_msg(_and_die("BUG! "
|
||||
// "str[start:%d,end:%d]:'%.*s'",
|
||||
// start, end, (int)(end-start), &str[start]);
|
||||
end--;
|
||||
}
|
||||
}
|
||||
if (!j) start = end;
|
||||
}
|
||||
/* Strip leading whitespace if necessary */
|
||||
//XXX: skip_whitespace()
|
||||
if (flags & FLAG_b)
|
||||
/* not using skip_whitespace() for speed */
|
||||
while (isspace(str[start])) start++;
|
||||
/* Strip trailing whitespace if necessary */
|
||||
if (flags & FLAG_bb)
|
||||
while (end > start && isspace(str[end-1])) end--;
|
||||
/* -kSTART,N.ENDCHAR: honor ENDCHAR (1-based) */
|
||||
/* Handle offsets on start and end */
|
||||
if (key->range[3]) {
|
||||
end = key->range[3];
|
||||
end += key->range[3] - 1;
|
||||
if (end > len) end = len;
|
||||
}
|
||||
/* -kN.STARTCHAR[,...]: honor STARTCHAR (1-based) */
|
||||
if (key->range[1]) {
|
||||
start += key->range[1] - 1;
|
||||
if (start > len) start = len;
|
||||
}
|
||||
/* Make the copy */
|
||||
if (end < start)
|
||||
end = start;
|
||||
if (end < start) end = start;
|
||||
str = xstrndup(str+start, end-start);
|
||||
/* Handle -d */
|
||||
if (flags & FLAG_d) {
|
||||
@@ -243,7 +225,7 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
y = *(char **)yarg;
|
||||
#endif
|
||||
/* Perform actual comparison */
|
||||
switch (flags & (FLAG_n | FLAG_M | FLAG_g)) {
|
||||
switch (flags & 7) {
|
||||
default:
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
break;
|
||||
@@ -295,7 +277,7 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
else if (!yy)
|
||||
retval = 1;
|
||||
else
|
||||
retval = dx - thyme.tm_mon;
|
||||
retval = (dx == thyme.tm_mon) ? 0 : dx - thyme.tm_mon;
|
||||
break;
|
||||
}
|
||||
/* Full floating point version of -n */
|
||||
@@ -320,14 +302,10 @@ static int compare_keys(const void *xarg, const void *yarg)
|
||||
} /* for */
|
||||
|
||||
/* Perform fallback sort if necessary */
|
||||
if (!retval && !(option_mask32 & FLAG_s)) {
|
||||
flags = option_mask32;
|
||||
if (!retval && !(option_mask32 & FLAG_s))
|
||||
retval = strcmp(*(char **)xarg, *(char **)yarg);
|
||||
}
|
||||
|
||||
if (flags & FLAG_r)
|
||||
return -retval;
|
||||
|
||||
if (flags & FLAG_r) return -retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -350,7 +328,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *line, **lines;
|
||||
char *str_ignored, *str_o, *str_t;
|
||||
llist_t *lst_k = NULL;
|
||||
int i;
|
||||
int i, flag;
|
||||
int linecount;
|
||||
unsigned opts;
|
||||
|
||||
@@ -373,7 +351,7 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* note: below this point we use option_mask32, not opts,
|
||||
* since that reduces register pressure and makes code smaller */
|
||||
|
||||
/* Parse sort key */
|
||||
/* parse sort key */
|
||||
while (lst_k) {
|
||||
enum {
|
||||
FLAG_allowed_for_k =
|
||||
@@ -400,18 +378,17 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
key->range[2*i+1] = str2u(&str_k);
|
||||
}
|
||||
while (*str_k) {
|
||||
int flag;
|
||||
const char *idx;
|
||||
const char *temp2;
|
||||
|
||||
if (*str_k == ',' && !i++) {
|
||||
str_k++;
|
||||
break;
|
||||
} /* no else needed: fall through to syntax error
|
||||
because comma isn't in OPT_STR */
|
||||
idx = strchr(OPT_STR, *str_k);
|
||||
if (!idx)
|
||||
temp2 = strchr(OPT_STR, *str_k);
|
||||
if (!temp2)
|
||||
bb_error_msg_and_die("unknown key option");
|
||||
flag = 1 << (idx - OPT_STR);
|
||||
flag = 1 << (temp2 - OPT_STR);
|
||||
if (flag & ~FLAG_allowed_for_k)
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
/* b after ',' means strip _trailing_ space */
|
||||
@@ -445,10 +422,10 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
} while (*++argv);
|
||||
|
||||
#if ENABLE_FEATURE_SORT_BIG
|
||||
/* If no key, perform alphabetic sort */
|
||||
/* if no key, perform alphabetic sort */
|
||||
if (!key_list)
|
||||
add_key()->range[0] = 1;
|
||||
/* Handle -c */
|
||||
/* handle -c */
|
||||
if (option_mask32 & FLAG_c) {
|
||||
int j = (option_mask32 & FLAG_u) ? -1 : 0;
|
||||
for (i = 1; i < linecount; i++) {
|
||||
@@ -462,21 +439,20 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* Perform the actual sort */
|
||||
qsort(lines, linecount, sizeof(lines[0]), compare_keys);
|
||||
|
||||
/* Handle -u */
|
||||
/* handle -u */
|
||||
if (option_mask32 & FLAG_u) {
|
||||
int j = 0;
|
||||
flag = 0;
|
||||
/* coreutils 6.3 drop lines for which only key is the same */
|
||||
/* -- disabling last-resort compare... */
|
||||
option_mask32 |= FLAG_s;
|
||||
for (i = 1; i < linecount; i++) {
|
||||
if (compare_keys(&lines[j], &lines[i]) == 0)
|
||||
if (compare_keys(&lines[flag], &lines[i]) == 0)
|
||||
free(lines[i]);
|
||||
else
|
||||
lines[++j] = lines[i];
|
||||
lines[++flag] = lines[i];
|
||||
}
|
||||
if (linecount)
|
||||
linecount = j+1;
|
||||
linecount = flag+1;
|
||||
}
|
||||
|
||||
/* Print it */
|
||||
@@ -485,11 +461,9 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (option_mask32 & FLAG_o)
|
||||
xmove_fd(xopen(str_o, O_WRONLY|O_CREAT|O_TRUNC), STDOUT_FILENO);
|
||||
#endif
|
||||
{
|
||||
int ch = (option_mask32 & FLAG_z) ? '\0' : '\n';
|
||||
for (i = 0; i < linecount; i++)
|
||||
printf("%s%c", lines[i], ch);
|
||||
}
|
||||
flag = (option_mask32 & FLAG_z) ? '\0' : '\n';
|
||||
for (i = 0; i < linecount; i++)
|
||||
printf("%s%c", lines[i], flag);
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -22,7 +22,6 @@
|
||||
//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
static const struct suffix_mult split_suffixes[] = {
|
||||
@@ -79,8 +78,6 @@ int split_main(int argc UNUSED_PARAM, char **argv)
|
||||
ssize_t bytes_read, to_write;
|
||||
char *src;
|
||||
|
||||
setup_common_bufsiz();
|
||||
|
||||
opt_complementary = "?2:a+"; /* max 2 args; -a N */
|
||||
opt = getopt32(argv, "l:b:a:", &count_p, &count_p, &suffix_len);
|
||||
|
||||
|
||||
+25
-68
@@ -12,83 +12,54 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config STAT
|
||||
//config: bool "stat"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: display file or filesystem status.
|
||||
//config:
|
||||
//config:config FEATURE_STAT_FORMAT
|
||||
//config: bool "Enable custom formats (-c)"
|
||||
//config: default y
|
||||
//config: depends on STAT
|
||||
//config: help
|
||||
//config: Without this, stat will not support the '-c format' option where
|
||||
//config: users can pass a custom format string for output. This adds about
|
||||
//config: 7k to a nonstatic build on amd64.
|
||||
//config:
|
||||
//config:config FEATURE_STAT_FILESYSTEM
|
||||
//config: bool "Enable display of filesystem status (-f)"
|
||||
//config: default y
|
||||
//config: depends on STAT
|
||||
//config: select PLATFORM_LINUX # statfs()
|
||||
//config: help
|
||||
//config: Without this, stat will not support the '-f' option to display
|
||||
//config: information about filesystem status.
|
||||
|
||||
|
||||
//usage:#define stat_trivial_usage
|
||||
//usage: "[OPTIONS] FILE..."
|
||||
//usage:#define stat_full_usage "\n\n"
|
||||
//usage: "Display file"
|
||||
//usage: IF_FEATURE_STAT_FILESYSTEM(" (default) or filesystem")
|
||||
//usage: " status\n"
|
||||
//usage: "Display file (default) or filesystem status\n"
|
||||
//usage: IF_FEATURE_STAT_FORMAT(
|
||||
//usage: "\n -c FMT Use the specified format"
|
||||
//usage: "\n -c fmt Use the specified format"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_STAT_FILESYSTEM(
|
||||
//usage: "\n -f Display filesystem status"
|
||||
//usage: )
|
||||
//usage: "\n -L Follow links"
|
||||
//usage: "\n -t Terse display"
|
||||
//usage: "\n -t Display info in terse form"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: "\n -Z Print security context"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_STAT_FORMAT(
|
||||
//usage: "\n\nFMT sequences"IF_FEATURE_STAT_FILESYSTEM(" for files")":\n"
|
||||
//usage: "\n\nValid format sequences for files:\n"
|
||||
//usage: " %a Access rights in octal\n"
|
||||
//usage: " %A Access rights in human readable form\n"
|
||||
//usage: " %b Number of blocks allocated (see %B)\n"
|
||||
//usage: " %B Size in bytes of each block reported by %b\n"
|
||||
//usage: " %B The size in bytes of each block reported by %b\n"
|
||||
//usage: " %d Device number in decimal\n"
|
||||
//usage: " %D Device number in hex\n"
|
||||
//usage: " %f Raw mode in hex\n"
|
||||
//usage: " %F File type\n"
|
||||
//usage: " %g Group ID\n"
|
||||
//usage: " %G Group name\n"
|
||||
//usage: " %g Group ID of owner\n"
|
||||
//usage: " %G Group name of owner\n"
|
||||
//usage: " %h Number of hard links\n"
|
||||
//usage: " %i Inode number\n"
|
||||
//usage: " %n File name\n"
|
||||
//usage: " %N File name, with -> TARGET if symlink\n"
|
||||
//usage: " %o I/O block size\n"
|
||||
//usage: " %s Total size in bytes\n"
|
||||
//usage: " %s Total size, in bytes\n"
|
||||
//usage: " %t Major device type in hex\n"
|
||||
//usage: " %T Minor device type in hex\n"
|
||||
//usage: " %u User ID\n"
|
||||
//usage: " %U User name\n"
|
||||
//usage: " %u User ID of owner\n"
|
||||
//usage: " %U User name of owner\n"
|
||||
//usage: " %x Time of last access\n"
|
||||
//usage: " %X Time of last access as seconds since Epoch\n"
|
||||
//usage: " %y Time of last modification\n"
|
||||
//usage: " %Y Time of last modification as seconds since Epoch\n"
|
||||
//usage: " %z Time of last change\n"
|
||||
//usage: " %Z Time of last change as seconds since Epoch\n"
|
||||
//usage: IF_FEATURE_STAT_FILESYSTEM(
|
||||
//usage: "\nFMT sequences for file systems:\n"
|
||||
//usage: "\nValid format sequences for file systems:\n"
|
||||
//usage: " %a Free blocks available to non-superuser\n"
|
||||
//usage: " %b Total data blocks\n"
|
||||
//usage: " %c Total file nodes\n"
|
||||
//usage: " %d Free file nodes\n"
|
||||
//usage: " %f Free blocks\n"
|
||||
//usage: " %b Total data blocks in file system\n"
|
||||
//usage: " %c Total file nodes in file system\n"
|
||||
//usage: " %d Free file nodes in file system\n"
|
||||
//usage: " %f Free blocks in file system\n"
|
||||
//usage: IF_SELINUX(
|
||||
//usage: " %C Security context in selinux\n"
|
||||
//usage: )
|
||||
@@ -100,17 +71,13 @@
|
||||
//usage: " %t Type in hex\n"
|
||||
//usage: " %T Type in human readable form"
|
||||
//usage: )
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
enum {
|
||||
OPT_TERSE = (1 << 0),
|
||||
OPT_DEREFERENCE = (1 << 1),
|
||||
OPT_FILESYS = (1 << 2) * ENABLE_FEATURE_STAT_FILESYSTEM,
|
||||
OPT_SELINUX = (1 << (2+ENABLE_FEATURE_STAT_FILESYSTEM)) * ENABLE_SELINUX,
|
||||
};
|
||||
#define OPT_FILESYS (1 << 0)
|
||||
#define OPT_TERSE (1 << 1)
|
||||
#define OPT_DEREFERENCE (1 << 2)
|
||||
#define OPT_SELINUX (1 << 3)
|
||||
|
||||
#if ENABLE_FEATURE_STAT_FORMAT
|
||||
typedef bool (*statfunc_ptr)(const char *, const char *);
|
||||
@@ -159,13 +126,12 @@ static const char *human_time(time_t t)
|
||||
|
||||
/*static char buf[sizeof("YYYY-MM-DD HH:MM:SS.000000000")] ALIGN1;*/
|
||||
#define buf bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
strcpy(strftime_YYYYMMDDHHMMSS(buf, COMMON_BUFSIZE, &t), ".000000000");
|
||||
|
||||
strcpy(strftime_YYYYMMDDHHMMSS(buf, sizeof(buf), &t), ".000000000");
|
||||
return buf;
|
||||
#undef buf
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_STAT_FILESYSTEM
|
||||
/* Return the type of the specified file system.
|
||||
* Some systems have statfvs.f_basetype[FSTYPSZ]. (AIX, HP-UX, and Solaris)
|
||||
* Others have statfs.f_fstypename[MFSNAMELEN]. (NetBSD 1.5.2)
|
||||
@@ -236,7 +202,6 @@ static unsigned long long get_f_fsid(const struct statfs *statfsbuf)
|
||||
while (--sz > 0);
|
||||
return r;
|
||||
}
|
||||
#endif /* FEATURE_STAT_FILESYSTEM */
|
||||
|
||||
#if ENABLE_FEATURE_STAT_FORMAT
|
||||
static void strcatc(char *str, char c)
|
||||
@@ -252,7 +217,6 @@ static void printfs(char *pformat, const char *msg)
|
||||
printf(pformat, msg);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_STAT_FILESYSTEM
|
||||
/* print statfs info */
|
||||
static void FAST_FUNC print_statfs(char *pformat, const char m,
|
||||
const char *const filename, const void *data
|
||||
@@ -299,7 +263,6 @@ static void FAST_FUNC print_statfs(char *pformat, const char m,
|
||||
printf(pformat, m);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* print stat info */
|
||||
static void FAST_FUNC print_stat(char *pformat, const char m,
|
||||
@@ -411,7 +374,7 @@ static void print_it(const char *masterformat,
|
||||
{
|
||||
/* Create a working copy of the format string */
|
||||
char *format = xstrdup(masterformat);
|
||||
/* Add 2 to accommodate our conversion of the stat '%s' format string
|
||||
/* Add 2 to accomodate our conversion of the stat '%s' format string
|
||||
* to the printf '%llu' one. */
|
||||
char *dest = xmalloc(strlen(format) + 2 + 1);
|
||||
char *b;
|
||||
@@ -460,7 +423,6 @@ static void print_it(const char *masterformat,
|
||||
}
|
||||
#endif /* FEATURE_STAT_FORMAT */
|
||||
|
||||
#if ENABLE_FEATURE_STAT_FILESYSTEM
|
||||
/* Stat the file system and print what we find. */
|
||||
#if !ENABLE_FEATURE_STAT_FORMAT
|
||||
#define do_statfs(filename, format) do_statfs(filename)
|
||||
@@ -576,7 +538,6 @@ static bool do_statfs(const char *filename, const char *format)
|
||||
#endif /* FEATURE_STAT_FORMAT */
|
||||
return 1;
|
||||
}
|
||||
#endif /* FEATURE_STAT_FILESYSTEM */
|
||||
|
||||
/* stat the file and print what we find */
|
||||
#if !ENABLE_FEATURE_STAT_FORMAT
|
||||
@@ -694,7 +655,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
);
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" %s\n", scontext);
|
||||
printf(" %lc\n", *scontext);
|
||||
else
|
||||
bb_putchar('\n');
|
||||
# endif
|
||||
@@ -739,8 +700,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
(unsigned long) statbuf.st_gid,
|
||||
(gw_ent != NULL) ? gw_ent->gr_name : "UNKNOWN");
|
||||
# if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX)
|
||||
printf(" S_Context: %s\n", scontext);
|
||||
printf(" S_Context: %lc\n", *scontext);
|
||||
# endif
|
||||
printf("Access: %s\n", human_time(statbuf.st_atime));
|
||||
printf("Modify: %s\n", human_time(statbuf.st_mtime));
|
||||
@@ -760,15 +720,12 @@ int stat_main(int argc UNUSED_PARAM, char **argv)
|
||||
statfunc_ptr statfunc = do_stat;
|
||||
|
||||
opt_complementary = "-1"; /* min one arg */
|
||||
opts = getopt32(argv, "tL"
|
||||
IF_FEATURE_STAT_FILESYSTEM("f")
|
||||
opts = getopt32(argv, "ftL"
|
||||
IF_SELINUX("Z")
|
||||
IF_FEATURE_STAT_FORMAT("c:", &format)
|
||||
);
|
||||
#if ENABLE_FEATURE_STAT_FILESYSTEM
|
||||
if (opts & OPT_FILESYS) /* -f */
|
||||
statfunc = do_statfs;
|
||||
#endif
|
||||
#if ENABLE_SELINUX
|
||||
if (opts & OPT_SELINUX) {
|
||||
selinux_or_die();
|
||||
|
||||
+5
-6
@@ -32,7 +32,6 @@
|
||||
//usage: "\n [SETTING] See manpage"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
#ifndef _POSIX_VDISABLE
|
||||
# define _POSIX_VDISABLE ((unsigned char) 0)
|
||||
@@ -318,7 +317,7 @@ enum {
|
||||
#define MI_ENTRY(N,T,F,B,M) N "\0"
|
||||
|
||||
/* Mode names given on command line */
|
||||
static const char mode_name[] ALIGN1 =
|
||||
static const char mode_name[] =
|
||||
MI_ENTRY("evenp", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("parity", combination, REV | OMIT, 0, 0 )
|
||||
MI_ENTRY("oddp", combination, REV | OMIT, 0, 0 )
|
||||
@@ -681,7 +680,7 @@ enum {
|
||||
#define CI_ENTRY(n,s,o) n "\0"
|
||||
|
||||
/* Name given on command line */
|
||||
static const char control_name[] ALIGN1 =
|
||||
static const char control_name[] =
|
||||
CI_ENTRY("intr", CINTR, VINTR )
|
||||
CI_ENTRY("quit", CQUIT, VQUIT )
|
||||
CI_ENTRY("erase", CERASE, VERASE )
|
||||
@@ -723,7 +722,7 @@ static const char control_name[] ALIGN1 =
|
||||
#undef CI_ENTRY
|
||||
#define CI_ENTRY(n,s,o) { s, o },
|
||||
|
||||
static const struct control_info control_info[] ALIGN2 = {
|
||||
static const struct control_info control_info[] = {
|
||||
/* This should be verbatim cut-n-paste copy of the above CI_ENTRYs */
|
||||
CI_ENTRY("intr", CINTR, VINTR )
|
||||
CI_ENTRY("quit", CQUIT, VQUIT )
|
||||
@@ -776,7 +775,7 @@ struct globals {
|
||||
unsigned current_col;
|
||||
char buf[10];
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
G.device_name = bb_msg_standard_input; \
|
||||
G.max_col = 80; \
|
||||
@@ -1404,7 +1403,7 @@ int stty_main(int argc UNUSED_PARAM, char **argv)
|
||||
perror_on_device_and_die("%s");
|
||||
|
||||
if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) {
|
||||
G.max_col = get_terminal_width(STDOUT_FILENO);
|
||||
get_terminal_width_height(STDOUT_FILENO, &G.max_col, NULL);
|
||||
output_func(&mode, display_all);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
+2
-5
@@ -21,7 +21,6 @@
|
||||
//usage: "\n -s Use System V sum algorithm (512byte blocks)"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
|
||||
|
||||
@@ -31,20 +30,18 @@ enum { SUM_BSD, PRINT_NAME, SUM_SYSV };
|
||||
/* Return 1 if successful. */
|
||||
static unsigned sum_file(const char *file, unsigned type)
|
||||
{
|
||||
#define buf bb_common_bufsiz1
|
||||
unsigned long long total_bytes = 0;
|
||||
int fd, r;
|
||||
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
|
||||
unsigned s = 0;
|
||||
|
||||
#define buf bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
|
||||
fd = open_or_warn_stdin(file);
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
|
||||
while (1) {
|
||||
size_t bytes_read = safe_read(fd, buf, COMMON_BUFSIZE);
|
||||
size_t bytes_read = safe_read(fd, buf, BUFSIZ);
|
||||
|
||||
if ((ssize_t)bytes_read <= 0) {
|
||||
r = (fd && close(fd) != 0);
|
||||
|
||||
+3
-75
@@ -3,39 +3,16 @@
|
||||
* Mini sync implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
* Copyright (C) 2015 by Ari Sundholm <ari@tuxera.com>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||
//config:config SYNC
|
||||
//config: bool "sync"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: sync is used to flush filesystem buffers.
|
||||
//config:config FEATURE_SYNC_FANCY
|
||||
//config: bool "Enable -d and -f flags (requres syncfs(2) in libc)"
|
||||
//config: default y
|
||||
//config: depends on SYNC
|
||||
//config: help
|
||||
//config: sync -d FILE... executes fdatasync() on each FILE.
|
||||
//config: sync -f FILE... executes syncfs() on each FILE.
|
||||
|
||||
//kbuild:lib-$(CONFIG_SYNC) += sync.o
|
||||
//applet:IF_SYNC(APPLET_NOFORK(sync, sync, BB_DIR_BIN, BB_SUID_DROP, sync))
|
||||
|
||||
//usage:#define sync_trivial_usage
|
||||
//usage: ""IF_FEATURE_SYNC_FANCY("[-df] [FILE]...")
|
||||
//usage: ""
|
||||
//usage:#define sync_full_usage "\n\n"
|
||||
//usage: IF_NOT_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks to disk"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_SYNC_FANCY(
|
||||
//usage: "Write all buffered blocks (in FILEs) to disk"
|
||||
//usage: "\n -d Avoid syncing metadata"
|
||||
//usage: "\n -f Sync filesystems underlying FILEs"
|
||||
//usage: )
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
@@ -44,59 +21,10 @@
|
||||
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
||||
{
|
||||
#if !ENABLE_FEATURE_SYNC_FANCY
|
||||
/* coreutils-6.9 compat */
|
||||
bb_warn_ignoring_args(argv[1]);
|
||||
|
||||
sync();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
#else
|
||||
unsigned opts;
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
enum {
|
||||
OPT_DATASYNC = (1 << 0),
|
||||
OPT_SYNCFS = (1 << 1),
|
||||
};
|
||||
|
||||
opt_complementary = "d--f:f--d";
|
||||
opts = getopt32(argv, "df");
|
||||
argv += optind;
|
||||
|
||||
/* Handle the no-argument case. */
|
||||
if (!argv[0])
|
||||
sync();
|
||||
|
||||
while (*argv) {
|
||||
int fd = open_or_warn(*argv, O_RDONLY);
|
||||
|
||||
if (fd < 0) {
|
||||
ret = EXIT_FAILURE;
|
||||
goto next;
|
||||
}
|
||||
if (opts & OPT_DATASYNC) {
|
||||
if (fdatasync(fd))
|
||||
goto err;
|
||||
goto do_close;
|
||||
}
|
||||
if (opts & OPT_SYNCFS) {
|
||||
/*
|
||||
* syncfs is documented to only fail with EBADF,
|
||||
* which can't happen here. So, no error checks.
|
||||
*/
|
||||
syncfs(fd);
|
||||
goto do_close;
|
||||
}
|
||||
if (fsync(fd)) {
|
||||
err:
|
||||
bb_simple_perror_msg(*argv);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
do_close:
|
||||
close(fd);
|
||||
next:
|
||||
++argv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
+6
-6
@@ -32,14 +32,15 @@
|
||||
//usage: "Print last 10 lines of each FILE (or stdin) to stdout.\n"
|
||||
//usage: "With more than one FILE, precede each with a filename header.\n"
|
||||
//usage: "\n -f Print data as file grows"
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: )
|
||||
//usage: "\n -n N[kbm] Print last N lines"
|
||||
//usage: "\n -n +N[kbm] Start on Nth line and print the rest"
|
||||
//usage: IF_FEATURE_FANCY_TAIL(
|
||||
//usage: "\n -c [+]N[kbm] Print last N bytes"
|
||||
//usage: "\n -q Never print headers"
|
||||
//usage: "\n -s SECONDS Wait SECONDS between reads with -f"
|
||||
//usage: "\n -v Always print headers"
|
||||
//usage: "\n -F Same as -f, but keep retrying"
|
||||
//usage: "\n"
|
||||
//usage: "\nN may be suffixed by k (x1024), b (x512), or m (x1024^2)."
|
||||
//usage: )
|
||||
@@ -49,14 +50,13 @@
|
||||
//usage: "nameserver 10.0.0.1\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
struct globals {
|
||||
bool from_top;
|
||||
bool exitcode;
|
||||
} FIX_ALIASING;
|
||||
#define G (*(struct globals*)bb_common_bufsiz1)
|
||||
#define INIT_G() do { setup_common_bufsiz(); } while (0)
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { } while (0)
|
||||
|
||||
static void tail_xprint_header(const char *fmt, const char *filename)
|
||||
{
|
||||
|
||||
+1
-3
@@ -23,7 +23,6 @@
|
||||
//usage: "Hello\n"
|
||||
|
||||
#include "libbb.h"
|
||||
#include "common_bufsiz.h"
|
||||
|
||||
int tee_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int tee_main(int argc, char **argv)
|
||||
@@ -38,7 +37,6 @@ int tee_main(int argc, char **argv)
|
||||
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
|
||||
ssize_t c;
|
||||
# define buf bb_common_bufsiz1
|
||||
setup_common_bufsiz();
|
||||
#else
|
||||
int c;
|
||||
#endif
|
||||
@@ -81,7 +79,7 @@ int tee_main(int argc, char **argv)
|
||||
/* names[0] will be filled later */
|
||||
|
||||
#if ENABLE_FEATURE_TEE_USE_BLOCK_IO
|
||||
while ((c = safe_read(STDIN_FILENO, buf, COMMON_BUFSIZE)) > 0) {
|
||||
while ((c = safe_read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
|
||||
fp = files;
|
||||
do
|
||||
fwrite(buf, 1, c, *fp);
|
||||
|
||||
+42
-38
@@ -39,9 +39,14 @@
|
||||
//config: help
|
||||
//config: Enable 64-bit support in test.
|
||||
|
||||
/* "test --help" is special-cased to ignore --help */
|
||||
//usage:#define test_trivial_usage NOUSAGE_STR
|
||||
//usage:#define test_full_usage ""
|
||||
/* "test --help" does not print help (POSIX compat), only "[ --help" does.
|
||||
* We display "<applet> EXPRESSION ]" here (not "<applet> EXPRESSION")
|
||||
* Unfortunately, it screws up generated BusyBox.html. TODO. */
|
||||
//usage:#define test_trivial_usage
|
||||
//usage: "EXPRESSION ]"
|
||||
//usage:#define test_full_usage "\n\n"
|
||||
//usage: "Check file types, compare values etc. Return a 0/1 exit code\n"
|
||||
//usage: "depending on logical value of EXPRESSION"
|
||||
//usage:
|
||||
//usage:#define test_example_usage
|
||||
//usage: "$ test 1 -eq 2\n"
|
||||
@@ -821,6 +826,7 @@ int test_main(int argc, char **argv)
|
||||
{
|
||||
int res;
|
||||
const char *arg0;
|
||||
// bool negate = 0;
|
||||
|
||||
arg0 = bb_basename(argv[0]);
|
||||
if (arg0[0] == '[') {
|
||||
@@ -838,7 +844,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
/* argc is unused after this point */
|
||||
|
||||
/* We must do DEINIT_S() prior to returning */
|
||||
INIT_S();
|
||||
@@ -857,45 +862,43 @@ int test_main(int argc, char **argv)
|
||||
*/
|
||||
/*ngroups = 0; - done by INIT_S() */
|
||||
|
||||
//argc--;
|
||||
argv++;
|
||||
args = argv;
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4.
|
||||
* Testcase: "test '(' = '('"
|
||||
* The general parser would misinterpret '(' as group start.
|
||||
*/
|
||||
if (1) {
|
||||
int negate = 0;
|
||||
again:
|
||||
if (!argv[0]) {
|
||||
/* "test" */
|
||||
res = 1;
|
||||
goto ret_special;
|
||||
}
|
||||
if (!argv[1]) {
|
||||
/* "test [!] arg" */
|
||||
res = (argv[0][0] == '\0');
|
||||
goto ret_special;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
ret_special:
|
||||
/* If there was leading "!" op... */
|
||||
res ^= negate;
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
if (LONE_CHAR(argv[0], '!')) {
|
||||
argv++;
|
||||
negate ^= 1;
|
||||
goto again;
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
if (!argv[0]) { /* "test" */
|
||||
res = 1;
|
||||
goto ret;
|
||||
}
|
||||
#if 0
|
||||
// Now it's fixed in the parser and should not be needed
|
||||
if (LONE_CHAR(argv[0], '!') && argv[1]) {
|
||||
negate = 1;
|
||||
//argc--;
|
||||
argv++;
|
||||
}
|
||||
if (!argv[1]) { /* "test [!] arg" */
|
||||
res = (*argv[0] == '\0');
|
||||
goto ret;
|
||||
}
|
||||
if (argv[2] && !argv[3]) {
|
||||
check_operator(argv[1]);
|
||||
if (last_operator->op_type == BINOP) {
|
||||
/* "test [!] arg1 <binary_op> arg2" */
|
||||
args = argv;
|
||||
res = (binop() == 0);
|
||||
goto ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Some complex expression. Undo '!' removal */
|
||||
if (negate) {
|
||||
negate = 0;
|
||||
//argc++;
|
||||
argv--;
|
||||
}
|
||||
#endif
|
||||
args = argv;
|
||||
res = !oexpr(check_operator(*args));
|
||||
|
||||
if (*args != NULL && *++args != NULL) {
|
||||
@@ -908,5 +911,6 @@ int test_main(int argc, char **argv)
|
||||
}
|
||||
ret:
|
||||
DEINIT_S();
|
||||
// return negate ? !res : res;
|
||||
return res;
|
||||
}
|
||||
+5
-18
@@ -91,6 +91,7 @@ static void map(char *pvector,
|
||||
* Character classes, e.g. [:upper:] ==> A...Z
|
||||
* Equiv classess, e.g. [=A=] ==> A (hmmmmmmm?)
|
||||
* not supported:
|
||||
* \ooo-\ooo - octal ranges
|
||||
* [x*N] - repeat char x N times
|
||||
* [x*] - repeat char x until it fills STRING2:
|
||||
* # echo qwe123 | /usr/bin/tr 123456789 '[d]'
|
||||
@@ -98,7 +99,7 @@ static void map(char *pvector,
|
||||
* # echo qwe123 | /usr/bin/tr 123456789 '[d*]'
|
||||
* qweddd
|
||||
*/
|
||||
static unsigned expand(char *arg, char **buffer_p)
|
||||
static unsigned expand(const char *arg, char **buffer_p)
|
||||
{
|
||||
char *buffer = *buffer_p;
|
||||
unsigned pos = 0;
|
||||
@@ -112,17 +113,9 @@ static unsigned expand(char *arg, char **buffer_p)
|
||||
*buffer_p = buffer = xrealloc(buffer, size);
|
||||
}
|
||||
if (*arg == '\\') {
|
||||
const char *z;
|
||||
arg++;
|
||||
z = arg;
|
||||
ac = bb_process_escape_sequence(&z);
|
||||
arg = (char *)z;
|
||||
arg--;
|
||||
*arg = ac;
|
||||
/*
|
||||
* fall through, there may be a range.
|
||||
* If not, current char will be treated anyway.
|
||||
*/
|
||||
buffer[pos++] = bb_process_escape_sequence(&arg);
|
||||
continue;
|
||||
}
|
||||
if (arg[1] == '-') { /* "0-9..." */
|
||||
ac = arg[2];
|
||||
@@ -131,15 +124,9 @@ static unsigned expand(char *arg, char **buffer_p)
|
||||
continue; /* next iter will copy '-' and stop */
|
||||
}
|
||||
i = (unsigned char) *arg;
|
||||
arg += 3; /* skip 0-9 or 0-\ */
|
||||
if (ac == '\\') {
|
||||
const char *z;
|
||||
z = arg;
|
||||
ac = bb_process_escape_sequence(&z);
|
||||
arg = (char *)z;
|
||||
}
|
||||
while (i <= ac) /* ok: i is unsigned _int_ */
|
||||
buffer[pos++] = i++;
|
||||
arg += 3; /* skip 0-9 */
|
||||
continue;
|
||||
}
|
||||
if ((ENABLE_FEATURE_TR_CLASSES || ENABLE_FEATURE_TR_EQUIV)
|
||||
|
||||
+5
-3
@@ -10,9 +10,11 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/true.html */
|
||||
|
||||
/* "true --help" is special-cased to ignore --help */
|
||||
//usage:#define true_trivial_usage NOUSAGE_STR
|
||||
//usage:#define true_full_usage ""
|
||||
//usage:#define true_trivial_usage
|
||||
//usage: ""
|
||||
//usage:#define true_full_usage "\n\n"
|
||||
//usage: "Return an exit code of TRUE (0)"
|
||||
//usage:
|
||||
//usage:#define true_example_usage
|
||||
//usage: "$ true\n"
|
||||
//usage: "$ echo $?\n"
|
||||
|
||||
Loaded 100 of 759 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user