Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
509f987e16 | ||
|
|
d591256a5c | ||
|
|
adb69765e5 | ||
|
|
70baf859a6 | ||
|
|
2c5ceb6065 | ||
|
|
e04a38c0c9 | ||
|
|
78ee8fc3e4 | ||
|
|
08cbe510dd | ||
|
|
af874cc63e | ||
|
|
b1aa377a3f | ||
|
|
2afdcc77cc | ||
|
|
c74f1d2cb4 | ||
|
|
62b7083c13 | ||
|
|
39bf15ba3e | ||
|
|
37277a23fe | ||
|
|
e3821088af | ||
|
|
4a80eb142a | ||
|
|
1574aff942 | ||
|
|
f5b9a22678 | ||
|
|
1123922320 | ||
|
|
ce5ba9277b | ||
|
|
20f02c3c87 | ||
|
|
277636670c | ||
|
|
4e71661e3a | ||
|
|
59675c625d |
No files matched your search
-11
@@ -50,14 +50,3 @@ cscope.files
|
||||
cscope.in.out
|
||||
cscope.out
|
||||
cscope.po.out
|
||||
|
||||
#
|
||||
# ctags output
|
||||
#
|
||||
tags
|
||||
TAGS
|
||||
|
||||
#
|
||||
# user-supplied scripts
|
||||
#
|
||||
/embed
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
mainmenu "Configuration"
|
||||
@@ -178,11 +178,6 @@ config BUSYBOX
|
||||
|
||||
Running "busybox APPLET [ARGS...]" will still work, of course.
|
||||
|
||||
config FEATURE_SHOW_SCRIPT
|
||||
bool "Support --show SCRIPT"
|
||||
default y
|
||||
depends on BUSYBOX
|
||||
|
||||
config FEATURE_INSTALLER
|
||||
bool "Support --install [-s] to install applet links at runtime"
|
||||
default y
|
||||
@@ -523,14 +518,6 @@ config USE_PORTABLE_CODE
|
||||
compiler other than gcc.
|
||||
If you do use gcc, this option may needlessly increase code size.
|
||||
|
||||
config STACK_OPTIMIZATION_386
|
||||
bool "Use -mpreferred-stack-boundary=2 on i386 arch"
|
||||
default y
|
||||
help
|
||||
This option makes for smaller code, but some libc versions
|
||||
do not work with it (they use SSE instructions without
|
||||
ensuring stack alignment).
|
||||
|
||||
comment 'Installation Options ("make install" behavior)'
|
||||
|
||||
choice
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 30
|
||||
SUBLEVEL = 1
|
||||
PATCHLEVEL = 28
|
||||
SUBLEVEL = 4
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -361,14 +361,14 @@ scripts/basic/%: scripts_basic ;
|
||||
|
||||
# This target generates Kbuild's and Config.in's from *.c files
|
||||
PHONY += gen_build_files
|
||||
gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c) $(wildcard $(srctree)/embed/*)
|
||||
gen_build_files: $(wildcard $(srctree)/*/*.c) $(wildcard $(srctree)/*/*/*.c)
|
||||
$(Q)$(srctree)/scripts/gen_build_files.sh $(srctree) $(objtree)
|
||||
|
||||
# bbox: we have helpers in applets/
|
||||
# we depend on scripts_basic, since scripts/basic/fixdep
|
||||
# must be built before any other host prog
|
||||
PHONY += applets_dir
|
||||
applets_dir: scripts_basic gen_build_files include/config/MARKER
|
||||
applets_dir: scripts_basic gen_build_files
|
||||
$(Q)$(MAKE) $(build)=applets
|
||||
|
||||
applets/%: applets_dir ;
|
||||
@@ -850,14 +850,11 @@ 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
|
||||
quiet_cmd_gen_embedded_scripts = GEN include/embedded_scripts.h
|
||||
cmd_gen_embedded_scripts = $(srctree)/scripts/embedded_scripts include/embedded_scripts.h $(srctree)/embed $(srctree)/applets_sh
|
||||
#bbox# piggybacked generation of few .h files
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h $(wildcard $(srctree)/embed/*) $(wildcard $(srctree)/applets_sh/*) $(srctree)/scripts/embedded_scripts
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h
|
||||
$(call cmd,split_autoconf)
|
||||
$(call cmd,gen_bbconfigopts)
|
||||
$(call cmd,gen_common_bufsiz)
|
||||
$(call cmd,gen_embedded_scripts)
|
||||
@touch $@
|
||||
|
||||
# Generate some files
|
||||
@@ -977,7 +974,6 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
|
||||
include/autoconf.h \
|
||||
include/bbconfigopts.h \
|
||||
include/bbconfigopts_bz2.h \
|
||||
include/embedded_scripts.h \
|
||||
include/usage_compressed.h \
|
||||
include/applet_tables.h \
|
||||
include/applets.h \
|
||||
|
||||
@@ -11,9 +11,6 @@ busybox.cfg.nosuid: $(srctree)/applets/busybox.mksuid $(objtree)/include/autocon
|
||||
$(Q)-SUID="DROP" $(SHELL) $^ > $@
|
||||
|
||||
.PHONY: install
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_DONT),y)
|
||||
INSTALL_OPTS:= --none
|
||||
endif
|
||||
ifeq ($(CONFIG_INSTALL_APPLET_SYMLINKS),y)
|
||||
INSTALL_OPTS:= --symlinks
|
||||
endif
|
||||
@@ -49,9 +46,6 @@ ifeq ($(strip $(CONFIG_FEATURE_SUID)),y)
|
||||
@echo
|
||||
endif
|
||||
|
||||
install-noclobber: INSTALL_OPTS+=--noclobber
|
||||
install-noclobber: install
|
||||
|
||||
uninstall: busybox.links
|
||||
rm -f $(CONFIG_PREFIX)/bin/busybox
|
||||
for i in `cat busybox.links` ; do rm -f $(CONFIG_PREFIX)$$i; done
|
||||
|
||||
@@ -156,10 +156,6 @@ CPPFLAGS += $(SELINUX_CFLAGS)
|
||||
LDLIBS += $(if $(SELINUX_LIBS),$(SELINUX_LIBS:-l%=%),$(SELINUX_PC_MODULES:lib%=%))
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FEATURE_NSLOOKUP_BIG),y)
|
||||
LDLIBS += resolv
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
LDLIBS += efence
|
||||
endif
|
||||
|
||||
+3
-3
@@ -72,7 +72,7 @@ brctl - noexec
|
||||
bunzip2 - runner
|
||||
bzcat - runner
|
||||
bzip2 - runner
|
||||
cal - noexec. can be runner: cal -n9999
|
||||
cal - runner: cal -n9999
|
||||
cat - runner: cat HUGEFILE
|
||||
chat - longterm (when used as intended - talking to modem over stdin/out)
|
||||
chattr - noexec. runner
|
||||
@@ -89,7 +89,7 @@ clear - NOFORK
|
||||
cmp - runner
|
||||
comm - runner
|
||||
conspy - interactive, longterm
|
||||
cp - noexec. sometimes runner
|
||||
cp - noexec. runner
|
||||
cpio - runner
|
||||
crond - daemon
|
||||
crontab - longterm (runs $EDITOR), leaks: open+xasprintf
|
||||
@@ -255,7 +255,7 @@ mount - suid
|
||||
mountpoint - noexec. leaks: option -n "print dev name": find_block_device -> readdir+xstrdup
|
||||
mpstat - longterm: "mpstat 1" runs indefinitely
|
||||
mt - hardware
|
||||
mv - noexec. sometimes runner
|
||||
mv - noexec candidate, runner
|
||||
nameif - noexec. openlog(), leaks: config_open2+ioctl_or_perror_and_die
|
||||
nbd-client - noexec
|
||||
nc - runner
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec >NOFORK_NOEXEC.lst1
|
||||
|
||||
false && grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
|
||||
| grep -v 'noexec.' | grep -v 'noexec$' \
|
||||
| grep -v ' suid' \
|
||||
| grep -v ' daemon' \
|
||||
| grep -v ' longterm' \
|
||||
| grep rare
|
||||
|
||||
echo === nofork candidate
|
||||
grep -F 'nofork candidate' NOFORK_NOEXEC.lst \
|
||||
|
||||
echo === noexec candidate
|
||||
grep -F 'noexec candidate' NOFORK_NOEXEC.lst \
|
||||
|
||||
echo === ^C
|
||||
grep -F '^C' NOFORK_NOEXEC.lst \
|
||||
| grep -F ' - ' \
|
||||
|
||||
echo === talks
|
||||
grep -F 'talks' NOFORK_NOEXEC.lst \
|
||||
| grep -F ' - ' \
|
||||
|
||||
echo ===
|
||||
grep -Fv 'NOFORK' NOFORK_NOEXEC.lst \
|
||||
| grep '^[^ ][^ ]* - ' \
|
||||
| grep -v 'noexec.' | grep -v ' - noexec$' \
|
||||
| grep -v ' suid' \
|
||||
| grep -v ' daemon' \
|
||||
| grep -v 'longterm' \
|
||||
| grep -v 'interactive' \
|
||||
| grep -v 'hardware' \
|
||||
+3
-23
@@ -10,7 +10,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@@ -62,7 +61,6 @@ static int str_isalnum_(const char *s)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
char tmp1[PATH_MAX], tmp2[PATH_MAX];
|
||||
|
||||
// In find_applet_by_name(), before linear search, narrow it down
|
||||
// by looking at N "equidistant" names. With ~350 applets:
|
||||
@@ -84,18 +82,9 @@ int main(int argc, char **argv)
|
||||
|
||||
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
|
||||
|
||||
for (i = j = 0; i < NUM_APPLETS-1; ++i) {
|
||||
if (cmp_name(applets+i, applets+i+1) == 0) {
|
||||
fprintf(stderr, "%s: duplicate applet name '%s'\n", argv[0],
|
||||
applets[i].name);
|
||||
j = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (j != 0 || !argv[1])
|
||||
if (!argv[1])
|
||||
return 1;
|
||||
snprintf(tmp1, PATH_MAX, "%s.%u.new", argv[1], (int) getpid());
|
||||
i = open(tmp1, O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
i = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0666);
|
||||
if (i < 0)
|
||||
return 1;
|
||||
dup2(i, 1);
|
||||
@@ -220,21 +209,12 @@ int main(int argc, char **argv)
|
||||
// fclose(fp);
|
||||
// }
|
||||
// if (strcmp(line_old, line_new) != 0) {
|
||||
snprintf(tmp2, PATH_MAX, "%s.%u.new", argv[2], (int) getpid());
|
||||
fp = fopen(tmp2, "w");
|
||||
fp = fopen(argv[2], "w");
|
||||
if (!fp)
|
||||
return 1;
|
||||
fputs(line_new, fp);
|
||||
if (fclose(fp))
|
||||
return 1;
|
||||
// }
|
||||
}
|
||||
|
||||
if (fclose(stdout))
|
||||
return 1;
|
||||
if (rename(tmp1, argv[1]))
|
||||
return 1;
|
||||
if (rename(tmp2, argv[2]))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Make busybox scripted applet list file.
|
||||
|
||||
# input $1: full path to Config.h
|
||||
# input $2: full path to applets.h
|
||||
# output (stdout): list of pathnames that should be linked to busybox
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-include/autoconf.h}
|
||||
APPLETS_H=${2:-include/applets.h}
|
||||
$HOSTCC -E -DMAKE_SCRIPTS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*SCRIPT/{
|
||||
print $2
|
||||
}'
|
||||
+32
-34
@@ -5,12 +5,9 @@ export LC_CTYPE=POSIX
|
||||
|
||||
prefix=$1
|
||||
if [ -z "$prefix" ]; then
|
||||
echo "usage: applets/install.sh DESTINATION TYPE [OPTS ...]"
|
||||
echo " TYPE is one of: --symlinks --hardlinks --binaries --scriptwrapper --none"
|
||||
echo " OPTS is one or more of: --cleanup --noclobber"
|
||||
echo "usage: applets/install.sh DESTINATION [--symlinks/--hardlinks/--binaries/--scriptwrapper]"
|
||||
exit 1
|
||||
fi
|
||||
shift # Keep only remaining options
|
||||
|
||||
# Source the configuration
|
||||
. ./.config
|
||||
@@ -24,23 +21,20 @@ scriptwrapper="n"
|
||||
binaries="n"
|
||||
cleanup="0"
|
||||
noclobber="0"
|
||||
while [ ${#} -gt 0 ]; do
|
||||
case "$1" 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";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
--none) h="";;
|
||||
*) echo "Unknown install option: $1"; exit 1;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
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";;
|
||||
--cleanup) cleanup="1";;
|
||||
--noclobber) noclobber="1";;
|
||||
"") h="";;
|
||||
*) echo "Unknown install option: $2"; exit 1;;
|
||||
esac
|
||||
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
|
||||
if [ -n "$DO_INSTALL_LIBS" ] && [ "$DO_INSTALL_LIBS" != "n" ]; then
|
||||
# get the target dir for the libs
|
||||
# assume it starts with lib
|
||||
libdir=$($CC -print-file-name=libc.so | \
|
||||
@@ -60,7 +54,7 @@ if [ -n "$DO_INSTALL_LIBS" ] && [ x"$DO_INSTALL_LIBS" != x"n" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
if [ x"$cleanup" = x"1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
||||
sub_shell_it=`
|
||||
cd "$prefix"
|
||||
@@ -83,13 +77,9 @@ install -m 755 busybox "$prefix/bin/busybox" || exit 1
|
||||
for i in $h; do
|
||||
appdir=`dirname "$i"`
|
||||
app=`basename "$i"`
|
||||
if [ x"$noclobber" = x"1" ] && ([ -e "$prefix/$i" ] || [ -h "$prefix/$i" ]); then
|
||||
echo " $prefix/$i already exists"
|
||||
continue
|
||||
fi
|
||||
mkdir -p "$prefix/$appdir" || exit 1
|
||||
if [ x"$scriptwrapper" = x"y" ]; then
|
||||
if [ x"$swrapall" != x"y" ] && [ x"$i" = x"/bin/sh" ]; then
|
||||
if [ "$scriptwrapper" = "y" ]; then
|
||||
if [ "$swrapall" != "y" ] && [ "$i" = "/bin/sh" ]; then
|
||||
ln $linkopts busybox "$prefix/$i" || exit 1
|
||||
else
|
||||
rm -f "$prefix/$i"
|
||||
@@ -97,17 +87,21 @@ for i in $h; do
|
||||
chmod +x "$prefix/$i"
|
||||
fi
|
||||
echo " $prefix/$i"
|
||||
elif [ x"$binaries" = x"y" ]; then
|
||||
elif [ "$binaries" = "y" ]; then
|
||||
# Copy the binary over rather
|
||||
if [ -e "$sharedlib_dir/$app" ]; then
|
||||
echo " Copying $sharedlib_dir/$app to $prefix/$i"
|
||||
cp -pPR "$sharedlib_dir/$app" "$prefix/$i" || exit 1
|
||||
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 [ x"$linkopts" = x"-f" ]; then
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
@@ -129,8 +123,12 @@ for i in $h; do
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo " $prefix/$i -> $bb_path"
|
||||
ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
||||
if [ "$noclobber" = "0" ] || [ ! -e "$prefix/$i" ]; then
|
||||
echo " $prefix/$i -> $bb_path"
|
||||
ln $linkopts "$bb_path" "$prefix/$i" || exit 1
|
||||
else
|
||||
echo " $prefix/$i already exists"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
This directory contains examples of applets implemented as shell scripts.
|
||||
|
||||
So far these scripts are not hooked to the build system and are not
|
||||
installed by "make install". If you want to use them,
|
||||
you need to install them by hand.
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
[ $# -ne 0 ] && DASH_I=-i
|
||||
sed $DASH_I -e 's/\r$//' "$@"
|
||||
+2
-1
@@ -1,3 +1,4 @@
|
||||
cat /etc/nologin.txt 2>/dev/null || echo This account is not available
|
||||
#!/bin/sh
|
||||
cat /etc/nologin.txt 2>/dev/null || echo "This account is not available"
|
||||
sleep 5
|
||||
exit 1
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
for i in "$@"
|
||||
do
|
||||
sed -e '1!G;h;$!d' "$i"
|
||||
done
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
# TODO: use getopt to avoid parsing options as filenames,
|
||||
# and to support -- and --help
|
||||
[ $# -ne 0 ] && DASH_I=-i
|
||||
sed $DASH_I -e 's/$/\r/' "$@"
|
||||
+1
-7
@@ -2,12 +2,6 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
# Allow i486 insns (basically, bswap insn)
|
||||
# Do not try to tune for 486+ (might add padding)
|
||||
CFLAGS += $(call cc-option,-march=i486 -mtune=i386,)
|
||||
|
||||
ifeq ($(CONFIG_STACK_OPTIMIZATION_386),y)
|
||||
# -mpreferred-stack-boundary=2 is essential in preventing gcc 4.2.x
|
||||
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
|
||||
CFLAGS += $(call cc-option,-mpreferred-stack-boundary=2,)
|
||||
endif
|
||||
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Archival Utilities"
|
||||
|
||||
+41
-28
@@ -21,6 +21,19 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
/* Note: must be kept in sync with archival/lzop.c */
|
||||
enum {
|
||||
OPT_STDOUT = 1 << 0,
|
||||
OPT_FORCE = 1 << 1,
|
||||
/* only some decompressors: */
|
||||
OPT_KEEP = 1 << 2,
|
||||
OPT_VERBOSE = 1 << 3,
|
||||
OPT_QUIET = 1 << 4,
|
||||
OPT_DECOMPRESS = 1 << 5,
|
||||
OPT_TEST = 1 << 6,
|
||||
SEAMLESS_MAGIC = (1 << 31) * ENABLE_ZCAT * SEAMLESS_COMPRESSION,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
{
|
||||
@@ -59,7 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
err_name:
|
||||
bb_simple_perror_msg(filename);
|
||||
@@ -78,15 +91,15 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
}
|
||||
} else
|
||||
if (option_mask32 & BBUNPK_SEAMLESS_MAGIC) {
|
||||
if (option_mask32 & SEAMLESS_MAGIC) {
|
||||
/* "clever zcat" on stdin */
|
||||
if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Special cases: test, stdout */
|
||||
if (option_mask32 & (BBUNPK_OPT_STDOUT|BBUNPK_OPT_TEST)) {
|
||||
if (option_mask32 & BBUNPK_OPT_TEST)
|
||||
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
||||
if (option_mask32 & OPT_TEST)
|
||||
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
||||
xfunc_die();
|
||||
filename = NULL;
|
||||
@@ -101,7 +114,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* -f: overwrite existing output files */
|
||||
if (option_mask32 & BBUNPK_OPT_FORCE) {
|
||||
if (option_mask32 & OPT_FORCE) {
|
||||
unlink(new_name);
|
||||
}
|
||||
|
||||
@@ -113,12 +126,12 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (!(option_mask32 & BBUNPK_OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
if (!(option_mask32 & OPT_FORCE) && isatty(STDIN_FILENO)) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
if (!(option_mask32 & BBUNPK_SEAMLESS_MAGIC)) {
|
||||
if (!(option_mask32 & SEAMLESS_MAGIC)) {
|
||||
init_transformer_state(&xstate);
|
||||
/*xstate.signature_skipped = 0; - already is */
|
||||
/*xstate.src_fd = STDIN_FILENO; - already is */
|
||||
@@ -132,7 +145,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
if (!(option_mask32 & BBUNPK_OPT_STDOUT))
|
||||
if (!(option_mask32 & OPT_STDOUT))
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
@@ -163,7 +176,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
/* Extreme bloat for gunzip compat */
|
||||
/* Some users do want this info... */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & BBUNPK_OPT_VERBOSE)) {
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE)) {
|
||||
unsigned percent = status
|
||||
? ((uoff_t)stat_buf.st_size * 100u / (unsigned long long)status)
|
||||
: 0;
|
||||
@@ -175,7 +188,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
/* Delete _source_ file */
|
||||
del = filename;
|
||||
if (option_mask32 & BBUNPK_OPT_KEEP) /* ... unless -k */
|
||||
if (option_mask32 & OPT_KEEP) /* ... unless -k */
|
||||
del = NULL;
|
||||
}
|
||||
if (del)
|
||||
@@ -186,7 +199,7 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
if (option_mask32 & BBUNPK_OPT_STDOUT)
|
||||
if (option_mask32 & OPT_STDOUT)
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
return exitcode;
|
||||
@@ -299,7 +312,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config GUNZIP
|
||||
//config: bool "gunzip (11 kb)"
|
||||
//config: bool "gunzip (12 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_GZIP_DECOMPRESS
|
||||
//config: help
|
||||
@@ -308,7 +321,7 @@ int uncompress_main(int argc UNUSED_PARAM, char **argv)
|
||||
//config: an archive, without decompressing it.
|
||||
//config:
|
||||
//config:config ZCAT
|
||||
//config: bool "zcat (24 kb)"
|
||||
//config: bool "zcat (25 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_GZIP_DECOMPRESS
|
||||
//config: help
|
||||
@@ -376,9 +389,9 @@ 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
|
||||
getopt32long(argv, BBUNPK_OPTSTR "dtn", gunzip_longopts);
|
||||
getopt32long(argv, "cfkvqdtn", gunzip_longopts);
|
||||
#else
|
||||
getopt32(argv, BBUNPK_OPTSTR "dtn");
|
||||
getopt32(argv, "cfkvqdtn");
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
@@ -387,7 +400,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
* But if seamless magic is enabled, then we are much more clever.
|
||||
*/
|
||||
if (ENABLE_ZCAT && (!ENABLE_GUNZIP || applet_name[1] == 'c'))
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT | BBUNPK_SEAMLESS_MAGIC;
|
||||
option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC;
|
||||
|
||||
return bbunpack(argv, unpack_gz_stream, make_new_name_gunzip, /*unused:*/ NULL);
|
||||
}
|
||||
@@ -413,7 +426,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config BUNZIP2
|
||||
//config: bool "bunzip2 (8.7 kb)"
|
||||
//config: bool "bunzip2 (8.8 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_BZIP2_DECOMPRESS
|
||||
//config: help
|
||||
@@ -427,7 +440,7 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//config: should probably say N here.
|
||||
//config:
|
||||
//config:config BZCAT
|
||||
//config: bool "bzcat (8.7 kb)"
|
||||
//config: bool "bzcat (8.8 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_BZIP2_DECOMPRESS
|
||||
//config: help
|
||||
@@ -440,10 +453,10 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
getopt32(argv, "cfkvqdt");
|
||||
argv += optind;
|
||||
if (ENABLE_BZCAT && (!ENABLE_BUNZIP2 || applet_name[2] == 'c')) /* bzcat */
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, unpack_bz2_stream, make_new_name_generic, "bz2");
|
||||
}
|
||||
@@ -481,7 +494,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//usage: "Decompress to stdout"
|
||||
|
||||
//config:config UNLZMA
|
||||
//config: bool "unlzma (7.5 kb)"
|
||||
//config: bool "unlzma (8.6 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unlzma is a compression utility using the Lempel-Ziv-Markov chain
|
||||
@@ -490,7 +503,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
//config: compressors.
|
||||
//config:
|
||||
//config:config LZCAT
|
||||
//config: bool "lzcat (7.5 kb)"
|
||||
//config: bool "lzcat (8.5 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Alias to "unlzma -c".
|
||||
@@ -513,15 +526,15 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_LZMA(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
IF_LZMA(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_LZMA
|
||||
/* lzma without -d or -t? */
|
||||
if (applet_name[2] == 'm' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
if (applet_name[2] == 'm' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* lzcat? */
|
||||
if (ENABLE_LZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_lzma_stream, make_new_name_generic, "lzma");
|
||||
@@ -581,15 +594,15 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
|
||||
int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int unxz_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_XZ(int opts =) getopt32(argv, BBUNPK_OPTSTR "dt");
|
||||
IF_XZ(int opts =) getopt32(argv, "cfkvqdt");
|
||||
# if ENABLE_XZ
|
||||
/* xz without -d or -t? */
|
||||
if (applet_name[2] == '\0' && !(opts & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)))
|
||||
if (applet_name[2] == '\0' && !(opts & (OPT_DECOMPRESS|OPT_TEST)))
|
||||
bb_show_usage();
|
||||
# endif
|
||||
/* xzcat? */
|
||||
if (ENABLE_XZCAT && applet_name[2] == 'c')
|
||||
option_mask32 |= BBUNPK_OPT_STDOUT;
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, unpack_xz_stream, make_new_name_generic, "xz");
|
||||
|
||||
+19
-43
@@ -7,7 +7,7 @@
|
||||
* about bzip2 library code.
|
||||
*/
|
||||
//config:config BZIP2
|
||||
//config: bool "bzip2 (16 kb)"
|
||||
//config: bool "bzip2 (18 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: bzip2 is a compression utility using the Burrows-Wheeler block
|
||||
@@ -19,23 +19,6 @@
|
||||
//config: Unless you have a specific application which requires bzip2, you
|
||||
//config: should probably say N here.
|
||||
//config:
|
||||
//config:config BZIP2_SMALL
|
||||
//config: int "Trade bytes for speed (0:fast, 9:small)"
|
||||
//config: default 8 # all "fast or small" options default to small
|
||||
//config: range 0 9
|
||||
//config: depends on BZIP2
|
||||
//config: help
|
||||
//config: Trade code size versus speed.
|
||||
//config: Approximate values with gcc-6.3.0 "bzip -9" compressing
|
||||
//config: linux-4.15.tar were:
|
||||
//config: value time (sec) code size (386)
|
||||
//config: 9 (smallest) 70.11 7687
|
||||
//config: 8 67.93 8091
|
||||
//config: 7 67.88 8405
|
||||
//config: 6 67.78 8624
|
||||
//config: 5 67.05 9427
|
||||
//config: 4-0 (fastest) 64.14 12083
|
||||
//config:
|
||||
//config:config FEATURE_BZIP2_DECOMPRESS
|
||||
//config: bool "Enable decompression"
|
||||
//config: default y
|
||||
@@ -65,11 +48,7 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if CONFIG_BZIP2_SMALL >= 4
|
||||
#define BZIP2_SPEED (9 - CONFIG_BZIP2_SMALL)
|
||||
#else
|
||||
#define BZIP2_SPEED 5
|
||||
#endif
|
||||
#define CONFIG_BZIP2_FAST 1
|
||||
|
||||
/* Speed test:
|
||||
* Compiled with gcc 4.2.1, run on Athlon 64 1800 MHz (512K L2 cache).
|
||||
@@ -77,7 +56,7 @@
|
||||
* (time to compress gcc-4.2.1.tar is 126.4% compared to bbox).
|
||||
* At SPEED 5 difference is 32.7%.
|
||||
*
|
||||
* Test run of all BZIP2_SPEED values on a 11Mb text file:
|
||||
* Test run of all CONFIG_BZIP2_FAST values on a 11Mb text file:
|
||||
* Size Time (3 runs)
|
||||
* 0: 10828 4.145 4.146 4.148
|
||||
* 1: 11097 3.845 3.860 3.861
|
||||
@@ -104,13 +83,15 @@
|
||||
/* No point in being shy and having very small buffer here.
|
||||
* bzip2 internal buffers are much bigger anyway, hundreds of kbytes.
|
||||
* If iobuf is several pages long, malloc() may use mmap,
|
||||
* making iobuf page aligned and thus (maybe) have one memcpy less
|
||||
* making iobuf is page aligned and thus (maybe) have one memcpy less
|
||||
* if kernel is clever enough.
|
||||
*/
|
||||
enum {
|
||||
IOBUF_SIZE = 8 * 1024
|
||||
};
|
||||
|
||||
static uint8_t level;
|
||||
|
||||
/* NB: compressStream() has to return -1 on errors, not die.
|
||||
* bbunpack() will correctly clean up in this case
|
||||
* (delete incomplete .bz2 file)
|
||||
@@ -162,7 +143,6 @@ static
|
||||
IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
unsigned opt, level;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
@@ -171,17 +151,6 @@ IF_DESKTOP(long long) int FAST_FUNC compressStream(transformer_state_t *xstate U
|
||||
#define wbuf (iobuf + IOBUF_SIZE)
|
||||
|
||||
iobuf = xmalloc(2 * IOBUF_SIZE);
|
||||
|
||||
opt = option_mask32 >> (BBUNPK_OPTSTRLEN IF_FEATURE_BZIP2_DECOMPRESS(+ 2) + 2);
|
||||
/* skipped BBUNPK_OPTSTR, "dt" and "zs" bits */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 0;
|
||||
for (;;) {
|
||||
level++;
|
||||
if (opt & 1) break;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
BZ2_bzCompressInit(strm, level);
|
||||
|
||||
while (1) {
|
||||
@@ -227,19 +196,26 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
*/
|
||||
|
||||
opt = getopt32(argv, "^"
|
||||
/* Must match BBUNPK_foo constants! */
|
||||
BBUNPK_OPTSTR IF_FEATURE_BZIP2_DECOMPRESS("dt") "zs123456789"
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
"cfkv" IF_FEATURE_BZIP2_DECOMPRESS("dt") "123456789qzs"
|
||||
"\0" "s2" /* -s means -2 (compatibility) */
|
||||
);
|
||||
#if ENABLE_FEATURE_BZIP2_DECOMPRESS /* bunzip2_main may not be visible... */
|
||||
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
|
||||
if (opt & 0x30) // -d and/or -t
|
||||
return bunzip2_main(argc, argv);
|
||||
opt >>= 6;
|
||||
#else
|
||||
/* clear "decompress" and "test" bits (or bbunpack() can get confused) */
|
||||
/* in !BZIP2_DECOMPRESS config, these bits are -zs and are unused */
|
||||
option_mask32 = opt & ~(BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST);
|
||||
opt >>= 4;
|
||||
#endif
|
||||
opt = (uint8_t)opt; /* isolate bits for -1..-8 */
|
||||
opt |= 0x100; /* if nothing else, assume -9 */
|
||||
level = 1;
|
||||
while (!(opt & 1)) {
|
||||
level++;
|
||||
opt >>= 1;
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
option_mask32 &= 0xf; /* ignore all except -cfkv */
|
||||
return bbunpack(argv, compressStream, append_ext, "bz2");
|
||||
}
|
||||
+5
-8
@@ -11,7 +11,7 @@
|
||||
* Only supports new ASCII and CRC formats
|
||||
*/
|
||||
//config:config CPIO
|
||||
//config: bool "cpio (15 kb)"
|
||||
//config: bool "cpio (14 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cpio is an archival utility program used to create, modify, and
|
||||
@@ -64,17 +64,15 @@
|
||||
//usage: "\n -p DIR Copy files to DIR"
|
||||
//usage: )
|
||||
//usage: "\nOptions:"
|
||||
//usage: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -H newc Archive format"
|
||||
//usage: )
|
||||
//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: "\n -L Dereference symlinks"
|
||||
//usage: "\n -0 Input is separated by NULs"
|
||||
//usage: IF_FEATURE_CPIO_O(
|
||||
//usage: "\n -H newc Archive format"
|
||||
//usage: )
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
|
||||
@@ -376,7 +374,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
"owner\0" Required_argument "R"
|
||||
"verbose\0" No_argument "v"
|
||||
"null\0" No_argument "0"
|
||||
"quiet\0" No_argument "\xff"
|
||||
"to-stdout\0" No_argument "\xfe"
|
||||
;
|
||||
@@ -511,7 +508,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
create_links_from_list(archive_handle->link_placeholders);
|
||||
create_symlinks_from_list(archive_handle->symlink_placeholders);
|
||||
|
||||
if (archive_handle->cpio__blocks != (off_t)-1
|
||||
&& !(opt & OPT_QUIET)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
* - (unknown, please let me know when you find any)
|
||||
*/
|
||||
//config:config DPKG
|
||||
//config: bool "dpkg (43 kb)"
|
||||
//config: bool "dpkg (44 kb)"
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DPKG_DEB
|
||||
//config: bool "dpkg-deb (30 kb)"
|
||||
//config: bool "dpkg_deb"
|
||||
//config: default y
|
||||
//config: select FEATURE_SEAMLESS_GZ
|
||||
//config: help
|
||||
|
||||
+218
-211
@@ -15,6 +15,21 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
/* big objects in bss:
|
||||
* 00000020 b bl_count
|
||||
* 00000074 b base_length
|
||||
* 00000078 b base_dist
|
||||
* 00000078 b static_dtree
|
||||
* 0000009c b bl_tree
|
||||
* 000000f4 b dyn_dtree
|
||||
* 00000100 b length_code
|
||||
* 00000200 b dist_code
|
||||
* 0000023d b depth
|
||||
* 00000400 b flag_buf
|
||||
* 0000047a b heap
|
||||
* 00000480 b static_ltree
|
||||
* 000008f4 b dyn_ltree
|
||||
*/
|
||||
/* TODO: full support for -v for DESKTOP
|
||||
* "/usr/bin/gzip -v a bogus aa" should say:
|
||||
a: 85.1% -- replaced with a.gz
|
||||
@@ -22,7 +37,7 @@ gzip: bogus: No such file or directory
|
||||
aa: 85.1% -- replaced with aa.gz
|
||||
*/
|
||||
//config:config GZIP
|
||||
//config: bool "gzip (17 kb)"
|
||||
//config: bool "gzip (19 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: gzip is used to compress files.
|
||||
@@ -93,12 +108,12 @@ aa: 85.1% -- replaced with aa.gz
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
//#define DEBUG 1
|
||||
/* Diagnostic functions */
|
||||
#ifdef DEBUG
|
||||
static int verbose;
|
||||
# define Assert(cond,msg) { if (!(cond)) bb_error_msg(msg); }
|
||||
# define Trace(x) fprintf x
|
||||
# define Tracev(x) {if (verbose) fprintf x; }
|
||||
@@ -114,6 +129,7 @@ static int verbose;
|
||||
# define Tracecv(c,x)
|
||||
#endif
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
#if CONFIG_GZIP_FAST == 0
|
||||
@@ -209,6 +225,7 @@ static int verbose;
|
||||
# define MAX_SUFFIX 30
|
||||
#endif
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Compile with MEDIUM_MEM to reduce the memory requirements or
|
||||
* with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the
|
||||
@@ -217,14 +234,15 @@ static int verbose;
|
||||
* affects the compression ratio. The compressed output
|
||||
* is still correct, and might even be smaller in some cases.
|
||||
*/
|
||||
|
||||
#ifdef SMALL_MEM
|
||||
# define HASH_BITS 13 /* Number of bits used to hash strings */
|
||||
# define HASH_BITS 13 /* Number of bits used to hash strings */
|
||||
#endif
|
||||
#ifdef MEDIUM_MEM
|
||||
# define HASH_BITS 14
|
||||
# define HASH_BITS 14
|
||||
#endif
|
||||
#ifndef HASH_BITS
|
||||
# define HASH_BITS 15
|
||||
# define HASH_BITS 15
|
||||
/* For portability to 16 bit machines, do not use values above 15. */
|
||||
#endif
|
||||
|
||||
@@ -237,6 +255,7 @@ static int verbose;
|
||||
#endif
|
||||
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* These types are not really 'char', 'short' and 'long'
|
||||
*/
|
||||
@@ -293,10 +312,46 @@ enum {
|
||||
#endif /* ENABLE_FEATURE_GZIP_LEVELS */
|
||||
};
|
||||
|
||||
struct globals {
|
||||
/* =========================================================================== */
|
||||
/* global buffers, allocated once */
|
||||
|
||||
struct globals {
|
||||
|
||||
#if 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
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
unsigned ins_h; /* hash index of string to be inserted */
|
||||
|
||||
#define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH)
|
||||
/* Number of bits by which ins_h and del_h must be shifted at each
|
||||
* input step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* H_SHIFT * MIN_MATCH >= HASH_BITS
|
||||
*/
|
||||
|
||||
unsigned prev_length;
|
||||
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
|
||||
unsigned strstart; /* start of string to insert */
|
||||
unsigned match_start; /* start of matching string */
|
||||
unsigned lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
#define DECLARE(type, array, size) \
|
||||
type * array
|
||||
#define ALLOC(type, array, size) \
|
||||
@@ -304,6 +359,8 @@ struct globals {
|
||||
#define FREE(array) \
|
||||
do { free(array); array = NULL; } while (0)
|
||||
|
||||
/* global buffers */
|
||||
|
||||
/* buffer for literals or lengths */
|
||||
/* DECLARE(uch, l_buf, LIT_BUFSIZE); */
|
||||
DECLARE(uch, l_buf, INBUFSIZ);
|
||||
@@ -333,46 +390,6 @@ struct globals {
|
||||
/* DECLARE(Pos, head, 1<<HASH_BITS); */
|
||||
#define head (G1.prev + WSIZE) /* hash head (see deflate.c) */
|
||||
|
||||
#if 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
|
||||
|
||||
/* =========================================================================== */
|
||||
/* all members below are zeroed out in pack_gzip() for each next file */
|
||||
|
||||
uint32_t crc; /* shift register contents */
|
||||
/*uint32_t *crc_32_tab;*/
|
||||
|
||||
/* window position at the beginning of the current output block. Gets
|
||||
* negative when the window is moved backwards.
|
||||
*/
|
||||
lng block_start;
|
||||
|
||||
unsigned ins_h; /* hash index of string to be inserted */
|
||||
|
||||
/* Number of bits by which ins_h and del_h must be shifted at each
|
||||
* input step. It must be such that after MIN_MATCH steps, the oldest
|
||||
* byte no longer takes part in the hash key, that is:
|
||||
* H_SHIFT * MIN_MATCH >= HASH_BITS
|
||||
*/
|
||||
#define H_SHIFT ((HASH_BITS+MIN_MATCH-1) / MIN_MATCH)
|
||||
|
||||
/* Length of the best match at previous step. Matches not greater than this
|
||||
* are discarded. This is used in the lazy match evaluation.
|
||||
*/
|
||||
unsigned prev_length;
|
||||
|
||||
unsigned strstart; /* start of string to insert */
|
||||
unsigned match_start; /* start of matching string */
|
||||
unsigned lookahead; /* number of valid bytes ahead in window */
|
||||
|
||||
/* number of input bytes */
|
||||
ulg isize; /* only 32 bits stored in .gz file */
|
||||
|
||||
@@ -384,35 +401,40 @@ struct globals {
|
||||
unsigned insize; /* valid bytes in l_buf */
|
||||
#endif
|
||||
unsigned outcnt; /* bytes in output buffer */
|
||||
|
||||
smallint eofile; /* flag set at end of input file */
|
||||
|
||||
/* ===========================================================================
|
||||
* Local data used by the "bit string" routines.
|
||||
*/
|
||||
|
||||
unsigned short bi_buf;
|
||||
|
||||
/* Output buffer. bits are inserted starting at the bottom (least significant
|
||||
* bits).
|
||||
*/
|
||||
unsigned bi_buf; /* was unsigned short */
|
||||
|
||||
#undef BUF_SIZE
|
||||
#define BUF_SIZE (int)(8 * sizeof(G1.bi_buf))
|
||||
|
||||
#define BUF_SIZE (8 * sizeof(G1.bi_buf))
|
||||
/* Number of bits used within bi_buf. (bi_buf might be implemented on
|
||||
* more than 16 bits on some systems.)
|
||||
*/
|
||||
unsigned bi_valid;
|
||||
|
||||
int bi_valid;
|
||||
|
||||
/* Current input function. Set to mem_read for in-memory compression */
|
||||
|
||||
#ifdef DEBUG
|
||||
ulg bits_sent; /* bit length of the compressed data */
|
||||
# define DEBUG_bits_sent(v) (void)(G1.bits_sent v)
|
||||
#else
|
||||
# define DEBUG_bits_sent(v) ((void)0)
|
||||
ulg bits_sent; /* bit length of the compressed data */
|
||||
#endif
|
||||
|
||||
/*uint32_t *crc_32_tab;*/
|
||||
uint32_t crc; /* shift register contents */
|
||||
};
|
||||
|
||||
#define G1 (*(ptr_to_globals - 1))
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Write the output buffer outbuf[0..outcnt-1] and update bytes_out.
|
||||
* (used for the compressed data only)
|
||||
@@ -426,6 +448,7 @@ static void flush_outbuf(void)
|
||||
G1.outcnt = 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
/* put_8bit is used for the compressed output */
|
||||
@@ -450,13 +473,12 @@ static void put_16bit(ush w)
|
||||
if (outcnt < OUTBUFSIZ-2) {
|
||||
/* Common case */
|
||||
ush *dst16 = (void*) dst;
|
||||
*dst16 = w; /* unaligned LSB 16-bit store */
|
||||
*dst16 = w; /* unalinged LSB 16-bit store */
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
G1.outcnt = ++outcnt;
|
||||
#else
|
||||
*dst = (uch)w;
|
||||
w >>= 8;
|
||||
@@ -466,38 +488,20 @@ static void put_16bit(ush w)
|
||||
G1.outcnt = outcnt + 2;
|
||||
return;
|
||||
}
|
||||
G1.outcnt = ++outcnt;
|
||||
#endif
|
||||
|
||||
/* Slowpath: we will need to do flush_outbuf() */
|
||||
G1.outcnt = ++outcnt;
|
||||
if (outcnt == OUTBUFSIZ)
|
||||
flush_outbuf(); /* here */
|
||||
put_8bit(w); /* or here */
|
||||
flush_outbuf();
|
||||
put_8bit(w);
|
||||
}
|
||||
|
||||
#define OPTIMIZED_PUT_32BIT (CONFIG_GZIP_FAST > 0 && BB_UNALIGNED_MEMACCESS_OK && BB_LITTLE_ENDIAN)
|
||||
static void put_32bit(ulg n)
|
||||
{
|
||||
if (OPTIMIZED_PUT_32BIT) {
|
||||
unsigned outcnt = G1.outcnt;
|
||||
if (outcnt < OUTBUFSIZ-4) {
|
||||
/* Common case */
|
||||
ulg *dst32 = (void*) &G1.outbuf[outcnt];
|
||||
*dst32 = n; /* unaligned LSB 32-bit store */
|
||||
//bb_error_msg("%p", dst32); // store alignment debugging
|
||||
G1.outcnt = outcnt + 4;
|
||||
return;
|
||||
}
|
||||
}
|
||||
put_16bit(n);
|
||||
put_16bit(n >> 16);
|
||||
}
|
||||
static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void)
|
||||
{
|
||||
/* If put_32bit() performs 32bit stores && it is used in send_bits() */
|
||||
if (OPTIMIZED_PUT_32BIT && BUF_SIZE > 16)
|
||||
flush_outbuf();
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Run a set of bytes through the crc shift register. If s is a NULL
|
||||
@@ -509,6 +513,7 @@ static void updcrc(uch * s, unsigned n)
|
||||
G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Read a new buffer from the current input file, perform end-of-line
|
||||
* translation, and update the crc and input file size.
|
||||
@@ -529,45 +534,34 @@ static unsigned file_read(void *buf, unsigned size)
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Send a value on a given number of bits.
|
||||
* IN assertion: length <= 16 and value fits in length bits.
|
||||
*/
|
||||
static void send_bits(unsigned value, unsigned length)
|
||||
static void send_bits(int value, int length)
|
||||
{
|
||||
unsigned new_buf;
|
||||
|
||||
#ifdef DEBUG
|
||||
Tracev((stderr, " l %2d v %4x ", length, value));
|
||||
Assert(length > 0 && length <= 15, "invalid length");
|
||||
DEBUG_bits_sent(+= length);
|
||||
G1.bits_sent += length;
|
||||
#endif
|
||||
BUILD_BUG_ON(BUF_SIZE != 32 && BUF_SIZE != 16);
|
||||
|
||||
new_buf = G1.bi_buf | (value << G1.bi_valid);
|
||||
/* NB: the above may sometimes do "<< 32" shift (undefined)
|
||||
* if check below is changed to "length > BUF_SIZE" instead of >= */
|
||||
length += G1.bi_valid;
|
||||
|
||||
/* If bi_buf is full */
|
||||
if (length >= BUF_SIZE) {
|
||||
/* ...use (valid) bits from bi_buf and
|
||||
* (BUF_SIZE - bi_valid) bits from value,
|
||||
* leaving (width - (BUF_SIZE-bi_valid)) unused bits in value.
|
||||
*/
|
||||
value >>= (BUF_SIZE - G1.bi_valid);
|
||||
if (BUF_SIZE == 32) {
|
||||
put_32bit(new_buf);
|
||||
} else { /* 16 */
|
||||
put_16bit(new_buf);
|
||||
}
|
||||
new_buf = value;
|
||||
length -= BUF_SIZE;
|
||||
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
|
||||
* (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
|
||||
* unused bits in value.
|
||||
*/
|
||||
if (G1.bi_valid > (int) BUF_SIZE - length) {
|
||||
G1.bi_buf |= (value << G1.bi_valid);
|
||||
put_16bit(G1.bi_buf);
|
||||
G1.bi_buf = (ush) value >> (BUF_SIZE - G1.bi_valid);
|
||||
G1.bi_valid += length - BUF_SIZE;
|
||||
} else {
|
||||
G1.bi_buf |= value << G1.bi_valid;
|
||||
G1.bi_valid += length;
|
||||
}
|
||||
G1.bi_buf = new_buf;
|
||||
G1.bi_valid = length;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Reverse the first len bits of a code, using straightforward code (a faster
|
||||
* method would use a table)
|
||||
@@ -585,24 +579,25 @@ static unsigned bi_reverse(unsigned code, int len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Write out any remaining bits in an incomplete byte.
|
||||
*/
|
||||
static void bi_windup(void)
|
||||
{
|
||||
unsigned bits = G1.bi_buf;
|
||||
int cnt = G1.bi_valid;
|
||||
|
||||
while (cnt > 0) {
|
||||
put_8bit(bits);
|
||||
bits >>= 8;
|
||||
cnt -= 8;
|
||||
if (G1.bi_valid > 8) {
|
||||
put_16bit(G1.bi_buf);
|
||||
} else if (G1.bi_valid > 0) {
|
||||
put_8bit(G1.bi_buf);
|
||||
}
|
||||
G1.bi_buf = 0;
|
||||
G1.bi_valid = 0;
|
||||
DEBUG_bits_sent(= (G1.bits_sent + 7) & ~7);
|
||||
#ifdef DEBUG
|
||||
G1.bits_sent = (G1.bits_sent + 7) & ~7;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Copy a stored block to the zip file, storing first the length and its
|
||||
* one's complement if requested.
|
||||
@@ -612,19 +607,21 @@ static void copy_block(char *buf, unsigned len, int header)
|
||||
bi_windup(); /* align on byte boundary */
|
||||
|
||||
if (header) {
|
||||
unsigned v = ((uint16_t)len) | ((~len) << 16);
|
||||
put_32bit(v);
|
||||
DEBUG_bits_sent(+= 2 * 16);
|
||||
put_16bit(len);
|
||||
put_16bit(~len);
|
||||
#ifdef DEBUG
|
||||
G1.bits_sent += 2 * 16;
|
||||
#endif
|
||||
}
|
||||
DEBUG_bits_sent(+= (ulg) len << 3);
|
||||
#ifdef DEBUG
|
||||
G1.bits_sent += (ulg) len << 3;
|
||||
#endif
|
||||
while (len--) {
|
||||
put_8bit(*buf++);
|
||||
}
|
||||
/* The above can 32-bit misalign outbuf */
|
||||
if (G1.outcnt & 3) /* syscalls are expensive, is it really misaligned? */
|
||||
flush_outbuf_if_32bit_optimized();
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Fill the window when the lookahead becomes insufficient.
|
||||
* Updates strstart and lookahead, and sets eofile if end of input file.
|
||||
@@ -682,12 +679,7 @@ static void fill_window(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Both users fill window with the same loop: */
|
||||
static void fill_window_if_needed(void)
|
||||
{
|
||||
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
|
||||
fill_window();
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Set match_start to the longest match starting at the given string and
|
||||
@@ -778,6 +770,7 @@ static int longest_match(IPos cur_match)
|
||||
return best_len;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
/* ===========================================================================
|
||||
* Check that the match at match_start is indeed a match.
|
||||
@@ -1056,14 +1049,24 @@ struct globals2 {
|
||||
ulg opt_len; /* bit length of current block with optimal trees */
|
||||
ulg static_len; /* bit length of current block with static trees */
|
||||
|
||||
// ulg compressed_len; /* total bit length of compressed file */
|
||||
ulg compressed_len; /* total bit length of compressed file */
|
||||
};
|
||||
|
||||
#define G2ptr ((struct globals2*)(ptr_to_globals))
|
||||
#define G2 (*G2ptr)
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
*/
|
||||
static void gen_codes(ct_data * tree, int max_code);
|
||||
static void build_tree(tree_desc * desc);
|
||||
static void scan_tree(ct_data * tree, int max_code);
|
||||
static void send_tree(ct_data * tree, int max_code);
|
||||
static int build_bl_tree(void);
|
||||
static void send_all_trees(int lcodes, int dcodes, int blcodes);
|
||||
static void compress_block(ct_data * ltree, ct_data * dtree);
|
||||
|
||||
|
||||
#ifndef DEBUG
|
||||
/* Send a code of the given tree. c and tree must not have side effects */
|
||||
# define SEND_CODE(c, tree) send_bits(tree[c].Code, tree[c].Len)
|
||||
@@ -1083,6 +1086,7 @@ struct globals2 {
|
||||
* The arguments must not have side effects.
|
||||
*/
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Initialize a new block.
|
||||
*/
|
||||
@@ -1105,6 +1109,7 @@ static void init_block(void)
|
||||
G2.flag_bit = 1;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Restore the heap property by moving down the tree starting at node k,
|
||||
* exchanging a node with the smallest of its two sons if necessary, stopping
|
||||
@@ -1142,6 +1147,7 @@ static void pqdownheap(ct_data * tree, int k)
|
||||
G2.heap[k] = v;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Compute the optimal bit lengths for a tree and update the total bit length
|
||||
* for the current block.
|
||||
@@ -1239,6 +1245,7 @@ static void gen_bitlen(tree_desc * desc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Generate the codes for a given tree and bit counts (which need not be
|
||||
* optimal).
|
||||
@@ -1282,6 +1289,7 @@ static void gen_codes(ct_data * tree, int max_code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Construct one Huffman tree and assigns the code bit strings and lengths.
|
||||
* Update the total bit length for the current block.
|
||||
@@ -1388,6 +1396,7 @@ static void build_tree(tree_desc * desc)
|
||||
gen_codes((ct_data *) tree, max_code);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Scan a literal or distance tree to determine the frequencies of the codes
|
||||
* in the bit length tree. Updates opt_len to take into account the repeat
|
||||
@@ -1442,6 +1451,7 @@ static void scan_tree(ct_data * tree, int max_code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Send a literal or distance tree in compressed form, using the codes in
|
||||
* bl_tree.
|
||||
@@ -1499,6 +1509,7 @@ static void send_tree(ct_data * tree, int max_code)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Construct the Huffman tree for the bit lengths and return the index in
|
||||
* bl_order of the last bit length code to send.
|
||||
@@ -1527,11 +1538,12 @@ static int build_bl_tree(void)
|
||||
}
|
||||
/* Update opt_len to include the bit length tree and counts */
|
||||
G2.opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4;
|
||||
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
|
||||
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
|
||||
|
||||
return max_blindex;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Send the header for a block using dynamic Huffman trees: the counts, the
|
||||
* lengths of the bit length codes, the literal tree and the distance tree.
|
||||
@@ -1552,15 +1564,16 @@ static void send_all_trees(int lcodes, int dcodes, int blcodes)
|
||||
Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
|
||||
send_bits(G2.bl_tree[bl_order[rank]].Len, 3);
|
||||
}
|
||||
Tracev((stderr, "\nbl tree: sent %ld", (long)G1.bits_sent));
|
||||
Tracev((stderr, "\nbl tree: sent %ld", G1.bits_sent));
|
||||
|
||||
send_tree((ct_data *) G2.dyn_ltree, lcodes - 1); /* send the literal tree */
|
||||
Tracev((stderr, "\nlit tree: sent %ld", (long)G1.bits_sent));
|
||||
Tracev((stderr, "\nlit tree: sent %ld", G1.bits_sent));
|
||||
|
||||
send_tree((ct_data *) G2.dyn_dtree, dcodes - 1); /* send the distance tree */
|
||||
Tracev((stderr, "\ndist tree: sent %ld", (long)G1.bits_sent));
|
||||
Tracev((stderr, "\ndist tree: sent %ld", G1.bits_sent));
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Save the match info and tally the frequency counts. Return true if
|
||||
* the current block must be flushed.
|
||||
@@ -1606,8 +1619,7 @@ static int ct_tally(int dist, int lc)
|
||||
out_length >>= 3;
|
||||
Trace((stderr,
|
||||
"\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ",
|
||||
G2.last_lit, G2.last_dist,
|
||||
(long)in_length, (long)out_length,
|
||||
G2.last_lit, G2.last_dist, in_length, out_length,
|
||||
100L - out_length * 100L / in_length));
|
||||
if (G2.last_dist < G2.last_lit / 2 && out_length < in_length / 2)
|
||||
return 1;
|
||||
@@ -1667,12 +1679,13 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||
SEND_CODE(END_BLOCK, ltree);
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Determine the best encoding for the current block: dynamic trees, static
|
||||
* trees or store, and output the encoded block to the zip file. This function
|
||||
* returns the total compressed length for the file so far.
|
||||
*/
|
||||
static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
static ulg flush_block(char *buf, ulg stored_len, int eof)
|
||||
{
|
||||
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
|
||||
int max_blindex; /* index of last bit length code of non zero freq */
|
||||
@@ -1681,10 +1694,10 @@ static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
|
||||
/* Construct the literal and distance trees */
|
||||
build_tree(&G2.l_desc);
|
||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
|
||||
Tracev((stderr, "\nlit data: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
|
||||
|
||||
build_tree(&G2.d_desc);
|
||||
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", (long)G2.opt_len, (long)G2.static_len));
|
||||
Tracev((stderr, "\ndist data: dyn %ld, stat %ld", G2.opt_len, G2.static_len));
|
||||
/* At this point, opt_len and static_len are the total bit lengths of
|
||||
* the compressed block data, excluding the tree representations.
|
||||
*/
|
||||
@@ -1700,9 +1713,7 @@ static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
|
||||
Trace((stderr,
|
||||
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ",
|
||||
(unsigned long)opt_lenb, (unsigned long)G2.opt_len,
|
||||
(unsigned long)static_lenb, (unsigned long)G2.static_len,
|
||||
(unsigned long)stored_len,
|
||||
opt_lenb, G2.opt_len, static_lenb, G2.static_len, stored_len,
|
||||
G2.last_lit, G2.last_dist));
|
||||
|
||||
if (static_lenb <= opt_lenb)
|
||||
@@ -1712,17 +1723,14 @@ static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
* and if the zip file can be seeked (to rewrite the local header),
|
||||
* the whole file is transformed into a stored file:
|
||||
*/
|
||||
// seekable() is constant FALSE in busybox, and G2.compressed_len is disabled
|
||||
// (this was the only user)
|
||||
// if (stored_len <= opt_lenb && eof && G2.compressed_len == 0L && seekable()) {
|
||||
// /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
|
||||
// if (buf == NULL)
|
||||
// bb_error_msg("block vanished");
|
||||
//
|
||||
// G2.compressed_len = stored_len << 3;
|
||||
// copy_block(buf, (unsigned) stored_len, 0); /* without header */
|
||||
// } else
|
||||
if (stored_len + 4 <= opt_lenb && buf != NULL) {
|
||||
if (stored_len <= opt_lenb && eof && G2.compressed_len == 0L && seekable()) {
|
||||
/* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
|
||||
if (buf == NULL)
|
||||
bb_error_msg("block vanished");
|
||||
|
||||
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.
|
||||
* Otherwise we can't have processed more than WSIZE input bytes since
|
||||
@@ -1731,35 +1739,35 @@ static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
* transform a block into a stored block.
|
||||
*/
|
||||
send_bits((STORED_BLOCK << 1) + eof, 3); /* send block type */
|
||||
// G2.compressed_len = ((G2.compressed_len + 3 + 7) & ~7L)
|
||||
// + ((stored_len + 4) << 3);
|
||||
G2.compressed_len = (G2.compressed_len + 3 + 7) & ~7L;
|
||||
G2.compressed_len += (stored_len + 4) << 3;
|
||||
|
||||
copy_block(buf, (unsigned) stored_len, 1); /* with header */
|
||||
} else
|
||||
if (static_lenb == opt_lenb) {
|
||||
} 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);
|
||||
// G2.compressed_len += 3 + G2.static_len;
|
||||
G2.compressed_len += 3 + G2.static_len;
|
||||
} else {
|
||||
send_bits((DYN_TREES << 1) + eof, 3);
|
||||
send_all_trees(G2.l_desc.max_code + 1, G2.d_desc.max_code + 1,
|
||||
max_blindex + 1);
|
||||
compress_block((ct_data *) G2.dyn_ltree, (ct_data *) G2.dyn_dtree);
|
||||
// G2.compressed_len += 3 + G2.opt_len;
|
||||
G2.compressed_len += 3 + G2.opt_len;
|
||||
}
|
||||
// Assert(G2.compressed_len == G1.bits_sent, "bad compressed size");
|
||||
Assert(G2.compressed_len == G1.bits_sent, "bad compressed size");
|
||||
init_block();
|
||||
|
||||
if (eof) {
|
||||
bi_windup();
|
||||
// G2.compressed_len += 7; /* align on byte boundary */
|
||||
G2.compressed_len += 7; /* align on byte boundary */
|
||||
}
|
||||
// Tracev((stderr, "\ncomprlen %lu(%lu) ",
|
||||
// (unsigned long)G2.compressed_len >> 3,
|
||||
// (unsigned long)G2.compressed_len - 7 * eof));
|
||||
Tracev((stderr, "\ncomprlen %lu(%lu) ", G2.compressed_len >> 3,
|
||||
G2.compressed_len - 7 * eof));
|
||||
|
||||
return; /* was "return G2.compressed_len >> 3;" */
|
||||
return G2.compressed_len >> 3;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Update a hash value with the given input byte
|
||||
* IN assertion: all calls to UPDATE_HASH are made with consecutive
|
||||
@@ -1768,6 +1776,7 @@ static void flush_block(char *buf, ulg stored_len, int eof)
|
||||
*/
|
||||
#define UPDATE_HASH(h, c) (h = (((h)<<H_SHIFT) ^ (c)) & HASH_MASK)
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Same as above, but achieves better compression. We use a lazy
|
||||
* evaluation for matches: a match is finally adopted only if there is
|
||||
@@ -1802,7 +1811,7 @@ do { \
|
||||
head[G1.ins_h] = (s); \
|
||||
} while (0)
|
||||
|
||||
static NOINLINE void deflate(void)
|
||||
static ulg deflate(void)
|
||||
{
|
||||
IPos hash_head; /* head of hash chain */
|
||||
IPos prev_match; /* previous match */
|
||||
@@ -1891,35 +1900,40 @@ static NOINLINE void deflate(void)
|
||||
G1.strstart++;
|
||||
G1.lookahead--;
|
||||
}
|
||||
Assert(G1.strstart <= G1.isize && G1.lookahead <= G1.isize, "a bit too far");
|
||||
Assert(G1.strstart <= G1.isize && lookahead <= G1.isize, "a bit too far");
|
||||
|
||||
/* Make sure that we always have enough lookahead, except
|
||||
* at the end of the input file. We need MAX_MATCH bytes
|
||||
* for the next match, plus MIN_MATCH bytes to insert the
|
||||
* string following the next match.
|
||||
*/
|
||||
fill_window_if_needed();
|
||||
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
|
||||
fill_window();
|
||||
}
|
||||
if (match_available)
|
||||
ct_tally(0, G1.window[G1.strstart - 1]);
|
||||
|
||||
FLUSH_BLOCK(1); /* eof */
|
||||
return FLUSH_BLOCK(1); /* eof */
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Initialize the bit string routines.
|
||||
*/
|
||||
static void bi_init(void)
|
||||
{
|
||||
//G1.bi_buf = 0; // globals are zeroed in pack_gzip()
|
||||
//G1.bi_valid = 0; // globals are zeroed in pack_gzip()
|
||||
//DEBUG_bits_sent(= 0L); // globals are zeroed in pack_gzip()
|
||||
G1.bi_buf = 0;
|
||||
G1.bi_valid = 0;
|
||||
#ifdef DEBUG
|
||||
G1.bits_sent = 0L;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Initialize the "longest match" routines for a new file
|
||||
*/
|
||||
static void lm_init(unsigned *flags16p)
|
||||
static void lm_init(ush * flagsp)
|
||||
{
|
||||
unsigned j;
|
||||
|
||||
@@ -1928,11 +1942,11 @@ static void lm_init(unsigned *flags16p)
|
||||
/* prev will be initialized on the fly */
|
||||
|
||||
/* speed options for the general purpose bit flag */
|
||||
*flags16p |= 2; /* FAST 4, SLOW 2 */
|
||||
*flagsp |= 2; /* FAST 4, SLOW 2 */
|
||||
/* ??? reduce max_chain_length for binary files */
|
||||
|
||||
//G1.strstart = 0; // globals are zeroed in pack_gzip()
|
||||
//G1.block_start = 0L; // globals are zeroed in pack_gzip()
|
||||
G1.strstart = 0;
|
||||
G1.block_start = 0L;
|
||||
|
||||
G1.lookahead = file_read(G1.window,
|
||||
sizeof(int) <= 2 ? (unsigned) WSIZE : 2 * WSIZE);
|
||||
@@ -1942,14 +1956,14 @@ static void lm_init(unsigned *flags16p)
|
||||
G1.lookahead = 0;
|
||||
return;
|
||||
}
|
||||
//G1.eofile = 0; // globals are zeroed in pack_gzip()
|
||||
|
||||
G1.eofile = 0;
|
||||
/* Make sure that we always have enough lookahead. This is important
|
||||
* if input comes from a device such as a tty.
|
||||
*/
|
||||
fill_window_if_needed();
|
||||
while (G1.lookahead < MIN_LOOKAHEAD && !G1.eofile)
|
||||
fill_window();
|
||||
|
||||
//G1.ins_h = 0; // globals are zeroed in pack_gzip()
|
||||
G1.ins_h = 0;
|
||||
for (j = 0; j < MIN_MATCH - 1; j++)
|
||||
UPDATE_HASH(G1.ins_h, G1.window[j]);
|
||||
/* If lookahead < MIN_MATCH, ins_h is garbage, but this is
|
||||
@@ -1957,6 +1971,7 @@ static void lm_init(unsigned *flags16p)
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Allocate the match buffer, initialize the various tables and save the
|
||||
* location of the internal file attribute (ascii/binary) and method
|
||||
@@ -1970,7 +1985,7 @@ static void ct_init(void)
|
||||
int code; /* code value */
|
||||
int dist; /* distance index */
|
||||
|
||||
// //G2.compressed_len = 0L; // globals are zeroed in pack_gzip()
|
||||
G2.compressed_len = 0L;
|
||||
|
||||
#ifdef NOT_NEEDED
|
||||
if (G2.static_dtree[0].Len != 0)
|
||||
@@ -2011,33 +2026,27 @@ static void ct_init(void)
|
||||
Assert(dist == 256, "ct_init: 256+dist != 512");
|
||||
|
||||
/* Construct the codes of the static literal tree */
|
||||
//for (n = 0; n <= MAX_BITS; n++) // globals are zeroed in pack_gzip()
|
||||
// G2.bl_count[n] = 0;
|
||||
/* already zeroed - it's in bss
|
||||
for (n = 0; n <= MAX_BITS; n++)
|
||||
G2.bl_count[n] = 0; */
|
||||
|
||||
n = 0;
|
||||
while (n <= 143) {
|
||||
G2.static_ltree[n++].Len = 8;
|
||||
//G2.bl_count[8]++;
|
||||
G2.bl_count[8]++;
|
||||
}
|
||||
//G2.bl_count[8] = 143 + 1;
|
||||
while (n <= 255) {
|
||||
G2.static_ltree[n++].Len = 9;
|
||||
//G2.bl_count[9]++;
|
||||
G2.bl_count[9]++;
|
||||
}
|
||||
//G2.bl_count[9] = 255 - 143;
|
||||
while (n <= 279) {
|
||||
G2.static_ltree[n++].Len = 7;
|
||||
//G2.bl_count[7]++;
|
||||
G2.bl_count[7]++;
|
||||
}
|
||||
//G2.bl_count[7] = 279 - 255;
|
||||
while (n <= 287) {
|
||||
G2.static_ltree[n++].Len = 8;
|
||||
//G2.bl_count[8]++;
|
||||
G2.bl_count[8]++;
|
||||
}
|
||||
//G2.bl_count[8] += 287 - 279;
|
||||
G2.bl_count[7] = 279 - 255;
|
||||
G2.bl_count[8] = (143 + 1) + (287 - 279);
|
||||
G2.bl_count[9] = 255 - 143;
|
||||
/* Codes 286 and 287 do not exist, but we must include them in the
|
||||
* tree construction to get a canonical Huffman tree (longest code
|
||||
* all ones)
|
||||
@@ -2054,15 +2063,17 @@ static void ct_init(void)
|
||||
init_block();
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Deflate in to out.
|
||||
* IN assertions: the input and output buffers are cleared.
|
||||
*/
|
||||
|
||||
static void zip(void)
|
||||
{
|
||||
unsigned deflate_flags;
|
||||
ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
|
||||
|
||||
//G1.outcnt = 0; // globals are zeroed in pack_gzip()
|
||||
G1.outcnt = 0;
|
||||
|
||||
/* Write the header to the gzip file. See algorithm.doc for the format */
|
||||
/* magic header for gzip files: 1F 8B */
|
||||
@@ -2076,13 +2087,10 @@ static void zip(void)
|
||||
|
||||
bi_init();
|
||||
ct_init();
|
||||
deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */
|
||||
lm_init(&deflate_flags);
|
||||
|
||||
put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */
|
||||
|
||||
/* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */
|
||||
flush_outbuf_if_32bit_optimized();
|
||||
put_8bit(deflate_flags); /* extra flags */
|
||||
put_8bit(3); /* OS identifier = 3 (Unix) */
|
||||
|
||||
deflate();
|
||||
|
||||
@@ -2093,21 +2101,20 @@ static void zip(void)
|
||||
flush_outbuf();
|
||||
}
|
||||
|
||||
|
||||
/* ======================================================================== */
|
||||
static
|
||||
IF_DESKTOP(long long) int FAST_FUNC pack_gzip(transformer_state_t *xstate UNUSED_PARAM)
|
||||
{
|
||||
/* Reinit G1.xxx except pointers to allocated buffers, and entire G2 */
|
||||
memset(&G1.crc, 0, (sizeof(G1) - offsetof(struct globals, crc)) + sizeof(G2));
|
||||
|
||||
/* Clear input and output buffers */
|
||||
//G1.outcnt = 0;
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
//G1.insize = 0;
|
||||
G1.insize = 0;
|
||||
#endif
|
||||
//G1.isize = 0;
|
||||
G1.isize = 0;
|
||||
|
||||
/* Reinit G2.xxx */
|
||||
memset(&G2, 0, sizeof(G2));
|
||||
G2.l_desc.dyn_tree = G2.dyn_ltree;
|
||||
G2.l_desc.static_tree = G2.static_ltree;
|
||||
G2.l_desc.extra_bits = extra_lbits;
|
||||
@@ -2211,16 +2218,16 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
opt = getopt32long(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789", gzip_longopts);
|
||||
opt = getopt32long(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789", gzip_longopts);
|
||||
#else
|
||||
opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_GZIP_DECOMPRESS("dt") "n123456789");
|
||||
opt = getopt32(argv, "cfkv" IF_FEATURE_GZIP_DECOMPRESS("dt") "qn123456789");
|
||||
#endif
|
||||
#if ENABLE_FEATURE_GZIP_DECOMPRESS /* gunzip_main may not be visible... */
|
||||
if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
|
||||
if (opt & 0x30) // -d and/or -t
|
||||
return gunzip_main(argc, argv);
|
||||
#endif
|
||||
#if ENABLE_FEATURE_GZIP_LEVELS
|
||||
opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */
|
||||
opt >>= ENABLE_FEATURE_GZIP_DECOMPRESS ? 8 : 6; /* drop cfkv[dt]qn bits */
|
||||
if (opt == 0)
|
||||
opt = 1 << 6; /* default: 6 */
|
||||
opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */
|
||||
@@ -2229,7 +2236,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
max_lazy_match = gzip_level_config[opt].lazy2 * 2;
|
||||
nice_match = gzip_level_config[opt].nice2 * 2;
|
||||
#endif
|
||||
option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */
|
||||
option_mask32 &= 0xf; /* retain only -cfkv */
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
@@ -2239,7 +2246,7 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
ALLOC(ush, G1.prev, 1L << BITS);
|
||||
|
||||
/* Initialize the CRC32 table */
|
||||
global_crc32_new_table_le();
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
|
||||
argv += optind;
|
||||
return bbunpack(argv, pack_gzip, append_ext, "gz");
|
||||
|
||||
@@ -91,7 +91,6 @@ lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o
|
||||
lib-$(CONFIG_FEATURE_SH_EMBEDDED_SCRIPTS) += open_transformer.o decompress_bunzip2.o
|
||||
|
||||
ifneq ($(lib-y),)
|
||||
lib-y += $(COMMON_FILES)
|
||||
|
||||
+152
-159
@@ -113,8 +113,9 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
int32_t loSt,
|
||||
int32_t hiSt)
|
||||
{
|
||||
int32_t sp;
|
||||
uint32_t r;
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m;
|
||||
int32_t sp, lo, hi;
|
||||
uint32_t med, r, r3;
|
||||
int32_t stackLo[FALLBACK_QSORT_STACK_SIZE];
|
||||
int32_t stackHi[FALLBACK_QSORT_STACK_SIZE];
|
||||
|
||||
@@ -124,11 +125,6 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
fpush(loSt, hiSt);
|
||||
|
||||
while (sp > 0) {
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m;
|
||||
int32_t lo, hi;
|
||||
uint32_t med;
|
||||
uint32_t r3;
|
||||
|
||||
AssertH(sp < FALLBACK_QSORT_STACK_SIZE - 1, 1004);
|
||||
|
||||
fpop(lo, hi);
|
||||
@@ -165,7 +161,7 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
ltLo++;
|
||||
unLo++;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
}
|
||||
@@ -176,7 +172,7 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
mswap(fmap[unHi], fmap[gtHi]);
|
||||
gtHi--; unHi--;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
}
|
||||
@@ -231,19 +227,17 @@ void fallbackQSort3(uint32_t* fmap,
|
||||
#define UNALIGNED_BH(zz) ((zz) & 0x01f)
|
||||
|
||||
static
|
||||
void fallbackSort(EState* state)
|
||||
void fallbackSort(uint32_t* fmap,
|
||||
uint32_t* eclass,
|
||||
uint32_t* bhtab,
|
||||
int32_t nblock)
|
||||
{
|
||||
int32_t ftab[257];
|
||||
int32_t ftabCopy[256];
|
||||
int32_t H, i, j, k, l, r, cc, cc1;
|
||||
int32_t nNotDone;
|
||||
int32_t nBhtab;
|
||||
/* params */
|
||||
uint32_t *const fmap = state->arr1;
|
||||
uint32_t *const eclass = state->arr2;
|
||||
#define eclass8 ((uint8_t*)eclass)
|
||||
uint32_t *const bhtab = state->ftab;
|
||||
const int32_t nblock = state->nblock;
|
||||
uint8_t* eclass8 = (uint8_t*)eclass;
|
||||
|
||||
/*
|
||||
* Initial 1-char radix sort to generate
|
||||
@@ -332,7 +326,7 @@ void fallbackSort(EState* state)
|
||||
if (cc != cc1) {
|
||||
SET_BH(i);
|
||||
cc = cc1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,7 +349,6 @@ void fallbackSort(EState* state)
|
||||
eclass8[fmap[i]] = (uint8_t)j;
|
||||
}
|
||||
AssertH(j < 256, 1005);
|
||||
#undef eclass8
|
||||
}
|
||||
|
||||
#undef SET_BH
|
||||
@@ -374,25 +367,25 @@ void fallbackSort(EState* state)
|
||||
/*---------------------------------------------*/
|
||||
static
|
||||
NOINLINE
|
||||
int mainGtU(EState* state,
|
||||
int mainGtU(
|
||||
uint32_t i1,
|
||||
uint32_t i2)
|
||||
uint32_t i2,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
uint32_t nblock,
|
||||
int32_t* budget)
|
||||
{
|
||||
int32_t k;
|
||||
uint8_t c1, c2;
|
||||
uint16_t s1, s2;
|
||||
|
||||
uint8_t *const block = state->block;
|
||||
uint16_t *const quadrant = state->quadrant;
|
||||
const int32_t nblock = state->nblock;
|
||||
|
||||
/* Loop unrolling here is actually very useful
|
||||
* (generated code is much simpler),
|
||||
* code size increase is only 270 bytes (i386)
|
||||
* but speeds up compression 10% overall
|
||||
*/
|
||||
|
||||
#if BZIP2_SPEED >= 1
|
||||
#if CONFIG_BZIP2_FAST >= 1
|
||||
|
||||
#define TIMES_8(code) \
|
||||
code; code; code; code; \
|
||||
@@ -442,7 +435,7 @@ int mainGtU(EState* state,
|
||||
if (i1 >= nblock) i1 -= nblock;
|
||||
if (i2 >= nblock) i2 -= nblock;
|
||||
|
||||
state->budget--;
|
||||
(*budget)--;
|
||||
k -= 8;
|
||||
} while (k >= 0);
|
||||
|
||||
@@ -459,45 +452,42 @@ int mainGtU(EState* state,
|
||||
* usually small, typically <= 20.
|
||||
*/
|
||||
static
|
||||
const uint32_t incs[14] = {
|
||||
const int32_t incs[14] = {
|
||||
1, 4, 13, 40, 121, 364, 1093, 3280,
|
||||
9841, 29524, 88573, 265720,
|
||||
797161, 2391484
|
||||
};
|
||||
|
||||
static
|
||||
void mainSimpleSort(EState* state,
|
||||
void mainSimpleSort(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
int32_t nblock,
|
||||
int32_t lo,
|
||||
int32_t hi,
|
||||
int32_t d)
|
||||
int32_t d,
|
||||
int32_t* budget)
|
||||
{
|
||||
uint32_t *const ptr = state->ptr;
|
||||
int32_t i, j, h, bigN, hp;
|
||||
uint32_t v;
|
||||
|
||||
/* At which increment to start? */
|
||||
int hp = 0;
|
||||
{
|
||||
int bigN = hi - lo;
|
||||
if (bigN <= 0)
|
||||
return;
|
||||
while (incs[hp] <= bigN)
|
||||
hp++;
|
||||
hp--;
|
||||
}
|
||||
bigN = hi - lo + 1;
|
||||
if (bigN < 2) return;
|
||||
|
||||
hp = 0;
|
||||
while (incs[hp] < bigN) hp++;
|
||||
hp--;
|
||||
|
||||
for (; hp >= 0; hp--) {
|
||||
int32_t i;
|
||||
unsigned h;
|
||||
|
||||
h = incs[hp];
|
||||
|
||||
i = lo + h;
|
||||
while (1) {
|
||||
unsigned j;
|
||||
unsigned v;
|
||||
|
||||
/*-- copy 1 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
@@ -506,23 +496,24 @@ void mainSimpleSort(EState* state,
|
||||
i++;
|
||||
|
||||
/* 1.5% overall speedup, +290 bytes */
|
||||
#if BZIP2_SPEED >= 3
|
||||
#if CONFIG_BZIP2_FAST >= 3
|
||||
/*-- copy 2 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
}
|
||||
ptr[j] = v;
|
||||
i++;
|
||||
|
||||
/*-- copy 3 --*/
|
||||
if (i > hi) break;
|
||||
v = ptr[i];
|
||||
j = i;
|
||||
while (mainGtU(state, ptr[j-h]+d, v+d)) {
|
||||
while (mainGtU(ptr[j-h]+d, v+d, block, quadrant, nblock, budget)) {
|
||||
ptr[j] = ptr[j-h];
|
||||
j = j - h;
|
||||
if (j <= (lo + h - 1)) break;
|
||||
@@ -530,7 +521,7 @@ void mainSimpleSort(EState* state,
|
||||
ptr[j] = v;
|
||||
i++;
|
||||
#endif
|
||||
if (state->budget < 0) return;
|
||||
if (*budget < 0) return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -554,7 +545,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
};
|
||||
/* here b >= a */
|
||||
if (b > c) {
|
||||
b = c;
|
||||
@@ -595,12 +586,15 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
#define MAIN_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
void mainQSort3(EState* state,
|
||||
void mainQSort3(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
int32_t nblock,
|
||||
int32_t loSt,
|
||||
int32_t hiSt
|
||||
/*int32_t dSt*/)
|
||||
int32_t hiSt,
|
||||
int32_t dSt,
|
||||
int32_t* budget)
|
||||
{
|
||||
enum { dSt = BZ_N_RADIX };
|
||||
int32_t unLo, unHi, ltLo, gtHi, n, m, med;
|
||||
int32_t sp, lo, hi, d;
|
||||
|
||||
@@ -612,9 +606,6 @@ void mainQSort3(EState* state,
|
||||
int32_t nextHi[3];
|
||||
int32_t nextD [3];
|
||||
|
||||
uint32_t *const ptr = state->ptr;
|
||||
uint8_t *const block = state->block;
|
||||
|
||||
sp = 0;
|
||||
mpush(loSt, hiSt, dSt);
|
||||
|
||||
@@ -625,8 +616,8 @@ void mainQSort3(EState* state,
|
||||
if (hi - lo < MAIN_QSORT_SMALL_THRESH
|
||||
|| d > MAIN_QSORT_DEPTH_THRESH
|
||||
) {
|
||||
mainSimpleSort(state, lo, hi, d);
|
||||
if (state->budget < 0)
|
||||
mainSimpleSort(ptr, block, quadrant, nblock, lo, hi, d, budget);
|
||||
if (*budget < 0)
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
@@ -647,8 +638,8 @@ void mainQSort3(EState* state,
|
||||
ltLo++;
|
||||
unLo++;
|
||||
continue;
|
||||
}
|
||||
if (n > 0) break;
|
||||
};
|
||||
if (n > 0) break;
|
||||
unLo++;
|
||||
}
|
||||
while (1) {
|
||||
@@ -660,8 +651,8 @@ void mainQSort3(EState* state,
|
||||
gtHi--;
|
||||
unHi--;
|
||||
continue;
|
||||
}
|
||||
if (n < 0) break;
|
||||
};
|
||||
if (n < 0) break;
|
||||
unHi--;
|
||||
}
|
||||
if (unLo > unHi)
|
||||
@@ -730,24 +721,28 @@ void mainQSort3(EState* state,
|
||||
#define CLEARMASK (~(SETMASK))
|
||||
|
||||
static NOINLINE
|
||||
void mainSort(EState* state)
|
||||
void mainSort(EState* state,
|
||||
uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
uint32_t* ftab,
|
||||
int32_t nblock,
|
||||
int32_t* budget)
|
||||
{
|
||||
int32_t i, j;
|
||||
int32_t i, j, k, ss, sb;
|
||||
uint8_t c1;
|
||||
int32_t numQSorted;
|
||||
uint16_t s;
|
||||
Bool bigDone[256];
|
||||
uint8_t runningOrder[256];
|
||||
/* bbox: moved to EState to save stack
|
||||
int32_t runningOrder[256];
|
||||
int32_t copyStart[256];
|
||||
int32_t copyEnd [256];
|
||||
*/
|
||||
#define runningOrder (state->mainSort__runningOrder)
|
||||
#define copyStart (state->mainSort__copyStart)
|
||||
#define copyEnd (state->mainSort__copyEnd)
|
||||
|
||||
uint32_t *const ptr = state->ptr;
|
||||
uint8_t *const block = state->block;
|
||||
uint32_t *const ftab = state->ftab;
|
||||
const int32_t nblock = state->nblock;
|
||||
uint16_t *const quadrant = state->quadrant;
|
||||
|
||||
/*-- set up the 2-byte frequency table --*/
|
||||
/* was: for (i = 65536; i >= 0; i--) ftab[i] = 0; */
|
||||
memset(ftab, 0, 65537 * sizeof(ftab[0]));
|
||||
@@ -755,25 +750,25 @@ void mainSort(EState* state)
|
||||
j = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
/* 3%, +300 bytes */
|
||||
#if BZIP2_SPEED >= 2
|
||||
#if CONFIG_BZIP2_FAST >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
quadrant[i] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-1] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-1]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-1]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-2] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-2]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-2]) << 8);
|
||||
ftab[j]++;
|
||||
quadrant[i-3] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i-3]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i-3]) << 8);
|
||||
ftab[j]++;
|
||||
}
|
||||
#endif
|
||||
for (; i >= 0; i--) {
|
||||
quadrant[i] = 0;
|
||||
j = (j >> 8) | (((unsigned)block[i]) << 8);
|
||||
j = (j >> 8) | (((uint16_t)block[i]) << 8);
|
||||
ftab[j]++;
|
||||
}
|
||||
|
||||
@@ -790,36 +785,33 @@ void mainSort(EState* state)
|
||||
ftab[i] = j;
|
||||
}
|
||||
|
||||
{
|
||||
unsigned s;
|
||||
s = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
#if BZIP2_SPEED >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
s = (s >> 8) | (block[i-1] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-1;
|
||||
s = (s >> 8) | (block[i-2] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-2;
|
||||
s = (s >> 8) | (block[i-3] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-3;
|
||||
}
|
||||
s = block[0] << 8;
|
||||
i = nblock - 1;
|
||||
#if CONFIG_BZIP2_FAST >= 2
|
||||
for (; i >= 3; i -= 4) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
s = (s >> 8) | (block[i-1] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-1;
|
||||
s = (s >> 8) | (block[i-2] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-2;
|
||||
s = (s >> 8) | (block[i-3] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i-3;
|
||||
}
|
||||
#endif
|
||||
for (; i >= 0; i--) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
}
|
||||
for (; i >= 0; i--) {
|
||||
s = (s >> 8) | (block[i] << 8);
|
||||
j = ftab[s] - 1;
|
||||
ftab[s] = j;
|
||||
ptr[j] = i;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -833,23 +825,24 @@ void mainSort(EState* state)
|
||||
}
|
||||
|
||||
{
|
||||
int32_t vv;
|
||||
/* bbox: was: int32_t h = 1; */
|
||||
/* do h = 3 * h + 1; while (h <= 256); */
|
||||
unsigned h = 364;
|
||||
uint32_t h = 364;
|
||||
|
||||
do {
|
||||
/*h = h / 3;*/
|
||||
h = (h * 171) >> 9; /* bbox: fast h/3 */
|
||||
for (i = h; i <= 255; i++) {
|
||||
unsigned vv, jh;
|
||||
vv = runningOrder[i]; /* uint8[] */
|
||||
vv = runningOrder[i];
|
||||
j = i;
|
||||
while (jh = j - h, BIGFREQ(runningOrder[jh]) > BIGFREQ(vv)) {
|
||||
runningOrder[j] = runningOrder[jh];
|
||||
j = jh;
|
||||
if (j < h)
|
||||
break;
|
||||
while (BIGFREQ(runningOrder[j-h]) > BIGFREQ(vv)) {
|
||||
runningOrder[j] = runningOrder[j-h];
|
||||
j = j - h;
|
||||
if (j <= (h - 1))
|
||||
goto zero;
|
||||
}
|
||||
zero:
|
||||
runningOrder[j] = vv;
|
||||
}
|
||||
} while (h != 1);
|
||||
@@ -859,8 +852,9 @@ void mainSort(EState* state)
|
||||
* The main sorting loop.
|
||||
*/
|
||||
|
||||
for (i = 0; /*i <= 255*/; i++) {
|
||||
unsigned ss;
|
||||
numQSorted = 0;
|
||||
|
||||
for (i = 0; i <= 255; i++) {
|
||||
|
||||
/*
|
||||
* Process big buckets, starting with the least full.
|
||||
@@ -880,14 +874,17 @@ void mainSort(EState* state)
|
||||
*/
|
||||
for (j = 0; j <= 255; j++) {
|
||||
if (j != ss) {
|
||||
unsigned sb;
|
||||
sb = (ss << 8) + j;
|
||||
if (!(ftab[sb] & SETMASK)) {
|
||||
int32_t lo = ftab[sb] /*& CLEARMASK (redundant)*/;
|
||||
int32_t lo = ftab[sb] & CLEARMASK;
|
||||
int32_t hi = (ftab[sb+1] & CLEARMASK) - 1;
|
||||
if (hi > lo) {
|
||||
mainQSort3(state, lo, hi /*,BZ_N_RADIX*/);
|
||||
if (state->budget < 0) return;
|
||||
mainQSort3(
|
||||
ptr, block, quadrant, nblock,
|
||||
lo, hi, BZ_N_RADIX, budget
|
||||
);
|
||||
if (*budget < 0) return;
|
||||
numQSorted += (hi - lo + 1);
|
||||
}
|
||||
}
|
||||
ftab[sb] |= SETMASK;
|
||||
@@ -909,8 +906,6 @@ void mainSort(EState* state)
|
||||
copyEnd [j] = (ftab[(j << 8) + ss + 1] & CLEARMASK) - 1;
|
||||
}
|
||||
for (j = ftab[ss << 8] & CLEARMASK; j < copyStart[ss]; j++) {
|
||||
unsigned c1;
|
||||
int32_t k;
|
||||
k = ptr[j] - 1;
|
||||
if (k < 0)
|
||||
k += nblock;
|
||||
@@ -919,8 +914,6 @@ void mainSort(EState* state)
|
||||
ptr[copyStart[c1]++] = k;
|
||||
}
|
||||
for (j = (ftab[(ss+1) << 8] & CLEARMASK) - 1; j > copyEnd[ss]; j--) {
|
||||
unsigned c1;
|
||||
int32_t k;
|
||||
k = ptr[j]-1;
|
||||
if (k < 0)
|
||||
k += nblock;
|
||||
@@ -940,9 +933,6 @@ void mainSort(EState* state)
|
||||
for (j = 0; j <= 255; j++)
|
||||
ftab[(j << 8) + ss] |= SETMASK;
|
||||
|
||||
if (i == 255)
|
||||
break;
|
||||
|
||||
/*
|
||||
* Step 3:
|
||||
* The [ss] big bucket is now done. Record this fact,
|
||||
@@ -984,15 +974,15 @@ void mainSort(EState* state)
|
||||
*/
|
||||
bigDone[ss] = True;
|
||||
|
||||
{
|
||||
unsigned bbStart = ftab[ss << 8] & CLEARMASK;
|
||||
unsigned bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
|
||||
unsigned shifts = 0;
|
||||
if (i < 255) {
|
||||
int32_t bbStart = ftab[ss << 8] & CLEARMASK;
|
||||
int32_t bbSize = (ftab[(ss+1) << 8] & CLEARMASK) - bbStart;
|
||||
int32_t shifts = 0;
|
||||
|
||||
while ((bbSize >> shifts) > 65534) shifts++;
|
||||
|
||||
for (j = bbSize-1; j >= 0; j--) {
|
||||
unsigned a2update = ptr[bbStart + j]; /* uint32[] */
|
||||
int32_t a2update = ptr[bbStart + j];
|
||||
uint16_t qVal = (uint16_t)(j >> shifts);
|
||||
quadrant[a2update] = qVal;
|
||||
if (a2update < BZ_N_OVERSHOOT)
|
||||
@@ -1025,24 +1015,31 @@ void mainSort(EState* state)
|
||||
* arr1[0 .. nblock-1] holds sorted order
|
||||
*/
|
||||
static NOINLINE
|
||||
int32_t BZ2_blockSort(EState* state)
|
||||
void BZ2_blockSort(EState* s)
|
||||
{
|
||||
/* In original bzip2 1.0.4, it's a parameter, but 30
|
||||
* (which was the default) should work ok. */
|
||||
enum { wfact = 30 };
|
||||
unsigned i;
|
||||
int32_t origPtr = origPtr;
|
||||
|
||||
if (state->nblock >= 10000) {
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint32_t* ftab = s->ftab;
|
||||
int32_t nblock = s->nblock;
|
||||
uint16_t* quadrant;
|
||||
int32_t budget;
|
||||
int32_t i;
|
||||
|
||||
if (nblock < 10000) {
|
||||
fallbackSort(s->arr1, s->arr2, ftab, nblock);
|
||||
} else {
|
||||
/* Calculate the location for quadrant, remembering to get
|
||||
* the alignment right. Assumes that &(block[0]) is at least
|
||||
* 2-byte aligned -- this should be ok since block is really
|
||||
* the first section of arr2.
|
||||
*/
|
||||
i = state->nblock + BZ_N_OVERSHOOT;
|
||||
if (i & 1)
|
||||
i++;
|
||||
state->quadrant = (uint16_t*) &(state->block[i]);
|
||||
i = nblock + BZ_N_OVERSHOOT;
|
||||
if (i & 1) i++;
|
||||
quadrant = (uint16_t*)(&(block[i]));
|
||||
|
||||
/* (wfact-1) / 3 puts the default-factor-30
|
||||
* transition point at very roughly the same place as
|
||||
@@ -1051,26 +1048,22 @@ int32_t BZ2_blockSort(EState* state)
|
||||
* resulting compressed stream is now the same regardless
|
||||
* of whether or not we use the main sort or fallback sort.
|
||||
*/
|
||||
state->budget = state->nblock * ((wfact-1) / 3);
|
||||
mainSort(state);
|
||||
if (state->budget >= 0)
|
||||
goto good;
|
||||
}
|
||||
fallbackSort(state);
|
||||
good:
|
||||
budget = nblock * ((wfact-1) / 3);
|
||||
|
||||
#if BZ_LIGHT_DEBUG
|
||||
origPtr = -1;
|
||||
#endif
|
||||
for (i = 0; i < state->nblock; i++) {
|
||||
if (state->ptr[i] == 0) {
|
||||
origPtr = i;
|
||||
break;
|
||||
mainSort(s, ptr, block, quadrant, ftab, nblock, &budget);
|
||||
if (budget < 0) {
|
||||
fallbackSort(s->arr1, s->arr2, ftab, nblock);
|
||||
}
|
||||
}
|
||||
|
||||
AssertH(origPtr != -1, 1003);
|
||||
return origPtr;
|
||||
s->origPtr = -1;
|
||||
for (i = 0; i < s->nblock; i++)
|
||||
if (ptr[i] == 0) {
|
||||
s->origPtr = i;
|
||||
break;
|
||||
};
|
||||
|
||||
AssertH(s->origPtr != -1, 1003);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -55,9 +55,8 @@ void prepare_new_block(EState* s)
|
||||
{
|
||||
int i;
|
||||
s->nblock = 0;
|
||||
//indexes into s->zbits[], initialzation moved to init of s->zbits
|
||||
//s->posZ = s->zbits; // was: s->numZ = 0;
|
||||
//s->state_out_pos = s->zbits;
|
||||
s->numZ = 0;
|
||||
s->state_out_pos = 0;
|
||||
BZ_INITIALISE_CRC(s->blockCRC);
|
||||
/* inlined memset would be nice to have here */
|
||||
for (i = 0; i < 256; i++)
|
||||
@@ -87,7 +86,7 @@ int isempty_RL(EState* s)
|
||||
static
|
||||
void BZ2_bzCompressInit(bz_stream *strm, int blockSize100k)
|
||||
{
|
||||
unsigned n;
|
||||
int32_t n;
|
||||
EState* s;
|
||||
|
||||
s = xzalloc(sizeof(EState));
|
||||
@@ -238,10 +237,11 @@ void /*Bool*/ copy_output_until_stop(EState* s)
|
||||
if (s->strm->avail_out == 0) break;
|
||||
|
||||
/*-- block done? --*/
|
||||
if (s->state_out_pos >= s->posZ) break;
|
||||
if (s->state_out_pos >= s->numZ) break;
|
||||
|
||||
/*progress_out = True;*/
|
||||
*(s->strm->next_out) = *s->state_out_pos++;
|
||||
*(s->strm->next_out) = s->zbits[s->state_out_pos];
|
||||
s->state_out_pos++;
|
||||
s->strm->avail_out--;
|
||||
s->strm->next_out++;
|
||||
s->strm->total_out++;
|
||||
@@ -261,7 +261,7 @@ void /*Bool*/ handle_compress(bz_stream *strm)
|
||||
while (1) {
|
||||
if (s->state == BZ_S_OUTPUT) {
|
||||
/*progress_out |=*/ copy_output_until_stop(s);
|
||||
if (s->state_out_pos < s->posZ) break;
|
||||
if (s->state_out_pos < s->numZ) break;
|
||||
if (s->mode == BZ_M_FINISHING
|
||||
//# && s->avail_in_expect == 0
|
||||
&& s->strm->avail_in == 0
|
||||
@@ -336,7 +336,7 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
/*if (s->avail_in_expect != s->strm->avail_in)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FLUSH_OK;
|
||||
s->mode = BZ_M_RUNNING;
|
||||
return BZ_RUN_OK;
|
||||
@@ -349,9 +349,9 @@ int BZ2_bzCompress(bz_stream *strm, int action)
|
||||
return BZ_SEQUENCE_ERROR;*/
|
||||
/*progress =*/ handle_compress(strm);
|
||||
/*if (!progress) return BZ_SEQUENCE_ERROR;*/
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
//#if (s->avail_in_expect > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
//# return BZ_FINISH_OK;
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->posZ)
|
||||
if (s->strm->avail_in > 0 || !isempty_RL(s) || s->state_out_pos < s->numZ)
|
||||
return BZ_FINISH_OK;
|
||||
/*s->mode = BZ_M_IDLE;*/
|
||||
return BZ_STREAM_END;
|
||||
|
||||
@@ -120,11 +120,8 @@ typedef struct EState {
|
||||
|
||||
/* mode this stream is in, and whether inputting */
|
||||
/* or outputting data */
|
||||
uint8_t mode;
|
||||
uint8_t state;
|
||||
|
||||
/* misc administratium */
|
||||
uint8_t blockSize100k;
|
||||
int32_t mode;
|
||||
int32_t state;
|
||||
|
||||
/* remembers avail_in when flush/finish requested */
|
||||
/* bbox: not needed, strm->avail_in always has the same value */
|
||||
@@ -132,19 +129,20 @@ typedef struct EState {
|
||||
/* uint32_t avail_in_expect; */
|
||||
|
||||
/* for doing the block sorting */
|
||||
int32_t origPtr;
|
||||
uint32_t *arr1;
|
||||
uint32_t *arr2;
|
||||
uint32_t *ftab;
|
||||
|
||||
uint16_t *quadrant;
|
||||
int32_t budget;
|
||||
|
||||
/* aliases for arr1 and arr2 */
|
||||
uint32_t *ptr;
|
||||
uint8_t *block;
|
||||
uint16_t *mtfv;
|
||||
uint8_t *zbits;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* run-length-encoding of the input */
|
||||
uint32_t state_in_ch;
|
||||
int32_t state_in_len;
|
||||
@@ -152,23 +150,20 @@ typedef struct EState {
|
||||
/* input and output limits and current posns */
|
||||
int32_t nblock;
|
||||
int32_t nblockMAX;
|
||||
//int32_t numZ; // index into s->zbits[], replaced by pointer:
|
||||
uint8_t *posZ;
|
||||
uint8_t *state_out_pos;
|
||||
int32_t numZ;
|
||||
int32_t state_out_pos;
|
||||
|
||||
/* the buffer for bit stream creation */
|
||||
uint32_t bsBuff;
|
||||
int32_t bsLive;
|
||||
|
||||
/* guess what */
|
||||
uint32_t *crc32table;
|
||||
|
||||
/* block and combined CRCs */
|
||||
uint32_t blockCRC;
|
||||
uint32_t combinedCRC;
|
||||
|
||||
/* misc administratium */
|
||||
int32_t blockNo;
|
||||
int32_t blockSize100k;
|
||||
|
||||
/* stuff for coding the MTF values */
|
||||
int32_t nMTF;
|
||||
@@ -188,7 +183,7 @@ typedef struct EState {
|
||||
/* stack-saving measures: these can be local, but they are too big */
|
||||
int32_t sendMTFValues__code [BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
int32_t sendMTFValues__rfreq[BZ_N_GROUPS][BZ_MAX_ALPHA_SIZE];
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FAST >= 5
|
||||
/* second dimension: only 3 needed; 4 makes index calculations faster */
|
||||
uint32_t sendMTFValues__len_pack[BZ_MAX_ALPHA_SIZE][4];
|
||||
#endif
|
||||
@@ -196,6 +191,7 @@ typedef struct EState {
|
||||
int32_t BZ2_hbMakeCodeLengths__weight[BZ_MAX_ALPHA_SIZE * 2];
|
||||
int32_t BZ2_hbMakeCodeLengths__parent[BZ_MAX_ALPHA_SIZE * 2];
|
||||
|
||||
int32_t mainSort__runningOrder[256];
|
||||
int32_t mainSort__copyStart[256];
|
||||
int32_t mainSort__copyEnd[256];
|
||||
} EState;
|
||||
@@ -203,7 +199,7 @@ typedef struct EState {
|
||||
|
||||
/*-- compression. --*/
|
||||
|
||||
static int32_t
|
||||
static void
|
||||
BZ2_blockSort(EState*);
|
||||
|
||||
static void
|
||||
|
||||
+132
-207
@@ -32,12 +32,6 @@ in the file LICENSE.
|
||||
|
||||
/* #include "bzlib_private.h" */
|
||||
|
||||
#if BZIP2_SPEED >= 5
|
||||
# define ALWAYS_INLINE_5 ALWAYS_INLINE
|
||||
#else
|
||||
# define ALWAYS_INLINE_5 /*nothing*/
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*--- Bit stream I/O ---*/
|
||||
/*---------------------------------------------------*/
|
||||
@@ -56,7 +50,8 @@ static NOINLINE
|
||||
void bsFinishWrite(EState* s)
|
||||
{
|
||||
while (s->bsLive > 0) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
@@ -66,74 +61,39 @@ void bsFinishWrite(EState* s)
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
/* Helps only on level 5, on other levels hurts. ? */
|
||||
ALWAYS_INLINE_5
|
||||
#if CONFIG_BZIP2_FAST >= 5
|
||||
ALWAYS_INLINE
|
||||
#endif
|
||||
void bsW(EState* s, int32_t n, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->zbits[s->numZ] = (uint8_t)(s->bsBuff >> 24);
|
||||
s->numZ++;
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (32 - s->bsLive - n));
|
||||
s->bsLive += n;
|
||||
}
|
||||
/* Same with n == 16: */
|
||||
static
|
||||
ALWAYS_INLINE_5
|
||||
void bsW16(EState* s, uint32_t v)
|
||||
{
|
||||
while (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (v << (16 - s->bsLive));
|
||||
s->bsLive += 16;
|
||||
}
|
||||
/* Same with n == 1: */
|
||||
static
|
||||
ALWAYS_INLINE /* one callsite */
|
||||
void bsW1_1(EState* s)
|
||||
{
|
||||
/* need space for only 1 bit, no need for loop freeing > 8 bits */
|
||||
if (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
s->bsBuff |= (1 << (31 - s->bsLive));
|
||||
s->bsLive += 1;
|
||||
}
|
||||
static
|
||||
ALWAYS_INLINE_5
|
||||
void bsW1_0(EState* s)
|
||||
{
|
||||
/* need space for only 1 bit, no need for loop freeing > 8 bits */
|
||||
if (s->bsLive >= 8) {
|
||||
*s->posZ++ = (uint8_t)(s->bsBuff >> 24);
|
||||
s->bsBuff <<= 8;
|
||||
s->bsLive -= 8;
|
||||
}
|
||||
//s->bsBuff |= (0 << (31 - s->bsLive));
|
||||
s->bsLive += 1;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static ALWAYS_INLINE
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW16(s, u);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU32(EState* s, unsigned u)
|
||||
{
|
||||
//bsW(s, 32, u); // can't use: may try "uint32 << -n"
|
||||
bsW16(s, (u >> 16) & 0xffff);
|
||||
bsW16(s, u & 0xffff);
|
||||
bsW(s, 8, (u >> 24) & 0xff);
|
||||
bsW(s, 8, (u >> 16) & 0xff);
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
static
|
||||
void bsPutU16(EState* s, unsigned u)
|
||||
{
|
||||
bsW(s, 8, (u >> 8) & 0xff);
|
||||
bsW(s, 8, u & 0xff);
|
||||
}
|
||||
|
||||
|
||||
@@ -146,57 +106,25 @@ static
|
||||
void makeMaps_e(EState* s)
|
||||
{
|
||||
int i;
|
||||
unsigned cnt = 0;
|
||||
s->nInUse = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (s->inUse[i]) {
|
||||
s->unseqToSeq[i] = cnt;
|
||||
cnt++;
|
||||
s->unseqToSeq[i] = s->nInUse;
|
||||
s->nInUse++;
|
||||
}
|
||||
}
|
||||
s->nInUse = cnt;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------*/
|
||||
/*
|
||||
* This bit of code is performance-critical.
|
||||
* On 32bit x86, gcc-6.3.0 was observed to spill ryy_j to stack,
|
||||
* resulting in abysmal performance (x3 slowdown).
|
||||
* Forcing it into a separate function alleviates register pressure,
|
||||
* and spillage no longer happens.
|
||||
* Other versions of gcc do not exhibit this problem, but out-of-line code
|
||||
* seems to be helping them too (code is both smaller and faster).
|
||||
* Therefore NOINLINE is enabled for the entire 32bit x86 arch for now,
|
||||
* without a check for gcc version.
|
||||
*/
|
||||
static
|
||||
#if defined __i386__
|
||||
NOINLINE
|
||||
#endif
|
||||
int inner_loop(uint8_t *yy, uint8_t ll_i)
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
while (ll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
}
|
||||
yy[0] = rtmp;
|
||||
return ryy_j - &(yy[0]);
|
||||
}
|
||||
static NOINLINE
|
||||
void generateMTFValues(EState* s)
|
||||
{
|
||||
uint8_t yy[256];
|
||||
int i;
|
||||
int zPend;
|
||||
int32_t i, j;
|
||||
int32_t zPend;
|
||||
int32_t wr;
|
||||
int32_t EOB;
|
||||
|
||||
/*
|
||||
* After sorting (eg, here),
|
||||
@@ -220,74 +148,95 @@ void generateMTFValues(EState* s)
|
||||
* compressBlock().
|
||||
*/
|
||||
uint32_t* ptr = s->ptr;
|
||||
uint8_t* block = s->block;
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
makeMaps_e(s);
|
||||
EOB = s->nInUse+1;
|
||||
|
||||
for (i = 0; i <= EOB; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
wr = 0;
|
||||
zPend = 0;
|
||||
for (i = 0; i <= s->nInUse+1; i++)
|
||||
s->mtfFreq[i] = 0;
|
||||
|
||||
for (i = 0; i < s->nInUse; i++)
|
||||
yy[i] = (uint8_t) i;
|
||||
|
||||
for (i = 0; i < s->nblock; i++) {
|
||||
uint8_t ll_i = ll_i; /* gcc 4.3.1 thinks it may be used w/o init */
|
||||
int32_t j;
|
||||
|
||||
uint8_t ll_i;
|
||||
AssertD(wr <= i, "generateMTFValues(1)");
|
||||
j = ptr[i] - 1;
|
||||
if (j < 0)
|
||||
j += s->nblock;
|
||||
ll_i = s->unseqToSeq[s->block[j]];
|
||||
ll_i = s->unseqToSeq[block[j]];
|
||||
AssertD(ll_i < s->nInUse, "generateMTFValues(2a)");
|
||||
|
||||
if (yy[0] == ll_i) {
|
||||
zPend++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (zPend > 0) {
|
||||
process_zPend:
|
||||
zPend--;
|
||||
while (1) {
|
||||
#if 0
|
||||
if (zPend & 1) {
|
||||
s->mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
s->mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
#else /* same as above, since BZ_RUNA is 0 and BZ_RUNB is 1 */
|
||||
unsigned run = zPend & 1;
|
||||
s->mtfv[wr] = run;
|
||||
} else {
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB; wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA; wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2) break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
{
|
||||
register uint8_t rtmp;
|
||||
register uint8_t* ryy_j;
|
||||
register uint8_t rll_i;
|
||||
rtmp = yy[1];
|
||||
yy[1] = yy[0];
|
||||
ryy_j = &(yy[1]);
|
||||
rll_i = ll_i;
|
||||
while (rll_i != rtmp) {
|
||||
register uint8_t rtmp2;
|
||||
ryy_j++;
|
||||
rtmp2 = rtmp;
|
||||
rtmp = *ryy_j;
|
||||
*ryy_j = rtmp2;
|
||||
};
|
||||
yy[0] = rtmp;
|
||||
j = ryy_j - &(yy[0]);
|
||||
mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[run]++;
|
||||
#endif
|
||||
zPend -= 2;
|
||||
if (zPend < 0)
|
||||
break;
|
||||
zPend = (unsigned)zPend / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
if (i < 0) /* came via "goto process_zPend"? exit */
|
||||
goto end;
|
||||
zPend = 0;
|
||||
}
|
||||
j = inner_loop(yy, ll_i);
|
||||
s->mtfv[wr] = j+1;
|
||||
wr++;
|
||||
s->mtfFreq[j+1]++;
|
||||
}
|
||||
|
||||
i = -1;
|
||||
if (zPend > 0)
|
||||
goto process_zPend; /* "process it and come back here" */
|
||||
end:
|
||||
s->mtfv[wr] = s->nInUse+1;
|
||||
if (zPend > 0) {
|
||||
zPend--;
|
||||
while (1) {
|
||||
if (zPend & 1) {
|
||||
mtfv[wr] = BZ_RUNB;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNB]++;
|
||||
} else {
|
||||
mtfv[wr] = BZ_RUNA;
|
||||
wr++;
|
||||
s->mtfFreq[BZ_RUNA]++;
|
||||
}
|
||||
if (zPend < 2)
|
||||
break;
|
||||
zPend = (uint32_t)(zPend - 2) / 2;
|
||||
/* bbox: unsigned div is easier */
|
||||
};
|
||||
zPend = 0;
|
||||
}
|
||||
|
||||
mtfv[wr] = EOB;
|
||||
wr++;
|
||||
s->mtfFreq[s->nInUse+1]++;
|
||||
s->mtfFreq[EOB]++;
|
||||
|
||||
s->nMTF = wr;
|
||||
}
|
||||
@@ -300,11 +249,8 @@ void generateMTFValues(EState* s)
|
||||
static NOINLINE
|
||||
void sendMTFValues(EState* s)
|
||||
{
|
||||
int32_t t, i;
|
||||
unsigned iter;
|
||||
unsigned gs;
|
||||
int32_t alphaSize;
|
||||
unsigned nSelectors, selCtr;
|
||||
int32_t v, t, i, j, gs, ge, bt, bc, iter;
|
||||
int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
|
||||
int32_t nGroups;
|
||||
|
||||
/*
|
||||
@@ -320,49 +266,39 @@ void sendMTFValues(EState* s)
|
||||
#define rfreq sendMTFValues__rfreq
|
||||
#define len_pack sendMTFValues__len_pack
|
||||
|
||||
unsigned /*uint16_t*/ cost[BZ_N_GROUPS];
|
||||
uint16_t cost[BZ_N_GROUPS];
|
||||
int32_t fave[BZ_N_GROUPS];
|
||||
|
||||
uint16_t* mtfv = s->mtfv;
|
||||
|
||||
alphaSize = s->nInUse + 2;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++) {
|
||||
unsigned v;
|
||||
for (t = 0; t < BZ_N_GROUPS; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->len[t][v] = BZ_GREATER_ICOST;
|
||||
}
|
||||
|
||||
/*--- Decide how many coding tables to use ---*/
|
||||
AssertH(s->nMTF > 0, 3001);
|
||||
// 1..199 = 2
|
||||
// 200..599 = 3
|
||||
// 600..1199 = 4
|
||||
// 1200..2399 = 5
|
||||
// 2400..99999 = 6
|
||||
nGroups = 2;
|
||||
nGroups += (s->nMTF >= 200);
|
||||
nGroups += (s->nMTF >= 600);
|
||||
nGroups += (s->nMTF >= 1200);
|
||||
nGroups += (s->nMTF >= 2400);
|
||||
if (s->nMTF < 200) nGroups = 2; else
|
||||
if (s->nMTF < 600) nGroups = 3; else
|
||||
if (s->nMTF < 1200) nGroups = 4; else
|
||||
if (s->nMTF < 2400) nGroups = 5; else
|
||||
nGroups = 6;
|
||||
|
||||
/*--- Generate an initial set of coding tables ---*/
|
||||
{
|
||||
unsigned nPart, remF;
|
||||
int32_t nPart, remF, tFreq, aFreq;
|
||||
|
||||
nPart = nGroups;
|
||||
remF = s->nMTF;
|
||||
gs = 0;
|
||||
while (nPart > 0) {
|
||||
unsigned v;
|
||||
unsigned ge;
|
||||
unsigned tFreq, aFreq;
|
||||
|
||||
tFreq = remF / nPart;
|
||||
ge = gs;
|
||||
ge = gs - 1;
|
||||
aFreq = 0;
|
||||
while (aFreq < tFreq && ge < alphaSize) {
|
||||
aFreq += s->mtfFreq[ge++];
|
||||
while (aFreq < tFreq && ge < alphaSize-1) {
|
||||
ge++;
|
||||
aFreq += s->mtfFreq[ge];
|
||||
}
|
||||
ge--;
|
||||
|
||||
if (ge > gs
|
||||
&& nPart != nGroups && nPart != 1
|
||||
@@ -388,19 +324,19 @@ void sendMTFValues(EState* s)
|
||||
* Iterate up to BZ_N_ITERS times to improve the tables.
|
||||
*/
|
||||
for (iter = 0; iter < BZ_N_ITERS; iter++) {
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned v;
|
||||
for (t = 0; t < nGroups; t++)
|
||||
fave[t] = 0;
|
||||
|
||||
for (t = 0; t < nGroups; t++)
|
||||
for (v = 0; v < alphaSize; v++)
|
||||
s->rfreq[t][v] = 0;
|
||||
}
|
||||
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FAST >= 5
|
||||
/*
|
||||
* Set up an auxiliary length table which is used to fast-track
|
||||
* the common case (nGroups == 6).
|
||||
*/
|
||||
if (nGroups == 6) {
|
||||
unsigned v;
|
||||
for (v = 0; v < alphaSize; v++) {
|
||||
s->len_pack[v][0] = (s->len[1][v] << 16) | s->len[0][v];
|
||||
s->len_pack[v][1] = (s->len[3][v] << 16) | s->len[2][v];
|
||||
@@ -411,9 +347,6 @@ void sendMTFValues(EState* s)
|
||||
nSelectors = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
unsigned bt, bc;
|
||||
|
||||
/*--- Set group start & end marks. --*/
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
@@ -427,7 +360,7 @@ void sendMTFValues(EState* s)
|
||||
*/
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] = 0;
|
||||
#if BZIP2_SPEED >= 5
|
||||
#if CONFIG_BZIP2_FAST >= 5
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
register uint32_t cost01, cost23, cost45;
|
||||
@@ -457,7 +390,7 @@ void sendMTFValues(EState* s)
|
||||
{
|
||||
/*--- slow version which correctly handles all situations ---*/
|
||||
for (i = gs; i <= ge; i++) {
|
||||
unsigned /*uint16_t*/ icv = mtfv[i];
|
||||
uint16_t icv = mtfv[i];
|
||||
for (t = 0; t < nGroups; t++)
|
||||
cost[t] += s->len[t][icv];
|
||||
}
|
||||
@@ -476,6 +409,7 @@ void sendMTFValues(EState* s)
|
||||
bt = t;
|
||||
}
|
||||
}
|
||||
fave[bt]++;
|
||||
s->selector[nSelectors] = bt;
|
||||
nSelectors++;
|
||||
|
||||
@@ -483,7 +417,7 @@ void sendMTFValues(EState* s)
|
||||
* Increment the symbol frequencies for the selected table.
|
||||
*/
|
||||
/* 1% faster compress. +800 bytes */
|
||||
#if BZIP2_SPEED >= 4
|
||||
#if CONFIG_BZIP2_FAST >= 4
|
||||
if (nGroups == 6 && 50 == ge-gs+1) {
|
||||
/*--- fast track the common case ---*/
|
||||
#define BZ_ITUR(nn) s->rfreq[bt][mtfv[gs + (nn)]]++
|
||||
@@ -530,7 +464,6 @@ void sendMTFValues(EState* s)
|
||||
for (i = 0; i < nGroups; i++)
|
||||
pos[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
unsigned j;
|
||||
ll_i = s->selector[i];
|
||||
j = 0;
|
||||
tmp = pos[j];
|
||||
@@ -539,16 +472,16 @@ void sendMTFValues(EState* s)
|
||||
tmp2 = tmp;
|
||||
tmp = pos[j];
|
||||
pos[j] = tmp2;
|
||||
}
|
||||
};
|
||||
pos[0] = tmp;
|
||||
s->selectorMtf[i] = j;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*--- Assign actual codes for the tables. --*/
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned minLen = 32; //todo: s->len[t][0];
|
||||
unsigned maxLen = 0; //todo: s->len[t][0];
|
||||
minLen = 32;
|
||||
maxLen = 0;
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
|
||||
if (s->len[t][i] < minLen) minLen = s->len[t][i];
|
||||
@@ -576,16 +509,15 @@ void sendMTFValues(EState* s)
|
||||
}
|
||||
}
|
||||
|
||||
bsW16(s, inUse16);
|
||||
bsW(s, 16, inUse16);
|
||||
|
||||
inUse16 <<= (sizeof(int)*8 - 16); /* move 15th bit into sign bit */
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (inUse16 < 0) {
|
||||
unsigned v16 = 0;
|
||||
unsigned j;
|
||||
for (j = 0; j < 16; j++)
|
||||
v16 = v16*2 + s->inUse[i * 16 + j];
|
||||
bsW16(s, v16);
|
||||
bsW(s, 16, v16);
|
||||
}
|
||||
inUse16 <<= 1;
|
||||
}
|
||||
@@ -595,20 +527,19 @@ void sendMTFValues(EState* s)
|
||||
bsW(s, 3, nGroups);
|
||||
bsW(s, 15, nSelectors);
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
unsigned j;
|
||||
for (j = 0; j < s->selectorMtf[i]; j++)
|
||||
bsW1_1(s);
|
||||
bsW1_0(s);
|
||||
bsW(s, 1, 1);
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
|
||||
/*--- Now the coding tables. ---*/
|
||||
for (t = 0; t < nGroups; t++) {
|
||||
unsigned curr = s->len[t][0];
|
||||
int32_t curr = s->len[t][0];
|
||||
bsW(s, 5, curr);
|
||||
for (i = 0; i < alphaSize; i++) {
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ }
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ }
|
||||
bsW1_0(s);
|
||||
while (curr < s->len[t][i]) { bsW(s, 2, 2); curr++; /* 10 */ };
|
||||
while (curr > s->len[t][i]) { bsW(s, 2, 3); curr--; /* 11 */ };
|
||||
bsW(s, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -616,8 +547,6 @@ void sendMTFValues(EState* s)
|
||||
selCtr = 0;
|
||||
gs = 0;
|
||||
while (1) {
|
||||
unsigned ge;
|
||||
|
||||
if (gs >= s->nMTF)
|
||||
break;
|
||||
ge = gs + BZ_G_SIZE - 1;
|
||||
@@ -676,21 +605,17 @@ void sendMTFValues(EState* s)
|
||||
static
|
||||
void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
{
|
||||
int32_t origPtr = origPtr;
|
||||
|
||||
if (s->nblock > 0) {
|
||||
BZ_FINALISE_CRC(s->blockCRC);
|
||||
s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
|
||||
s->combinedCRC ^= s->blockCRC;
|
||||
if (s->blockNo > 1)
|
||||
s->posZ = s->zbits; // was: s->numZ = 0;
|
||||
s->numZ = 0;
|
||||
|
||||
origPtr = BZ2_blockSort(s);
|
||||
BZ2_blockSort(s);
|
||||
}
|
||||
|
||||
s->zbits = &((uint8_t*)s->arr2)[s->nblock];
|
||||
s->posZ = s->zbits;
|
||||
s->state_out_pos = s->zbits;
|
||||
|
||||
/*-- If this is the first block, create the stream header. --*/
|
||||
if (s->blockNo == 1) {
|
||||
@@ -724,9 +649,9 @@ void BZ2_compressBlock(EState* s, int is_last_block)
|
||||
* so as to maintain backwards compatibility with
|
||||
* older versions of bzip2.
|
||||
*/
|
||||
bsW1_0(s);
|
||||
bsW(s, 1, 0);
|
||||
|
||||
bsW(s, 24, origPtr);
|
||||
bsW(s, 24, s->origPtr);
|
||||
generateMTFValues(s);
|
||||
sendMTFValues(s);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ in the file LICENSE.
|
||||
|
||||
|
||||
/* 90 bytes, 0.3% of overall compress speed */
|
||||
#if BZIP2_SPEED >= 1
|
||||
#if CONFIG_BZIP2_FAST >= 1
|
||||
|
||||
/* macro works better than inline (gcc 4.2.1) */
|
||||
#define DOWNHEAP1(heap, weight, Heap) \
|
||||
@@ -217,7 +217,7 @@ void BZ2_hbAssignCodes(int32_t *code,
|
||||
if (length[i] == n) {
|
||||
code[i] = vec;
|
||||
vec++;
|
||||
}
|
||||
};
|
||||
}
|
||||
vec <<= 1;
|
||||
}
|
||||
|
||||
@@ -122,10 +122,13 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
|
||||
/* Handle hard links separately */
|
||||
if (hard_link) {
|
||||
create_or_remember_link(&archive_handle->link_placeholders,
|
||||
hard_link,
|
||||
dst_name,
|
||||
1);
|
||||
res = link(hard_link, dst_name);
|
||||
if (res != 0) {
|
||||
/* shared message */
|
||||
bb_perror_msg("can't create %slink '%s' to '%s'",
|
||||
"hard", dst_name, hard_link
|
||||
);
|
||||
}
|
||||
/* Hardlinks have no separate mode/ownership, skip chown/chmod */
|
||||
goto ret;
|
||||
}
|
||||
@@ -192,10 +195,9 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
*
|
||||
* Untarring bug.tar would otherwise place evil.py in '/tmp'.
|
||||
*/
|
||||
create_or_remember_link(&archive_handle->link_placeholders,
|
||||
create_or_remember_symlink(&archive_handle->symlink_placeholders,
|
||||
file_header->link_target,
|
||||
dst_name,
|
||||
0);
|
||||
dst_name);
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
case S_IFBLK:
|
||||
|
||||
@@ -37,7 +37,7 @@ static const char *const tar_var[] = {
|
||||
static void xputenv(char *str)
|
||||
{
|
||||
if (putenv(str))
|
||||
bb_die_memory_exhausted();
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
}
|
||||
|
||||
static void str2env(char *env[], int idx, const char *str)
|
||||
|
||||
@@ -100,14 +100,14 @@ struct bunzip_data {
|
||||
unsigned dbufSize;
|
||||
|
||||
/* For I/O error handling */
|
||||
jmp_buf *jmpbuf;
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Big things go last (register-relative addressing can be larger for big offsets) */
|
||||
uint32_t crc32Table[256];
|
||||
uint8_t selectors[32768]; /* nSelectors=15 bits */
|
||||
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
||||
};
|
||||
typedef struct bunzip_data bunzip_data;
|
||||
/* typedef struct bunzip_data bunzip_data; -- done in .h file */
|
||||
|
||||
|
||||
/* Return the next nnn bits of input. All reads from the compressed input
|
||||
@@ -127,7 +127,7 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
|
||||
/* if "no input fd" case: in_fd == -1, read fails, we jump */
|
||||
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
|
||||
if (bd->inbufCount <= 0)
|
||||
longjmp(*bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
longjmp(bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
bd->inbufPos = 0;
|
||||
}
|
||||
|
||||
@@ -151,12 +151,12 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
|
||||
|
||||
return bits;
|
||||
}
|
||||
//#define get_bits(bd, n) (dbg("%d:get_bits()", __LINE__), get_bits(bd, n))
|
||||
|
||||
/* Unpacks the next block and sets up for the inverse Burrows-Wheeler step. */
|
||||
static int get_next_block(bunzip_data *bd)
|
||||
{
|
||||
int groupCount, selector,
|
||||
struct group_data *hufGroup;
|
||||
int groupCount, *base, *limit, selector,
|
||||
i, j, symCount, symTotal, nSelectors, byteCount[256];
|
||||
uint8_t uc, symToByte[256], mtfSymbol[256], *selectors;
|
||||
uint32_t *dbuf;
|
||||
@@ -179,19 +179,15 @@ static int get_next_block(bunzip_data *bd)
|
||||
i = get_bits(bd, 24);
|
||||
j = get_bits(bd, 24);
|
||||
bd->headerCRC = get_bits(bd, 32);
|
||||
if ((i == 0x177245) && (j == 0x385090))
|
||||
return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359))
|
||||
return RETVAL_NOT_BZIP_DATA;
|
||||
if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* We can add support for blockRandomised if anybody complains. There was
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
if (get_bits(bd, 1))
|
||||
return RETVAL_OBSOLETE_INPUT;
|
||||
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
|
||||
origPtr = get_bits(bd, 24);
|
||||
if (origPtr > bd->dbufSize)
|
||||
return RETVAL_DATA_ERROR;
|
||||
if (origPtr > bd->dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
@@ -235,21 +231,13 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Get next value */
|
||||
int n = 0;
|
||||
while (get_bits(bd, 1)) {
|
||||
if (n >= groupCount)
|
||||
return RETVAL_DATA_ERROR;
|
||||
if (n >= groupCount) return RETVAL_DATA_ERROR;
|
||||
n++;
|
||||
}
|
||||
/* Decode MTF to get the next selector */
|
||||
tmp_byte = mtfSymbol[n];
|
||||
while (--n >= 0)
|
||||
mtfSymbol[n + 1] = mtfSymbol[n];
|
||||
//We catch it later, in the second loop where we use selectors[i].
|
||||
//Maybe this is a better place, though?
|
||||
// if (tmp_byte >= groupCount) {
|
||||
// dbg("%d: selectors[%d]:%d groupCount:%d",
|
||||
// __LINE__, i, tmp_byte, groupCount);
|
||||
// return RETVAL_DATA_ERROR;
|
||||
// }
|
||||
mtfSymbol[0] = selectors[i] = tmp_byte;
|
||||
}
|
||||
|
||||
@@ -260,8 +248,6 @@ static int get_next_block(bunzip_data *bd)
|
||||
uint8_t length[MAX_SYMBOLS];
|
||||
/* 8 bits is ALMOST enough for temp[], see below */
|
||||
unsigned temp[MAX_HUFCODE_BITS+1];
|
||||
struct group_data *hufGroup;
|
||||
int *base, *limit;
|
||||
int minLen, maxLen, pp, len_m1;
|
||||
|
||||
/* Read Huffman code lengths for each symbol. They're stored in
|
||||
@@ -297,10 +283,8 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Find largest and smallest lengths in this group */
|
||||
minLen = maxLen = length[0];
|
||||
for (i = 1; i < symCount; i++) {
|
||||
if (length[i] > maxLen)
|
||||
maxLen = length[i];
|
||||
else if (length[i] < minLen)
|
||||
minLen = length[i];
|
||||
if (length[i] > maxLen) maxLen = length[i];
|
||||
else if (length[i] < minLen) minLen = length[i];
|
||||
}
|
||||
|
||||
/* Calculate permute[], base[], and limit[] tables from length[].
|
||||
@@ -336,8 +320,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
/* Count symbols coded for at each bit length */
|
||||
/* NB: in pathological cases, temp[8] can end ip being 256.
|
||||
* That's why uint8_t is too small for temp[]. */
|
||||
for (i = 0; i < symCount; i++)
|
||||
temp[length[i]]++;
|
||||
for (i = 0; i < symCount; i++) temp[length[i]]++;
|
||||
|
||||
/* Calculate limit[] (the largest symbol-coding value at each bit
|
||||
* length, which is (previous limit<<1)+symbols at this level), and
|
||||
@@ -380,22 +363,12 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
runPos = dbufCount = selector = 0;
|
||||
for (;;) {
|
||||
struct group_data *hufGroup;
|
||||
int *base, *limit;
|
||||
int nextSym;
|
||||
uint8_t ngrp;
|
||||
|
||||
/* Fetch next Huffman coding group from list. */
|
||||
symCount = GROUP_SIZE - 1;
|
||||
if (selector >= nSelectors)
|
||||
return RETVAL_DATA_ERROR;
|
||||
ngrp = selectors[selector++];
|
||||
if (ngrp >= groupCount) {
|
||||
dbg("%d selectors[%d]:%d groupCount:%d",
|
||||
__LINE__, selector-1, ngrp, groupCount);
|
||||
return RETVAL_DATA_ERROR;
|
||||
}
|
||||
hufGroup = bd->groups + ngrp;
|
||||
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup = bd->groups + selectors[selector++];
|
||||
base = hufGroup->base - 1;
|
||||
limit = hufGroup->limit - 1;
|
||||
|
||||
@@ -430,8 +403,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
}
|
||||
/* Figure how many bits are in next symbol and unget extras */
|
||||
i = hufGroup->minLen;
|
||||
while (nextSym > limit[i])
|
||||
++i;
|
||||
while (nextSym > limit[i]) ++i;
|
||||
j = hufGroup->maxLen - i;
|
||||
if (j < 0)
|
||||
return RETVAL_DATA_ERROR;
|
||||
@@ -575,7 +547,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
in outbuf. IOW: on EOF returns len ("all bytes are not filled"), not 0.
|
||||
(Why? This allows to get rid of one local variable)
|
||||
*/
|
||||
static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
{
|
||||
const uint32_t *dbuf;
|
||||
int pos, current, previous;
|
||||
@@ -699,10 +671,7 @@ static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
|
||||
should work for NOFORK applets too, we must be extremely careful to not leak
|
||||
any allocations! */
|
||||
static int FAST_FUNC start_bunzip(
|
||||
void *jmpbuf,
|
||||
bunzip_data **bdp,
|
||||
int in_fd,
|
||||
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd,
|
||||
const void *inbuf, int len)
|
||||
{
|
||||
bunzip_data *bd;
|
||||
@@ -714,14 +683,11 @@ static int FAST_FUNC start_bunzip(
|
||||
|
||||
/* Figure out how much data to allocate */
|
||||
i = sizeof(bunzip_data);
|
||||
if (in_fd != -1)
|
||||
i += IOBUF_SIZE;
|
||||
if (in_fd != -1) i += IOBUF_SIZE;
|
||||
|
||||
/* Allocate bunzip_data. Most fields initialize to zero. */
|
||||
bd = *bdp = xzalloc(i);
|
||||
|
||||
bd->jmpbuf = jmpbuf;
|
||||
|
||||
/* Setup input buffer */
|
||||
bd->in_fd = in_fd;
|
||||
if (-1 == in_fd) {
|
||||
@@ -736,6 +702,10 @@ static int FAST_FUNC start_bunzip(
|
||||
/* Init the CRC32 table (big endian) */
|
||||
crc32_filltable(bd->crc32Table, 1);
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
|
||||
/* Ensure that file starts with "BZh['1'-'9']." */
|
||||
/* Update: now caller verifies 1st two bytes, makes .gz/.bz2
|
||||
* integration easier */
|
||||
@@ -759,7 +729,7 @@ static int FAST_FUNC start_bunzip(
|
||||
return RETVAL_OK;
|
||||
}
|
||||
|
||||
static void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
{
|
||||
free(bd->dbuf);
|
||||
free(bd);
|
||||
@@ -782,12 +752,8 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
len = 0;
|
||||
while (1) { /* "Process one BZ... stream" loop */
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(jmpbuf);
|
||||
if (i == 0)
|
||||
i = start_bunzip(&jmpbuf, &bd, xstate->src_fd, outbuf + 2, len);
|
||||
i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len);
|
||||
|
||||
if (i == 0) {
|
||||
while (1) { /* "Produce some output bytes" loop */
|
||||
@@ -809,7 +775,7 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
/* Observed case when i == RETVAL_OK:
|
||||
* "bzcat z.bz2", where "z.bz2" is a bzipped zero-length file
|
||||
* (to be exact, z.bz2 is exactly these 14 bytes:
|
||||
* 42 5a 68 39 17 72 45 38 50 90 00 00 00 00).
|
||||
* 42 5a 68 39 17 72 45 38 50 90 00 00 00 00).
|
||||
*/
|
||||
&& i != RETVAL_OK
|
||||
) {
|
||||
@@ -847,36 +813,6 @@ unpack_bz2_stream(transformer_state_t *xstate)
|
||||
return i ? i : IF_DESKTOP(total_written) + 0;
|
||||
}
|
||||
|
||||
char* FAST_FUNC
|
||||
unpack_bz2_data(const char *packed, int packed_len, int unpacked_len)
|
||||
{
|
||||
char *outbuf = NULL;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
jmp_buf jmpbuf;
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
i = setjmp(jmpbuf);
|
||||
if (i == 0) {
|
||||
i = start_bunzip(&jmpbuf,
|
||||
&bd,
|
||||
/* src_fd: */ -1,
|
||||
/* inbuf: */ packed,
|
||||
/* len: */ packed_len
|
||||
);
|
||||
}
|
||||
/* read_bunzip can longjmp and end up here with i != 0
|
||||
* on read data errors! Not trivial */
|
||||
if (i == 0) {
|
||||
/* Cannot use xmalloc: will leak bd in NOFORK case! */
|
||||
outbuf = malloc_or_warn(unpacked_len);
|
||||
if (outbuf)
|
||||
read_bunzip(bd, outbuf, unpacked_len);
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static char *const bunzip_errors[] = {
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
#include <setjmp.h>
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
@@ -279,8 +280,8 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current
|
||||
/* Given a list of code lengths and a maximum table size, make a set of
|
||||
* tables to decode that set of codes. Return zero on success, one if
|
||||
* the given code set is incomplete (the tables are still built in this
|
||||
* case), two if the input is invalid (an oversubscribed set of lengths)
|
||||
* - in this case stores NULL in *t.
|
||||
* case), two if the input is invalid (all zero length codes or an
|
||||
* oversubscribed set of lengths) - in this case stores NULL in *t.
|
||||
*
|
||||
* b: code lengths in bits (all assumed <= BMAX)
|
||||
* n: number of codes (assumed <= N_MAX)
|
||||
@@ -329,15 +330,8 @@ static int huft_build(const unsigned *b, const unsigned n,
|
||||
p++; /* can't combine with above line (Solaris bug) */
|
||||
} while (--i);
|
||||
if (c[0] == n) { /* null input - all zero length codes */
|
||||
q = xzalloc(3 * sizeof(*q));
|
||||
//q[0].v.t = NULL;
|
||||
q[1].e = 99; /* invalid code marker */
|
||||
q[1].b = 1;
|
||||
q[2].e = 99; /* invalid code marker */
|
||||
q[2].b = 1;
|
||||
*t = q + 1;
|
||||
*m = 1;
|
||||
return 0;
|
||||
*m = 0;
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Find minimum and maximum length, bound *m by those */
|
||||
@@ -1006,7 +1000,7 @@ inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate)
|
||||
gunzip_bb = 0;
|
||||
|
||||
/* Create the crc table */
|
||||
gunzip_crc_table = crc32_new_table_le();
|
||||
gunzip_crc_table = crc32_filltable(NULL, 0);
|
||||
gunzip_crc = ~0;
|
||||
|
||||
error_msg = "corrupted data";
|
||||
|
||||
@@ -11,13 +11,6 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
#if 0
|
||||
# define dbg(...) bb_error_msg(__VA_ARGS__)
|
||||
#else
|
||||
# define dbg(...) ((void)0)
|
||||
#endif
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
# define speed_inline ALWAYS_INLINE
|
||||
# define size_inline
|
||||
@@ -224,7 +217,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
rc_t *rc;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
uint32_t buffer_size;
|
||||
uint8_t previous_byte = 0;
|
||||
size_t buffer_pos = 0, global_pos = 0;
|
||||
int len = 0;
|
||||
@@ -254,8 +246,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if (header.dict_size == 0)
|
||||
header.dict_size++;
|
||||
|
||||
buffer_size = MIN(header.dst_size, header.dict_size);
|
||||
buffer = xmalloc(buffer_size);
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
{
|
||||
int num_probs;
|
||||
@@ -350,14 +341,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
if ((int32_t)pos < 0) {
|
||||
if ((int32_t)pos < 0)
|
||||
pos += header.dict_size;
|
||||
/* see unzip_bad_lzma_2.zip: */
|
||||
if (pos >= buffer_size) {
|
||||
dbg("%d pos:%d buffer_size:%d", __LINE__, pos, buffer_size);
|
||||
goto bad;
|
||||
}
|
||||
}
|
||||
previous_byte = buffer[pos];
|
||||
goto one_byte1;
|
||||
#else
|
||||
@@ -432,9 +417,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
// Note: (int32_t)rep0 may be < 0 here
|
||||
// (I have linux-3.3.4.tar.lzma which has it).
|
||||
// I moved the check after "++rep0 == 0" check below.
|
||||
prob3 = p + LZMA_ALIGN;
|
||||
}
|
||||
i2 = 1;
|
||||
@@ -445,13 +427,8 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
i2 <<= 1;
|
||||
}
|
||||
}
|
||||
rep0++;
|
||||
if ((int32_t)rep0 <= 0) {
|
||||
if (rep0 == 0)
|
||||
break;
|
||||
dbg("%d rep0:%d", __LINE__, rep0);
|
||||
goto bad;
|
||||
}
|
||||
if (++rep0 == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
len += LZMA_MATCH_MIN_LEN;
|
||||
@@ -476,10 +453,7 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
if ((int32_t)pos < 0) {
|
||||
pos += header.dict_size;
|
||||
/* bug 10436 has an example file where this triggers: */
|
||||
//if ((int32_t)pos < 0)
|
||||
// goto bad;
|
||||
/* more stringent test (see unzip_bad_lzma_1.zip): */
|
||||
if (pos >= buffer_size)
|
||||
if ((int32_t)pos < 0)
|
||||
goto bad;
|
||||
}
|
||||
previous_byte = buffer[pos];
|
||||
@@ -508,12 +482,6 @@ unpack_lzma_stream(transformer_state_t *xstate)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
/* One of our users, bbunpack(), expects _us_ to emit
|
||||
* the error message (since it's the best place to give
|
||||
* potentially more detailed information).
|
||||
* Do not fail silently.
|
||||
*/
|
||||
bb_error_msg("corrupted data");
|
||||
total_written = -1; /* failure */
|
||||
}
|
||||
rc_free(rc);
|
||||
|
||||
@@ -52,7 +52,7 @@ unpack_xz_stream(transformer_state_t *xstate)
|
||||
IF_DESKTOP(long long) int total = 0;
|
||||
|
||||
if (!global_crc32_table)
|
||||
global_crc32_new_table_le();
|
||||
global_crc32_table = crc32_filltable(NULL, /*endian:*/ 0);
|
||||
|
||||
memset(&iobuf, 0, sizeof(iobuf));
|
||||
membuf = xmalloc(2 * BUFSIZ);
|
||||
|
||||
@@ -34,6 +34,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
char raw[60];
|
||||
struct ar_header formatted;
|
||||
} ar;
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned ar_long_name_size;
|
||||
#endif
|
||||
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
if (read(archive_handle->src_fd, ar.raw, 60) != 60) {
|
||||
@@ -77,10 +81,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries
|
||||
*/
|
||||
archive_handle->ar__long_name_size = size;
|
||||
free(archive_handle->ar__long_names);
|
||||
archive_handle->ar__long_names = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->ar__long_names, size);
|
||||
ar_long_name_size = size;
|
||||
free(ar_long_names);
|
||||
ar_long_names = xmalloc(size);
|
||||
xread(archive_handle->src_fd, ar_long_names, size);
|
||||
archive_handle->offset += size;
|
||||
/* Return next header */
|
||||
return get_header_ar(archive_handle);
|
||||
@@ -103,13 +107,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
unsigned long_offset;
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in ar__long_names) that contains the real filename */
|
||||
* (saved in ar_long_names) that conatains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10,
|
||||
sizeof(ar.formatted.name) - 1);
|
||||
if (long_offset >= archive_handle->ar__long_name_size) {
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(archive_handle->ar__long_names + long_offset);
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@@ -126,7 +130,7 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
struct archive_handle_t *sa = archive_handle->dpkg__sub_archive;
|
||||
while (archive_handle->dpkg__action_data_subarchive(sa) == EXIT_SUCCESS)
|
||||
continue;
|
||||
create_links_from_list(sa->link_placeholders);
|
||||
create_symlinks_from_list(sa->symlink_placeholders);
|
||||
} else
|
||||
#endif
|
||||
archive_handle->action_data(archive_handle);
|
||||
|
||||
@@ -414,8 +414,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
// case 'D': /* GNU dump dir */
|
||||
// case 'M': /* Continuation of multi volume archive */
|
||||
// case 'N': /* Old GNU for names > 100 characters */
|
||||
case 'V': /* Volume header */
|
||||
; /* Fall through to skip it */
|
||||
// case 'V': /* Volume header */
|
||||
#endif
|
||||
}
|
||||
skip_ext_hdr:
|
||||
|
||||
@@ -487,7 +487,7 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
}
|
||||
|
||||
/* this is a public functions, but there is no prototype in a header file */
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in , unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
************************************************************************/
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len /*, void* wrkmem */)
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
register uint8_t* op;
|
||||
register const uint8_t* ip;
|
||||
|
||||
@@ -278,7 +278,8 @@ static transformer_state_t *open_transformer(const char *fname, int fail_if_not_
|
||||
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA) {
|
||||
/* .lzma has no header/signature, can only detect it by extension */
|
||||
if (is_suffixed_with(fname, ".lzma")) {
|
||||
char *sfx = strrchr(fname, '.');
|
||||
if (sfx && strcmp(sfx+1, "lzma") == 0) {
|
||||
xstate = xzalloc(sizeof(*xstate));
|
||||
xstate->src_fd = fd;
|
||||
xstate->xformer = unpack_lzma_stream;
|
||||
|
||||
@@ -5,14 +5,13 @@
|
||||
#include "libbb.h"
|
||||
#include "bb_archive.h"
|
||||
|
||||
void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
|
||||
void FAST_FUNC create_or_remember_symlink(llist_t **symlink_placeholders,
|
||||
const char *target,
|
||||
const char *linkname,
|
||||
int hard_link)
|
||||
const char *linkname)
|
||||
{
|
||||
if (hard_link || target[0] == '/' || strstr(target, "..")) {
|
||||
llist_add_to_end(link_placeholders,
|
||||
xasprintf("%c%s%c%s", hard_link, linkname, '\0', target)
|
||||
if (target[0] == '/' || strstr(target, "..")) {
|
||||
llist_add_to(symlink_placeholders,
|
||||
xasprintf("%s%c%s", linkname, '\0', target)
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -24,17 +23,17 @@ void FAST_FUNC create_or_remember_link(llist_t **link_placeholders,
|
||||
}
|
||||
}
|
||||
|
||||
void FAST_FUNC create_links_from_list(llist_t *list)
|
||||
void FAST_FUNC create_symlinks_from_list(llist_t *list)
|
||||
{
|
||||
while (list) {
|
||||
char *target;
|
||||
|
||||
target = list->data + 1 + strlen(list->data + 1) + 1;
|
||||
if ((*list->data ? link : symlink) (target, list->data + 1)) {
|
||||
target = list->data + strlen(list->data) + 1;
|
||||
if (symlink(target, list->data)) {
|
||||
/* shared message */
|
||||
bb_error_msg_and_die("can't create %slink '%s' to '%s'",
|
||||
*list->data ? "hard" : "sym",
|
||||
list->data + 1, target
|
||||
"sym",
|
||||
list->data, target
|
||||
);
|
||||
}
|
||||
list = list->link;
|
||||
|
||||
+227
-217
@@ -25,7 +25,7 @@
|
||||
"Minimalized" for busybox by Alain Knaff
|
||||
*/
|
||||
//config:config LZOP
|
||||
//config: bool "lzop (12 kb)"
|
||||
//config: bool "lzop (13 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Lzop compression/decompresion.
|
||||
@@ -80,7 +80,7 @@
|
||||
//usage: "\n -F Don't verify checksum"
|
||||
//usage:
|
||||
//usage:#define unlzop_trivial_usage
|
||||
//usage: "[-cfUvF] [FILE]..."
|
||||
//usage: "[-cfkvF] [FILE]..."
|
||||
//usage:#define unlzop_full_usage "\n\n"
|
||||
//usage: " -c Write to stdout"
|
||||
//usage: "\n -f Force"
|
||||
@@ -141,7 +141,8 @@ static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
|
||||
#define TEST_OP (op <= op_end)
|
||||
|
||||
static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len /*, void* wrkmem */)
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
uint8_t* op;
|
||||
uint8_t* ip;
|
||||
@@ -438,33 +439,36 @@ typedef struct chksum_t {
|
||||
} chksum_t;
|
||||
|
||||
typedef struct header_t {
|
||||
/* used to have auxiliary fields here */
|
||||
unsigned version;
|
||||
unsigned lib_version;
|
||||
unsigned version_needed_to_extract;
|
||||
uint32_t flags;
|
||||
uint32_t mode;
|
||||
uint32_t mtime;
|
||||
uint32_t gmtdiff;
|
||||
uint32_t header_checksum;
|
||||
|
||||
/* Starting from here, the layout and endianness
|
||||
* are exactly in on-disk format.
|
||||
*/
|
||||
uint16_t version_be16;
|
||||
uint16_t lib_version_be16;
|
||||
uint16_t version_needed_to_extract_be16;
|
||||
uint8_t method;
|
||||
uint8_t level;
|
||||
uint32_t flags32; /* be32 on disk, but we keep this field in native order */
|
||||
uint32_t mode_be32;
|
||||
uint32_t mtime_be32;
|
||||
uint32_t gmtdiff_be32;
|
||||
char len_and_name[1+255+1];
|
||||
uint32_t extra_field_len;
|
||||
uint32_t extra_field_checksum;
|
||||
|
||||
unsigned char method;
|
||||
unsigned char level;
|
||||
|
||||
/* info */
|
||||
char name[255+1];
|
||||
} header_t;
|
||||
|
||||
struct globals {
|
||||
/*const uint32_t *lzo_crc32_table;*/
|
||||
chksum_t chksum;
|
||||
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 (*ptr_to_globals)
|
||||
#define INIT_G() do { \
|
||||
setup_common_bufsiz(); \
|
||||
/*SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));*/ \
|
||||
} while (0)
|
||||
//#define INIT_G() do {
|
||||
// SET_PTR_TO_GLOBALS(xzalloc(sizeof(G)));
|
||||
//} while (0)
|
||||
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -545,24 +549,24 @@ lzo_crc32(uint32_t c, const uint8_t* buf, unsigned len)
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
static void init_chksum(void)
|
||||
static void init_chksum(chksum_t *ct)
|
||||
{
|
||||
G.chksum.f_adler32 = ADLER32_INIT_VALUE;
|
||||
G.chksum.f_crc32 = CRC32_INIT_VALUE;
|
||||
ct->f_adler32 = ADLER32_INIT_VALUE;
|
||||
ct->f_crc32 = CRC32_INIT_VALUE;
|
||||
}
|
||||
|
||||
static void add_bytes_to_chksum(const void* buf, int cnt)
|
||||
static void add_bytes_to_chksum(chksum_t *ct, const void* buf, int cnt)
|
||||
{
|
||||
/* We need to handle the two checksums at once, because at the
|
||||
* beginning of the header, we don't know yet which one we'll
|
||||
* eventually need */
|
||||
G.chksum.f_adler32 = lzo_adler32(G.chksum.f_adler32, (const uint8_t*)buf, cnt);
|
||||
G.chksum.f_crc32 = lzo_crc32(G.chksum.f_crc32, (const uint8_t*)buf, cnt);
|
||||
ct->f_adler32 = lzo_adler32(ct->f_adler32, (const uint8_t*)buf, cnt);
|
||||
ct->f_crc32 = lzo_crc32(ct->f_crc32, (const uint8_t*)buf, cnt);
|
||||
}
|
||||
|
||||
static uint32_t chksum_getresult(uint32_t h_flags32)
|
||||
static uint32_t chksum_getresult(chksum_t *ct, const header_t *h)
|
||||
{
|
||||
return (h_flags32 & F_H_CRC32) ? G.chksum.f_crc32 : G.chksum.f_adler32;
|
||||
return (h->flags & F_H_CRC32) ? ct->f_crc32 : ct->f_adler32;
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
@@ -572,23 +576,50 @@ static uint32_t read32(void)
|
||||
xread(0, &v, 4);
|
||||
return ntohl(v);
|
||||
}
|
||||
|
||||
static void write32(uint32_t v)
|
||||
{
|
||||
v = htonl(v);
|
||||
xwrite(1, &v, 4);
|
||||
}
|
||||
|
||||
static void f_write(const void* buf, int cnt)
|
||||
{
|
||||
xwrite(1, buf, cnt);
|
||||
add_bytes_to_chksum(&G.chksum_out, buf, cnt);
|
||||
}
|
||||
|
||||
static void f_read(void* buf, int cnt)
|
||||
{
|
||||
xread(0, buf, cnt);
|
||||
add_bytes_to_chksum(buf, cnt);
|
||||
add_bytes_to_chksum(&G.chksum_in, buf, cnt);
|
||||
}
|
||||
//static int f_read8(void)
|
||||
//{
|
||||
// uint8_t v;
|
||||
// f_read(&v, 1);
|
||||
// return v;
|
||||
//}
|
||||
//static unsigned f_read16(void)
|
||||
//{
|
||||
// uint16_t v;
|
||||
// f_read(&v, 2);
|
||||
// return ntohs(v);
|
||||
//}
|
||||
|
||||
static int f_read8(void)
|
||||
{
|
||||
uint8_t v;
|
||||
f_read(&v, 1);
|
||||
return v;
|
||||
}
|
||||
|
||||
static void f_write8(uint8_t v)
|
||||
{
|
||||
f_write(&v, 1);
|
||||
}
|
||||
|
||||
static unsigned f_read16(void)
|
||||
{
|
||||
uint16_t v;
|
||||
f_read(&v, 2);
|
||||
return ntohs(v);
|
||||
}
|
||||
|
||||
static void f_write16(uint16_t v)
|
||||
{
|
||||
v = htons(v);
|
||||
f_write(&v, 2);
|
||||
}
|
||||
|
||||
static uint32_t f_read32(void)
|
||||
{
|
||||
uint32_t v;
|
||||
@@ -596,30 +627,34 @@ static uint32_t f_read32(void)
|
||||
return ntohl(v);
|
||||
}
|
||||
|
||||
static void write32(uint32_t v)
|
||||
static void f_write32(uint32_t v)
|
||||
{
|
||||
v = htonl(v);
|
||||
xwrite(1, &v, 4);
|
||||
f_write(&v, 4);
|
||||
}
|
||||
static void f_write(const void* buf, int cnt)
|
||||
|
||||
/**********************************************************************/
|
||||
static int lzo_get_method(header_t *h)
|
||||
{
|
||||
xwrite(1, buf, cnt);
|
||||
add_bytes_to_chksum(buf, cnt);
|
||||
/* check method */
|
||||
if (h->method == M_LZO1X_1) {
|
||||
if (h->level == 0)
|
||||
h->level = 3;
|
||||
} else if (h->method == M_LZO1X_1_15) {
|
||||
if (h->level == 0)
|
||||
h->level = 1;
|
||||
} else if (h->method == M_LZO1X_999) {
|
||||
if (h->level == 0)
|
||||
h->level = 9;
|
||||
} else
|
||||
return -1; /* not a LZO method */
|
||||
|
||||
/* check compression level */
|
||||
if (h->level < 1 || h->level > 9)
|
||||
return 15;
|
||||
|
||||
return 0;
|
||||
}
|
||||
//static void f_write8(uint8_t v)
|
||||
//{
|
||||
// f_write(&v, 1);
|
||||
//}
|
||||
//static void f_write16(uint16_t v)
|
||||
//{
|
||||
// v = htons(v);
|
||||
// f_write(&v, 2);
|
||||
//}
|
||||
//static void f_write32(uint32_t v)
|
||||
//{
|
||||
// v = htonl(v);
|
||||
// f_write(&v, 4);
|
||||
//}
|
||||
|
||||
/**********************************************************************/
|
||||
#define LZO_BLOCK_SIZE (256 * 1024l)
|
||||
@@ -637,101 +672,86 @@ static NOINLINE int lzo_compress(const header_t *h)
|
||||
int r = 0; /* LZO_E_OK */
|
||||
uint8_t *const b1 = xzalloc(block_size);
|
||||
uint8_t *const b2 = xzalloc(MAX_COMPRESSED_SIZE(block_size));
|
||||
unsigned src_len = 0, dst_len = 0;
|
||||
uint32_t d_adler32 = ADLER32_INIT_VALUE;
|
||||
uint32_t d_crc32 = CRC32_INIT_VALUE;
|
||||
int l;
|
||||
uint8_t *wrk_mem = NULL;
|
||||
|
||||
/* Only these methods are possible, see lzo_set_method():
|
||||
* -1: M_LZO1X_1_15
|
||||
* -2..6: M_LZO1X_1
|
||||
* -7..9: M_LZO1X_999 if ENABLE_LZOP_COMPR_HIGH
|
||||
*/
|
||||
if (h->method == M_LZO1X_1)
|
||||
wrk_mem = xzalloc(LZO1X_1_MEM_COMPRESS);
|
||||
else /* check only if it's not the only possibility */
|
||||
IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
|
||||
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
else /* must be h->method == M_LZO1X_999 */
|
||||
else if (h->method == M_LZO1X_1_15)
|
||||
wrk_mem = xzalloc(LZO1X_1_15_MEM_COMPRESS);
|
||||
else if (h->method == M_LZO1X_999)
|
||||
wrk_mem = xzalloc(LZO1X_999_MEM_COMPRESS);
|
||||
#endif
|
||||
|
||||
for (;;) {
|
||||
unsigned src_len, dst_len;
|
||||
int l;
|
||||
uint32_t wordbuf[6];
|
||||
uint32_t *wordptr = wordbuf;
|
||||
|
||||
/* read a block */
|
||||
l = full_read(0, b1, block_size);
|
||||
src_len = (l > 0 ? l : 0);
|
||||
|
||||
/* write uncompressed block size */
|
||||
write32(src_len);
|
||||
|
||||
/* exit if last block */
|
||||
if (src_len == 0) {
|
||||
write32(0);
|
||||
if (src_len == 0)
|
||||
break;
|
||||
}
|
||||
*wordptr++ = htonl(src_len);
|
||||
|
||||
/* compute checksum of uncompressed block */
|
||||
if (h->flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
d_adler32 = lzo_adler32(ADLER32_INIT_VALUE, b1, src_len);
|
||||
if (h->flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
d_crc32 = lzo_crc32(CRC32_INIT_VALUE, b1, src_len);
|
||||
|
||||
/* compress */
|
||||
if (h->method == M_LZO1X_1)
|
||||
r = lzo1x_1_compress(b1, src_len, b2, &dst_len, wrk_mem);
|
||||
else IF_LZOP_COMPR_HIGH(if (h->method == M_LZO1X_1_15))
|
||||
else if (h->method == M_LZO1X_1_15)
|
||||
r = lzo1x_1_15_compress(b1, src_len, b2, &dst_len, wrk_mem);
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
else /* must be h->method == M_LZO1X_999 */
|
||||
else if (h->method == M_LZO1X_999)
|
||||
r = lzo1x_999_compress_level(b1, src_len, b2, &dst_len,
|
||||
wrk_mem, h->level);
|
||||
#endif
|
||||
else
|
||||
bb_error_msg_and_die("internal error");
|
||||
|
||||
if (r != 0) /* not LZO_E_OK */
|
||||
bb_error_msg_and_die("%s: %s", "internal error", "compression");
|
||||
bb_error_msg_and_die("internal error - compression failed");
|
||||
|
||||
/* write compressed block size */
|
||||
if (dst_len < src_len) {
|
||||
/* optimize */
|
||||
if (h->method == M_LZO1X_999) {
|
||||
unsigned new_len = src_len;
|
||||
r = lzo1x_optimize(b2, dst_len, b1, &new_len /*, NULL*/);
|
||||
r = lzo1x_optimize(b2, dst_len, b1, &new_len, NULL);
|
||||
if (r != 0 /*LZO_E_OK*/ || new_len != src_len)
|
||||
bb_error_msg_and_die("%s: %s", "internal error", "optimization");
|
||||
bb_error_msg_and_die("internal error - optimization failed");
|
||||
}
|
||||
*wordptr++ = htonl(dst_len);
|
||||
write32(dst_len);
|
||||
} else {
|
||||
/* data actually expanded => store data uncompressed */
|
||||
*wordptr++ = htonl(src_len);
|
||||
write32(src_len);
|
||||
}
|
||||
|
||||
/* write checksum of uncompressed block */
|
||||
if (h->flags32 & F_ADLER32_D)
|
||||
*wordptr++ = htonl(d_adler32);
|
||||
if (h->flags32 & F_CRC32_D)
|
||||
*wordptr++ = htonl(d_crc32);
|
||||
if (h->flags & F_ADLER32_D)
|
||||
write32(d_adler32);
|
||||
if (h->flags & F_CRC32_D)
|
||||
write32(d_crc32);
|
||||
|
||||
if (dst_len < src_len) {
|
||||
/* write checksum of compressed block */
|
||||
if (h->flags32 & F_ADLER32_C)
|
||||
*wordptr++ = htonl(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
|
||||
if (h->flags32 & F_CRC32_C)
|
||||
*wordptr++ = htonl(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
|
||||
}
|
||||
xwrite(1, wordbuf, ((char*)wordptr) - ((char*)wordbuf));
|
||||
if (dst_len < src_len) {
|
||||
if (h->flags & F_ADLER32_C)
|
||||
write32(lzo_adler32(ADLER32_INIT_VALUE, b2, dst_len));
|
||||
if (h->flags & F_CRC32_C)
|
||||
write32(lzo_crc32(CRC32_INIT_VALUE, b2, dst_len));
|
||||
/* write compressed block data */
|
||||
xwrite(1, b2, dst_len);
|
||||
} else {
|
||||
/* write uncompressed block data */
|
||||
xwrite(1, b1, src_len);
|
||||
}
|
||||
// /* if full_read() was nevertheless "short", it was EOF */
|
||||
// if (src_len < block_size)
|
||||
// break;
|
||||
}
|
||||
|
||||
free(wrk_mem);
|
||||
@@ -758,9 +778,7 @@ static FAST_FUNC void lzo_check(
|
||||
/**********************************************************************/
|
||||
// decompress a file
|
||||
/**********************************************************************/
|
||||
// used to have "const header_t *h" parameter, but since it uses
|
||||
// only flags32 field, changed to receive only that.
|
||||
static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
static NOINLINE int lzo_decompress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r;
|
||||
@@ -805,16 +823,16 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
}
|
||||
|
||||
/* read checksum of uncompressed block */
|
||||
if (h_flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
d_adler32 = read32();
|
||||
if (h_flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
d_crc32 = read32();
|
||||
|
||||
/* read checksum of compressed block */
|
||||
if (src_len < dst_len) {
|
||||
if (h_flags32 & F_ADLER32_C)
|
||||
if (h->flags & F_ADLER32_C)
|
||||
c_adler32 = read32();
|
||||
if (h_flags32 & F_CRC32_C)
|
||||
if (h->flags & F_CRC32_C)
|
||||
c_crc32 = read32();
|
||||
}
|
||||
|
||||
@@ -829,11 +847,11 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
if (!(option_mask32 & OPT_F)) {
|
||||
/* verify checksum of compressed block */
|
||||
if (h_flags32 & F_ADLER32_C)
|
||||
if (h->flags & F_ADLER32_C)
|
||||
lzo_check(ADLER32_INIT_VALUE,
|
||||
b1, src_len,
|
||||
lzo_adler32, c_adler32);
|
||||
if (h_flags32 & F_CRC32_C)
|
||||
if (h->flags & F_CRC32_C)
|
||||
lzo_check(CRC32_INIT_VALUE,
|
||||
b1, src_len,
|
||||
lzo_crc32, c_crc32);
|
||||
@@ -841,9 +859,9 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
/* decompress */
|
||||
// if (option_mask32 & OPT_F)
|
||||
// r = lzo1x_decompress(b1, src_len, b2, &d /*, NULL*/);
|
||||
// r = lzo1x_decompress(b1, src_len, b2, &d, NULL);
|
||||
// else
|
||||
r = lzo1x_decompress_safe(b1, src_len, b2, &d /*, NULL*/);
|
||||
r = lzo1x_decompress_safe(b1, src_len, b2, &d, NULL);
|
||||
|
||||
if (r != 0 /*LZO_E_OK*/ || dst_len != d) {
|
||||
bb_error_msg_and_die("corrupted data");
|
||||
@@ -856,11 +874,11 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
|
||||
if (!(option_mask32 & OPT_F)) {
|
||||
/* verify checksum of uncompressed block */
|
||||
if (h_flags32 & F_ADLER32_D)
|
||||
if (h->flags & F_ADLER32_D)
|
||||
lzo_check(ADLER32_INIT_VALUE,
|
||||
dst, dst_len,
|
||||
lzo_adler32, d_adler32);
|
||||
if (h_flags32 & F_CRC32_D)
|
||||
if (h->flags & F_CRC32_D)
|
||||
lzo_check(CRC32_INIT_VALUE,
|
||||
dst, dst_len,
|
||||
lzo_crc32, d_crc32);
|
||||
@@ -900,7 +918,7 @@ static NOINLINE int lzo_decompress(uint32_t h_flags32)
|
||||
* -00000020 00 00 2d 67 04 17 00 04 00 00 00 03 ed ec 9d 6d
|
||||
* +00000020 00 00 10 5f 00 c1 00 04 00 00 00 03 ed ec 9d 6d
|
||||
* ^^^^^^^^^^^
|
||||
* chksum
|
||||
* chksum_out
|
||||
* The rest is identical.
|
||||
*/
|
||||
static const unsigned char lzop_magic[9] ALIGN1 = {
|
||||
@@ -919,138 +937,138 @@ static void check_magic(void)
|
||||
/**********************************************************************/
|
||||
// lzop file header
|
||||
/**********************************************************************/
|
||||
static void write_header(header_t *h)
|
||||
static void write_header(const header_t *h)
|
||||
{
|
||||
char *end;
|
||||
int l;
|
||||
|
||||
xwrite(1, lzop_magic, sizeof(lzop_magic));
|
||||
|
||||
init_chksum();
|
||||
init_chksum(&G.chksum_out);
|
||||
|
||||
/* Our caller leaves name zero-filled, so len == 0 */
|
||||
end = h->len_and_name+1 + 0; /* 0 is strlen(h->len_and_name+1) */
|
||||
/* Store length byte */
|
||||
/*h->len_and_name[0] = end - (h->len_and_name+1); - zero already */
|
||||
f_write16(h->version);
|
||||
f_write16(h->lib_version);
|
||||
f_write16(h->version_needed_to_extract);
|
||||
f_write8(h->method);
|
||||
f_write8(h->level);
|
||||
f_write32(h->flags);
|
||||
f_write32(h->mode);
|
||||
f_write32(h->mtime);
|
||||
f_write32(h->gmtdiff);
|
||||
|
||||
f_write(&h->version_be16, end - (char*)&h->version_be16);
|
||||
l = (int) strlen(h->name);
|
||||
f_write8(l);
|
||||
if (l)
|
||||
f_write(h->name, l);
|
||||
|
||||
h->flags32 = htonl(h->flags32); /* native endianness for lzo_compress() */
|
||||
|
||||
write32(chksum_getresult(h->flags32));
|
||||
f_write32(chksum_getresult(&G.chksum_out, h));
|
||||
}
|
||||
|
||||
static int read_header(header_t *h)
|
||||
{
|
||||
int r;
|
||||
int l;
|
||||
uint32_t checksum;
|
||||
/* As it stands now, only h->flags32 is used by our caller.
|
||||
* Therefore we don't store many fields in h->FIELD.
|
||||
*/
|
||||
unsigned h_version;
|
||||
unsigned h_version_needed_to_extract;
|
||||
|
||||
init_chksum();
|
||||
memset(h, 0, sizeof(*h));
|
||||
h->version_needed_to_extract = 0x0900; /* first lzop version */
|
||||
h->level = 0;
|
||||
|
||||
/* We don't support versions < 0.94, since 0.94
|
||||
* came only 2 months after 0.90:
|
||||
* 0.90 (10 Aug 1997): First public release of lzop
|
||||
* 0.94 (15 Oct 1997): Header format change
|
||||
*/
|
||||
init_chksum(&G.chksum_in);
|
||||
|
||||
/* Read up to and including name length byte */
|
||||
f_read(&h->version_be16, ((char*)&h->len_and_name[1]) - ((char*)&h->version_be16));
|
||||
|
||||
h_version = htons(h->version_be16);
|
||||
if (h_version < 0x0940)
|
||||
return 3;
|
||||
h_version_needed_to_extract = htons(h->version_needed_to_extract_be16);
|
||||
if (h_version_needed_to_extract > LZOP_VERSION)
|
||||
return 16;
|
||||
if (h_version_needed_to_extract < 0x0940)
|
||||
h->version = f_read16();
|
||||
if (h->version < 0x0900)
|
||||
return 3;
|
||||
h->lib_version = f_read16();
|
||||
if (h->version >= 0x0940) {
|
||||
h->version_needed_to_extract = f_read16();
|
||||
if (h->version_needed_to_extract > LZOP_VERSION)
|
||||
return 16;
|
||||
if (h->version_needed_to_extract < 0x0900)
|
||||
return 3;
|
||||
}
|
||||
h->method = f_read8();
|
||||
if (h->version >= 0x0940)
|
||||
h->level = f_read8();
|
||||
h->flags = f_read32();
|
||||
if (h->flags & F_H_FILTER)
|
||||
return 16; /* filter not supported */
|
||||
h->mode = f_read32();
|
||||
h->mtime = f_read32();
|
||||
if (h->version >= 0x0940)
|
||||
h->gmtdiff = f_read32();
|
||||
|
||||
l = f_read8();
|
||||
if (l > 0)
|
||||
f_read(h->name, l);
|
||||
h->name[l] = 0;
|
||||
|
||||
checksum = chksum_getresult(&G.chksum_in, h);
|
||||
h->header_checksum = f_read32();
|
||||
if (h->header_checksum != checksum)
|
||||
return 2;
|
||||
|
||||
if (h->method <= 0)
|
||||
return 14;
|
||||
r = lzo_get_method(h);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
/* former lzo_get_method(h): */
|
||||
if (h->method == M_LZO1X_1) {
|
||||
if (h->level == 0)
|
||||
h->level = 3;
|
||||
} else if (h->method == M_LZO1X_1_15) {
|
||||
if (h->level == 0)
|
||||
h->level = 1;
|
||||
} else if (h->method == M_LZO1X_999) {
|
||||
if (h->level == 0)
|
||||
h->level = 9;
|
||||
} else
|
||||
return -1; /* not a LZO method */
|
||||
/* check compression level */
|
||||
if (h->level < 1 || h->level > 9)
|
||||
return 15;
|
||||
|
||||
h->flags32 = ntohl(h->flags32);
|
||||
if (h->flags32 & F_H_FILTER)
|
||||
return 16; /* filter not supported */
|
||||
/* check reserved flags */
|
||||
if (h->flags32 & F_RESERVED)
|
||||
if (h->flags & F_RESERVED)
|
||||
return -13;
|
||||
|
||||
l = h->len_and_name[0];
|
||||
if (l > 0)
|
||||
/* UNUSED */ f_read(h->len_and_name+1, l);
|
||||
/* UNUSED h->len_and_name[1+l] = 0; */
|
||||
|
||||
checksum = chksum_getresult(h->flags32);
|
||||
if (read32() != checksum)
|
||||
return 2;
|
||||
|
||||
/* skip extra field [not used yet] */
|
||||
if (h->flags32 & F_H_EXTRA_FIELD) {
|
||||
uint32_t extra_field_len;
|
||||
uint32_t extra_field_checksum;
|
||||
if (h->flags & F_H_EXTRA_FIELD) {
|
||||
uint32_t k;
|
||||
char dummy;
|
||||
|
||||
/* note: the checksum also covers the length */
|
||||
init_chksum();
|
||||
extra_field_len = f_read32();
|
||||
for (k = 0; k < extra_field_len; k++)
|
||||
f_read(&dummy, 1);
|
||||
checksum = chksum_getresult(h->flags32);
|
||||
extra_field_checksum = read32();
|
||||
if (extra_field_checksum != checksum)
|
||||
init_chksum(&G.chksum_in);
|
||||
h->extra_field_len = f_read32();
|
||||
for (k = 0; k < h->extra_field_len; k++)
|
||||
f_read8();
|
||||
checksum = chksum_getresult(&G.chksum_in, h);
|
||||
h->extra_field_checksum = f_read32();
|
||||
if (h->extra_field_checksum != checksum)
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void p_header(header_t *h)
|
||||
{
|
||||
int r;
|
||||
|
||||
r = read_header(h);
|
||||
if (r == 0)
|
||||
return;
|
||||
bb_error_msg_and_die("header_error %d", r);
|
||||
}
|
||||
|
||||
/**********************************************************************/
|
||||
// compress
|
||||
/**********************************************************************/
|
||||
static void lzo_set_method(header_t *h)
|
||||
{
|
||||
smallint level;
|
||||
|
||||
/* levels 2..6 or none (defaults to level 3) */
|
||||
h->method = M_LZO1X_1;
|
||||
level = 5; /* levels 2-6 are actually the same */
|
||||
int level = 1;
|
||||
|
||||
if (option_mask32 & OPT_1) {
|
||||
h->method = M_LZO1X_1_15;
|
||||
level = 1;
|
||||
}
|
||||
if (option_mask32 & OPT_789) {
|
||||
} else if (option_mask32 & OPT_789) {
|
||||
#if ENABLE_LZOP_COMPR_HIGH
|
||||
h->method = M_LZO1X_999;
|
||||
level = 9;
|
||||
if (option_mask32 & OPT_7)
|
||||
level = 7;
|
||||
else if (option_mask32 & OPT_8)
|
||||
level = 8;
|
||||
else
|
||||
level = 9;
|
||||
#else
|
||||
bb_error_msg_and_die("high compression not compiled in");
|
||||
#endif
|
||||
} else { /* levels 2..6 or none (defaults to level 3) */
|
||||
h->method = M_LZO1X_1;
|
||||
level = 5; /* levels 2-6 are actually the same */
|
||||
}
|
||||
|
||||
h->level = level;
|
||||
@@ -1065,21 +1083,18 @@ static int do_lzo_compress(void)
|
||||
|
||||
lzo_set_method(h);
|
||||
|
||||
h->version_be16 = htons(LZOP_VERSION & 0xffff);
|
||||
h->version_needed_to_extract_be16 = htons(0x0940);
|
||||
h->lib_version_be16 = htons(lzo_version() & 0xffff);
|
||||
h->version = (LZOP_VERSION & 0xffff);
|
||||
h->version_needed_to_extract = 0x0940;
|
||||
h->lib_version = lzo_version() & 0xffff;
|
||||
|
||||
h->flags32 = htonl((F_OS & F_OS_MASK) | (F_CS & F_CS_MASK));
|
||||
h->flags = (F_OS & F_OS_MASK) | (F_CS & F_CS_MASK);
|
||||
|
||||
if (!(option_mask32 & OPT_F) || h->method == M_LZO1X_999) {
|
||||
h->flags32 |= htonl(F_ADLER32_D);
|
||||
h->flags |= F_ADLER32_D;
|
||||
if (option_mask32 & OPT_C)
|
||||
h->flags32 |= htonl(F_ADLER32_C);
|
||||
h->flags |= F_ADLER32_C;
|
||||
}
|
||||
|
||||
/* write_header() also converts h->flags32 to native endianness */
|
||||
write_header(h);
|
||||
|
||||
return lzo_compress(h);
|
||||
#undef h
|
||||
}
|
||||
@@ -1089,14 +1104,11 @@ static int do_lzo_compress(void)
|
||||
/**********************************************************************/
|
||||
static int do_lzo_decompress(void)
|
||||
{
|
||||
int r;
|
||||
header_t header;
|
||||
|
||||
check_magic();
|
||||
r = read_header(&header);
|
||||
if (r != 0)
|
||||
bb_error_msg_and_die("header_error %d", r);
|
||||
return lzo_decompress(header.flags32);
|
||||
p_header(&header);
|
||||
return lzo_decompress(&header);
|
||||
}
|
||||
|
||||
static char* FAST_FUNC make_new_name_lzop(char *filename, const char *expected_ext UNUSED_PARAM)
|
||||
@@ -1121,8 +1133,6 @@ static IF_DESKTOP(long long) int FAST_FUNC pack_lzop(transformer_state_t *xstate
|
||||
int lzop_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
INIT_G();
|
||||
|
||||
getopt32(argv, OPTION_STRING);
|
||||
argv += optind;
|
||||
/* -U is "anti -k", invert bit for bbunpack(): */
|
||||
@@ -1139,6 +1149,6 @@ int lzop_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (ENABLE_UNLZOP && applet_name[4] == 'o')
|
||||
option_mask32 |= OPT_DECOMPRESS;
|
||||
|
||||
global_crc32_new_table_le();
|
||||
global_crc32_table = crc32_filltable(NULL, 0);
|
||||
return bbunpack(argv, pack_lzop, make_new_name_lzop, /*unused:*/ NULL);
|
||||
}
|
||||
+2
-2
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config RPM
|
||||
//config: bool "rpm (32 kb)"
|
||||
//config: bool "rpm (33 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Mini RPM applet - queries and extracts RPM packages.
|
||||
@@ -499,7 +499,7 @@ int rpm_main(int argc, char **argv)
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config RPM2CPIO
|
||||
//config: bool "rpm2cpio (21 kb)"
|
||||
//config: bool "rpm2cpio (20 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Converts a RPM file into a CPIO archive.
|
||||
|
||||
+50
-62
@@ -23,7 +23,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config TAR
|
||||
//config: bool "tar (39 kb)"
|
||||
//config: bool "tar (40 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: tar is an archiving program. It's commonly used with gzip to
|
||||
@@ -596,46 +596,35 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
|
||||
// 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
|
||||
volatile int vfork_exec_errno = 0;
|
||||
struct fd_pair data;
|
||||
struct fd_pair gzipDataPipe;
|
||||
# if WAIT_FOR_CHILD
|
||||
struct fd_pair status;
|
||||
xpiped_pair(status);
|
||||
struct fd_pair gzipStatusPipe;
|
||||
xpiped_pair(gzipStatusPipe);
|
||||
# endif
|
||||
xpiped_pair(data);
|
||||
xpiped_pair(gzipDataPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
if (xvfork() == 0) {
|
||||
gzipPid = xvfork();
|
||||
|
||||
if (gzipPid == 0) {
|
||||
/* child */
|
||||
int tfd;
|
||||
/* NB: close _first_, then move fds! */
|
||||
close(data.wr);
|
||||
close(gzipDataPipe.wr);
|
||||
# if WAIT_FOR_CHILD
|
||||
close(status.rd);
|
||||
/* status.wr will close only on exec -
|
||||
close(gzipStatusPipe.rd);
|
||||
/* gzipStatusPipe.wr will close only on exec -
|
||||
* parent waits for this close to happen */
|
||||
fcntl(status.wr, F_SETFD, FD_CLOEXEC);
|
||||
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
|
||||
# endif
|
||||
/* copy it: parent's tar_fd variable must not change */
|
||||
tfd = tar_fd;
|
||||
if (tfd == 0) {
|
||||
/* Output tar fd may be zero.
|
||||
* xmove_fd(data.rd, 0) would destroy it.
|
||||
* Reproducer:
|
||||
* exec 0>&-
|
||||
* exec 1>&-
|
||||
* tar czf Z.tar.gz FILE
|
||||
* Swapping move_fd's order wouldn't work:
|
||||
* data.rd is 1 and _it_ would be destroyed.
|
||||
*/
|
||||
tfd = dup(tfd);
|
||||
}
|
||||
xmove_fd(data.rd, 0);
|
||||
xmove_fd(tfd, 1);
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
BB_EXECLP(gzip, gzip, "-f", (char *)0);
|
||||
vfork_exec_errno = errno;
|
||||
@@ -643,18 +632,20 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
}
|
||||
|
||||
/* parent */
|
||||
xmove_fd(data.wr, tar_fd);
|
||||
close(data.rd);
|
||||
xmove_fd(gzipDataPipe.wr, tar_fd);
|
||||
close(gzipDataPipe.rd);
|
||||
# if WAIT_FOR_CHILD
|
||||
close(status.wr);
|
||||
close(gzipStatusPipe.wr);
|
||||
while (1) {
|
||||
/* Wait until child execs (or fails to) */
|
||||
char buf;
|
||||
int n = full_read(status.rd, &buf, 1);
|
||||
int n;
|
||||
|
||||
/* Wait until child execs (or fails to) */
|
||||
n = full_read(gzipStatusPipe.rd, &buf, 1);
|
||||
if (n < 0 /* && errno == EAGAIN */)
|
||||
continue; /* try it again */
|
||||
}
|
||||
close(status.rd);
|
||||
close(gzipStatusPipe.rd);
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
@@ -730,7 +721,11 @@ static NOINLINE int writeTarFile(
|
||||
return errorFlag;
|
||||
}
|
||||
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
|
||||
# define writeTarFile(...) 0
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -764,15 +759,15 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: IF_FEATURE_SEAMLESS_LZMA("a")
|
||||
//usage: IF_FEATURE_TAR_CREATE("h")
|
||||
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
//usage: "vokO] "
|
||||
//usage: "vO] "
|
||||
//usage: "[-f TARFILE] [-C DIR] "
|
||||
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define tar_full_usage "\n\n"
|
||||
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
|
||||
//usage: IF_NOT_FEATURE_TAR_CREATE("Extract ")
|
||||
//usage: "or list files from a tar file"
|
||||
//usage: "\n"
|
||||
//usage: "or list files from a tar file\n"
|
||||
//usage: "\nOperation:"
|
||||
//usage: IF_FEATURE_TAR_CREATE(
|
||||
//usage: "\n c Create"
|
||||
//usage: )
|
||||
@@ -781,13 +776,6 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: "\n -f FILE Name of TARFILE ('-' for stdin/out)"
|
||||
//usage: "\n -C DIR Change to DIR before operation"
|
||||
//usage: "\n -v Verbose"
|
||||
//usage: "\n -O Extract to stdout"
|
||||
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
|
||||
//usage: "\n -m Don't restore mtime"
|
||||
//usage: )
|
||||
//usage: "\n -o Don't restore user:group"
|
||||
///////:-p - accepted but ignored, restores mode (aliases in GNU tar: --preserve-permissions, --same-permissions)
|
||||
//usage: "\n -k Don't replace existing files"
|
||||
//usage: IF_FEATURE_SEAMLESS_Z(
|
||||
//usage: "\n -Z (De)compress using compress"
|
||||
//usage: )
|
||||
@@ -803,9 +791,13 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: IF_FEATURE_SEAMLESS_LZMA(
|
||||
//usage: "\n -a (De)compress using lzma"
|
||||
//usage: )
|
||||
//usage: "\n -O Extract to stdout"
|
||||
//usage: IF_FEATURE_TAR_CREATE(
|
||||
//usage: "\n -h Follow symlinks"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME(
|
||||
//usage: "\n -m Don't restore mtime"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_TAR_FROM(
|
||||
//usage: "\n -T FILE File with names to include"
|
||||
//usage: "\n -X FILE File with glob patterns to exclude"
|
||||
@@ -819,6 +811,9 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: "$ tar -cf /tmp/tarball.tar /usr/local\n"
|
||||
|
||||
// Supported but aren't in --help:
|
||||
// o no-same-owner
|
||||
// p same-permissions
|
||||
// k keep-old
|
||||
// no-recursion
|
||||
// numeric-owner
|
||||
// no-same-permissions
|
||||
@@ -1160,24 +1155,17 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (LONE_DASH(tar_filename)) {
|
||||
tar_handle->src_fd = tar_fd;
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else
|
||||
if (ENABLE_FEATURE_TAR_AUTODETECT
|
||||
&& ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
&& is_suffixed_with(tar_filename, ".lzma")
|
||||
/* We do this only for .lzma files, they have no signature.
|
||||
* All other compression formats are recognized in
|
||||
* get_header_tar() when first tar block has invalid format.
|
||||
* Doing it here for all filenames would falsely trigger
|
||||
* on e.g. tarball with 1st file named "BZh5".
|
||||
*/
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
tar_handle->src_fd = xopen(tar_filename, flags);
|
||||
if (ENABLE_FEATURE_TAR_AUTODETECT
|
||||
&& flags == O_RDONLY
|
||||
&& !(opt & OPT_ANY_COMPRESS)
|
||||
) {
|
||||
tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
|
||||
if (tar_handle->src_fd < 0)
|
||||
bb_perror_msg_and_die("can't open '%s'", tar_filename);
|
||||
} else {
|
||||
tar_handle->src_fd = xopen(tar_filename, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1256,7 +1244,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
while (get_header_tar(tar_handle) == EXIT_SUCCESS)
|
||||
bb_got_signal = EXIT_SUCCESS; /* saw at least one header, good */
|
||||
|
||||
create_links_from_list(tar_handle->link_placeholders);
|
||||
create_symlinks_from_list(tar_handle->symlink_placeholders);
|
||||
|
||||
/* Check that every file that should have been extracted was */
|
||||
while (tar_handle->accept) {
|
||||
|
||||
+25
-45
@@ -17,7 +17,7 @@
|
||||
* Zip64 + other methods
|
||||
*/
|
||||
//config:config UNZIP
|
||||
//config: bool "unzip (26 kb)"
|
||||
//config: bool "unzip (24 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unzip will list or extract files from a ZIP archive,
|
||||
@@ -153,15 +153,15 @@ typedef union {
|
||||
#define FIX_ENDIANNESS_CDF(cdf) \
|
||||
do { if (BB_BIG_ENDIAN) { \
|
||||
(cdf).fmt.version_made_by = SWAP_LE16((cdf).fmt.version_made_by); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed ); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len ); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.version_needed = SWAP_LE16((cdf).fmt.version_needed); \
|
||||
(cdf).fmt.method = SWAP_LE16((cdf).fmt.method ); \
|
||||
(cdf).fmt.modtime = SWAP_LE16((cdf).fmt.modtime ); \
|
||||
(cdf).fmt.moddate = SWAP_LE16((cdf).fmt.moddate ); \
|
||||
(cdf).fmt.crc32 = SWAP_LE32((cdf).fmt.crc32 ); \
|
||||
(cdf).fmt.cmpsize = SWAP_LE32((cdf).fmt.cmpsize ); \
|
||||
(cdf).fmt.ucmpsize = SWAP_LE32((cdf).fmt.ucmpsize ); \
|
||||
(cdf).fmt.filename_len = SWAP_LE16((cdf).fmt.filename_len); \
|
||||
(cdf).fmt.extra_len = SWAP_LE16((cdf).fmt.extra_len ); \
|
||||
(cdf).fmt.file_comment_length = SWAP_LE16((cdf).fmt.file_comment_length); \
|
||||
(cdf).fmt.external_attributes = SWAP_LE32((cdf).fmt.external_attributes); \
|
||||
}} while (0)
|
||||
@@ -336,9 +336,7 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
{
|
||||
/* Create all leading directories */
|
||||
char *name = xstrdup(fn);
|
||||
|
||||
/* mode of -1: set mode according to umask */
|
||||
if (bb_make_directory(dirname(name), -1, FILEUTILS_RECUR)) {
|
||||
if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
|
||||
xfunc_die(); /* bb_make_directory is noisy */
|
||||
}
|
||||
free(name);
|
||||
@@ -372,10 +370,9 @@ static void unzip_extract_symlink(llist_t **symlink_placeholders,
|
||||
target[xstate.mem_output_size] = '\0';
|
||||
#endif
|
||||
}
|
||||
create_or_remember_link(symlink_placeholders,
|
||||
create_or_remember_symlink(symlink_placeholders,
|
||||
target,
|
||||
dst_fn,
|
||||
0);
|
||||
dst_fn);
|
||||
free(target);
|
||||
}
|
||||
#endif
|
||||
@@ -456,9 +453,7 @@ static int get_lstat_mode(const char *dst_fn)
|
||||
struct stat stat_buf;
|
||||
if (lstat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'",
|
||||
dst_fn
|
||||
);
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
/* File does not exist */
|
||||
return -1;
|
||||
@@ -636,9 +631,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
if (++i > 2) {
|
||||
*ext = '\0';
|
||||
bb_error_msg_and_die("can't open %s[.zip]",
|
||||
src_fn
|
||||
);
|
||||
bb_error_msg_and_die("can't open %s[.zip]", src_fn);
|
||||
}
|
||||
strcpy(ext, extn[i - 1]);
|
||||
}
|
||||
@@ -650,11 +643,8 @@ int unzip_main(int argc, char **argv)
|
||||
xchdir(base_dir);
|
||||
|
||||
if (quiet <= 1) { /* not -qq */
|
||||
if (quiet == 0) {
|
||||
printf("Archive: %s\n",
|
||||
printable_string(src_fn)
|
||||
);
|
||||
}
|
||||
if (quiet == 0)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (opts & OPT_l) {
|
||||
puts(verbose ?
|
||||
" Length Method Size Cmpr Date Time CRC-32 Name\n"
|
||||
@@ -838,8 +828,7 @@ int unzip_main(int argc, char **argv)
|
||||
printf( "%9u " "%s " "%s\n",
|
||||
(unsigned)zip.fmt.ucmpsize,
|
||||
dtbuf,
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
dst_fn);
|
||||
} else {
|
||||
char method6[7];
|
||||
unsigned long percents;
|
||||
@@ -868,8 +857,7 @@ int unzip_main(int argc, char **argv)
|
||||
(unsigned)percents,
|
||||
dtbuf,
|
||||
zip.fmt.crc32,
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
dst_fn);
|
||||
total_size += zip.fmt.cmpsize;
|
||||
}
|
||||
total_usize += zip.fmt.ucmpsize;
|
||||
@@ -895,7 +883,7 @@ int unzip_main(int argc, char **argv)
|
||||
mode = get_lstat_mode(dst_fn);
|
||||
if (mode == -1) { /* ENOENT */
|
||||
if (!quiet) {
|
||||
printf(" creating: %s\n", printable_string(dst_fn));
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
if (bb_make_directory(dst_fn, dir_mode, FILEUTILS_IGNORE_CHMOD_ERR)) {
|
||||
@@ -904,9 +892,7 @@ int unzip_main(int argc, char **argv)
|
||||
} else {
|
||||
if (!S_ISDIR(mode)) {
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
printable_string(dst_fn),
|
||||
"directory"
|
||||
);
|
||||
dst_fn, "directory");
|
||||
}
|
||||
}
|
||||
goto skip_cmpsize;
|
||||
@@ -925,16 +911,12 @@ int unzip_main(int argc, char **argv)
|
||||
if (!S_ISREG(mode)) {
|
||||
fishy:
|
||||
bb_error_msg_and_die("'%s' exists but is not a %s",
|
||||
printable_string(dst_fn),
|
||||
"regular file"
|
||||
);
|
||||
dst_fn, "regular file");
|
||||
}
|
||||
if (overwrite == O_ALWAYS) {
|
||||
goto do_open_and_extract;
|
||||
}
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ",
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
my_fgets80(key_buf);
|
||||
/* User input could take a long time. Is it still a regular file? */
|
||||
mode = get_lstat_mode(dst_fn);
|
||||
@@ -964,9 +946,7 @@ int unzip_main(int argc, char **argv)
|
||||
if (!quiet) {
|
||||
printf(/* zip.fmt.method == 0
|
||||
? " extracting: %s\n"
|
||||
: */ " inflating: %s\n",
|
||||
printable_string(dst_fn)
|
||||
);
|
||||
: */ " inflating: %s\n", dst_fn);
|
||||
}
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
if (S_ISLNK(file_mode)) {
|
||||
@@ -1008,7 +988,7 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_UNZIP_CDF
|
||||
create_links_from_list(symlink_placeholders);
|
||||
create_symlinks_from_list(symlink_placeholders);
|
||||
#endif
|
||||
|
||||
if ((opts & OPT_l) && quiet <= 1) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Console Utilities"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DUMPKMAP
|
||||
//config: bool "dumpkmap (1.6 kb)"
|
||||
//config: bool "dumpkmap (1.3 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config FGCONSOLE
|
||||
//config: bool "fgconsole (1.5 kb)"
|
||||
//config: bool "fgconsole (1.6 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config KBD_MODE
|
||||
//config: bool "kbd_mode (4.1 kb)"
|
||||
//config: bool "kbd_mode (4 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -10,14 +10,14 @@
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config LOADFONT
|
||||
//config: bool "loadfont (5.2 kb)"
|
||||
//config: bool "loadfont (5.4 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
//config: This program loads a console font from standard input.
|
||||
//config:
|
||||
//config:config SETFONT
|
||||
//config: bool "setfont (24 kb)"
|
||||
//config: bool "setfont (26 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config LOADKMAP
|
||||
//config: bool "loadkmap (1.8 kb)"
|
||||
//config: bool "loadkmap (1.5 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config OPENVT
|
||||
//config: bool "openvt (7.2 kb)"
|
||||
//config: bool "openvt (7 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config RESET
|
||||
//config: bool "reset (345 bytes)"
|
||||
//config: bool "reset (275 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: This program is used to reset the terminal screen, if it
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config RESIZE
|
||||
//config: bool "resize (903 bytes)"
|
||||
//config: bool "resize (756 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: This program is used to (re)set the width and height of your current
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config SETCONSOLE
|
||||
//config: bool "setconsole (3.6 kb)"
|
||||
//config: bool "setconsole (3.7 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config SETKEYCODES
|
||||
//config: bool "setkeycodes (2.1 kb)"
|
||||
//config: bool "setkeycodes (1.7 kb)"
|
||||
//config: default y
|
||||
//config: select PLATFORM_LINUX
|
||||
//config: help
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setlogcons_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
char *devname;
|
||||
struct {
|
||||
char fn;
|
||||
char subarg;
|
||||
@@ -53,14 +52,7 @@ int setlogcons_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (argv[1])
|
||||
arg.subarg = xatou_range(argv[1], 0, 63);
|
||||
|
||||
/* Can just call it on "/dev/tty1" always, but...
|
||||
* in my testing, inactive (never opened) VTs are not
|
||||
* redirected to, despite ioctl not failing.
|
||||
*
|
||||
* By using "/dev/ttyN", ensure it is activated.
|
||||
*/
|
||||
devname = xasprintf("/dev/tty%u", arg.subarg);
|
||||
xioctl(xopen(devname, O_RDONLY), TIOCLINUX, &arg);
|
||||
xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see docs/Kconfig-language.txt.
|
||||
# see scripts/kbuild/config-language.txt.
|
||||
#
|
||||
|
||||
menu "Coreutils"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
|
||||
*/
|
||||
//config:config BASENAME
|
||||
//config: bool "basename (438 bytes)"
|
||||
//config: bool "basename (371 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: basename is used to strip the directory and suffix from filenames,
|
||||
|
||||
+5
-7
@@ -112,10 +112,10 @@ static int catv(unsigned opts, char **argv)
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
#if ENABLE_FEATURE_CATN
|
||||
bool eol_seen = (opts & (CAT_OPT_n|CAT_OPT_b));
|
||||
unsigned eol_char = (eol_seen ? '\n' : 0x100);
|
||||
unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
|
||||
unsigned lineno = 0;
|
||||
unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100;
|
||||
unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
|
||||
bool eol_seen = 1;
|
||||
#endif
|
||||
|
||||
BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE);
|
||||
@@ -195,7 +195,6 @@ int cat_main(int argc UNUSED_PARAM, char **argv)
|
||||
# define CAT_OPT_b (1<<1)
|
||||
if (opts & (CAT_OPT_n|CAT_OPT_b)) { /* -n or -b */
|
||||
struct number_state ns;
|
||||
int exitcode;
|
||||
|
||||
ns.width = 6;
|
||||
ns.start = 1;
|
||||
@@ -204,11 +203,10 @@ int cat_main(int argc UNUSED_PARAM, char **argv)
|
||||
ns.empty_str = "\n";
|
||||
ns.all = !(opts & CAT_OPT_b); /* -n without -b */
|
||||
ns.nonempty = (opts & CAT_OPT_b); /* -b (with or without -n) */
|
||||
exitcode = EXIT_SUCCESS;
|
||||
do {
|
||||
exitcode |= print_numbered_lines(&ns, *argv);
|
||||
print_numbered_lines(&ns, *argv);
|
||||
} while (*++argv);
|
||||
fflush_stdout_and_exit(exitcode);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
/*opts >>= 2;*/
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CHGRP
|
||||
//config: bool "chgrp (7.6 kb)"
|
||||
//config: bool "chgrp (7.2 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: chgrp is used to change the group ownership of files.
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CHMOD
|
||||
//config: bool "chmod (5.5 kb)"
|
||||
//config: bool "chmod (5.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: chmod is used to change the access permission of files.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CHOWN
|
||||
//config: bool "chown (7.6 kb)"
|
||||
//config: bool "chown (7.2 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: chown is used to change the user and/or group ownership
|
||||
|
||||
+27
-28
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CKSUM
|
||||
//config: bool "cksum (4.1 kb)"
|
||||
//config: bool "cksum (4.2 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cksum is used to calculate the CRC32 checksum of a file.
|
||||
@@ -31,6 +31,9 @@ int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, 1);
|
||||
uint32_t crc;
|
||||
off_t length, filesize;
|
||||
int bytes_read;
|
||||
int exit_code = EXIT_SUCCESS;
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
@@ -42,42 +45,38 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
setup_common_bufsiz();
|
||||
do {
|
||||
uint32_t crc;
|
||||
off_t filesize;
|
||||
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
|
||||
|
||||
if (fd < 0) {
|
||||
exit_code = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
crc = 0;
|
||||
filesize = 0;
|
||||
#define read_buf bb_common_bufsiz1
|
||||
for (;;) {
|
||||
uoff_t t;
|
||||
int bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE);
|
||||
if (bytes_read > 0) {
|
||||
filesize += bytes_read;
|
||||
} else {
|
||||
/* Checksum filesize bytes, LSB first, and exit */
|
||||
close(fd);
|
||||
fd = -1; /* break flag */
|
||||
t = filesize;
|
||||
bytes_read = 0;
|
||||
while (t != 0) {
|
||||
read_buf[bytes_read++] = (uint8_t)t;
|
||||
t >>= 8;
|
||||
}
|
||||
}
|
||||
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
|
||||
if (fd < 0)
|
||||
break;
|
||||
}
|
||||
length = 0;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
while ((bytes_read = safe_read(fd, read_buf, COMMON_BUFSIZE)) > 0) {
|
||||
length += bytes_read;
|
||||
crc = crc32_block_endian1(crc, read_buf, bytes_read, crc32_table);
|
||||
}
|
||||
close(fd);
|
||||
|
||||
filesize = length;
|
||||
|
||||
while (length) {
|
||||
crc = (crc << 8) ^ crc32_table[(uint8_t)(crc >> 24) ^ (uint8_t)length];
|
||||
/* must ensure that shift is unsigned! */
|
||||
if (sizeof(length) <= sizeof(unsigned))
|
||||
length = (unsigned)length >> 8;
|
||||
else if (sizeof(length) <= sizeof(unsigned long))
|
||||
length = (unsigned long)length >> 8;
|
||||
else
|
||||
length = (unsigned long long)length >> 8;
|
||||
}
|
||||
crc = ~crc;
|
||||
printf((*argv ? "%u %"OFF_FMT"u %s\n" : "%u %"OFF_FMT"u\n"),
|
||||
(unsigned)crc, filesize, *argv);
|
||||
|
||||
printf((*argv ? "%"PRIu32" %"OFF_FMT"i %s\n" : "%"PRIu32" %"OFF_FMT"i\n"),
|
||||
crc, filesize, *argv);
|
||||
} while (*argv && *++argv);
|
||||
|
||||
fflush_stdout_and_exit(exit_code);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config COMM
|
||||
//config: bool "comm (4.2 kb)"
|
||||
//config: bool "comm (3.9 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: comm is used to compare two files line by line and return
|
||||
|
||||
+1
-26
@@ -12,7 +12,7 @@
|
||||
* Size reduction.
|
||||
*/
|
||||
//config:config CP
|
||||
//config: bool "cp (10 kb)"
|
||||
//config: bool "cp (9.7 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cp is used to copy files and directories.
|
||||
@@ -24,14 +24,8 @@
|
||||
//config: help
|
||||
//config: Enable long options.
|
||||
//config: Also add support for --parents option.
|
||||
//config:
|
||||
//config:config FEATURE_CP_REFLINK
|
||||
//config: bool "Enable --reflink[=auto]"
|
||||
//config: default y
|
||||
//config: depends on FEATURE_CP_LONG_OPTIONS
|
||||
|
||||
//applet:IF_CP(APPLET_NOEXEC(cp, cp, BB_DIR_BIN, BB_SUID_DROP, cp))
|
||||
/* NOEXEC despite cases when it can be a "runner" (cp -r LARGE_DIR NEW_DIR) */
|
||||
|
||||
//kbuild:lib-$(CONFIG_CP) += cp.o
|
||||
|
||||
@@ -77,14 +71,10 @@ int cp_main(int argc, char **argv)
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
/*OPT_rmdest = FILEUTILS_RMDEST = 1 << FILEUTILS_CP_OPTNUM */
|
||||
OPT_parents = 1 << (FILEUTILS_CP_OPTNUM+1),
|
||||
OPT_reflink = 1 << (FILEUTILS_CP_OPTNUM+2),
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
char *reflink = NULL;
|
||||
# endif
|
||||
flags = getopt32long(argv, "^"
|
||||
FILEUTILS_CP_OPTSTR
|
||||
"\0"
|
||||
@@ -108,22 +98,7 @@ int cp_main(int argc, char **argv)
|
||||
"update\0" No_argument "u"
|
||||
"remove-destination\0" No_argument "\xff"
|
||||
"parents\0" No_argument "\xfe"
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
"reflink\0" Optional_argument "\xfd"
|
||||
, &reflink
|
||||
# endif
|
||||
);
|
||||
# if ENABLE_FEATURE_CP_REFLINK
|
||||
BUILD_BUG_ON((int)OPT_reflink != (int)FILEUTILS_REFLINK);
|
||||
if (flags & FILEUTILS_REFLINK) {
|
||||
if (!reflink)
|
||||
flags |= FILEUTILS_REFLINK_ALWAYS;
|
||||
else if (strcmp(reflink, "always") == 0)
|
||||
flags |= FILEUTILS_REFLINK_ALWAYS;
|
||||
else if (strcmp(reflink, "auto") != 0)
|
||||
bb_show_usage();
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
flags = getopt32(argv, "^"
|
||||
FILEUTILS_CP_OPTSTR
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config CUT
|
||||
//config: bool "cut (5.8 kb)"
|
||||
//config: bool "cut (5.3 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: cut is used to print selected parts of lines from
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
//config:config DATE
|
||||
//config: bool "date (7 kb)"
|
||||
//config: bool "date (7.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: date is used to set the system date or display the
|
||||
|
||||
+31
-70
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DD
|
||||
//config: bool "dd (7.5 kb)"
|
||||
//config: bool "dd (7.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dd copies a file (from standard input to standard output,
|
||||
@@ -37,7 +37,7 @@
|
||||
//config: elapsed time and speed.
|
||||
//config:
|
||||
//config:config FEATURE_DD_IBS_OBS
|
||||
//config: bool "Enable ibs, obs, iflag, oflag and conv options"
|
||||
//config: bool "Enable ibs, obs and conv options"
|
||||
//config: default y
|
||||
//config: depends on DD
|
||||
//config: help
|
||||
@@ -56,11 +56,8 @@
|
||||
//kbuild:lib-$(CONFIG_DD) += dd.o
|
||||
|
||||
//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] [seek=N]\n"
|
||||
//usage: IF_FEATURE_DD_IBS_OBS(
|
||||
//usage: " [conv=notrunc|noerror|sync|fsync]\n"
|
||||
//usage: " [iflag=skip_bytes|fullblock] [oflag=seek_bytes]"
|
||||
//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:#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"
|
||||
@@ -82,8 +79,6 @@
|
||||
//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: "\n iflag=fullblock Read full blocks"
|
||||
//usage: "\n oflag=seek_bytes seek=N is in bytes"
|
||||
//usage: )
|
||||
//usage: IF_FEATURE_DD_STATUS(
|
||||
//usage: "\n status=noxfer Suppress rate output"
|
||||
@@ -135,16 +130,11 @@ enum {
|
||||
/* start of input flags */
|
||||
FLAG_IFLAG_SHIFT = 5,
|
||||
FLAG_SKIP_BYTES = (1 << 5) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_FULLBLOCK = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of input flags */
|
||||
/* start of output flags */
|
||||
FLAG_OFLAG_SHIFT = 7,
|
||||
FLAG_SEEK_BYTES = (1 << 7) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
/* end of output flags */
|
||||
FLAG_TWOBUFS = (1 << 8) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 9,
|
||||
FLAG_STATUS_NONE = 1 << 10,
|
||||
FLAG_STATUS_NOXFER = 1 << 11,
|
||||
FLAG_TWOBUFS = (1 << 6) * ENABLE_FEATURE_DD_IBS_OBS,
|
||||
FLAG_COUNT = 1 << 7,
|
||||
FLAG_STATUS_NONE = 1 << 8,
|
||||
FLAG_STATUS_NOXFER = 1 << 9,
|
||||
};
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
@@ -205,18 +195,14 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
ssize_t n = full_write_or_warn(buf, len, filename);
|
||||
if (n < 0)
|
||||
return 1;
|
||||
if ((size_t)n == obs)
|
||||
G.out_full++;
|
||||
else if (n) /* > 0 */
|
||||
G.out_part++;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
G.total_bytes += n;
|
||||
#endif
|
||||
if ((size_t)n == obs) {
|
||||
G.out_full++;
|
||||
return 0;
|
||||
}
|
||||
if ((size_t)n == len) {
|
||||
G.out_part++;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_LFS
|
||||
@@ -258,16 +244,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs\0""count\0""seek\0""skip\0""if\0""of\0"IF_FEATURE_DD_STATUS("status\0")
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs\0""obs\0""conv\0""iflag\0""oflag\0"
|
||||
"ibs\0""obs\0""conv\0""iflag\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""fullblock\0";
|
||||
static const char oflag_words[] ALIGN1 =
|
||||
"seek_bytes\0";
|
||||
"skip_bytes\0";
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_STATUS
|
||||
static const char status_words[] ALIGN1 =
|
||||
@@ -286,7 +270,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
OP_obs,
|
||||
OP_conv,
|
||||
OP_iflag,
|
||||
OP_oflag,
|
||||
/* Must be in the same order as FLAG_XXX! */
|
||||
OP_conv_notrunc = 0,
|
||||
OP_conv_sync,
|
||||
@@ -307,8 +290,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Partially implemented: */
|
||||
//swab swap every pair of input bytes: will abort on non-even reads
|
||||
OP_iflag_skip_bytes,
|
||||
OP_iflag_fullblock,
|
||||
OP_oflag_seek_bytes,
|
||||
#endif
|
||||
};
|
||||
smallint exitcode = EXIT_FAILURE;
|
||||
@@ -324,13 +305,13 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
/* These are all zeroed at once! */
|
||||
struct {
|
||||
IF_FEATURE_DD_IBS_OBS(size_t ocount;)
|
||||
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 ocount (Z.ocount )
|
||||
#define oc (Z.oc )
|
||||
#define prev_read_size (Z.prev_read_size)
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
@@ -380,10 +361,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
G.flags |= parse_comma_flags(val, iflag_words, "iflag") << FLAG_IFLAG_SHIFT;
|
||||
/*continue;*/
|
||||
}
|
||||
if (what == OP_oflag) {
|
||||
G.flags |= parse_comma_flags(val, oflag_words, "oflag") << FLAG_OFLAG_SHIFT;
|
||||
/*continue;*/
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = xatoul_range_sfx(val, 1, ((size_t)-1L)/2, cwbkMG_suffixes);
|
||||
@@ -455,8 +432,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
xmove_fd(xopen(outfile, oflag), ofd);
|
||||
|
||||
if (seek && !(G.flags & FLAG_NOTRUNC)) {
|
||||
size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
|
||||
if (ftruncate(ofd, seek * blocksz) < 0) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
if (fstat(ofd, &st) < 0
|
||||
@@ -474,13 +450,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
size_t blocksz = (G.flags & FLAG_SKIP_BYTES) ? 1 : ibs;
|
||||
if (lseek(ifd, skip * blocksz, SEEK_CUR) < 0) {
|
||||
do {
|
||||
ssize_t n;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (G.flags & FLAG_FULLBLOCK)
|
||||
n = full_read(ifd, ibuf, blocksz);
|
||||
else
|
||||
#endif
|
||||
n = safe_read(ifd, ibuf, blocksz);
|
||||
ssize_t n = safe_read(ifd, ibuf, blocksz);
|
||||
if (n < 0)
|
||||
goto die_infile;
|
||||
if (n == 0)
|
||||
@@ -489,19 +459,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
}
|
||||
if (seek) {
|
||||
size_t blocksz = (G.flags & FLAG_SEEK_BYTES) ? 1 : obs;
|
||||
if (lseek(ofd, seek * blocksz, SEEK_CUR) < 0)
|
||||
if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
while (!(G.flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
ssize_t n;
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (G.flags & FLAG_FULLBLOCK)
|
||||
n = full_read(ifd, ibuf, ibs);
|
||||
else
|
||||
#endif
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
@@ -545,26 +510,24 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (G.flags & FLAG_TWOBUFS) {
|
||||
char *tmp = ibuf;
|
||||
while (n) {
|
||||
size_t d = obs - ocount;
|
||||
size_t d = obs - oc;
|
||||
|
||||
if (d > (size_t)n)
|
||||
d = n;
|
||||
memcpy(obuf + ocount, tmp, d);
|
||||
memcpy(obuf + oc, tmp, d);
|
||||
n -= d;
|
||||
tmp += d;
|
||||
ocount += d;
|
||||
if (ocount == obs) {
|
||||
oc += d;
|
||||
if (oc == obs) {
|
||||
if (write_and_stats(obuf, obs, obs, outfile))
|
||||
goto out_status;
|
||||
ocount = 0;
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
if (write_and_stats(ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
@@ -575,12 +538,10 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (ocount != 0) {
|
||||
if (write_and_stats(obuf, ocount, obs, outfile))
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
if (write_and_stats(obuf, oc, obs, outfile))
|
||||
goto out_status;
|
||||
}
|
||||
#endif
|
||||
if (close(ifd) < 0) {
|
||||
die_infile:
|
||||
bb_simple_perror_msg_and_die(infile);
|
||||
|
||||
+13
-21
@@ -18,7 +18,7 @@
|
||||
* Implement -P and -B; better coreutils compat; cleanup
|
||||
*/
|
||||
//config:config DF
|
||||
//config: bool "df (6.8 kb)"
|
||||
//config: bool "df (7.5 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: df reports the amount of disk space used and available
|
||||
@@ -91,6 +91,8 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned long blocks_used;
|
||||
unsigned blocks_percent_used;
|
||||
unsigned long df_disp_hr = 1024;
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned opt;
|
||||
@@ -206,11 +208,6 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
device = mount_entry->mnt_fsname;
|
||||
|
||||
/* GNU coreutils 6.10 skips certain mounts, try to be compatible */
|
||||
if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
|
||||
continue;
|
||||
|
||||
mount_point = mount_entry->mnt_dir;
|
||||
fs_type = mount_entry->mnt_type;
|
||||
|
||||
@@ -225,31 +222,26 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
s.f_frsize = s.f_bsize;
|
||||
|
||||
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
|
||||
unsigned long long blocks_used;
|
||||
unsigned long long blocks_total;
|
||||
unsigned blocks_percent_used;
|
||||
|
||||
if (opt & OPT_INODE) {
|
||||
s.f_blocks = s.f_files;
|
||||
s.f_bavail = s.f_bfree = s.f_ffree;
|
||||
s.f_frsize = 1;
|
||||
|
||||
if (df_disp_hr)
|
||||
df_disp_hr = 1;
|
||||
}
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_total = blocks_used + s.f_bavail;
|
||||
blocks_percent_used = blocks_total; /* 0% if blocks_total == 0, else... */
|
||||
if (blocks_total != 0) {
|
||||
/* Downscale sizes for narrower division */
|
||||
unsigned u;
|
||||
while (blocks_total >= INT_MAX / 101) {
|
||||
blocks_total >>= 1;
|
||||
blocks_used >>= 1;
|
||||
}
|
||||
u = (unsigned)blocks_used * 100u + (unsigned)blocks_total / 2;
|
||||
blocks_percent_used = u / (unsigned)blocks_total;
|
||||
blocks_percent_used = 0;
|
||||
if (blocks_used + s.f_bavail) {
|
||||
blocks_percent_used = (blocks_used * 100ULL
|
||||
+ (blocks_used + s.f_bavail)/2
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
|
||||
/* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
|
||||
if (ENABLE_FEATURE_SKIP_ROOTFS && strcmp(device, "rootfs") == 0)
|
||||
continue;
|
||||
|
||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DIRNAME
|
||||
//config: bool "dirname (329 bytes)"
|
||||
//config: bool "dirname (289 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dirname is used to strip a non-directory suffix from
|
||||
|
||||
@@ -12,14 +12,14 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config DOS2UNIX
|
||||
//config: bool "dos2unix (5.2 kb)"
|
||||
//config: bool "dos2unix (5.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: dos2unix is used to convert a text file from DOS format to
|
||||
//config: UNIX format, and vice versa.
|
||||
//config:
|
||||
//config:config UNIX2DOS
|
||||
//config: bool "unix2dos (5.2 kb)"
|
||||
//config: bool "unix2dos (5.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: unix2dos is used to convert a text file from UNIX format to
|
||||
|
||||
+4
-2
@@ -19,16 +19,18 @@
|
||||
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
|
||||
*/
|
||||
//config:config DU
|
||||
//config: bool "du (6.3 kb)"
|
||||
//config: bool "du (default blocksize of 512 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: du is used to report the amount of disk space used
|
||||
//config: for specified files.
|
||||
//config:
|
||||
//config:config FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
//config: bool "Use default blocksize of 1024 bytes (else it's 512 bytes)"
|
||||
//config: bool "Use a default blocksize of 1024 bytes (1K)"
|
||||
//config: default y
|
||||
//config: depends on DU
|
||||
//config: help
|
||||
//config: Use a blocksize of (1K) instead of the default 512b.
|
||||
|
||||
//applet:IF_DU(APPLET(du, BB_DIR_USR_BIN, BB_SUID_DROP))
|
||||
|
||||
|
||||
+2
-2
@@ -19,10 +19,10 @@
|
||||
* The previous version did not allow 4-digit octals.
|
||||
*/
|
||||
//config:config ECHO
|
||||
//config: bool "echo (1.8 kb)"
|
||||
//config: bool "echo (basic SuSv3 version taking no options)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: echo prints a specified string to stdout.
|
||||
//config: echo is used to print a specified string to stdout.
|
||||
//config:
|
||||
//config:# this entry also appears in shell/Config.in, next to the echo builtin
|
||||
//config:config FEATURE_FANCY_ECHO
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@
|
||||
* - use xfunc_error_retval
|
||||
*/
|
||||
//config:config ENV
|
||||
//config: bool "env (4 kb)"
|
||||
//config: bool "env (3.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: env is used to set an environment variable and run
|
||||
|
||||
+2
-2
@@ -21,13 +21,13 @@
|
||||
* Caveat: this versions of expand and unexpand don't accept tab lists.
|
||||
*/
|
||||
//config:config EXPAND
|
||||
//config: bool "expand (5.1 kb)"
|
||||
//config: bool "expand (5.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: By default, convert all tabs to spaces.
|
||||
//config:
|
||||
//config:config UNEXPAND
|
||||
//config: bool "unexpand (5.3 kb)"
|
||||
//config: bool "unexpand (6 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: By default, convert only leading sequences of blanks to tabs.
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
* provided they all associate ((x op x) op x).
|
||||
*/
|
||||
//config:config EXPR
|
||||
//config: bool "expr (6.6 kb)"
|
||||
//config: bool "expr (6.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: expr is used to calculate numbers and print the result
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config FACTOR
|
||||
//config: bool "factor (2.7 kb)"
|
||||
//config: bool "factor (2.6 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: factor factorizes integers
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config FSYNC
|
||||
//config: bool "fsync (3.6 kb)"
|
||||
//config: bool "fsync (3.7 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: fsync is used to flush file-related cached blocks to disk.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config HEAD
|
||||
//config: bool "head (3.8 kb)"
|
||||
//config: bool "head (3.7 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: head is used to print the first specified number of lines
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config HOSTID
|
||||
//config: bool "hostid (286 bytes)"
|
||||
//config: bool "hostid (247 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: hostid prints the numeric identifier (in hexadecimal) for
|
||||
|
||||
+2
-2
@@ -13,13 +13,13 @@
|
||||
* Added -G option Tito Ragusa (C) 2008 for SUSv3.
|
||||
*/
|
||||
//config:config ID
|
||||
//config: bool "id (7 kb)"
|
||||
//config: bool "id (6.7 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: id displays the current user and group ID names.
|
||||
//config:
|
||||
//config:config GROUPS
|
||||
//config: bool "groups (6.7 kb)"
|
||||
//config: bool "groups (6.5 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Print the group names associated with current user id.
|
||||
|
||||
+1
-5
@@ -214,11 +214,7 @@ int install_main(int argc, char **argv)
|
||||
dest = last;
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
/*
|
||||
* -D -t DIR1/DIR2/F3 FILE: create DIR1/DIR2/F3, copy FILE there
|
||||
* -D FILE DIR1/DIR2/F3: create DIR1/DIR2, copy FILE there as F3
|
||||
*/
|
||||
bb_make_directory((opts & OPT_TARGET) ? ddir : dirname(ddir), 0755, mkdir_flags);
|
||||
bb_make_directory(dirname(ddir), 0755, mkdir_flags);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config LINK
|
||||
//config: bool "link (3.2 kb)"
|
||||
//config: bool "link (3.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: link creates hard links between files.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config LN
|
||||
//config: bool "ln (4.9 kb)"
|
||||
//config: bool "ln (4.5 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: ln is used to create hard or soft links between files.
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
* a diagnostic message and an error return.
|
||||
*/
|
||||
//config:config LOGNAME
|
||||
//config: bool "logname (1.1 kb)"
|
||||
//config: bool "logname (894 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: logname is used to print the current user's login name.
|
||||
|
||||
+5
-13
@@ -421,7 +421,7 @@ static unsigned calc_name_len(const char *name)
|
||||
uni_stat_t uni_stat;
|
||||
|
||||
// TODO: quote tab as \t, etc, if -Q
|
||||
name = printable_string2(&uni_stat, name);
|
||||
name = printable_string(&uni_stat, name);
|
||||
|
||||
if (!(option_mask32 & OPT_Q)) {
|
||||
return uni_stat.unicode_width;
|
||||
@@ -450,7 +450,7 @@ static unsigned print_name(const char *name)
|
||||
uni_stat_t uni_stat;
|
||||
|
||||
// TODO: quote tab as \t, etc, if -Q
|
||||
name = printable_string2(&uni_stat, name);
|
||||
name = printable_string(&uni_stat, name);
|
||||
|
||||
if (!(option_mask32 & OPT_Q)) {
|
||||
fputs(name, stdout);
|
||||
@@ -1016,15 +1016,7 @@ static void scan_and_display_dirs_recur(struct dnode **dn, int first)
|
||||
subdnp = scan_one_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if (option_mask32 & (OPT_s|OPT_l)) {
|
||||
if (option_mask32 & OPT_h) {
|
||||
printf("total %-"HUMAN_READABLE_MAX_WIDTH_STR"s\n",
|
||||
/* print size, no fractions, use suffixes */
|
||||
make_human_readable_str(calculate_blocks(subdnp) * 1024,
|
||||
0, 0)
|
||||
);
|
||||
} else {
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
}
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
}
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
@@ -1204,8 +1196,8 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
nfiles = 0;
|
||||
do {
|
||||
cur = my_stat(*argv, *argv,
|
||||
/* follow links on command line unless -l, -i, -s or -F: */
|
||||
!(option_mask32 & (OPT_l|OPT_i|OPT_s|OPT_F))
|
||||
/* follow links on command line unless -l, -s or -F: */
|
||||
!(option_mask32 & (OPT_l|OPT_s|OPT_F))
|
||||
/* ... or if -H: */
|
||||
|| (option_mask32 & OPT_H)
|
||||
/* ... or if -L, but my_stat always follows links if -L */
|
||||
|
||||
@@ -6,31 +6,31 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config MD5SUM
|
||||
//config: bool "md5sum (6.5 kb)"
|
||||
//config: bool "md5sum (6.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Compute and check MD5 message digest
|
||||
//config: md5sum is used to print or check MD5 checksums.
|
||||
//config:
|
||||
//config:config SHA1SUM
|
||||
//config: bool "sha1sum (5.9 kb)"
|
||||
//config: bool "sha1sum (6 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Compute and check SHA1 message digest
|
||||
//config:
|
||||
//config:config SHA256SUM
|
||||
//config: bool "sha256sum (7 kb)"
|
||||
//config: bool "sha256sum (7.1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Compute and check SHA256 message digest
|
||||
//config:
|
||||
//config:config SHA512SUM
|
||||
//config: bool "sha512sum (7.4 kb)"
|
||||
//config: bool "sha512sum (7.6 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Compute and check SHA512 message digest
|
||||
//config:
|
||||
//config:config SHA3SUM
|
||||
//config: bool "sha3sum (6.1 kb)"
|
||||
//config: bool "sha3sum (6.3 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Compute and check SHA3 message digest
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
/* Nov 28, 2006 Yoshinori Sato <ysato@users.sourceforge.jp>: Add SELinux Support.
|
||||
*/
|
||||
//config:config MKDIR
|
||||
//config: bool "mkdir (4.5 kb)"
|
||||
//config: bool "mkdir (4.4 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: mkdir is used to create directories with the specified names.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config MKFIFO
|
||||
//config: bool "mkfifo (3.8 kb)"
|
||||
//config: bool "mkfifo (3.7 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: mkfifo is used to create FIFOs (named pipes).
|
||||
|
||||
+29
-29
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config MKNOD
|
||||
//config: bool "mknod (4.5 kb)"
|
||||
//config: bool "mknod (4 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: mknod is used to create FIFOs or block/character special
|
||||
@@ -20,7 +20,7 @@
|
||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||
|
||||
//usage:#define mknod_trivial_usage
|
||||
//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE [MAJOR MINOR]"
|
||||
//usage: "[-m MODE] " IF_SELINUX("[-Z] ") "NAME TYPE MAJOR MINOR"
|
||||
//usage:#define mknod_full_usage "\n\n"
|
||||
//usage: "Create a special file (block, character, or pipe)\n"
|
||||
//usage: "\n -m MODE Creation mode (default a=rw)"
|
||||
@@ -30,7 +30,7 @@
|
||||
//usage: "\nTYPE:"
|
||||
//usage: "\n b Block device"
|
||||
//usage: "\n c or u Character device"
|
||||
//usage: "\n p Named pipe (MAJOR MINOR must be omitted)"
|
||||
//usage: "\n p Named pipe (MAJOR and MINOR are ignored)"
|
||||
//usage:
|
||||
//usage:#define mknod_example_usage
|
||||
//usage: "$ mknod /dev/fd0 b 2 0\n"
|
||||
@@ -47,40 +47,40 @@ static const char modes_chars[] ALIGN1 = { 'p', 'c', 'u', 'b', 0, 1, 1, 2 };
|
||||
static const mode_t modes_cubp[] = { S_IFIFO, S_IFCHR, S_IFBLK };
|
||||
|
||||
int mknod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mknod_main(int argc UNUSED_PARAM, char **argv)
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
mode_t mode;
|
||||
dev_t dev;
|
||||
const char *type, *arg;
|
||||
const char *name;
|
||||
|
||||
mode = getopt_mk_fifo_nod(argv);
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
argc -= optind;
|
||||
|
||||
if (!argv[0] || !argv[1])
|
||||
bb_show_usage();
|
||||
type = strchr(modes_chars, argv[1][0]);
|
||||
if (!type)
|
||||
bb_show_usage();
|
||||
if (argc >= 2) {
|
||||
name = strchr(modes_chars, argv[1][0]);
|
||||
if (name != NULL) {
|
||||
mode |= modes_cubp[(int)(name[4])];
|
||||
|
||||
mode |= modes_cubp[(int)(type[4])];
|
||||
dev = 0;
|
||||
if (*name != 'p') {
|
||||
argc -= 2;
|
||||
if (argc == 2) {
|
||||
/* Autodetect what the system supports; these macros should
|
||||
* optimize out to two constants. */
|
||||
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
|
||||
xatoul_range(argv[3], 0, minor(UINT_MAX)));
|
||||
}
|
||||
}
|
||||
|
||||
dev = 0;
|
||||
arg = argv[2];
|
||||
if (*type != 'p') {
|
||||
if (!argv[2] || !argv[3])
|
||||
bb_show_usage();
|
||||
/* Autodetect what the system supports; these macros should
|
||||
* optimize out to two constants. */
|
||||
dev = makedev(xatoul_range(argv[2], 0, major(UINT_MAX)),
|
||||
xatoul_range(argv[3], 0, minor(UINT_MAX)));
|
||||
arg = argv[4];
|
||||
if (argc == 2) {
|
||||
name = *argv;
|
||||
if (mknod(name, mode, dev) == 0) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (arg)
|
||||
bb_show_usage();
|
||||
|
||||
if (mknod(argv[0], mode, dev) != 0) {
|
||||
bb_simple_perror_msg_and_die(argv[0]);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
bb_show_usage();
|
||||
}
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
* -p; else /tmp [deprecated]
|
||||
*/
|
||||
//config:config MKTEMP
|
||||
//config: bool "mktemp (4.2 kb)"
|
||||
//config: bool "mktemp (4 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: mktemp is used to create unique temporary files
|
||||
|
||||
+3
-4
@@ -12,13 +12,12 @@
|
||||
* Size reduction and improved error checking.
|
||||
*/
|
||||
//config:config MV
|
||||
//config: bool "mv (10 kb)"
|
||||
//config: bool "mv (9.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: mv is used to move or rename files or directories.
|
||||
|
||||
//applet:IF_MV(APPLET_NOEXEC(mv, mv, BB_DIR_BIN, BB_SUID_DROP, mv))
|
||||
/* NOEXEC despite cases when it can be a "runner" (mv LARGE_DIR OTHER_FS) */
|
||||
//applet:IF_MV(APPLET(mv, BB_DIR_BIN, BB_SUID_DROP))
|
||||
|
||||
//kbuild:lib-$(CONFIG_MV) += mv.o
|
||||
|
||||
@@ -101,7 +100,7 @@ int mv_main(int argc, char **argv)
|
||||
if (fprintf(stderr, "mv: overwrite '%s'? ", dest) < 0) {
|
||||
goto RET_1; /* Ouch! fprintf failed! */
|
||||
}
|
||||
if (!bb_ask_y_confirmation()) {
|
||||
if (!bb_ask_confirmation()) {
|
||||
goto RET_0;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-13
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config NICE
|
||||
//config: bool "nice (2.1 kb)"
|
||||
//config: bool "nice (1.8 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: nice runs a program with modified scheduling priority.
|
||||
@@ -22,10 +22,11 @@
|
||||
//usage: "Change scheduling priority, run PROG\n"
|
||||
//usage: "\n -n ADJUST Adjust priority by ADJUST"
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include "libbb.h"
|
||||
|
||||
int nice_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int nice_main(int argc UNUSED_PARAM, char **argv)
|
||||
int nice_main(int argc, char **argv)
|
||||
{
|
||||
int old_priority, adjustment;
|
||||
|
||||
@@ -39,21 +40,18 @@ int nice_main(int argc UNUSED_PARAM, char **argv)
|
||||
adjustment = 10; /* Set default adjustment. */
|
||||
|
||||
if (argv[0][0] == '-') {
|
||||
char *nnn = argv[0] + 1;
|
||||
if (nnn[0] == 'n') { /* -n */
|
||||
nnn += 1;
|
||||
if (!nnn[0]) { /* "-n NNN" */
|
||||
nnn = *++argv;
|
||||
if (argv[0][1] == 'n') { /* -n */
|
||||
if (argv[0][2]) { /* -nNNNN (w/o space) */
|
||||
argv[0] += 2; argv--; argc++;
|
||||
}
|
||||
/* else: "-nNNN" (w/o space) */
|
||||
} else { /* -NNN (NNN may be negative) == -n NNN */
|
||||
argv[0] += 1; argv--; argc++;
|
||||
}
|
||||
/* else: "-NNN" (NNN may be negative) - same as "-n NNN" */
|
||||
|
||||
if (!nnn || !argv[1]) { /* Missing priority or PROG! */
|
||||
if (argc < 4) { /* Missing priority and/or utility! */
|
||||
bb_show_usage();
|
||||
}
|
||||
adjustment = xatoi_range(nnn, INT_MIN/2, INT_MAX/2);
|
||||
argv++;
|
||||
adjustment = xatoi_range(argv[1], INT_MIN/2, INT_MAX/2);
|
||||
argv += 2;
|
||||
}
|
||||
|
||||
{ /* Set our priority. */
|
||||
|
||||
+3
-6
@@ -5,7 +5,7 @@
|
||||
* Licensed under GPLv2, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config NL
|
||||
//config: bool "nl (4.6 kb)"
|
||||
//config: bool "nl (4.3 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: nl is used to number lines of files.
|
||||
@@ -58,8 +58,6 @@ int nl_main(int argc UNUSED_PARAM, char **argv)
|
||||
"number-width\0" Required_argument "w"
|
||||
;
|
||||
#endif
|
||||
int exitcode;
|
||||
|
||||
ns.width = 6;
|
||||
ns.start = 1;
|
||||
ns.inc = 1;
|
||||
@@ -74,10 +72,9 @@ int nl_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!*argv)
|
||||
*--argv = (char*)"-";
|
||||
|
||||
exitcode = EXIT_SUCCESS;
|
||||
do {
|
||||
exitcode |= print_numbered_lines(&ns, *argv);
|
||||
print_numbered_lines(&ns, *argv);
|
||||
} while (*++argv);
|
||||
|
||||
fflush_stdout_and_exit(exitcode);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+11
-35
@@ -4,7 +4,7 @@
|
||||
* Licensed under GPLv2, see LICENSE in this source tree
|
||||
*/
|
||||
//config:config NPROC
|
||||
//config: bool "nproc (3.7 kb)"
|
||||
//config: bool "nproc (248 bytes)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: Print number of CPUs
|
||||
@@ -14,14 +14,10 @@
|
||||
//kbuild:lib-$(CONFIG_NPROC) += nproc.o
|
||||
|
||||
//usage:#define nproc_trivial_usage
|
||||
//usage: ""IF_LONG_OPTS("--all --ignore=N")
|
||||
//usage: ""
|
||||
//TODO: "[--all] [--ignore=N]"
|
||||
//usage:#define nproc_full_usage "\n\n"
|
||||
//usage: "Print number of available CPUs"
|
||||
//usage: IF_LONG_OPTS(
|
||||
//usage: "\n"
|
||||
//usage: "\n --all Number of installed CPUs"
|
||||
//usage: "\n --ignore=N Exclude N CPUs"
|
||||
//usage: )
|
||||
//usage: "Print number of CPUs"
|
||||
|
||||
#include <sched.h>
|
||||
#include "libbb.h"
|
||||
@@ -30,30 +26,13 @@ int nproc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
unsigned long mask[1024];
|
||||
int count = 0;
|
||||
#if ENABLE_LONG_OPTS
|
||||
int ignore = 0;
|
||||
int opts = getopt32long(argv, "\xfe:+",
|
||||
"ignore\0" Required_argument "\xfe"
|
||||
"all\0" No_argument "\xff"
|
||||
, &ignore
|
||||
);
|
||||
unsigned i, count = 0;
|
||||
|
||||
//getopt32(argv, "");
|
||||
|
||||
//if --all, count /sys/devices/system/cpu/cpuN dirs, else:
|
||||
|
||||
if (opts & (1 << 1)) {
|
||||
DIR *cpusd = opendir("/sys/devices/system/cpu");
|
||||
if (cpusd) {
|
||||
struct dirent *de;
|
||||
while (NULL != (de = readdir(cpusd))) {
|
||||
char *cpuid = strstr(de->d_name, "cpu");
|
||||
if (cpuid && isdigit(cpuid[strlen(cpuid) - 1]))
|
||||
count++;
|
||||
}
|
||||
closedir(cpusd);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
if (sched_getaffinity(0, sizeof(mask), (void*)mask) == 0) {
|
||||
int i;
|
||||
for (i = 0; i < ARRAY_SIZE(mask); i++) {
|
||||
unsigned long m = mask[i];
|
||||
while (m) {
|
||||
@@ -63,11 +42,8 @@ int nproc_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IF_LONG_OPTS(count -= ignore;)
|
||||
if (count <= 0)
|
||||
count = 1;
|
||||
|
||||
if (count == 0)
|
||||
count++;
|
||||
printf("%u\n", count);
|
||||
|
||||
return 0;
|
||||
|
||||
+11
-17
@@ -211,14 +211,7 @@ struct globals {
|
||||
|
||||
bool not_first;
|
||||
bool prev_pair_equal;
|
||||
|
||||
char address_fmt[sizeof("%0n"OFF_FMT"xc")];
|
||||
} FIX_ALIASING;
|
||||
/* Corresponds to 'x' above */
|
||||
#define address_base_char G.address_fmt[sizeof(G.address_fmt)-3]
|
||||
/* Corresponds to 'n' above */
|
||||
#define address_pad_len_char G.address_fmt[2]
|
||||
|
||||
#if !ENABLE_LONG_OPTS
|
||||
enum { G_pseudo_offset = 0 };
|
||||
#endif
|
||||
@@ -227,7 +220,6 @@ enum { G_pseudo_offset = 0 };
|
||||
setup_common_bufsiz(); \
|
||||
BUILD_BUG_ON(sizeof(G) > COMMON_BUFSIZE); \
|
||||
G.bytes_per_block = 32; \
|
||||
strcpy(G.address_fmt, "%0n"OFF_FMT"xc"); \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -852,12 +844,18 @@ format_address_none(off_t address UNUSED_PARAM, char c UNUSED_PARAM)
|
||||
{
|
||||
}
|
||||
|
||||
static char address_fmt[] ALIGN1 = "%0n"OFF_FMT"xc";
|
||||
/* Corresponds to 'x' above */
|
||||
#define address_base_char address_fmt[sizeof(address_fmt)-3]
|
||||
/* Corresponds to 'n' above */
|
||||
#define address_pad_len_char address_fmt[2]
|
||||
|
||||
static void
|
||||
format_address_std(off_t address, char c)
|
||||
{
|
||||
/* Corresponds to 'c' */
|
||||
G.address_fmt[sizeof(G.address_fmt)-2] = c;
|
||||
printf(G.address_fmt, address);
|
||||
address_fmt[sizeof(address_fmt)-2] = c;
|
||||
printf(address_fmt, address);
|
||||
}
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
@@ -1373,13 +1371,9 @@ int od_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < G.n_specs; i++) {
|
||||
printf("%d: fmt='%s' width=%d\n",
|
||||
i, G.spec[i].fmt_string,
|
||||
width_bytes[G.spec[i].size]);
|
||||
}
|
||||
for (i = 0; i < G.n_specs; i++) {
|
||||
printf("%d: fmt=\"%s\" width=%d\n",
|
||||
i, spec[i].fmt_string, width_bytes[spec[i].size]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config PASTE
|
||||
//config: bool "paste (4.9 kb)"
|
||||
//config: bool "paste (4.5 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: paste is used to paste lines of different files together
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
||||
*/
|
||||
//config:config PRINTENV
|
||||
//config: bool "printenv (1.3 kb)"
|
||||
//config: bool "printenv (1 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: printenv is used to print all or part of environment.
|
||||
|
||||
+3
-12
@@ -38,7 +38,7 @@
|
||||
/* 19990508 Busy Boxed! Dave Cinege */
|
||||
|
||||
//config:config PRINTF
|
||||
//config: bool "printf (3.8 kb)"
|
||||
//config: bool "printf (3.3 kb)"
|
||||
//config: default y
|
||||
//config: help
|
||||
//config: printf is used to format and print specified strings.
|
||||
@@ -95,12 +95,6 @@ static int multiconvert(const char *arg, void *result, converter convert)
|
||||
|
||||
static void FAST_FUNC conv_strtoull(const char *arg, void *result)
|
||||
{
|
||||
/* Allow leading '+' - bb_strtoull() by itself does not allow it,
|
||||
* and probably shouldn't (other callers might require purely numeric
|
||||
* inputs to be allowed.
|
||||
*/
|
||||
if (arg[0] == '+')
|
||||
arg++;
|
||||
*(unsigned long long*)result = bb_strtoull(arg, NULL, 0);
|
||||
/* both coreutils 6.10 and bash 3.2:
|
||||
* $ printf '%x\n' -2
|
||||
@@ -113,8 +107,6 @@ static void FAST_FUNC conv_strtoull(const char *arg, void *result)
|
||||
}
|
||||
static void FAST_FUNC conv_strtoll(const char *arg, void *result)
|
||||
{
|
||||
if (arg[0] == '+')
|
||||
arg++;
|
||||
*(long long*)result = bb_strtoll(arg, NULL, 0);
|
||||
}
|
||||
static void FAST_FUNC conv_strtod(const char *arg, void *result)
|
||||
@@ -199,7 +191,6 @@ static void print_direc(char *format, unsigned fmt_length,
|
||||
if (have_width - 1 == have_prec)
|
||||
have_width = NULL;
|
||||
|
||||
/* multiconvert sets errno = 0, but %s needs it cleared */
|
||||
errno = 0;
|
||||
|
||||
switch (format[fmt_length - 1]) {
|
||||
@@ -208,7 +199,7 @@ static void print_direc(char *format, unsigned fmt_length,
|
||||
break;
|
||||
case 'd':
|
||||
case 'i':
|
||||
llv = my_xstrtoll(skip_whitespace(argument));
|
||||
llv = my_xstrtoll(argument);
|
||||
print_long:
|
||||
if (!have_width) {
|
||||
if (!have_prec)
|
||||
@@ -226,7 +217,7 @@ static void print_direc(char *format, unsigned fmt_length,
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
llv = my_xstrtoull(skip_whitespace(argument));
|
||||
llv = my_xstrtoull(argument);
|
||||
/* cheat: unsigned long and long have same width, so... */
|
||||
goto print_long;
|
||||
case 's':
|
||||
|
||||
Loaded 100 of 882 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user