Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84641942e5 | ||
|
|
bacaff6e54 |
No files matched your search
-34
@@ -1,34 +0,0 @@
|
||||
#
|
||||
# Kbuild ignores
|
||||
#
|
||||
.*
|
||||
*.o
|
||||
*.o.*
|
||||
*.a
|
||||
*.s
|
||||
|
||||
#
|
||||
# Never ignore these
|
||||
#
|
||||
!.gitignore
|
||||
|
||||
#
|
||||
# Normal output
|
||||
#
|
||||
/busybox
|
||||
/busybox_unstripped*
|
||||
|
||||
#
|
||||
# Backups / patches
|
||||
#
|
||||
*~
|
||||
*.orig
|
||||
*.rej
|
||||
/*.patch
|
||||
|
||||
#
|
||||
# debugging stuff
|
||||
#
|
||||
core
|
||||
.gdb_history
|
||||
.gdbinit
|
||||
@@ -166,11 +166,8 @@ Paul Fox <pgf@foxharp.boston.ma.us>
|
||||
Roberto A. Foglietta <me@roberto.foglietta.name>
|
||||
port: dnsd
|
||||
|
||||
Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
|
||||
Bernhard Fischer <rep.nop@aon.at>
|
||||
misc
|
||||
|
||||
Mike Frysinger <vapier@gentoo.org>
|
||||
initial e2fsprogs, printenv, setarch, sum, misc
|
||||
|
||||
Jie Zhang <jie.zhang@analog.com>
|
||||
fixed two bugs in msh and hush (exitcode of killed processes)
|
||||
@@ -30,22 +30,17 @@ config EXTRA_COMPAT
|
||||
some GNU extensions in libc. You probably only need this option
|
||||
if you plan to run busybox on desktop.
|
||||
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will be supported in head, tail, and fold. (Note: should
|
||||
affect renice too.)
|
||||
|
||||
config USE_PORTABLE_CODE
|
||||
bool "Avoid using GCC-specific code constructs"
|
||||
config FEATURE_ASSUME_UNICODE
|
||||
bool "Assume that 1:1 char/glyph correspondence is not true"
|
||||
default n
|
||||
help
|
||||
Use this option if you are trying to compile busybox with
|
||||
compiler other than gcc.
|
||||
If you do use gcc, this option may needlessly increase code size.
|
||||
This makes various applets aware that one byte is not
|
||||
one character on screen.
|
||||
|
||||
Busybox aims to eventually work correctly with Unicode displays.
|
||||
Any older encodings are not guaranteed to work.
|
||||
Probably by the time when busybox will be fully Unicode-clean,
|
||||
other encodings will be mainly of historic interest.
|
||||
|
||||
choice
|
||||
prompt "Buffer allocation policy"
|
||||
@@ -119,29 +114,7 @@ config LOCALE_SUPPORT
|
||||
Enable this if your system has locale support and you would like
|
||||
busybox to support locale settings.
|
||||
|
||||
config FEATURE_ASSUME_UNICODE
|
||||
bool "Support Unicode"
|
||||
default n
|
||||
help
|
||||
This makes various applets aware that one byte is not
|
||||
one character on screen.
|
||||
|
||||
Busybox aims to eventually work correctly with Unicode displays.
|
||||
Any older encodings are not guaranteed to work.
|
||||
Probably by the time when busybox will be fully Unicode-clean,
|
||||
other encodings will be mainly of historic interest.
|
||||
|
||||
config FEATURE_CHECK_UNICODE_IN_ENV
|
||||
bool "Check $LANG environment variable"
|
||||
default y
|
||||
depends on FEATURE_ASSUME_UNICODE && !LOCALE_SUPPORT
|
||||
help
|
||||
With this option on, Unicode support is activated
|
||||
only if LANG variable has the value of the form "xxxx.utf8"
|
||||
|
||||
Otherwise, Unicode support will be always enabled and active.
|
||||
|
||||
config LONG_OPTS
|
||||
config GETOPT_LONG
|
||||
bool "Support for --long-options"
|
||||
default y
|
||||
help
|
||||
@@ -182,17 +155,15 @@ config FEATURE_SUID
|
||||
default n
|
||||
help
|
||||
With this option you can install the busybox binary belonging
|
||||
to root with the suid bit set, and it will automatically drop
|
||||
to root with the suid bit set, and it'll and it'll automatically drop
|
||||
priviledges for applets that don't need root access.
|
||||
|
||||
If you are really paranoid and don't want to do this, build two
|
||||
If you're really paranoid and don't want to do this, build two
|
||||
busybox binaries with different applets in them (and the appropriate
|
||||
symlinks pointing to each binary), and only set the suid bit on the
|
||||
one that needs it. The applets currently marked to need the suid bit
|
||||
are:
|
||||
|
||||
crontab, dnsd, findfs, ipcrm, ipcs, login, passwd, ping, su,
|
||||
traceroute, vlock.
|
||||
are login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs,
|
||||
and vlock.
|
||||
|
||||
config FEATURE_SUID_CONFIG
|
||||
bool "Runtime SUID/SGID configuration via /etc/busybox.conf"
|
||||
@@ -283,18 +254,18 @@ config BUSYBOX_EXEC_PATH
|
||||
# These are auto-selected by other options
|
||||
|
||||
config FEATURE_SYSLOG
|
||||
bool #No description makes it a hidden option
|
||||
bool "Support for logging to syslog"
|
||||
default n
|
||||
#help
|
||||
# This option is auto-selected when you select any applet which may
|
||||
# send its output to syslog. You do not need to select it manually.
|
||||
help
|
||||
This option is auto-selected when you select any applet which may
|
||||
send its output to syslog. You do not need to select it manually.
|
||||
|
||||
config FEATURE_HAVE_RPC
|
||||
bool #No description makes it a hidden option
|
||||
bool "RPC support"
|
||||
default n
|
||||
#help
|
||||
# This is automatically selected if any of enabled applets need it.
|
||||
# You do not need to select it manually.
|
||||
help
|
||||
This is automatically selected if any of enabled applets need it.
|
||||
You do not need to select it manually.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -431,18 +402,9 @@ config CROSS_COMPILER_PREFIX
|
||||
help
|
||||
If you want to build BusyBox with a cross compiler, then you
|
||||
will need to set this to the cross-compiler prefix, for example,
|
||||
"i386-uclibc-".
|
||||
|
||||
Note that CROSS_COMPILE environment variable or
|
||||
"make CROSS_COMPILE=xxx ..." will override this selection.
|
||||
|
||||
Native builds leave this empty.
|
||||
|
||||
config EXTRA_CFLAGS
|
||||
string "Additional CFLAGS"
|
||||
default ""
|
||||
help
|
||||
Additional CFLAGS to pass to the compiler verbatim.
|
||||
"i386-uclibc-". Note that CROSS_COMPILE environment variable
|
||||
or "make CROSS_COMPILE=xxx ..." will override this selection.
|
||||
For native build leave it empty.
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -520,8 +482,17 @@ config EFENCE
|
||||
|
||||
endchoice
|
||||
|
||||
### config PARSE
|
||||
### bool "Uniform config file parser debugging applet: parse"
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3?"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will be supported in head, tail, and fold. (Note: should
|
||||
affect renice too.)
|
||||
|
||||
config PARSE
|
||||
bool "Uniform config file parser debugging applet: parse"
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -619,10 +590,9 @@ source modutils/Config.in
|
||||
source util-linux/Config.in
|
||||
source miscutils/Config.in
|
||||
source networking/Config.in
|
||||
source printutils/Config.in
|
||||
source mailutils/Config.in
|
||||
source procps/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
source shell/Config.in
|
||||
source sysklogd/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
source printutils/Config.in
|
||||
@@ -19,24 +19,11 @@ it, is to enable all features and then use "standalone shell" mode with a
|
||||
blank command $PATH.
|
||||
|
||||
To enable all features, use "make defconfig", which produces the largest
|
||||
general-purpose configuration. It's allyesconfig minus debugging options,
|
||||
general-purpose configuration. (It's allyesconfig minus debugging options,
|
||||
optional packaging choices, and a few special-purpose features requiring
|
||||
extra configuration to use. Then enable "standalone shell" feature:
|
||||
extra configuration to use.)
|
||||
|
||||
make defconfig
|
||||
make menuconfig
|
||||
# select Busybox Settings
|
||||
# then General Configuration
|
||||
# then exec prefers applets
|
||||
# exit back to top level menu
|
||||
# select Shells
|
||||
# then Standalone shell
|
||||
# exit back to top level menu
|
||||
# exit and save new configuration
|
||||
# OR
|
||||
# use these commands to modify .config directly:
|
||||
sed -e 's/.*FEATURE_PREFER_APPLETS.*/CONFIG_FEATURE_PREFER_APPLETS=y/' -i .config
|
||||
sed -e 's/.*FEATURE_SH_STANDALONE.*/CONFIG_FEATURE_SH_STANDALONE=y/' -i .config
|
||||
make
|
||||
PATH= ./busybox ash
|
||||
|
||||
@@ -117,7 +104,7 @@ somewhere else.
|
||||
|
||||
To build out of tree, cd to an empty directory and configure busybox from there:
|
||||
|
||||
make KBUILD_SRC=/path/to/source -f /path/to/source/Makefile defconfig
|
||||
make -f /path/to/source/Makefile defconfig
|
||||
make
|
||||
make install
|
||||
|
||||
@@ -134,4 +121,5 @@ More Information:
|
||||
|
||||
Se also the busybox FAQ, under the questions "How can I get started using
|
||||
BusyBox" and "How do I build a BusyBox-based system?" The BusyBox FAQ is
|
||||
available from http://www.busybox.net/FAQ.html
|
||||
available from http://www.busybox.net/FAQ.html or as the file
|
||||
docs/busybox.net/FAQ.html in this tarball.
|
||||
@@ -10,7 +10,7 @@ distributed under.
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
@@ -313,7 +313,7 @@ the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 16
|
||||
PATCHLEVEL = 12
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
@@ -168,7 +168,6 @@ ifeq ($(CROSS_COMPILE),)
|
||||
CROSS_COMPILE := $(shell grep ^CONFIG_CROSS_COMPILER_PREFIX .config 2>/dev/null)
|
||||
CROSS_COMPILE := $(subst CONFIG_CROSS_COMPILER_PREFIX=,,$(CROSS_COMPILE))
|
||||
CROSS_COMPILE := $(subst ",,$(CROSS_COMPILE))
|
||||
#")
|
||||
endif
|
||||
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
@@ -358,15 +357,6 @@ scripts_basic:
|
||||
# To avoid any implicit rule to kick in, define an empty command.
|
||||
scripts/basic/%: scripts_basic ;
|
||||
|
||||
# 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
|
||||
$(Q)$(MAKE) $(build)=applets
|
||||
|
||||
applets/%: applets_dir ;
|
||||
|
||||
PHONY += outputmakefile
|
||||
# outputmakefile generates a Makefile in the output directory, if using a
|
||||
# separate output directory. This allows convenient use of make in the
|
||||
@@ -466,7 +456,6 @@ libs-y := \
|
||||
libbb/ \
|
||||
libpwdgrp/ \
|
||||
loginutils/ \
|
||||
mailutils/ \
|
||||
miscutils/ \
|
||||
modutils/ \
|
||||
networking/ \
|
||||
@@ -516,7 +505,7 @@ endif
|
||||
# command line.
|
||||
# This allow a user to issue only 'make' to build a kernel including modules
|
||||
# Defaults busybox but it is usually overridden in the arch makefile
|
||||
all: busybox doc
|
||||
all: busybox
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
|
||||
@@ -806,7 +795,7 @@ ifneq ($(KBUILD_MODULES),)
|
||||
$(Q)rm -f $(MODVERDIR)/*
|
||||
endif
|
||||
|
||||
archprepare: prepare1 scripts_basic applets_dir
|
||||
archprepare: prepare1 scripts_basic
|
||||
|
||||
prepare0: archprepare FORCE
|
||||
$(Q)$(MAKE) $(build)=.
|
||||
@@ -977,12 +966,6 @@ clean: archclean $(clean-dirs)
|
||||
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
|
||||
-type f -print | xargs rm -f
|
||||
|
||||
PHONY += doc-clean
|
||||
doc-clean: rm-files := docs/busybox.pod \
|
||||
docs/BusyBox.html docs/BusyBox.1 docs/BusyBox.txt
|
||||
doc-clean:
|
||||
$(call cmd,rmfiles)
|
||||
|
||||
# mrproper - Delete all generated files, including .config
|
||||
#
|
||||
mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
|
||||
|
||||
+8
-16
@@ -105,25 +105,15 @@ bigdata: busybox_unstripped
|
||||
.PHONY: doc
|
||||
doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
# FIXME: Doesn't belong here
|
||||
cmd_doc =
|
||||
quiet_cmd_doc = $(Q)echo " DOC $(@F)"
|
||||
silent_cmd_doc =
|
||||
disp_doc = $($(quiet)cmd_doc)
|
||||
|
||||
# sed adds newlines after "Options:" etc,
|
||||
# this is needed in order to get good BusyBox.{1,txt,html}
|
||||
docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
|
||||
$(srctree)/include/usage.h \
|
||||
$(srctree)/docs/busybox_footer.pod \
|
||||
applets/usage_pod
|
||||
$(srctree)/docs/autodocifier.pl
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-( \
|
||||
cat $(srctree)/docs/busybox_header.pod; \
|
||||
applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \
|
||||
cat $(srctree)/docs/busybox_footer.pod; \
|
||||
) > docs/busybox.pod
|
||||
$(Q)-( cat $(srctree)/docs/busybox_header.pod ; \
|
||||
$(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \
|
||||
cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
@@ -133,7 +123,8 @@ docs/BusyBox.txt: docs/busybox.pod
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(KERNELVERSION)" $< > $@
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
$(disp_doc)
|
||||
@@ -143,7 +134,8 @@ docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
$(Q)-mkdir -p docs/busybox.net
|
||||
$(Q)-pod2html --noindex $< > $@
|
||||
$(Q)-pod2html --noindex $< > \
|
||||
docs/busybox.net/BusyBox.html
|
||||
$(Q)-rm -f pod2htm*
|
||||
|
||||
# documentation, cross-reference
|
||||
|
||||
+3
-18
@@ -23,7 +23,6 @@ CFLAGS += $(call cc-option,-Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef,)
|
||||
CFLAGS += $(call cc-option,-Wstrict-prototypes,)
|
||||
CFLAGS += $(call cc-option,-Wunused -Wunused-parameter,)
|
||||
CFLAGS += $(call cc-option,-Wunused-function -Wunused-value,)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
# warn about C99 declaration after statement
|
||||
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
@@ -32,15 +31,6 @@ CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
|
||||
|
||||
ifeq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Werror,)
|
||||
## TODO:
|
||||
## gcc version 4.4.0 20090506 (Red Hat 4.4.0-4) (GCC) is a PITA:
|
||||
## const char *ptr; ... off_t v = *(off_t*)ptr; -> BOOM
|
||||
## and no easy way to convince it to shut the hell up.
|
||||
## We have a lot of such things all over the place.
|
||||
## Classic *(off_t*)(void*)ptr does not work,
|
||||
## and I am unwilling to do crazy gcc specific ({ void *ppp = ...; })
|
||||
## stuff in macros. This would obfuscate the code too much.
|
||||
#CFLAGS += $(call cc-ifversion, -eq, 0404, -fno-strict-aliasing)
|
||||
endif
|
||||
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
|
||||
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
|
||||
@@ -91,11 +81,6 @@ CFLAGS_busybox += $(ARCH_PIE)
|
||||
CFLAGS += $(ARCH_FPIE)
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_EXTRA_CFLAGS),)
|
||||
CFLAGS += $(strip $(subst ",,$(CONFIG_EXTRA_CFLAGS)))
|
||||
#"))
|
||||
endif
|
||||
|
||||
LDLIBS += m crypt
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
@@ -114,12 +99,12 @@ ifeq ($(CONFIG_DMALLOC),y)
|
||||
LDLIBS += dmalloc
|
||||
endif
|
||||
|
||||
# If a flat binary should be built, CFLAGS_busybox="-elf2flt"
|
||||
# If a flat binary should be built, CFLAGS_busybox="-Wl,-elf2flt"
|
||||
# env var should be set for make invocation.
|
||||
# Here we check whether CFLAGS_busybox indeed contains that flag.
|
||||
# (For historical reasons, we also check LDFLAGS, which doesn't
|
||||
# seem to be entirely correct variable to put "-elf2flt" into).
|
||||
W_ELF2FLT = -elf2flt
|
||||
# seem to be entirely correct variable to put "-Wl,-elf2flt" into).
|
||||
W_ELF2FLT = -Wl,-elf2flt
|
||||
ifneq (,$(findstring $(W_ELF2FLT),$(LDFLAGS) $(CFLAGS_busybox)))
|
||||
SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
@@ -6,7 +6,6 @@ help:
|
||||
@echo 'Cleaning:'
|
||||
@echo ' clean - delete temporary files created by build'
|
||||
@echo ' distclean - delete all non-source files (including .config)'
|
||||
@echo ' doc-clean - delete all generated documentation'
|
||||
@echo
|
||||
@echo 'Build:'
|
||||
@echo ' all - Executable and documentation'
|
||||
|
||||
@@ -68,9 +68,9 @@ Downloading the current source code:
|
||||
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
|
||||
|
||||
Anonymous GIT access is available. For instructions, check out:
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
|
||||
http://www.busybox.net/source.html
|
||||
http://busybox.net/subversion.html
|
||||
|
||||
For those that are actively contributing and would like to check files in,
|
||||
see:
|
||||
@@ -78,7 +78,7 @@ Downloading the current source code:
|
||||
http://busybox.net/developer.html
|
||||
|
||||
The developers also have a bug and patch tracking system
|
||||
(https://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
(http://bugs.busybox.net) although posting a bug/patch to the mailing list
|
||||
is generally a faster way of getting it fixed, and the complete archive of
|
||||
what happened is the subversion changelog.
|
||||
|
||||
|
||||
@@ -6,18 +6,24 @@ do one of these bounce an email off the person it's listed under to see if they
|
||||
have any suggestions how they plan to go about it, and to minimize conflicts
|
||||
between your work and theirs. But otherwise, all of these are fair game.
|
||||
|
||||
Rob Landley suggested this:
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Rob Landley suggested these:
|
||||
Add a libbb/platform.c
|
||||
Implement fdprintf() for platforms that haven't got one.
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Cleanup bb_asprintf()
|
||||
|
||||
Remove obsolete _() wrapper crud for internationalization we don't do.
|
||||
Figure out where we need utf8 support, and add it.
|
||||
|
||||
sh
|
||||
The command shell situation is a mess. We have two different
|
||||
The command shell situation is a big mess. We have three different
|
||||
shells that don't really share any code, and the "standalone shell" doesn't
|
||||
work all that well (especially not in a chroot environment), due to apps not
|
||||
being reentrant.
|
||||
|
||||
lash is phased out. hush can be configured down to be nearly as small,
|
||||
but less buggy :)
|
||||
init
|
||||
General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
|
||||
Do a SUSv3 audit
|
||||
Look at the full Single Unix Specification version 3 (available online at
|
||||
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
|
||||
@@ -26,7 +32,6 @@ Rob Landley suggested this:
|
||||
|
||||
Even better would be some kind of automated compliance test harness that
|
||||
exercises each command line option and the various corner cases.
|
||||
|
||||
Internationalization
|
||||
How much internationalization should we do?
|
||||
|
||||
@@ -94,10 +99,15 @@ Rob Landley suggested this:
|
||||
This one's open to everybody, but I'll wind up doing it...
|
||||
|
||||
|
||||
Bernhard Reutner-Fischer <busybox@busybox.net> suggests to look at these:
|
||||
Bernhard Fischer <busybox@busybox.net> suggests to look at these:
|
||||
New debug options:
|
||||
-Wlarger-than-127
|
||||
Cleanup any big users
|
||||
-Wunused-parameter
|
||||
Facilitate applet PROTOTYPES to provide means for having applets that
|
||||
do a) not take any arguments b) need only one of argc or argv c) need
|
||||
both argc and argv. All of these three options should go for the most
|
||||
feature complete denominator.
|
||||
Collate BUFSIZ IOBUF_SIZE MY_BUF_SIZE PIPE_PROGRESS_SIZE BUFSIZE PIPESIZE
|
||||
make bb_common_bufsiz1 configurable, size wise.
|
||||
make pipesize configurable, size wise.
|
||||
@@ -122,6 +132,14 @@ patch
|
||||
And while we're at it, a new patch filename quoting format is apparently
|
||||
coming soon: http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
|
||||
---
|
||||
man
|
||||
It would be nice to have a man command. Not one that handles troff or
|
||||
anything, just one that can handle preformatted ascii man pages, possibly
|
||||
compressed. This could probably be a script in the extras directory that
|
||||
calls cat/zcat/bzcat | less
|
||||
|
||||
(How doclifter might work into this is anybody's guess.)
|
||||
---
|
||||
ar
|
||||
Write support!
|
||||
---
|
||||
@@ -165,7 +183,8 @@ Unify archivers
|
||||
---
|
||||
Text buffer support.
|
||||
Several existing applets (sort, vi, less...) read
|
||||
a whole file into memory and act on it. Use open_read_close().
|
||||
a whole file into memory and act on it. There might be an opportunity
|
||||
for shared code in there that could be moved into libbb...
|
||||
---
|
||||
Memory Allocation
|
||||
We have a CONFIG_BUFFER mechanism that lets us select whether to do memory
|
||||
@@ -217,7 +236,7 @@ Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS
|
||||
FEATURE_CLEAN_UP
|
||||
This is more an unresolved issue than a to-do item. More thought is needed.
|
||||
|
||||
Normally we rely on exit() to free memory, close files and unmap segments
|
||||
Normally we rely on exit() to free memory, close files, and unmap segments
|
||||
for us. This makes most calls to free(), close(), and unmap() optional in
|
||||
busybox applets that don't intend to run for very long, and optional stuff
|
||||
can be omitted to save size.
|
||||
@@ -246,6 +265,7 @@ FEATURE_CLEAN_UP
|
||||
For right now, exit() handles it just fine.
|
||||
|
||||
|
||||
|
||||
Minor stuff:
|
||||
watchdog.c could autodetect the timer duration via:
|
||||
if(!ioctl (fd, WDIOC_GETTIMEOUT, &tmo)) timer_duration = 1 + (tmo / 2);
|
||||
@@ -260,16 +280,14 @@ Minor stuff:
|
||||
---
|
||||
possible code duplication ingroup() and is_a_group_member()
|
||||
---
|
||||
Move __get_hz() to a better place and (re)use it in route.c, ash.c
|
||||
Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
|
||||
---
|
||||
See grep -r strtod
|
||||
Alot of duplication that wants cleanup.
|
||||
---
|
||||
in_ether duplicated in network/{interface,ifconfig}.c
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
---
|
||||
support start-stop-daemon -d <chdir-path>
|
||||
|
||||
|
||||
Code cleanup:
|
||||
|
||||
@@ -278,100 +296,3 @@ Replace deprecated functions.
|
||||
---
|
||||
vdprintf() -> similar sized functionality
|
||||
---
|
||||
|
||||
(TODO list after discussion 11.05.2009)
|
||||
|
||||
* shrink tc/brctl/ip
|
||||
tc/brctl seem like fairly large things to try and tackle in your timeframe,
|
||||
and i think people have posted attempts in the past. Adding additional
|
||||
options to ip though seems reasonable.
|
||||
|
||||
* add tests for some applets
|
||||
|
||||
* implement POSIX utilities and audit them for POSIX conformance. then
|
||||
audit them for GNU conformance. then document all your findings in a new
|
||||
doc/conformance.txt file while perhaps implementing some of the missing
|
||||
features.
|
||||
you can find the latest POSIX documentation (1003.1-2008) here:
|
||||
http://www.opengroup.org/onlinepubs/9699919799/
|
||||
and the complete list of all utilities that POSIX covers:
|
||||
http://www.opengroup.org/onlinepubs/9699919799/idx/utilities.html
|
||||
The first step would to generate a file/matrix what is already archived
|
||||
(also IPV6)
|
||||
|
||||
* ntpdate/ntpd (see ntpclient and openntp for examples)
|
||||
|
||||
* implement 'at'
|
||||
|
||||
* rpcbind (former portmap) or equivalent
|
||||
so that we don't have to use -o nolock on nfs mounts
|
||||
|
||||
* check IPV6 compliance
|
||||
|
||||
* generate a mini example using kernel+busybox only (+libc) for example
|
||||
|
||||
* more support for advanced linux 2.6.x features, see: iotop
|
||||
most likely there is more
|
||||
|
||||
* even more support for statistics: mpstat, iostat, powertop....
|
||||
|
||||
|
||||
Unicode work needed:
|
||||
|
||||
Unicode support uses libc multibyte functions if LOCALE_SUPPORT is on
|
||||
(in this case, the code will also support many more encodings),
|
||||
or uses a limited subset of re-implemented multibyte functions
|
||||
which only understand "one byte == one char" and unicode.
|
||||
This is useful if you build against uclibc with locale support disabled.
|
||||
|
||||
Unicode-dependent applets must call check_unicode_in_env() when they
|
||||
begin executing.
|
||||
|
||||
Applet code may conditionalize on FEATURE_ASSUME_UNICODE
|
||||
in order to use more efficient code if unicode support is not requested.
|
||||
|
||||
Available functions (if you need more, implement them in libbb/unicode.c
|
||||
so that they work without LOCALE_SUPPORT too):
|
||||
|
||||
int bb_mbstrlen(str) - multibyte-aware strlen
|
||||
size_t mbstowcs(wdest, src, n)
|
||||
size_t wcstombs(dest, wsrc, n)
|
||||
size_t wcrtomb(str, wc, wstate)
|
||||
int iswspace(wc)
|
||||
int iswalnum(wc)
|
||||
int iswpunct(wc)
|
||||
|
||||
Applets which only need to align columns on screen correctly:
|
||||
|
||||
ls - already done, use source as an example
|
||||
df
|
||||
dumpleases
|
||||
lsmod
|
||||
|
||||
Applets which need to account for Unicode chars
|
||||
while processing the output:
|
||||
|
||||
[un]expand
|
||||
fold
|
||||
man
|
||||
watch
|
||||
cut (-b and -c are currently the same, needs fixing)
|
||||
|
||||
These applets need to ensure that unicode input
|
||||
is handled correctly (say, <unicode><backspace> sequence):
|
||||
|
||||
getty, login
|
||||
rm -i
|
||||
unzip (overwrite prompt)
|
||||
|
||||
Viewers/editors are more difficult (many cases to get right).
|
||||
libbb/lineedit.c is an example how to do it:
|
||||
|
||||
less, most, ed, vi
|
||||
awk
|
||||
[ef]grep
|
||||
sed
|
||||
|
||||
Probably needs some specialized work:
|
||||
|
||||
loadkeys
|
||||
+91
-166
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.16.0
|
||||
# Wed Jan 27 21:01:26 2010
|
||||
# Busybox version: 1.12.0.svn
|
||||
# Wed Aug 20 00:24:07 2008
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -13,9 +13,8 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
# General Configuration
|
||||
#
|
||||
CONFIG_DESKTOP=y
|
||||
CONFIG_EXTRA_COMPAT=y
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
# CONFIG_EXTRA_COMPAT is not set
|
||||
CONFIG_FEATURE_ASSUME_UNICODE=y
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -24,9 +23,7 @@ CONFIG_FEATURE_VERBOSE_USAGE=y
|
||||
CONFIG_FEATURE_COMPRESS_USAGE=y
|
||||
CONFIG_FEATURE_INSTALLER=y
|
||||
# CONFIG_LOCALE_SUPPORT is not set
|
||||
# CONFIG_FEATURE_ASSUME_UNICODE is not set
|
||||
# CONFIG_FEATURE_CHECK_UNICODE_IN_ENV is not set
|
||||
CONFIG_LONG_OPTS=y
|
||||
CONFIG_GETOPT_LONG=y
|
||||
CONFIG_FEATURE_DEVPTS=y
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
CONFIG_FEATURE_PIDFILE=y
|
||||
@@ -50,7 +47,6 @@ CONFIG_NOMMU=y
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
CONFIG_CROSS_COMPILER_PREFIX=""
|
||||
CONFIG_EXTRA_CFLAGS=""
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
@@ -61,6 +57,8 @@ CONFIG_EXTRA_CFLAGS=""
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
# CONFIG_EFENCE is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_PARSE is not set
|
||||
|
||||
#
|
||||
# Installation Options
|
||||
@@ -90,8 +88,6 @@ CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
CONFIG_FEATURE_TAB_COMPLETION=y
|
||||
CONFIG_FEATURE_USERNAME_COMPLETION=y
|
||||
CONFIG_FEATURE_EDITING_FANCY_PROMPT=y
|
||||
CONFIG_FEATURE_EDITING_ASK_TERMINAL=y
|
||||
CONFIG_FEATURE_NON_POSIX_CP=y
|
||||
CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y
|
||||
CONFIG_FEATURE_COPYBUF_KB=4
|
||||
CONFIG_MONOTONIC_SYSCALL=y
|
||||
@@ -115,15 +111,11 @@ CONFIG_BUNZIP2=y
|
||||
CONFIG_BZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
CONFIG_FEATURE_CPIO_O=y
|
||||
CONFIG_FEATURE_CPIO_P=y
|
||||
CONFIG_DPKG=y
|
||||
CONFIG_DPKG_DEB=y
|
||||
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
CONFIG_RPM=y
|
||||
CONFIG_TAR=y
|
||||
@@ -135,7 +127,6 @@ CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
@@ -151,22 +142,18 @@ CONFIG_CATV=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_FEATURE_CP_LONG_OPTIONS=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_FEATURE_DATE_ISOFMT=y
|
||||
CONFIG_FEATURE_DATE_COMPAT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_FEATURE_DF_FANCY=y
|
||||
CONFIG_FEATURE_DF_INODE=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
@@ -182,7 +169,6 @@ CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_FSYNC=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_FEATURE_FANCY_HEAD=y
|
||||
CONFIG_HOSTID=y
|
||||
@@ -222,8 +208,6 @@ CONFIG_RMDIR=y
|
||||
CONFIG_FEATURE_RMDIR_LONG_OPTIONS=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SHA256SUM=y
|
||||
CONFIG_SHA512SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_FEATURE_FLOAT_SLEEP=y
|
||||
@@ -278,7 +262,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
# Common options for md5sum, sha1sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -299,8 +283,6 @@ CONFIG_FEATURE_RESIZE_PRINT=y
|
||||
CONFIG_SETCONSOLE=y
|
||||
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
|
||||
CONFIG_SETFONT=y
|
||||
CONFIG_FEATURE_SETFONT_TEXTUAL_MAP=y
|
||||
CONFIG_DEFAULT_SETFONT_DIR=""
|
||||
CONFIG_SETKEYCODES=y
|
||||
CONFIG_SETLOGCONS=y
|
||||
CONFIG_SHOWKEY=y
|
||||
@@ -322,11 +304,12 @@ CONFIG_WHICH=y
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_FEATURE_AWK_MATH=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
@@ -370,7 +353,6 @@ CONFIG_FEATURE_FIND_DELETE=y
|
||||
CONFIG_FEATURE_FIND_PATH=y
|
||||
CONFIG_FEATURE_FIND_REGEX=y
|
||||
CONFIG_FEATURE_FIND_CONTEXT=y
|
||||
CONFIG_FEATURE_FIND_LINKS=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
@@ -385,6 +367,7 @@ CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
# Init Utilities
|
||||
#
|
||||
CONFIG_INIT=y
|
||||
# CONFIG_DEBUG_INIT is not set
|
||||
CONFIG_FEATURE_USE_INITTAB=y
|
||||
CONFIG_FEATURE_KILL_REMOVED=y
|
||||
CONFIG_FEATURE_KILL_DELAY=1
|
||||
@@ -394,8 +377,6 @@ CONFIG_FEATURE_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_INIT_COREDUMPS=y
|
||||
CONFIG_FEATURE_INITRD=y
|
||||
CONFIG_HALT=y
|
||||
# CONFIG_FEATURE_CALL_TELINIT is not set
|
||||
CONFIG_TELINIT_PATH=""
|
||||
CONFIG_MESG=y
|
||||
|
||||
#
|
||||
@@ -405,17 +386,13 @@ CONFIG_FEATURE_SHADOWPASSWDS=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_USE_BB_SHADOW=y
|
||||
CONFIG_USE_BB_CRYPT=y
|
||||
CONFIG_USE_BB_CRYPT_SHA=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDGROUP_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_FEATURE_DEL_USER_FROM_GROUP=y
|
||||
CONFIG_FEATURE_CHECK_NAMES=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_FEATURE_ADDUSER_LONG_OPTIONS=y
|
||||
CONFIG_FIRST_SYSTEM_ID=100
|
||||
CONFIG_LAST_SYSTEM_ID=999
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
@@ -448,36 +425,32 @@ CONFIG_LSATTR=y
|
||||
CONFIG_MODPROBE_SMALL=y
|
||||
CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE=y
|
||||
CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
|
||||
# CONFIG_INSMOD is not set
|
||||
# CONFIG_RMMOD is not set
|
||||
# CONFIG_LSMOD is not set
|
||||
# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
|
||||
# CONFIG_MODPROBE is not set
|
||||
# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
|
||||
# CONFIG_DEPMOD is not set
|
||||
|
||||
#
|
||||
# Options common to multiple modutils
|
||||
#
|
||||
# CONFIG_FEATURE_2_4_MODULES is not set
|
||||
CONFIG_FEATURE_INSMOD_TRY_MMAP=y
|
||||
# CONFIG_FEATURE_DEPMOD_PRUNE_FANCY is not set
|
||||
# CONFIG_FEATURE_DEPMOD_ALIAS is not set
|
||||
# CONFIG_INSMOD is not set
|
||||
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
|
||||
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
|
||||
# CONFIG_RMMOD is not set
|
||||
# CONFIG_LSMOD is not set
|
||||
# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
|
||||
# CONFIG_MODPROBE is not set
|
||||
# CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS is not set
|
||||
# CONFIG_FEATURE_MODPROBE_FANCY_ALIAS is not set
|
||||
# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
|
||||
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
|
||||
# CONFIG_FEATURE_MODUTILS_ALIAS is not set
|
||||
# CONFIG_FEATURE_MODUTILS_SYMBOLS is not set
|
||||
# CONFIG_FEATURE_2_4_MODULES is not set
|
||||
# CONFIG_FEATURE_2_6_MODULES is not set
|
||||
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
|
||||
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
|
||||
# CONFIG_FEATURE_QUERY_MODULE_INTERFACE is not set
|
||||
|
||||
#
|
||||
# Linux System Utilities
|
||||
#
|
||||
# CONFIG_ACPID is not set
|
||||
# CONFIG_FEATURE_ACPID_COMPAT is not set
|
||||
CONFIG_BLKID=y
|
||||
CONFIG_DMESG=y
|
||||
CONFIG_FEATURE_DMESG_PRETTY=y
|
||||
CONFIG_FBSET=y
|
||||
@@ -496,17 +469,13 @@ CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FINDFS=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_EXT2=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
|
||||
#
|
||||
# Minix filesystem support
|
||||
#
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_MKFS_REISER=y
|
||||
CONFIG_MKFS_VFAT=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_FEATURE_GETOPT_LONG=y
|
||||
CONFIG_HEXDUMP=y
|
||||
CONFIG_FEATURE_HEXDUMP_REVERSE=y
|
||||
CONFIG_HD=y
|
||||
@@ -516,8 +485,6 @@ CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
CONFIG_IPCRM=y
|
||||
CONFIG_IPCS=y
|
||||
CONFIG_LOSETUP=y
|
||||
CONFIG_LSPCI=y
|
||||
CONFIG_LSUSB=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
@@ -525,12 +492,11 @@ CONFIG_FEATURE_MDEV_RENAME_REGEXP=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_FEATURE_MDEV_LOAD_FIRMWARE=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_UUID=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_VOLUMEID=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
@@ -561,7 +527,6 @@ CONFIG_RDEV=y
|
||||
CONFIG_READPROFILE=y
|
||||
CONFIG_RTCWAKE=y
|
||||
CONFIG_SCRIPT=y
|
||||
CONFIG_SCRIPTREPLAY=y
|
||||
CONFIG_SETARCH=y
|
||||
CONFIG_SWAPONOFF=y
|
||||
CONFIG_FEATURE_SWAPON_PRI=y
|
||||
@@ -580,9 +545,6 @@ CONFIG_FEATURE_MOUNT_LOOP=y
|
||||
#
|
||||
CONFIG_ADJTIMEX=y
|
||||
CONFIG_BBCONFIG=y
|
||||
CONFIG_BEEP=y
|
||||
CONFIG_FEATURE_BEEP_FREQ=4000
|
||||
CONFIG_FEATURE_BEEP_LENGTH_MS=30
|
||||
CONFIG_CHAT=y
|
||||
CONFIG_FEATURE_CHAT_NOFAIL=y
|
||||
CONFIG_FEATURE_CHAT_TTY_HIFI=y
|
||||
@@ -593,26 +555,18 @@ CONFIG_FEATURE_CHAT_VAR_ABORT_LEN=y
|
||||
CONFIG_FEATURE_CHAT_CLR_ABORT=y
|
||||
CONFIG_CHRT=y
|
||||
CONFIG_CROND=y
|
||||
CONFIG_FEATURE_CROND_D=y
|
||||
CONFIG_DEBUG_CROND_OPTION=y
|
||||
CONFIG_FEATURE_CROND_CALL_SENDMAIL=y
|
||||
CONFIG_FEATURE_CROND_DIR="/var/spool/cron"
|
||||
CONFIG_CRONTAB=y
|
||||
CONFIG_DC=y
|
||||
CONFIG_FEATURE_DC_LIBM=y
|
||||
# CONFIG_DEVFSD is not set
|
||||
# CONFIG_DEVFSD_MODLOAD is not set
|
||||
# CONFIG_DEVFSD_FG_NP is not set
|
||||
# CONFIG_DEVFSD_VERBOSE is not set
|
||||
# CONFIG_FEATURE_DEVFS is not set
|
||||
CONFIG_DEVMEM=y
|
||||
CONFIG_EJECT=y
|
||||
CONFIG_FEATURE_EJECT_SCSI=y
|
||||
CONFIG_FBSPLASH=y
|
||||
CONFIG_FLASHCP=y
|
||||
# CONFIG_FLASH_LOCK is not set
|
||||
# CONFIG_FLASH_UNLOCK is not set
|
||||
# CONFIG_FLASH_ERASEALL is not set
|
||||
CONFIG_IONICE=y
|
||||
CONFIG_INOTIFYD=y
|
||||
CONFIG_LAST=y
|
||||
CONFIG_FEATURE_LAST_SMALL=y
|
||||
@@ -621,11 +575,9 @@ CONFIG_LESS=y
|
||||
CONFIG_FEATURE_LESS_MAXLINES=9999999
|
||||
CONFIG_FEATURE_LESS_BRACKETS=y
|
||||
CONFIG_FEATURE_LESS_FLAGS=y
|
||||
CONFIG_FEATURE_LESS_FLAGCS=y
|
||||
CONFIG_FEATURE_LESS_MARKS=y
|
||||
CONFIG_FEATURE_LESS_REGEXP=y
|
||||
CONFIG_FEATURE_LESS_WINCH=y
|
||||
CONFIG_FEATURE_LESS_DASHCMD=y
|
||||
CONFIG_FEATURE_LESS_LINENUMS=y
|
||||
CONFIG_HDPARM=y
|
||||
CONFIG_FEATURE_HDPARM_GET_IDENTITY=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y
|
||||
@@ -649,17 +601,13 @@ CONFIG_STRINGS=y
|
||||
CONFIG_TASKSET=y
|
||||
CONFIG_FEATURE_TASKSET_FANCY=y
|
||||
CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
CONFIG_WALL=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
CONFIG_FEATURE_UNIX_LOCAL=y
|
||||
CONFIG_FEATURE_PREFER_IPV4_ADDRESS=y
|
||||
CONFIG_VERBOSE_RESOLUTION_ERRORS=y
|
||||
CONFIG_ARP=y
|
||||
@@ -670,9 +618,6 @@ CONFIG_FEATURE_BRCTL_SHOW=y
|
||||
CONFIG_DNSD=y
|
||||
CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
@@ -680,9 +625,11 @@ CONFIG_HOSTNAME=y
|
||||
CONFIG_HTTPD=y
|
||||
CONFIG_FEATURE_HTTPD_RANGES=y
|
||||
CONFIG_FEATURE_HTTPD_USE_SENDFILE=y
|
||||
CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP=y
|
||||
CONFIG_FEATURE_HTTPD_SETUID=y
|
||||
CONFIG_FEATURE_HTTPD_BASIC_AUTH=y
|
||||
CONFIG_FEATURE_HTTPD_AUTH_MD5=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES=y
|
||||
CONFIG_FEATURE_HTTPD_CGI=y
|
||||
CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR=y
|
||||
CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV=y
|
||||
@@ -696,7 +643,6 @@ CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
|
||||
CONFIG_FEATURE_IFCONFIG_HW=y
|
||||
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
|
||||
CONFIG_IFENSLAVE=y
|
||||
CONFIG_IFPLUGD=y
|
||||
CONFIG_IFUPDOWN=y
|
||||
CONFIG_IFUPDOWN_IFSTATE_PATH="/var/run/ifstate"
|
||||
CONFIG_FEATURE_IFUPDOWN_IP=y
|
||||
@@ -738,45 +684,41 @@ CONFIG_NETSTAT=y
|
||||
CONFIG_FEATURE_NETSTAT_WIDE=y
|
||||
CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_NTPD=y
|
||||
CONFIG_FEATURE_NTPD_SERVER=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_PSCAN=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_SENDMAIL=y
|
||||
CONFIG_FETCHMAIL=y
|
||||
CONFIG_SLATTACH=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
CONFIG_TELNETD=y
|
||||
CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
CONFIG_FEATURE_TELNETD_INETD_WAIT=y
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_TFTPD=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
|
||||
CONFIG_TFTP_DEBUG=y
|
||||
CONFIG_DEBUG_TFTP=y
|
||||
CONFIG_TRACEROUTE=y
|
||||
CONFIG_TRACEROUTE6=y
|
||||
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
|
||||
CONFIG_UDHCPD=y
|
||||
CONFIG_DHCPRELAY=y
|
||||
CONFIG_DUMPLEASES=y
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
|
||||
CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_APP_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
CONFIG_FEATURE_UDHCP_RFC3397=y
|
||||
CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
CONFIG_FEATURE_UDHCP_DEBUG=y
|
||||
CONFIG_FEATURE_RFC3397=y
|
||||
CONFIG_DHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script"
|
||||
CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS=80
|
||||
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS="-R -n"
|
||||
CONFIG_VCONFIG=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_FEATURE_WGET_STATUSBAR=y
|
||||
@@ -784,28 +726,8 @@ CONFIG_FEATURE_WGET_AUTHENTICATION=y
|
||||
CONFIG_FEATURE_WGET_LONG_OPTIONS=y
|
||||
CONFIG_ZCIP=y
|
||||
CONFIG_TCPSVD=y
|
||||
CONFIG_TUNCTL=y
|
||||
CONFIG_FEATURE_TUNCTL_UG=y
|
||||
CONFIG_UDPSVD=y
|
||||
|
||||
#
|
||||
# Print Utilities
|
||||
#
|
||||
CONFIG_LPD=y
|
||||
CONFIG_LPR=y
|
||||
CONFIG_LPQ=y
|
||||
|
||||
#
|
||||
# Mail Utilities
|
||||
#
|
||||
CONFIG_MAKEMIME=y
|
||||
CONFIG_FEATURE_MIME_CHARSET="us-ascii"
|
||||
CONFIG_POPMAILDIR=y
|
||||
CONFIG_FEATURE_POPMAILDIR_DELIVERY=y
|
||||
CONFIG_REFORMIME=y
|
||||
CONFIG_FEATURE_REFORMIME_COMPAT=y
|
||||
CONFIG_SENDMAIL=y
|
||||
|
||||
#
|
||||
# Process Utilities
|
||||
#
|
||||
@@ -823,65 +745,32 @@ CONFIG_PKILL=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_FEATURE_PS_TIME=y
|
||||
CONFIG_FEATURE_PS_ADDITIONAL_COLUMNS=y
|
||||
CONFIG_FEATURE_PS_UNUSUAL_SYSTEMS=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_FEATURE_TOP_CPU_GLOBAL_PERCENTS=y
|
||||
CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_UPTIME=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
#
|
||||
# Runit Utilities
|
||||
#
|
||||
CONFIG_RUNSV=y
|
||||
CONFIG_RUNSVDIR=y
|
||||
CONFIG_FEATURE_RUNSVDIR_LOG=y
|
||||
CONFIG_SV=y
|
||||
CONFIG_SV_DEFAULT_SERVICE_DIR="/var/service"
|
||||
CONFIG_SVLOGD=y
|
||||
CONFIG_CHPST=y
|
||||
CONFIG_SETUIDGID=y
|
||||
CONFIG_ENVUIDGID=y
|
||||
CONFIG_ENVDIR=y
|
||||
CONFIG_SOFTLIMIT=y
|
||||
|
||||
#
|
||||
# SELinux Utilities
|
||||
#
|
||||
CONFIG_CHCON=y
|
||||
CONFIG_FEATURE_CHCON_LONG_OPTIONS=y
|
||||
CONFIG_GETENFORCE=y
|
||||
CONFIG_GETSEBOOL=y
|
||||
CONFIG_LOAD_POLICY=y
|
||||
CONFIG_MATCHPATHCON=y
|
||||
CONFIG_RESTORECON=y
|
||||
CONFIG_RUNCON=y
|
||||
CONFIG_FEATURE_RUNCON_LONG_OPTIONS=y
|
||||
CONFIG_SELINUXENABLED=y
|
||||
CONFIG_SETENFORCE=y
|
||||
CONFIG_SETFILES=y
|
||||
CONFIG_FEATURE_SETFILES_CHECK_OPTION=y
|
||||
CONFIG_SETSEBOOL=y
|
||||
CONFIG_SESTATUS=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
CONFIG_FEATURE_SH_IS_HUSH=y
|
||||
# CONFIG_FEATURE_SH_IS_NONE is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH is not set
|
||||
# CONFIG_ASH_BASH_COMPAT is not set
|
||||
# CONFIG_ASH_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_READ_NCHARS is not set
|
||||
# CONFIG_ASH_READ_TIMEOUT is not set
|
||||
# CONFIG_ASH_ALIAS is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT is not set
|
||||
# CONFIG_ASH_MATH_SUPPORT_64 is not set
|
||||
# CONFIG_ASH_GETOPTS is not set
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
# CONFIG_ASH_BUILTIN_PRINTF is not set
|
||||
@@ -892,7 +781,6 @@ CONFIG_FEATURE_SH_IS_HUSH=y
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
CONFIG_HUSH=y
|
||||
CONFIG_HUSH_BASH_COMPAT=y
|
||||
CONFIG_HUSH_HELP=y
|
||||
CONFIG_HUSH_INTERACTIVE=y
|
||||
CONFIG_HUSH_JOB=y
|
||||
@@ -900,14 +788,12 @@ CONFIG_HUSH_TICK=y
|
||||
CONFIG_HUSH_IF=y
|
||||
CONFIG_HUSH_LOOPS=y
|
||||
CONFIG_HUSH_CASE=y
|
||||
CONFIG_HUSH_FUNCTIONS=y
|
||||
CONFIG_HUSH_LOCAL=y
|
||||
CONFIG_HUSH_EXPORT_N=y
|
||||
CONFIG_HUSH_RANDOM_SUPPORT=y
|
||||
CONFIG_LASH=y
|
||||
CONFIG_MSH=y
|
||||
CONFIG_SH_MATH_SUPPORT=y
|
||||
CONFIG_SH_MATH_SUPPORT_64=y
|
||||
|
||||
#
|
||||
# Bourne Shell Options
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
CONFIG_FEATURE_SH_NOFORK=y
|
||||
@@ -926,3 +812,42 @@ CONFIG_LOGREAD=y
|
||||
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_LOGGER=y
|
||||
|
||||
#
|
||||
# Runit Utilities
|
||||
#
|
||||
CONFIG_RUNSV=y
|
||||
CONFIG_RUNSVDIR=y
|
||||
CONFIG_SV=y
|
||||
CONFIG_SVLOGD=y
|
||||
CONFIG_CHPST=y
|
||||
CONFIG_SETUIDGID=y
|
||||
CONFIG_ENVUIDGID=y
|
||||
CONFIG_ENVDIR=y
|
||||
CONFIG_SOFTLIMIT=y
|
||||
|
||||
#
|
||||
# Selinux Utilities
|
||||
#
|
||||
CONFIG_CHCON=y
|
||||
CONFIG_FEATURE_CHCON_LONG_OPTIONS=y
|
||||
CONFIG_GETENFORCE=y
|
||||
CONFIG_GETSEBOOL=y
|
||||
CONFIG_LOAD_POLICY=y
|
||||
CONFIG_MATCHPATHCON=y
|
||||
CONFIG_RESTORECON=y
|
||||
CONFIG_RUNCON=y
|
||||
CONFIG_FEATURE_RUNCON_LONG_OPTIONS=y
|
||||
CONFIG_SELINUXENABLED=y
|
||||
CONFIG_SETENFORCE=y
|
||||
CONFIG_SETFILES=y
|
||||
CONFIG_FEATURE_SETFILES_CHECK_OPTION=y
|
||||
CONFIG_SETSEBOOL=y
|
||||
CONFIG_SESTATUS=y
|
||||
|
||||
#
|
||||
# Print Utilities
|
||||
#
|
||||
CONFIG_LPD=y
|
||||
CONFIG_LPR=y
|
||||
CONFIG_LPQ=y
|
||||
@@ -1,2 +0,0 @@
|
||||
/applet_tables
|
||||
/usage
|
||||
+6
-16
@@ -8,33 +8,23 @@ obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage usage_pod applet_tables
|
||||
hostprogs-y += usage applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
# This trick decreases amount of rebuilds
|
||||
# if tree is merely renamed/copied
|
||||
ifeq ($(srctree),$(objtree))
|
||||
srctree_slash =
|
||||
else
|
||||
srctree_slash = $(srctree)/
|
||||
endif
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
|
||||
HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/applet_tables: .config $(srctree_slash)include/applets.h
|
||||
applets/usage: .config $(srctree_slash)include/applets.h
|
||||
applets/usage_pod: .config include/applet_tables.h $(srctree_slash)include/applets.h
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
applets/applet_tables: .config
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
include/usage_compressed.h: applets/usage $(srctree_slash)applets/usage_compressed
|
||||
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
|
||||
quiet_cmd_gen_applet_tables = GEN include/applet_tables.h
|
||||
|
||||
+10
-15
@@ -70,33 +70,29 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Keep in sync with include/busybox.h! */
|
||||
|
||||
printf("/* This is a generated file, don't edit */\n\n");
|
||||
puts("/* This is a generated file, don't edit */\n");
|
||||
|
||||
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
|
||||
if (NUM_APPLETS == 1) {
|
||||
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
|
||||
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
printf("#ifndef SKIP_definitions\n");
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
puts("\nconst char applet_names[] ALIGN1 = \"\"");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
}
|
||||
printf(";\n\n");
|
||||
puts(";");
|
||||
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
puts("\nint (*const applet_main[])(int argc, char **argv) = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("%s_main,\n", applets[i].main);
|
||||
}
|
||||
printf("};\n");
|
||||
printf("#endif\n\n");
|
||||
puts("};");
|
||||
|
||||
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
|
||||
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
@@ -109,10 +105,10 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
printf("};\n\n");
|
||||
puts("};");
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
|
||||
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].install_loc; /* 3 bits */
|
||||
@@ -121,10 +117,9 @@ int main(int argc, char **argv)
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
printf("};\n");
|
||||
puts("};\n");
|
||||
#endif
|
||||
printf("#endif /* SKIP_definitions */\n");
|
||||
printf("\n");
|
||||
|
||||
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
return 0;
|
||||
|
||||
+7
-12
@@ -1,24 +1,19 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2008 Denys Vlasenko.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "autoconf.h"
|
||||
#include "../include/autoconf.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#define BB_MMU 0
|
||||
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
#define USE_FOR_MMU(...)
|
||||
#else
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#define BB_MMU 1
|
||||
#define USE_FOR_NOMMU(...)
|
||||
#define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
|
||||
@@ -7,7 +7,6 @@ test "$target" || exit 1
|
||||
test "$loc" || loc=.
|
||||
test -x "$loc/usage" || exit 1
|
||||
test "$SED" || SED=sed
|
||||
test "$DD" || DD=dd
|
||||
|
||||
sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
@@ -18,18 +17,18 @@ echo 'static const char packed_usage[] ALIGN1 = {'
|
||||
## Breaks on big-endian systems!
|
||||
## # Extra effort to avoid using "od -t x1": -t is not available
|
||||
## # in non-CONFIG_DESKTOPed busybox od
|
||||
##
|
||||
##
|
||||
## "$loc/usage" | bzip2 -1 | od -v -x \
|
||||
## | $SED -e 's/^[^ ]*//' \
|
||||
## -e 's/ //g' \
|
||||
## -e '/^$/d' \
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## | $SED -e 's/ //g' \
|
||||
## | grep -v '^$' \
|
||||
## | $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
|
||||
"$loc/usage" | bzip2 -1 | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(..\)/0x\1,/g'
|
||||
| $SED -e 's/ //g' \
|
||||
| grep -v '^$' \
|
||||
| $SED -e 's/\(..\)/0x\1,/g'
|
||||
|
||||
echo '};'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
@@ -1,100 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2009 Denys Vlasenko.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "autoconf.h"
|
||||
|
||||
#define SKIP_applet_main
|
||||
#define ALIGN1 /* nothing, just to placate applet_tables.h */
|
||||
#define ALIGN2 /* nothing, just to placate applet_tables.h */
|
||||
#include "applet_tables.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#else
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *names;
|
||||
const char *usage;
|
||||
int col, len2;
|
||||
|
||||
col = 0;
|
||||
names = applet_names;
|
||||
while (*names) {
|
||||
len2 = strlen(names) + 2;
|
||||
if (col >= 76 - len2) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
if (col == 0) {
|
||||
col = 6;
|
||||
printf("\t");
|
||||
} else {
|
||||
printf(", ");
|
||||
}
|
||||
printf(names);
|
||||
col += len2;
|
||||
names += len2 - 1;
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("=head1 COMMAND DESCRIPTIONS\n\n");
|
||||
printf("=over 4\n\n");
|
||||
|
||||
names = applet_names;
|
||||
usage = usage_messages;
|
||||
while (*names) {
|
||||
if (*names >= 'a' && *names <= 'z'
|
||||
&& *usage != NOUSAGE_STR[0]
|
||||
) {
|
||||
printf("=item B<%s>\n\n", names);
|
||||
if (*usage)
|
||||
printf("%s %s\n\n", names, usage);
|
||||
else
|
||||
printf("%s\n\n", names);
|
||||
}
|
||||
names += strlen(names) + 1;
|
||||
usage += strlen(usage) + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: we used to make options bold with B<> and output an example too:
|
||||
|
||||
=item B<cat>
|
||||
|
||||
cat [B<-u>] [FILE]...
|
||||
|
||||
Concatenate FILE(s) and print them to stdout
|
||||
|
||||
Options:
|
||||
-u Use unbuffered i/o (ignored)
|
||||
|
||||
Example:
|
||||
$ cat /proc/uptime
|
||||
110716.72 17.67
|
||||
|
||||
*/
|
||||
+10
-48
@@ -53,12 +53,12 @@ config AR
|
||||
probably say N here.
|
||||
|
||||
config FEATURE_AR_LONG_FILENAMES
|
||||
bool "Support for long filenames (not needed for debs)"
|
||||
bool "Support for long filenames (not need for debs)"
|
||||
default n
|
||||
depends on AR
|
||||
help
|
||||
By default the ar format can only store the first 15 characters
|
||||
of the filename, this option removes that limitation.
|
||||
By default the ar format can only store the first 15 characters of
|
||||
the filename, this option removes that limitation.
|
||||
It supports the GNU ar long filename method which moves multiple long
|
||||
filenames into a the data section of a new ar entry.
|
||||
|
||||
@@ -110,17 +110,9 @@ config FEATURE_CPIO_O
|
||||
This implementation of cpio can create cpio archives in the "newc"
|
||||
format only.
|
||||
|
||||
config FEATURE_CPIO_P
|
||||
bool "Support for passthrough mode"
|
||||
default n
|
||||
depends on FEATURE_CPIO_O
|
||||
help
|
||||
Passthrough mode. Rarely used.
|
||||
|
||||
config DPKG
|
||||
bool "dpkg"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg is a medium-level tool to install, build, remove and manage
|
||||
Debian packages.
|
||||
@@ -131,9 +123,9 @@ config DPKG
|
||||
config DPKG_DEB
|
||||
bool "dpkg_deb"
|
||||
default n
|
||||
select FEATURE_SEAMLESS_GZ
|
||||
help
|
||||
dpkg-deb unpacks and provides information about Debian archives.
|
||||
dpkg-deb packs, unpacks and provides information about Debian
|
||||
archives.
|
||||
|
||||
This implementation of dpkg-deb cannot pack archives.
|
||||
|
||||
@@ -165,28 +157,6 @@ config GZIP
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config FEATURE_GZIP_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on GZIP && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 106 Bytes
|
||||
|
||||
config LZOP
|
||||
bool "lzop"
|
||||
default n
|
||||
help
|
||||
Lzop compression/decompresion.
|
||||
|
||||
config LZOP_COMPR_HIGH
|
||||
bool "lzop complession levels 7,8,9 (not very useful)"
|
||||
default n
|
||||
depends on LZOP
|
||||
help
|
||||
High levels (7,8,9) of lzop compression. These levels
|
||||
are actually slower than gzip at equivalent compression ratios
|
||||
and take up 3.2K of code.
|
||||
|
||||
config RPM2CPIO
|
||||
bool "rpm2cpio"
|
||||
default n
|
||||
@@ -218,11 +188,11 @@ config FEATURE_TAR_CREATE
|
||||
tar archives using the `-c' option.
|
||||
|
||||
config FEATURE_TAR_AUTODETECT
|
||||
bool "Autodetect compressed tarballs"
|
||||
bool "Autodetect gz/bz2 compressed tarballs"
|
||||
default n
|
||||
depends on FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA
|
||||
help
|
||||
With this option tar can automatically detect compressed
|
||||
With this option tar can automatically detect gzip/bzip2 compressed
|
||||
tarballs. Currently it works only on files (not pipes etc).
|
||||
|
||||
config FEATURE_TAR_FROM
|
||||
@@ -263,7 +233,7 @@ config FEATURE_TAR_GNU_EXTENSIONS
|
||||
config FEATURE_TAR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on TAR && LONG_OPTS
|
||||
depends on TAR && GETOPT_LONG
|
||||
help
|
||||
Enable use of long options, increases size by about 400 Bytes
|
||||
|
||||
@@ -276,14 +246,6 @@ config FEATURE_TAR_UNAME_GNAME
|
||||
listings (-t) and preserving permissions when unpacking (-p).
|
||||
+200 bytes.
|
||||
|
||||
config FEATURE_TAR_NOPRESERVE_TIME
|
||||
bool "Enable -m (do not preserve time) option"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
With this option busybox supports GNU tar -m
|
||||
(do not preserve time) option.
|
||||
|
||||
endif #tar
|
||||
|
||||
config UNCOMPRESS
|
||||
@@ -313,8 +275,8 @@ config FEATURE_LZMA_FAST
|
||||
default n
|
||||
depends on UNLZMA
|
||||
help
|
||||
This option reduces decompression time by about 25% at the cost of
|
||||
a 1K bigger binary.
|
||||
This option reduces decompression time by about 33% at the cost of
|
||||
a 2K bigger binary.
|
||||
|
||||
config UNZIP
|
||||
bool "unzip"
|
||||
|
||||
@@ -16,8 +16,6 @@ lib-$(CONFIG_DPKG) += dpkg.o
|
||||
lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o
|
||||
lib-$(CONFIG_GUNZIP) += bbunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o bbunzip.o
|
||||
lib-$(CONFIG_LZOP) += lzop.o lzo1x_1.o lzo1x_1o.o lzo1x_d.o bbunzip.o
|
||||
lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
|
||||
+5
-6
@@ -38,7 +38,7 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
static const char msg_unsupported_err[] ALIGN1 =
|
||||
"archive %s is not supported";
|
||||
@@ -51,7 +51,6 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argv, "ptxovcr");
|
||||
argv += optind;
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
@@ -63,7 +62,7 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
@@ -75,11 +74,11 @@ int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = xopen(*argv++, O_RDONLY);
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
|
||||
while (*argv) {
|
||||
while (optind < argc) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&archive_handle->accept, *argv++);
|
||||
llist_add_to(&(archive_handle->accept), argv[optind++]);
|
||||
}
|
||||
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
+11
-27
@@ -30,14 +30,13 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
|
||||
int FAST_FUNC bbunpack(char **argv,
|
||||
char* (*make_new_name)(char *filename),
|
||||
IF_DESKTOP(long long) int (*unpacker)(unpack_info_t *info)
|
||||
USE_DESKTOP(long long) int (*unpacker)(void)
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
IF_DESKTOP(long long) int status;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
unpack_info_t info;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
@@ -93,29 +92,14 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
/* memset(&info, 0, sizeof(info)); */
|
||||
info.mtime = 0; /* so far it has one member only */
|
||||
status = unpacker(&info);
|
||||
status = unpacker();
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
if (status >= 0) {
|
||||
/* TODO: restore other things? */
|
||||
if (info.mtime) {
|
||||
struct timeval times[2];
|
||||
|
||||
times[1].tv_sec = times[0].tv_sec = info.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
* then closing resets the mtime
|
||||
* back to current time. */
|
||||
utimes(new_name, times); /* ignoring errors */
|
||||
}
|
||||
|
||||
/* TODO: restore user/group/times here? */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
@@ -175,7 +159,7 @@ char* make_new_name_bunzip2(char *filename)
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
{
|
||||
return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
@@ -251,9 +235,9 @@ char* make_new_name_gunzip(char *filename)
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info)
|
||||
USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
{
|
||||
IF_DESKTOP(long long) int status = -1;
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(STDIN_FILENO) == 0x1f) {
|
||||
@@ -263,7 +247,7 @@ IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info)
|
||||
if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
|
||||
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info);
|
||||
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
}
|
||||
@@ -325,7 +309,7 @@ char* make_new_name_unlzma(char *filename)
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
{
|
||||
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
@@ -360,9 +344,9 @@ char* make_new_name_uncompress(char *filename)
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
{
|
||||
IF_DESKTOP(long long) int status = -1;
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
|
||||
bb_error_msg("invalid magic");
|
||||
|
||||
@@ -585,7 +585,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
|
||||
#define MAIN_QSORT_STACK_SIZE 100
|
||||
|
||||
static NOINLINE
|
||||
static
|
||||
void mainQSort3(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
|
||||
+5
-6
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define CONFIG_BZIP2_FEATURE_SPEED 1
|
||||
|
||||
@@ -64,7 +63,7 @@ static uint8_t level;
|
||||
* total written bytes so far otherwise
|
||||
*/
|
||||
static
|
||||
IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
USE_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, void *wbuf)
|
||||
{
|
||||
int n, n2, ret;
|
||||
|
||||
@@ -98,13 +97,13 @@ IF_DESKTOP(long long) int bz_write(bz_stream *strm, void* rbuf, ssize_t rlen, vo
|
||||
if (rlen && strm->avail_in == 0)
|
||||
break;
|
||||
}
|
||||
return 0 IF_DESKTOP( + strm->total_out );
|
||||
return 0 USE_DESKTOP( + strm->total_out );
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int compressStream(unpack_info_t *info UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int compressStream(void)
|
||||
{
|
||||
IF_DESKTOP(long long) int total;
|
||||
USE_DESKTOP(long long) int total;
|
||||
ssize_t count;
|
||||
bz_stream bzs; /* it's small */
|
||||
#define strm (&bzs)
|
||||
@@ -163,7 +162,7 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
opt_complementary = "s2"; /* -s means -2 (compatibility) */
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_BUNZIP2("dt") "123456789qzs");
|
||||
opt = getopt32(argv, "cfv" USE_BUNZIP2("dt") "123456789qzs");
|
||||
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
return bunzip2_main(argc, argv);
|
||||
|
||||
+107
-190
@@ -14,95 +14,6 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
|
||||
Modes:
|
||||
-t, --list List the archive
|
||||
-i, --extract Extract files from an archive
|
||||
-o, --create Create the archive
|
||||
-p, --pass-through Copy-pass mode [was ist das?!]
|
||||
|
||||
Options valid in any mode:
|
||||
--block-size=SIZE I/O block size = SIZE * 512 bytes
|
||||
-B I/O block size = 5120 bytes
|
||||
-c Use the old portable (ASCII) archive format
|
||||
-C, --io-size=NUMBER I/O block size in bytes
|
||||
-f, --nonmatching Only copy files that do not match given pattern
|
||||
-F, --file=FILE Use FILE instead of standard input or output
|
||||
-H, --format=FORMAT Use given archive FORMAT
|
||||
-M, --message=STRING Print STRING when the end of a volume of the
|
||||
backup media is reached
|
||||
-n, --numeric-uid-gid If -v, show numeric UID and GID
|
||||
--quiet Do not print the number of blocks copied
|
||||
--rsh-command=COMMAND Use remote COMMAND instead of rsh
|
||||
-v, --verbose Verbosely list the files processed
|
||||
-V, --dot Print a "." for each file processed
|
||||
-W, --warning=FLAG Control warning display: 'none','truncate','all';
|
||||
multiple options accumulate
|
||||
|
||||
Options valid only in --extract mode:
|
||||
-b, --swap Swap both halfwords of words and bytes of
|
||||
halfwords in the data (equivalent to -sS)
|
||||
-r, --rename Interactively rename files
|
||||
-s, --swap-bytes Swap the bytes of each halfword in the files
|
||||
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
|
||||
--to-stdout Extract files to standard output
|
||||
-E, --pattern-file=FILE Read additional patterns specifying filenames to
|
||||
extract or list from FILE
|
||||
--only-verify-crc Verify CRC's, don't actually extract the files
|
||||
|
||||
Options valid only in --create mode:
|
||||
-A, --append Append to an existing archive
|
||||
-O FILE File to use instead of standard output
|
||||
|
||||
Options valid only in --pass-through mode:
|
||||
-l, --link Link files instead of copying them, when possible
|
||||
|
||||
Options valid in --extract and --create modes:
|
||||
--absolute-filenames Do not strip file system prefix components from
|
||||
the file names
|
||||
--no-absolute-filenames Create all files relative to the current dir
|
||||
|
||||
Options valid in --create and --pass-through modes:
|
||||
-0, --null A list of filenames is terminated by a NUL
|
||||
-a, --reset-access-time Reset the access times of files after reading them
|
||||
-I FILE File to use instead of standard input
|
||||
-L, --dereference Dereference symbolic links (copy the files
|
||||
that they point to instead of copying the links)
|
||||
-R, --owner=[USER][:.][GROUP] Set owner of created files
|
||||
|
||||
Options valid in --extract and --pass-through modes:
|
||||
-d, --make-directories Create leading directories where needed
|
||||
-m, --preserve-modification-time Retain mtime when creating files
|
||||
--no-preserve-owner Do not change the ownership of the files
|
||||
--sparse Write files with blocks of zeros as sparse files
|
||||
-u, --unconditional Replace all files unconditionally
|
||||
*/
|
||||
enum {
|
||||
CPIO_OPT_EXTRACT = (1 << 0),
|
||||
CPIO_OPT_TEST = (1 << 1),
|
||||
CPIO_OPT_NUL_TERMINATED = (1 << 2),
|
||||
CPIO_OPT_UNCONDITIONAL = (1 << 3),
|
||||
CPIO_OPT_VERBOSE = (1 << 4),
|
||||
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
|
||||
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
|
||||
CPIO_OPT_DEREF = (1 << 7),
|
||||
CPIO_OPT_FILE = (1 << 8),
|
||||
OPTBIT_FILE = 8,
|
||||
IF_FEATURE_CPIO_O(OPTBIT_CREATE ,)
|
||||
IF_FEATURE_CPIO_O(OPTBIT_FORMAT ,)
|
||||
IF_FEATURE_CPIO_P(OPTBIT_PASSTHROUGH,)
|
||||
IF_LONG_OPTS( OPTBIT_QUIET ,)
|
||||
IF_LONG_OPTS( OPTBIT_2STDOUT ,)
|
||||
CPIO_OPT_CREATE = IF_FEATURE_CPIO_O((1 << OPTBIT_CREATE )) + 0,
|
||||
CPIO_OPT_FORMAT = IF_FEATURE_CPIO_O((1 << OPTBIT_FORMAT )) + 0,
|
||||
CPIO_OPT_PASSTHROUGH = IF_FEATURE_CPIO_P((1 << OPTBIT_PASSTHROUGH)) + 0,
|
||||
CPIO_OPT_QUIET = IF_LONG_OPTS( (1 << OPTBIT_QUIET )) + 0,
|
||||
CPIO_OPT_2STDOUT = IF_LONG_OPTS( (1 << OPTBIT_2STDOUT )) + 0,
|
||||
};
|
||||
|
||||
#define OPTION_STR "it0uvdmLF:"
|
||||
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
static off_t cpio_pad4(off_t size)
|
||||
{
|
||||
@@ -117,9 +28,8 @@ static off_t cpio_pad4(off_t size)
|
||||
|
||||
/* Return value will become exit code.
|
||||
* It's ok to exit instead of return. */
|
||||
static NOINLINE int cpio_o(void)
|
||||
static int cpio_o(void)
|
||||
{
|
||||
static const char trailer[] ALIGN1 = "TRAILER!!!";
|
||||
struct name_s {
|
||||
struct name_s *next;
|
||||
char name[1];
|
||||
@@ -138,9 +48,7 @@ static NOINLINE int cpio_o(void)
|
||||
char *line;
|
||||
struct stat st;
|
||||
|
||||
line = (option_mask32 & CPIO_OPT_NUL_TERMINATED)
|
||||
? bb_get_chunk_from_file(stdin, NULL)
|
||||
: xmalloc_fgetline(stdin);
|
||||
line = xmalloc_fgetline(stdin);
|
||||
|
||||
if (line) {
|
||||
/* Strip leading "./[./]..." from the filename */
|
||||
@@ -153,10 +61,7 @@ static NOINLINE int cpio_o(void)
|
||||
free(line);
|
||||
continue;
|
||||
}
|
||||
if ((option_mask32 & CPIO_OPT_DEREF)
|
||||
? stat(name, &st)
|
||||
: lstat(name, &st)
|
||||
) {
|
||||
if (lstat(name, &st)) {
|
||||
abort_cpio_o:
|
||||
bb_simple_perror_msg_and_die(name);
|
||||
}
|
||||
@@ -214,7 +119,7 @@ static NOINLINE int cpio_o(void)
|
||||
} else {
|
||||
/* If no (more) hardlinks to output,
|
||||
* output "trailer" entry */
|
||||
name = trailer;
|
||||
name = "TRAILER!!!";
|
||||
/* st.st_size == 0 is a must, but for uniformity
|
||||
* in the output, we zero out everything */
|
||||
memset(&st, 0, sizeof(st));
|
||||
@@ -252,7 +157,7 @@ static NOINLINE int cpio_o(void)
|
||||
free(lpath);
|
||||
} else { /* S_ISREG */
|
||||
int fd = xopen(name, O_RDONLY);
|
||||
fflush_all();
|
||||
fflush(stdout);
|
||||
/* We must abort if file got shorter too! */
|
||||
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
|
||||
bytes += st.st_size;
|
||||
@@ -262,7 +167,7 @@ static NOINLINE int cpio_o(void)
|
||||
}
|
||||
|
||||
if (!line) {
|
||||
if (name != trailer)
|
||||
if (links)
|
||||
goto next_link;
|
||||
/* TODO: GNU cpio pads trailer to 512 bytes, do we want that? */
|
||||
return EXIT_SUCCESS;
|
||||
@@ -273,109 +178,125 @@ static NOINLINE int cpio_o(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* GNU cpio 2.9 --help (abridged):
|
||||
|
||||
Modes:
|
||||
-i, --extract Extract files from an archive
|
||||
-o, --create Create the archive
|
||||
-p, --pass-through Copy-pass mode [was ist das?!]
|
||||
-t, --list List the archive
|
||||
|
||||
Options valid in any mode:
|
||||
--block-size=SIZE I/O block size = SIZE * 512 bytes
|
||||
-B I/O block size = 5120 bytes
|
||||
-c Use the old portable (ASCII) archive format
|
||||
-C, --io-size=NUMBER I/O block size in bytes
|
||||
-f, --nonmatching Only copy files that do not match given pattern
|
||||
-F, --file=FILE Use FILE instead of standard input or output
|
||||
-H, --format=FORMAT Use given archive FORMAT
|
||||
-M, --message=STRING Print STRING when the end of a volume of the
|
||||
backup media is reached
|
||||
-n, --numeric-uid-gid If -v, show numeric UID and GID
|
||||
--quiet Do not print the number of blocks copied
|
||||
--rsh-command=COMMAND Use remote COMMAND instead of rsh
|
||||
-v, --verbose Verbosely list the files processed
|
||||
-V, --dot Print a "." for each file processed
|
||||
-W, --warning=FLAG Control warning display: 'none','truncate','all';
|
||||
multiple options accumulate
|
||||
|
||||
Options valid only in --extract mode:
|
||||
-b, --swap Swap both halfwords of words and bytes of
|
||||
halfwords in the data (equivalent to -sS)
|
||||
-r, --rename Interactively rename files
|
||||
-s, --swap-bytes Swap the bytes of each halfword in the files
|
||||
-S, --swap-halfwords Swap the halfwords of each word (4 bytes)
|
||||
--to-stdout Extract files to standard output
|
||||
-E, --pattern-file=FILE Read additional patterns specifying filenames to
|
||||
extract or list from FILE
|
||||
--only-verify-crc Verify CRC's, don't actually extract the files
|
||||
|
||||
Options valid only in --create mode:
|
||||
-A, --append Append to an existing archive
|
||||
-O FILE File to use instead of standard output
|
||||
|
||||
Options valid only in --pass-through mode:
|
||||
-l, --link Link files instead of copying them, when possible
|
||||
|
||||
Options valid in --extract and --create modes:
|
||||
--absolute-filenames Do not strip file system prefix components from
|
||||
the file names
|
||||
--no-absolute-filenames Create all files relative to the current dir
|
||||
|
||||
Options valid in --create and --pass-through modes:
|
||||
-0, --null A list of filenames is terminated by a NUL
|
||||
-a, --reset-access-time Reset the access times of files after reading them
|
||||
-I FILE File to use instead of standard input
|
||||
-L, --dereference Dereference symbolic links (copy the files
|
||||
that they point to instead of copying the links)
|
||||
-R, --owner=[USER][:.][GROUP] Set owner of created files
|
||||
|
||||
Options valid in --extract and --pass-through modes:
|
||||
-d, --make-directories Create leading directories where needed
|
||||
-m, --preserve-modification-time Retain mtime when creating files
|
||||
--no-preserve-owner Do not change the ownership of the files
|
||||
--sparse Write files with blocks of zeros as sparse files
|
||||
-u, --unconditional Replace all files unconditionally
|
||||
*/
|
||||
|
||||
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
char *cpio_filename;
|
||||
IF_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
USE_FEATURE_CPIO_O(const char *cpio_fmt = "";)
|
||||
unsigned opt;
|
||||
enum {
|
||||
CPIO_OPT_EXTRACT = (1 << 0),
|
||||
CPIO_OPT_TEST = (1 << 1),
|
||||
CPIO_OPT_UNCONDITIONAL = (1 << 2),
|
||||
CPIO_OPT_VERBOSE = (1 << 3),
|
||||
CPIO_OPT_FILE = (1 << 4),
|
||||
CPIO_OPT_CREATE_LEADING_DIR = (1 << 5),
|
||||
CPIO_OPT_PRESERVE_MTIME = (1 << 6),
|
||||
CPIO_OPT_CREATE = (1 << 7),
|
||||
CPIO_OPT_FORMAT = (1 << 8),
|
||||
};
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
#if ENABLE_GETOPT_LONG
|
||||
applet_long_options =
|
||||
"extract\0" No_argument "i"
|
||||
"list\0" No_argument "t"
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
"create\0" No_argument "o"
|
||||
"format\0" Required_argument "H"
|
||||
#if ENABLE_FEATURE_CPIO_P
|
||||
"pass-through\0" No_argument "p"
|
||||
#endif
|
||||
#endif
|
||||
"verbose\0" No_argument "v"
|
||||
"quiet\0" No_argument "\xff"
|
||||
"to-stdout\0" No_argument "\xfe"
|
||||
;
|
||||
#endif
|
||||
|
||||
/* Initialize */
|
||||
archive_handle = init_handle();
|
||||
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||
|
||||
/* As of now we do not enforce this: */
|
||||
/* -i,-t,-o,-p are mutually exclusive */
|
||||
/* -u,-d,-m make sense only with -i or -p */
|
||||
/* -L makes sense only with -o or -p */
|
||||
#if ENABLE_FEATURE_CPIO_O
|
||||
opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
|
||||
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
/* no parameters */
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, OPTION_STR, &cpio_filename);
|
||||
if (opt & CPIO_OPT_FILE) { /* -F */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
#else
|
||||
/* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */
|
||||
opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0";
|
||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
|
||||
argv += optind;
|
||||
if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
if (opt & CPIO_OPT_PASSTHROUGH) {
|
||||
pid_t pid;
|
||||
struct fd_pair pp;
|
||||
|
||||
if (argv[0] == NULL)
|
||||
bb_show_usage();
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR)
|
||||
mkdir(argv[0], 0777);
|
||||
/* Crude existence check:
|
||||
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||
* This would check for existence earlier and cleaner.
|
||||
* As it stands now, if we fail xchdir later,
|
||||
* child dies on EPIPE, unless it caught
|
||||
* a diffrerent problem earlier.
|
||||
* This is good enough for now.
|
||||
*/
|
||||
#if !BB_MMU
|
||||
pp.rd = 3;
|
||||
pp.wr = 4;
|
||||
if (!re_execed) {
|
||||
close(3);
|
||||
close(4);
|
||||
xpiped_pair(pp);
|
||||
}
|
||||
#else
|
||||
xpiped_pair(pp);
|
||||
#endif
|
||||
pid = fork_or_rexec(argv - optind);
|
||||
if (pid == 0) { /* child */
|
||||
close(pp.rd);
|
||||
xmove_fd(pp.wr, STDOUT_FILENO);
|
||||
goto dump;
|
||||
}
|
||||
/* parent */
|
||||
xchdir(*argv++);
|
||||
close(pp.wr);
|
||||
xmove_fd(pp.rd, STDIN_FILENO);
|
||||
//opt &= ~CPIO_OPT_PASSTHROUGH;
|
||||
opt |= CPIO_OPT_EXTRACT;
|
||||
goto skip;
|
||||
}
|
||||
/* -o */
|
||||
if (opt & CPIO_OPT_CREATE) {
|
||||
if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
|
||||
if (*cpio_fmt != 'n')
|
||||
bb_show_usage();
|
||||
if (opt & CPIO_OPT_FILE) {
|
||||
xmove_fd(xopen3(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666), STDOUT_FILENO);
|
||||
fclose(stdout);
|
||||
stdout = fopen_for_write(cpio_filename);
|
||||
/* Paranoia: I don't trust libc that much */
|
||||
xdup2(fileno(stdout), STDOUT_FILENO);
|
||||
}
|
||||
dump:
|
||||
return cpio_o();
|
||||
}
|
||||
skip:
|
||||
#else
|
||||
opt = getopt32(argv, "ituvF:dm", &cpio_filename);
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
@@ -384,16 +305,16 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
if (opt & CPIO_OPT_TEST) {
|
||||
/* if both extract and test options are given, ignore extract option */
|
||||
opt &= ~CPIO_OPT_EXTRACT;
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
opt &= ~CPIO_OPT_EXTRACT;
|
||||
}
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
if (opt & CPIO_OPT_EXTRACT) {
|
||||
archive_handle->action_data = data_extract_all;
|
||||
if (opt & CPIO_OPT_2STDOUT)
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & CPIO_OPT_UNCONDITIONAL) {
|
||||
archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
@@ -403,29 +324,25 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (opt & CPIO_OPT_FILE) { /* -F */
|
||||
archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
if (opt & CPIO_OPT_PRESERVE_MTIME) {
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&archive_handle->accept, *argv);
|
||||
llist_add_to(&(archive_handle->accept), *argv);
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* see get_header_cpio */
|
||||
archive_handle->cpio__blocks = (off_t)-1;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
if (archive_handle->cpio__blocks != (off_t)-1
|
||||
&& !(opt & CPIO_OPT_QUIET)
|
||||
) {
|
||||
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+101
-120
@@ -6,10 +6,6 @@
|
||||
* written by glenn mcgrath with the help of others
|
||||
* copyright (c) 2001 by glenn mcgrath
|
||||
*
|
||||
* parts of the version comparison code is plucked from the real dpkg
|
||||
* application which is licensed GPLv2 and
|
||||
* copyright (c) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
|
||||
*
|
||||
* started life as a busybox implementation of udpkg
|
||||
*
|
||||
* licensed under gplv2 or later, see file license in this tarball for details.
|
||||
@@ -29,7 +25,6 @@
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <fnmatch.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/* note: if you vary hash_prime sizes be aware,
|
||||
@@ -139,7 +134,7 @@ static void make_hash(const char *key, unsigned *start, unsigned *decrement, con
|
||||
/* shifts the ascii based value and adds it to previous value
|
||||
* shift amount is mod 24 because long int is 32 bit and data
|
||||
* to be shifted is 8, don't want to shift data to where it has
|
||||
* no effect */
|
||||
* no effect*/
|
||||
hash_num += (key[i] + key[i-1]) << ((key[i] * i) % 24);
|
||||
}
|
||||
*start = (unsigned) hash_num % hash_prime;
|
||||
@@ -187,52 +182,60 @@ static unsigned search_status_hashtable(const char *key)
|
||||
return probe_address;
|
||||
}
|
||||
|
||||
static int order(char x)
|
||||
/* Need to rethink version comparison, maybe the official dpkg has something i can use ? */
|
||||
static int version_compare_part(const char *version1, const char *version2)
|
||||
{
|
||||
return (x == '~' ? -1
|
||||
: x == '\0' ? 0
|
||||
: isdigit(x) ? 0
|
||||
: isalpha(x) ? x
|
||||
: (unsigned char)x + 256
|
||||
);
|
||||
}
|
||||
int upstream_len1 = 0;
|
||||
int upstream_len2 = 0;
|
||||
char *name1_char;
|
||||
char *name2_char;
|
||||
int len1 = 0;
|
||||
int len2 = 0;
|
||||
int tmp_int;
|
||||
int ver_num1;
|
||||
int ver_num2;
|
||||
|
||||
/* This code is taken from dpkg and modified slightly to work with busybox */
|
||||
static int version_compare_part(const char *val, const char *ref)
|
||||
{
|
||||
if (!val) val = "";
|
||||
if (!ref) ref = "";
|
||||
if (version1 == NULL) {
|
||||
version1 = xstrdup("");
|
||||
}
|
||||
if (version2 == NULL) {
|
||||
version2 = xstrdup("");
|
||||
}
|
||||
upstream_len1 = strlen(version1);
|
||||
upstream_len2 = strlen(version2);
|
||||
|
||||
while (*val || *ref) {
|
||||
int first_diff;
|
||||
|
||||
while ((*val && !isdigit(*val)) || (*ref && !isdigit(*ref))) {
|
||||
int vc = order(*val);
|
||||
int rc = order(*ref);
|
||||
if (vc != rc)
|
||||
return vc - rc;
|
||||
val++;
|
||||
ref++;
|
||||
while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
|
||||
/* Compare non-digit section */
|
||||
tmp_int = strcspn(&version1[len1], "0123456789");
|
||||
name1_char = xstrndup(&version1[len1], tmp_int);
|
||||
len1 += tmp_int;
|
||||
tmp_int = strcspn(&version2[len2], "0123456789");
|
||||
name2_char = xstrndup(&version2[len2], tmp_int);
|
||||
len2 += tmp_int;
|
||||
tmp_int = strcmp(name1_char, name2_char);
|
||||
free(name1_char);
|
||||
free(name2_char);
|
||||
if (tmp_int != 0) {
|
||||
return tmp_int;
|
||||
}
|
||||
|
||||
while (*val == '0')
|
||||
val++;
|
||||
while (*ref == '0')
|
||||
ref++;
|
||||
|
||||
first_diff = 0;
|
||||
while (isdigit(*val) && isdigit(*ref)) {
|
||||
if (first_diff == 0)
|
||||
first_diff = *val - *ref;
|
||||
val++;
|
||||
ref++;
|
||||
}
|
||||
if (isdigit(*val))
|
||||
return 1;
|
||||
if (isdigit(*ref))
|
||||
/* Compare digits */
|
||||
tmp_int = strspn(&version1[len1], "0123456789");
|
||||
name1_char = xstrndup(&version1[len1], tmp_int);
|
||||
len1 += tmp_int;
|
||||
tmp_int = strspn(&version2[len2], "0123456789");
|
||||
name2_char = xstrndup(&version2[len2], tmp_int);
|
||||
len2 += tmp_int;
|
||||
ver_num1 = atoi(name1_char);
|
||||
ver_num2 = atoi(name2_char);
|
||||
free(name1_char);
|
||||
free(name2_char);
|
||||
if (ver_num1 < ver_num2) {
|
||||
return -1;
|
||||
if (first_diff)
|
||||
return first_diff;
|
||||
}
|
||||
if (ver_num1 > ver_num2) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -245,34 +248,39 @@ static int version_compare(const unsigned ver1, const unsigned ver2)
|
||||
{
|
||||
char *ch_ver1 = name_hashtable[ver1];
|
||||
char *ch_ver2 = name_hashtable[ver2];
|
||||
unsigned long epoch1 = 0, epoch2 = 0;
|
||||
char *colon;
|
||||
|
||||
char epoch1, epoch2;
|
||||
char *deb_ver1, *deb_ver2;
|
||||
char *ver1_ptr, *ver2_ptr;
|
||||
char *upstream_ver1;
|
||||
char *upstream_ver2;
|
||||
int result;
|
||||
|
||||
/* Compare epoch */
|
||||
colon = strchr(ch_ver1, ':');
|
||||
if (colon) {
|
||||
epoch1 = atoi(ch_ver1);
|
||||
ch_ver1 = colon + 1;
|
||||
if (ch_ver1[1] == ':') {
|
||||
epoch1 = ch_ver1[0];
|
||||
ver1_ptr = strchr(ch_ver1, ':') + 1;
|
||||
} else {
|
||||
epoch1 = '0';
|
||||
ver1_ptr = ch_ver1;
|
||||
}
|
||||
colon = strchr(ch_ver2, ':');
|
||||
if (colon) {
|
||||
epoch2 = atoi(ch_ver2);
|
||||
ch_ver2 = colon + 1;
|
||||
if (ch_ver2[1] == ':') {
|
||||
epoch2 = ch_ver2[0];
|
||||
ver2_ptr = strchr(ch_ver2, ':') + 1;
|
||||
} else {
|
||||
epoch2 = '0';
|
||||
ver2_ptr = ch_ver2;
|
||||
}
|
||||
if (epoch1 < epoch2) {
|
||||
return -1;
|
||||
}
|
||||
if (epoch1 > epoch2) {
|
||||
else if (epoch1 > epoch2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Compare upstream version */
|
||||
upstream_ver1 = xstrdup(ch_ver1);
|
||||
upstream_ver2 = xstrdup(ch_ver2);
|
||||
upstream_ver1 = xstrdup(ver1_ptr);
|
||||
upstream_ver2 = xstrdup(ver2_ptr);
|
||||
|
||||
/* Chop off debian version, and store for later use */
|
||||
deb_ver1 = strrchr(upstream_ver1, '-');
|
||||
@@ -493,7 +501,7 @@ static void free_package(common_node_t *node)
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the next package field from package_buffer, separated into the field name
|
||||
* Gets the next package field from package_buffer, seperated into the field name
|
||||
* and field value, it returns the int offset to the first character of the next field
|
||||
*/
|
||||
static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
|
||||
@@ -806,7 +814,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
write_flag = FALSE;
|
||||
tmp_string = strstr(control_buffer, "Status:");
|
||||
if (tmp_string != NULL) {
|
||||
/* Separate the status value from the control buffer */
|
||||
/* Seperate the status value from the control buffer */
|
||||
tmp_string += 7;
|
||||
tmp_string += strspn(tmp_string, " \n\t");
|
||||
status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
|
||||
@@ -912,7 +920,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
/* Create a separate backfile to dpkg */
|
||||
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
|
||||
if (errno != ENOENT)
|
||||
bb_error_msg_and_die("can't create backup status file");
|
||||
bb_error_msg_and_die("cannot create backup status file");
|
||||
/* Its ok if renaming the status file fails because status
|
||||
* file doesnt exist, maybe we are starting from scratch */
|
||||
bb_error_msg("no status file found, creating new one");
|
||||
@@ -1285,7 +1293,7 @@ static void free_array(char **array)
|
||||
* the status_hashtable to retrieve the info. This results in smaller code than
|
||||
* scanning the status file. The resulting list, however, is unsorted.
|
||||
*/
|
||||
static void list_packages(const char *pattern)
|
||||
static void list_packages(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -1306,9 +1314,6 @@ static void list_packages(const char *pattern)
|
||||
name_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->name];
|
||||
vers_str = name_hashtable[package_hashtable[status_hashtable[i]->package]->version];
|
||||
|
||||
if (pattern && fnmatch(pattern, name_str, 0))
|
||||
continue;
|
||||
|
||||
/* get abbreviation for status field 1 */
|
||||
s1 = stat_str[0] == 'i' ? 'i' : 'r';
|
||||
|
||||
@@ -1354,8 +1359,8 @@ static void remove_package(const unsigned package_num, int noisy)
|
||||
free_array(exclude_files);
|
||||
free_array(remove_files);
|
||||
|
||||
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
|
||||
exclude_files = xzalloc(sizeof(exclude_files[0]) * 3);
|
||||
/* Create a list of files in /var/lib/dpkg/info/<package>.* to keep */
|
||||
exclude_files = xzalloc(sizeof(char*) * 3);
|
||||
exclude_files[0] = xstrdup(conffile_name);
|
||||
exclude_files[1] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
|
||||
|
||||
@@ -1393,25 +1398,20 @@ static void purge_package(const unsigned package_num)
|
||||
sprintf(list_name, "/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
remove_files = create_list(list_name);
|
||||
|
||||
exclude_files = xzalloc(sizeof(char*));
|
||||
|
||||
/* Some directories cant be removed straight away, so do multiple passes */
|
||||
while (remove_file_array(remove_files, NULL))
|
||||
continue;
|
||||
while (remove_file_array(remove_files, exclude_files)) /* repeat */;
|
||||
free_array(remove_files);
|
||||
|
||||
/* Create a list of all /var/lib/dpkg/info/<package> files */
|
||||
remove_files = all_control_list(package_name);
|
||||
|
||||
/* Delete all of them except the postrm script */
|
||||
exclude_files = xzalloc(sizeof(exclude_files[0]) * 2);
|
||||
exclude_files[0] = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "postrm");
|
||||
remove_file_array(remove_files, exclude_files);
|
||||
free_array(exclude_files);
|
||||
|
||||
/* Run and remove postrm script */
|
||||
run_package_script_or_die(package_name, "postrm");
|
||||
remove_file_array(remove_files, NULL);
|
||||
|
||||
free_array(remove_files);
|
||||
free(exclude_files);
|
||||
|
||||
/* Run postrm script */
|
||||
run_package_script_or_die(package_name, "postrm");
|
||||
|
||||
/* Change package status */
|
||||
set_status(status_num, "not-installed", 3);
|
||||
@@ -1446,7 +1446,7 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
}
|
||||
|
||||
static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
@@ -1466,47 +1466,28 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
}
|
||||
|
||||
static void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->dpkg__buffer = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
}
|
||||
|
||||
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
|
||||
{
|
||||
ar_handle->dpkg__sub_archive->action_data = data_extract_to_buffer;
|
||||
ar_handle->dpkg__sub_archive->accept = myaccept;
|
||||
ar_handle->dpkg__sub_archive->filter = filter_accept_list;
|
||||
ar_handle->sub_archive->action_data = data_extract_to_buffer;
|
||||
ar_handle->sub_archive->accept = myaccept;
|
||||
ar_handle->sub_archive->filter = filter_accept_list;
|
||||
|
||||
unpack_ar_archive(ar_handle);
|
||||
close(ar_handle->src_fd);
|
||||
|
||||
return ar_handle->dpkg__sub_archive->dpkg__buffer;
|
||||
return ar_handle->sub_archive->buffer;
|
||||
}
|
||||
|
||||
static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
|
||||
{
|
||||
char *name_ptr = archive_handle->file_header->name;
|
||||
|
||||
/* Skip all leading "/" */
|
||||
while (*name_ptr == '/')
|
||||
name_ptr++;
|
||||
/* Skip all leading "./" and "../" */
|
||||
while (name_ptr[0] == '.') {
|
||||
if (name_ptr[1] == '.' && name_ptr[2] == '/')
|
||||
name_ptr++;
|
||||
if (name_ptr[1] != '/')
|
||||
break;
|
||||
name_ptr += 2;
|
||||
}
|
||||
|
||||
name_ptr += strspn(name_ptr, "./");
|
||||
if (name_ptr[0] != '\0') {
|
||||
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
|
||||
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
|
||||
data_extract_all(archive_handle);
|
||||
}
|
||||
}
|
||||
@@ -1546,11 +1527,11 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
llist_add_to(&accept_list, c);
|
||||
i++;
|
||||
}
|
||||
archive_handle->dpkg__sub_archive->accept = accept_list;
|
||||
archive_handle->dpkg__sub_archive->filter = filter_accept_list;
|
||||
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->dpkg__sub_archive->dpkg__buffer = info_prefix;
|
||||
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->sub_archive->accept = accept_list;
|
||||
archive_handle->sub_archive->filter = filter_accept_list;
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = info_prefix;
|
||||
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Run the preinst prior to extracting */
|
||||
@@ -1559,19 +1540,19 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
/* Extract data.tar.gz to the root directory */
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_data(archive_handle);
|
||||
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */
|
||||
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
|
||||
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Create the list file */
|
||||
list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
out_stream = xfopen_for_write(list_filename);
|
||||
while (archive_handle->dpkg__sub_archive->passed) {
|
||||
while (archive_handle->sub_archive->passed) {
|
||||
/* the leading . has been stripped by data_extract_all_prefix already */
|
||||
fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream);
|
||||
fputs(archive_handle->sub_archive->passed->data, out_stream);
|
||||
fputc('\n', out_stream);
|
||||
archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link;
|
||||
archive_handle->sub_archive->passed = archive_handle->sub_archive->passed->link;
|
||||
}
|
||||
fclose(out_stream);
|
||||
|
||||
@@ -1645,7 +1626,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* if the list action was given print the installed packages and exit */
|
||||
if (opt & OPT_list_installed) {
|
||||
list_packages(argv[0]);
|
||||
list_packages();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1665,7 +1646,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
init_archive_deb_control(archive_handle);
|
||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||
if (deb_file[deb_count]->control_file == NULL) {
|
||||
bb_error_msg_and_die("can't extract control file");
|
||||
bb_error_msg_and_die("cannot extract control file");
|
||||
}
|
||||
deb_file[deb_count]->filename = xstrdup(argv[0]);
|
||||
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
|
||||
+44
-58
@@ -40,7 +40,6 @@ aa: 85.1% -- replaced with aa.gz
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -267,7 +266,7 @@ struct globals {
|
||||
#define DECLARE(type, array, size) \
|
||||
type * array
|
||||
#define ALLOC(type, array, size) \
|
||||
array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type))
|
||||
array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type));
|
||||
#define FREE(array) \
|
||||
do { free(array); array = NULL; } while (0)
|
||||
|
||||
@@ -388,6 +387,19 @@ static void put_32bit(ulg n)
|
||||
put_16bit(n >> 16);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Clear input and output buffers
|
||||
*/
|
||||
static void clear_bufs(void)
|
||||
{
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
G1.insize = 0;
|
||||
#endif
|
||||
G1.isize = 0;
|
||||
}
|
||||
|
||||
|
||||
/* ===========================================================================
|
||||
* Run a set of bytes through the crc shift register. If s is a NULL
|
||||
* pointer, then initialize the crc shift register contents instead.
|
||||
@@ -1173,7 +1185,7 @@ static void gen_codes(ct_data * tree, int max_code)
|
||||
|
||||
Tracec(tree != G2.static_ltree,
|
||||
(stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
|
||||
(n > ' ' ? n : ' '), len, tree[n].Code,
|
||||
(isgraph(n) ? n : ' '), len, tree[n].Code,
|
||||
next_code[len] - 1));
|
||||
}
|
||||
}
|
||||
@@ -1541,7 +1553,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||
lc = G1.l_buf[lx++];
|
||||
if ((flag & 1) == 0) {
|
||||
SEND_CODE(lc, ltree); /* send a literal byte */
|
||||
Tracecv(lc > ' ', (stderr, " '%c' ", lc));
|
||||
Tracecv(isgraph(lc), (stderr, " '%c' ", lc));
|
||||
} else {
|
||||
/* Here, lc is the match length - MIN_MATCH */
|
||||
code = G2.length_code[lc];
|
||||
@@ -2002,64 +2014,17 @@ char* make_new_name_gzip(char *filename)
|
||||
}
|
||||
|
||||
static
|
||||
IF_DESKTOP(long long) int pack_gzip(unpack_info_t *info UNUSED_PARAM)
|
||||
USE_DESKTOP(long long) int pack_gzip(void)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
/* Clear input and output buffers */
|
||||
G1.outcnt = 0;
|
||||
#ifdef DEBUG
|
||||
G1.insize = 0;
|
||||
#endif
|
||||
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;
|
||||
G2.l_desc.extra_base = LITERALS + 1;
|
||||
G2.l_desc.elems = L_CODES;
|
||||
G2.l_desc.max_length = MAX_BITS;
|
||||
//G2.l_desc.max_code = 0;
|
||||
G2.d_desc.dyn_tree = G2.dyn_dtree;
|
||||
G2.d_desc.static_tree = G2.static_dtree;
|
||||
G2.d_desc.extra_bits = extra_dbits;
|
||||
//G2.d_desc.extra_base = 0;
|
||||
G2.d_desc.elems = D_CODES;
|
||||
G2.d_desc.max_length = MAX_BITS;
|
||||
//G2.d_desc.max_code = 0;
|
||||
G2.bl_desc.dyn_tree = G2.bl_tree;
|
||||
//G2.bl_desc.static_tree = NULL;
|
||||
G2.bl_desc.extra_bits = extra_blbits,
|
||||
//G2.bl_desc.extra_base = 0;
|
||||
G2.bl_desc.elems = BL_CODES;
|
||||
G2.bl_desc.max_length = MAX_BL_BITS;
|
||||
//G2.bl_desc.max_code = 0;
|
||||
|
||||
clear_bufs();
|
||||
s.st_ctime = 0;
|
||||
fstat(STDIN_FILENO, &s);
|
||||
zip(s.st_ctime);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
static const char gzip_longopts[] ALIGN1 =
|
||||
"stdout\0" No_argument "c"
|
||||
"to-stdout\0" No_argument "c"
|
||||
"force\0" No_argument "f"
|
||||
"verbose\0" No_argument "v"
|
||||
#if ENABLE_GUNZIP
|
||||
"decompress\0" No_argument "d"
|
||||
"uncompress\0" No_argument "d"
|
||||
"test\0" No_argument "t"
|
||||
#endif
|
||||
"quiet\0" No_argument "q"
|
||||
"fast\0" No_argument "1"
|
||||
"best\0" No_argument "9"
|
||||
;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -2083,11 +2048,8 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
applet_long_options = gzip_longopts;
|
||||
#endif
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
|
||||
opt = getopt32(argv, "cfv" USE_GUNZIP("dt") "q123456789n");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
if (opt & 0x18) // -d and/or -t
|
||||
return gunzip_main(argc, argv);
|
||||
@@ -2098,8 +2060,32 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//if (opt & 0x4) // -v
|
||||
argv += optind;
|
||||
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
barrier();
|
||||
G2.l_desc.dyn_tree = G2.dyn_ltree;
|
||||
G2.l_desc.static_tree = G2.static_ltree;
|
||||
G2.l_desc.extra_bits = extra_lbits;
|
||||
G2.l_desc.extra_base = LITERALS + 1;
|
||||
G2.l_desc.elems = L_CODES;
|
||||
G2.l_desc.max_length = MAX_BITS;
|
||||
//G2.l_desc.max_code = 0;
|
||||
|
||||
G2.d_desc.dyn_tree = G2.dyn_dtree;
|
||||
G2.d_desc.static_tree = G2.static_dtree;
|
||||
G2.d_desc.extra_bits = extra_dbits;
|
||||
//G2.d_desc.extra_base = 0;
|
||||
G2.d_desc.elems = D_CODES;
|
||||
G2.d_desc.max_length = MAX_BITS;
|
||||
//G2.d_desc.max_code = 0;
|
||||
|
||||
G2.bl_desc.dyn_tree = G2.bl_tree;
|
||||
//G2.bl_desc.static_tree = NULL;
|
||||
G2.bl_desc.extra_bits = extra_blbits,
|
||||
//G2.bl_desc.extra_base = 0;
|
||||
G2.bl_desc.elems = BL_CODES;
|
||||
G2.bl_desc.max_length = MAX_BL_BITS;
|
||||
//G2.bl_desc.max_code = 0;
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "liblzo_interface.h"
|
||||
|
||||
/* lzo-2.03/src/config1x.h */
|
||||
#define M2_MIN_LEN 3
|
||||
#define M2_MAX_LEN 8
|
||||
#define M3_MAX_LEN 33
|
||||
#define M4_MAX_LEN 9
|
||||
#define M1_MAX_OFFSET 0x0400
|
||||
#define M2_MAX_OFFSET 0x0800
|
||||
#define M3_MAX_OFFSET 0x4000
|
||||
#define M4_MAX_OFFSET 0xbfff
|
||||
#define M1_MARKER 0
|
||||
#define M3_MARKER 32
|
||||
#define M4_MARKER 16
|
||||
|
||||
#define MX_MAX_OFFSET (M1_MAX_OFFSET + M2_MAX_OFFSET)
|
||||
#define MIN_LOOKAHEAD (M2_MAX_LEN + 1)
|
||||
|
||||
#define LZO_EOF_CODE
|
||||
|
||||
/* lzo-2.03/src/lzo_dict.h */
|
||||
#define GINDEX(m_pos,m_off,dict,dindex,in) m_pos = dict[dindex]
|
||||
#define DX2(p,s1,s2) \
|
||||
(((((unsigned)((p)[2]) << (s2)) ^ (p)[1]) << (s1)) ^ (p)[0])
|
||||
//#define DA3(p,s1,s2,s3) ((DA2((p)+1,s2,s3) << (s1)) + (p)[0])
|
||||
//#define DS3(p,s1,s2,s3) ((DS2((p)+1,s2,s3) << (s1)) - (p)[0])
|
||||
#define DX3(p,s1,s2,s3) ((DX2((p)+1,s2,s3) << (s1)) ^ (p)[0])
|
||||
|
||||
#define D_SIZE (1U << D_BITS)
|
||||
#define D_MASK ((1U << D_BITS) - 1)
|
||||
#define D_HIGH ((D_MASK >> 1) + 1)
|
||||
|
||||
#define LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,max_offset) \
|
||||
( \
|
||||
m_pos = ip - (unsigned)(ip - m_pos), \
|
||||
((uintptr_t)m_pos < (uintptr_t)in \
|
||||
|| (m_off = (unsigned)(ip - m_pos)) <= 0 \
|
||||
|| m_off > max_offset) \
|
||||
)
|
||||
|
||||
#define DENTRY(p,in) (p)
|
||||
#define UPDATE_I(dict,drun,index,p,in) dict[index] = DENTRY(p,in)
|
||||
|
||||
#define DMS(v,s) ((unsigned) (((v) & (D_MASK >> (s))) << (s)))
|
||||
#define DM(v) ((unsigned) ((v) & D_MASK))
|
||||
#define DMUL(a,b) ((unsigned) ((a) * (b)))
|
||||
|
||||
/* lzo-2.03/src/lzo_ptr.h */
|
||||
#define pd(a,b) ((unsigned)((a)-(b)))
|
||||
|
||||
# define TEST_IP (ip < ip_end)
|
||||
# define NEED_IP(x) \
|
||||
if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun
|
||||
|
||||
# undef TEST_OP /* don't need both of the tests here */
|
||||
# define TEST_OP 1
|
||||
# define NEED_OP(x) \
|
||||
if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun
|
||||
|
||||
#define HAVE_ANY_OP 1
|
||||
|
||||
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
|
||||
# define TEST_LB(m_pos) if (m_pos < out || m_pos >= op) goto lookbehind_overrun
|
||||
//# define TEST_LBO(m_pos,o) if (m_pos < out || m_pos >= op - (o)) goto lookbehind_overrun
|
||||
//#else
|
||||
//# define TEST_LB(m_pos) ((void) 0)
|
||||
//# define TEST_LBO(m_pos,o) ((void) 0)
|
||||
//#endif
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define LZO1X
|
||||
#undef LZO1Y
|
||||
|
||||
#undef assert
|
||||
/*
|
||||
static void die_at(int line)
|
||||
{
|
||||
bb_error_msg_and_die("internal error at %d", line);
|
||||
}
|
||||
#define assert(v) if (!(v)) die_at(__LINE__)
|
||||
*/
|
||||
#define assert(v) ((void)0)
|
||||
|
||||
int lzo1x_1_compress(const uint8_t* src, unsigned src_len,
|
||||
uint8_t* dst, unsigned* dst_len,
|
||||
void* wrkmem);
|
||||
int lzo1x_1_15_compress(const uint8_t* src, unsigned src_len,
|
||||
uint8_t* dst, unsigned* dst_len,
|
||||
void* wrkmem);
|
||||
int lzo1x_999_compress_level(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem,
|
||||
int compression_level);
|
||||
|
||||
/* decompression */
|
||||
//int lzo1x_decompress(const uint8_t* src, unsigned src_len,
|
||||
// uint8_t* dst, unsigned* dst_len,
|
||||
// void* wrkmem /* NOT USED */);
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const uint8_t* src, unsigned src_len,
|
||||
uint8_t* dst, unsigned* dst_len,
|
||||
void* wrkmem /* NOT USED */);
|
||||
|
||||
#define LZO_E_OK 0
|
||||
#define LZO_E_ERROR (-1)
|
||||
#define LZO_E_OUT_OF_MEMORY (-2) /* [not used right now] */
|
||||
#define LZO_E_NOT_COMPRESSIBLE (-3) /* [not used right now] */
|
||||
#define LZO_E_INPUT_OVERRUN (-4)
|
||||
#define LZO_E_OUTPUT_OVERRUN (-5)
|
||||
#define LZO_E_LOOKBEHIND_OVERRUN (-6)
|
||||
#define LZO_E_EOF_NOT_FOUND (-7)
|
||||
#define LZO_E_INPUT_NOT_CONSUMED (-8)
|
||||
#define LZO_E_NOT_YET_IMPLEMENTED (-9) /* [not used right now] */
|
||||
|
||||
/* lzo-2.03/include/lzo/lzoconf.h */
|
||||
#define LZO_VERSION 0x2030
|
||||
@@ -4,13 +4,12 @@
|
||||
#
|
||||
# Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
|
||||
lib-y:=
|
||||
|
||||
COMMON_FILES:= \
|
||||
lib-y:= \
|
||||
\
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
@@ -50,7 +49,3 @@ lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_unzip.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
|
||||
ifneq ($(lib-y),)
|
||||
lib-y += $(COMMON_FILES)
|
||||
endif
|
||||
@@ -10,6 +10,6 @@ void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
|
||||
{
|
||||
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle->src_fd, skip_amount);
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
}
|
||||
@@ -13,33 +13,31 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
int res;
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *slash = strrchr(file_header->name, '/');
|
||||
if (slash) {
|
||||
*slash = '\0';
|
||||
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
|
||||
*slash = '/';
|
||||
}
|
||||
char *name = xstrdup(file_header->name);
|
||||
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
}
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
/* Remove the entry if it exists */
|
||||
if ((!S_ISDIR(file_header->mode))
|
||||
if (((file_header->mode & S_IFMT) != S_IFDIR)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat existing_sb;
|
||||
if (lstat(file_header->name, &existing_sb) == -1) {
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat old file");
|
||||
bb_perror_msg_and_die("cannot stat old file");
|
||||
}
|
||||
}
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", file_header->name);
|
||||
@@ -48,21 +46,20 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately
|
||||
* We identified hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode)
|
||||
&& file_header->link_target
|
||||
&& file_header->size == 0
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_target)
|
||||
&& (file_header->size == 0)
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("can't create %slink "
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "hard",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
@@ -72,25 +69,18 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_fd = xopen3(file_header->name,
|
||||
flags,
|
||||
file_header->mode
|
||||
);
|
||||
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
file_header->mode);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
break;
|
||||
}
|
||||
case S_IFDIR:
|
||||
res = mkdir(file_header->name, file_header->mode);
|
||||
if ((res == -1)
|
||||
&& (errno != EISDIR) /* btw, Linux doesn't return this */
|
||||
&& (errno != EEXIST)
|
||||
if ((res == -1) && (errno != EISDIR)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't make dir %s", file_header->name);
|
||||
bb_perror_msg("cannot make dir %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
@@ -99,7 +89,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't create %slink "
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "sym",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
@@ -113,7 +103,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("can't create node %s", file_header->name);
|
||||
bb_perror_msg("cannot create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -121,41 +111,36 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_OWNER)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) {
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
|
||||
if (file_header->tar__uname) {
|
||||
//TODO: cache last name/id pair?
|
||||
struct passwd *pwd = getpwnam(file_header->tar__uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->tar__gname) {
|
||||
struct group *grp = getgrnam(file_header->tar__gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
/* GNU tar 1.15.1 uses chown, not lchown */
|
||||
chown(file_header->name, uid, gid);
|
||||
} else
|
||||
if (file_header->uname) {
|
||||
struct passwd *pwd = getpwnam(file_header->uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->gname) {
|
||||
struct group *grp = getgrnam(file_header->gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
lchown(file_header->name, uid, gid);
|
||||
#else
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
#endif
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
if (!S_ISLNK(file_header->mode)) {
|
||||
if ((file_header->mode & S_IFMT) != S_IFLNK) {
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_PERM)) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
|
||||
struct timeval t[2];
|
||||
|
||||
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
|
||||
t[1].tv_usec = t[0].tv_usec = 0;
|
||||
utimes(file_header->name, t);
|
||||
if (archive_handle->ah_flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -8,5 +8,5 @@
|
||||
|
||||
void FAST_FUNC data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle->src_fd, archive_handle->file_header->size);
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -648,10 +648,10 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
|
||||
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
char *outbuf;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
@@ -666,7 +666,7 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
i = RETVAL_SHORT_WRITE;
|
||||
break;
|
||||
}
|
||||
IF_DESKTOP(total_written += i;)
|
||||
USE_DESKTOP(total_written += i;)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,10 +686,10 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
dealloc_bunzip(bd);
|
||||
free(outbuf);
|
||||
|
||||
return i ? i : IF_DESKTOP(total_written) + 0;
|
||||
return i ? i : USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_bz2_stream_prime(int src_fd, int dst_fd)
|
||||
{
|
||||
unsigned char magic[2];
|
||||
|
||||
@@ -72,11 +72,11 @@
|
||||
* be stored in the compressed file.
|
||||
*/
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_Z_stream(int fd_in, int fd_out)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
IF_DESKTOP(long long) int retval = -1;
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
USE_DESKTOP(long long) int retval = -1;
|
||||
unsigned char *stackp;
|
||||
long code;
|
||||
int finchar;
|
||||
@@ -265,7 +265,7 @@ unpack_Z_stream(int fd_in, int fd_out)
|
||||
if (outpos >= OBUFSIZ) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
@@ -294,10 +294,10 @@ unpack_Z_stream(int fd_in, int fd_out)
|
||||
if (outpos > 0) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
IF_DESKTOP(total_written += outpos;)
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
retval = IF_DESKTOP(total_written) + 0;
|
||||
retval = USE_DESKTOP(total_written) + 0;
|
||||
err:
|
||||
free(inbuf);
|
||||
free(outbuf);
|
||||
|
||||
@@ -8,15 +8,14 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
# define speed_inline ALWAYS_INLINE
|
||||
# define size_inline
|
||||
#else
|
||||
# define speed_inline
|
||||
# define size_inline ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
|
||||
@@ -45,48 +44,36 @@ typedef struct {
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
|
||||
|
||||
/* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */
|
||||
static size_inline void rc_read(rc_t *rc)
|
||||
/* Called twice: once at startup and once in rc_normalize() */
|
||||
static void rc_read(rc_t *rc)
|
||||
{
|
||||
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
|
||||
//TODO: return -1 instead
|
||||
//This will make unlzma delete broken unpacked file on unpack errors
|
||||
if (buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_1() */
|
||||
static void rc_do_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->ptr >= rc->buffer_end)
|
||||
rc_read(rc);
|
||||
rc->range <<= 8;
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
static rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
{
|
||||
int i;
|
||||
rc_t *rc;
|
||||
|
||||
rc = xzalloc(sizeof(*rc) + RC_BUFFER_SIZE);
|
||||
rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);
|
||||
|
||||
rc->fd = fd;
|
||||
/* rc->ptr = rc->buffer_end; */
|
||||
/* rc->buffer_size = buffer_size; */
|
||||
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
|
||||
rc->ptr = rc->buffer_end;
|
||||
|
||||
rc->code = 0;
|
||||
rc->range = 0xFFFFFFFF;
|
||||
for (i = 0; i < 5; i++) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
if (rc->ptr >= rc->buffer_end)
|
||||
rc_read(rc);
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
#else
|
||||
rc_do_normalize(rc);
|
||||
#endif
|
||||
}
|
||||
rc->range = 0xFFFFFFFF;
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -96,6 +83,14 @@ static ALWAYS_INLINE void rc_free(rc_t *rc)
|
||||
free(rc);
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
|
||||
static void rc_do_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->ptr >= rc->buffer_end)
|
||||
rc_read(rc);
|
||||
rc->range <<= 8;
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
@@ -103,28 +98,49 @@ static ALWAYS_INLINE void rc_normalize(rc_t *rc)
|
||||
}
|
||||
}
|
||||
|
||||
/* rc_is_bit_1 is called 9 times */
|
||||
static speed_inline int rc_is_bit_1(rc_t *rc, uint16_t *p)
|
||||
/* rc_is_bit_0 is called 9 times */
|
||||
/* Why rc_is_bit_0_helper exists?
|
||||
* Because we want to always expose (rc->code < rc->bound) to optimizer.
|
||||
* Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined
|
||||
* only if we compile for speed.
|
||||
*/
|
||||
static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
rc_normalize(rc);
|
||||
rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
|
||||
if (rc->code < rc->bound) {
|
||||
rc->range = rc->bound;
|
||||
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
|
||||
return 0;
|
||||
}
|
||||
return rc->bound;
|
||||
}
|
||||
static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
uint32_t t = rc_is_bit_0_helper(rc, p);
|
||||
return rc->code < t;
|
||||
}
|
||||
|
||||
/* Called ~10 times, but very small, thus inlined */
|
||||
static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
rc->range = rc->bound;
|
||||
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
|
||||
}
|
||||
static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)
|
||||
{
|
||||
rc->range -= rc->bound;
|
||||
rc->code -= rc->bound;
|
||||
*p -= *p >> RC_MOVE_BITS;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Called 4 times in unlzma loop */
|
||||
static speed_inline int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
|
||||
{
|
||||
int ret = rc_is_bit_1(rc, p);
|
||||
*symbol = *symbol * 2 + ret;
|
||||
return ret;
|
||||
if (rc_is_bit_0(rc, p)) {
|
||||
rc_update_bit_0(rc, p);
|
||||
*symbol *= 2;
|
||||
return 0;
|
||||
} else {
|
||||
rc_update_bit_1(rc, p);
|
||||
*symbol = *symbol * 2 + 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
@@ -156,7 +172,7 @@ typedef struct {
|
||||
uint8_t pos;
|
||||
uint32_t dict_size;
|
||||
uint64_t dst_size;
|
||||
} PACKED lzma_header_t;
|
||||
} __attribute__ ((packed)) lzma_header_t;
|
||||
|
||||
|
||||
/* #defines will force compiler to compute/optimize each one with each usage.
|
||||
@@ -212,19 +228,22 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
{
|
||||
IF_DESKTOP(long long total_written = 0;)
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
int lc, pb, lp;
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint32_t pos;
|
||||
uint16_t *p;
|
||||
uint16_t *prob;
|
||||
uint16_t *prob_lit;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i;
|
||||
int i, mi;
|
||||
uint8_t *buffer;
|
||||
uint8_t previous_byte = 0;
|
||||
size_t buffer_pos = 0, global_pos = 0;
|
||||
@@ -232,17 +251,14 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
return -1;
|
||||
}
|
||||
xread(src_fd, &header, sizeof(header));
|
||||
|
||||
i = header.pos / 9;
|
||||
if (header.pos >= (9 * 5 * 5))
|
||||
bb_error_msg_and_die("bad header");
|
||||
mi = header.pos / 9;
|
||||
lc = header.pos % 9;
|
||||
pb = i / 5;
|
||||
lp = i % 5;
|
||||
pb = mi / 5;
|
||||
lp = mi % 5;
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
@@ -250,13 +266,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
header.dst_size = SWAP_LE64(header.dst_size);
|
||||
|
||||
if (header.dict_size == 0)
|
||||
header.dict_size++;
|
||||
header.dict_size = 1;
|
||||
|
||||
buffer = xmalloc(MIN(header.dst_size, header.dict_size));
|
||||
|
||||
num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
||||
p = xmalloc(num_probs * sizeof(*p));
|
||||
num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
||||
num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
@@ -264,13 +280,11 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
uint16_t *prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
|
||||
if (!rc_is_bit_1(rc, prob)) {
|
||||
static const char next_state[LZMA_NUM_STATES] =
|
||||
{ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
|
||||
int mi = 1;
|
||||
|
||||
prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
mi = 1;
|
||||
rc_update_bit_0(rc, prob);
|
||||
prob = (p + LZMA_LITERAL
|
||||
+ (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
||||
+ (previous_byte >> (8 - lc))
|
||||
@@ -280,8 +294,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
if (state >= LZMA_NUM_LIT_STATES) {
|
||||
int match_byte;
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
match_byte = buffer[pos];
|
||||
@@ -290,16 +304,22 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
bit ^= (rc_get_bit(rc, prob + 0x100 + bit + mi, &mi) << 8); /* 0x100 or 0 */
|
||||
prob_lit = prob + 0x100 + bit + mi;
|
||||
bit ^= (rc_get_bit(rc, prob_lit, &mi) << 8); /* 0x100 or 0 */
|
||||
if (bit)
|
||||
break;
|
||||
} while (mi < 0x100);
|
||||
}
|
||||
while (mi < 0x100) {
|
||||
rc_get_bit(rc, prob + mi, &mi);
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
}
|
||||
|
||||
state = next_state[state];
|
||||
state -= 3;
|
||||
if (state < 4-3)
|
||||
state = 0;
|
||||
if (state >= 10-3)
|
||||
state -= 6-3;
|
||||
|
||||
previous_byte = (uint8_t) mi;
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
@@ -310,7 +330,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
#else
|
||||
len = 1;
|
||||
@@ -318,46 +338,59 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
#endif
|
||||
} else {
|
||||
int offset;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
uint16_t *prob_len;
|
||||
|
||||
prob2 = p + LZMA_IS_REP + state;
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
rc_update_bit_1(rc, prob);
|
||||
prob = p + LZMA_IS_REP + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
rep3 = rep2;
|
||||
rep2 = rep1;
|
||||
rep1 = rep0;
|
||||
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
|
||||
prob2 = p + LZMA_LEN_CODER;
|
||||
prob = p + LZMA_LEN_CODER;
|
||||
} else {
|
||||
prob2 += LZMA_IS_REP_G0 - LZMA_IS_REP;
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
prob2 = (p + LZMA_IS_REP_0_LONG
|
||||
rc_update_bit_1(rc, prob);
|
||||
prob = p + LZMA_IS_REP_G0 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
prob = (p + LZMA_IS_REP_0_LONG
|
||||
+ (state << LZMA_NUM_POS_BITS_MAX)
|
||||
+ pos_state
|
||||
);
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
goto one_byte1;
|
||||
#else
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
len = 1;
|
||||
goto string;
|
||||
#endif
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
}
|
||||
} else {
|
||||
uint32_t distance;
|
||||
|
||||
prob2 += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
|
||||
distance = rep1;
|
||||
if (rc_is_bit_1(rc, prob2)) {
|
||||
prob2 += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
|
||||
distance = rep2;
|
||||
if (rc_is_bit_1(rc, prob2)) {
|
||||
rc_update_bit_1(rc, prob);
|
||||
prob = p + LZMA_IS_REP_G1 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
distance = rep1;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
prob = p + LZMA_IS_REP_G2 + state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
distance = rep2;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
distance = rep3;
|
||||
rep3 = rep2;
|
||||
}
|
||||
@@ -367,27 +400,31 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
rep0 = distance;
|
||||
}
|
||||
state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
|
||||
prob2 = p + LZMA_REP_LEN_CODER;
|
||||
prob = p + LZMA_REP_LEN_CODER;
|
||||
}
|
||||
|
||||
prob_len = prob2 + LZMA_LEN_CHOICE;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
if (!rc_is_bit_1(rc, prob_len)) {
|
||||
prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS);
|
||||
prob_len = prob + LZMA_LEN_CHOICE;
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_LOW
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS));
|
||||
offset = 0;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
} else {
|
||||
prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
|
||||
if (!rc_is_bit_1(rc, prob_len)) {
|
||||
prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS);
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
prob_len = prob + LZMA_LEN_CHOICE_2;
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
prob_len = (prob + LZMA_LEN_MID
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS));
|
||||
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits += LZMA_LEN_NUM_MID_BITS - LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits = LZMA_LEN_NUM_MID_BITS;
|
||||
} else {
|
||||
prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
prob_len = prob + LZMA_LEN_HIGH;
|
||||
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
||||
+ (1 << LZMA_LEN_NUM_MID_BITS));
|
||||
num_bits += LZMA_LEN_NUM_HIGH_BITS - LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
||||
}
|
||||
}
|
||||
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
|
||||
@@ -395,55 +432,56 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
if (state < 4) {
|
||||
int pos_slot;
|
||||
uint16_t *prob3;
|
||||
|
||||
state += LZMA_NUM_LIT_STATES;
|
||||
prob3 = p + LZMA_POS_SLOT +
|
||||
prob = p + LZMA_POS_SLOT +
|
||||
((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
rc_bit_tree_decode(rc, prob3,
|
||||
LZMA_NUM_POS_SLOT_BITS, &pos_slot);
|
||||
rep0 = pos_slot;
|
||||
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
&pos_slot);
|
||||
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
||||
int i2, mi2, num_bits2 = (pos_slot >> 1) - 1;
|
||||
num_bits = (pos_slot >> 1) - 1;
|
||||
rep0 = 2 | (pos_slot & 1);
|
||||
if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
|
||||
rep0 <<= num_bits2;
|
||||
prob3 = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
|
||||
rep0 <<= num_bits;
|
||||
prob = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
|
||||
} else {
|
||||
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
|
||||
num_bits -= LZMA_NUM_ALIGN_BITS;
|
||||
while (num_bits--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
prob = p + LZMA_ALIGN;
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
prob3 = p + LZMA_ALIGN;
|
||||
num_bits = LZMA_NUM_ALIGN_BITS;
|
||||
}
|
||||
i2 = 1;
|
||||
mi2 = 1;
|
||||
while (num_bits2--) {
|
||||
if (rc_get_bit(rc, prob3 + mi2, &mi2))
|
||||
rep0 |= i2;
|
||||
i2 <<= 1;
|
||||
i = 1;
|
||||
mi = 1;
|
||||
while (num_bits--) {
|
||||
if (rc_get_bit(rc, prob + mi, &mi))
|
||||
rep0 |= i;
|
||||
i <<= 1;
|
||||
}
|
||||
}
|
||||
} else
|
||||
rep0 = pos_slot;
|
||||
if (++rep0 == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
len += LZMA_MATCH_MIN_LEN;
|
||||
IF_NOT_FEATURE_LZMA_FAST(string:)
|
||||
SKIP_FEATURE_LZMA_FAST(string:)
|
||||
do {
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
IF_NOT_FEATURE_LZMA_FAST(one_byte2:)
|
||||
SKIP_FEATURE_LZMA_FAST(one_byte2:)
|
||||
buffer[buffer_pos++] = previous_byte;
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)
|
||||
goto bad;
|
||||
IF_DESKTOP(total_written += header.dict_size;)
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
} while (len != 0 && buffer_pos < header.dst_size);
|
||||
@@ -451,8 +489,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
{
|
||||
IF_NOT_DESKTOP(int total_written = 0; /* success */)
|
||||
IF_DESKTOP(total_written += buffer_pos;)
|
||||
SKIP_DESKTOP(int total_written = 0; /* success */)
|
||||
USE_DESKTOP(total_written += buffer_pos;)
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
|
||||
bad:
|
||||
total_written = -1; /* failure */
|
||||
|
||||
@@ -503,7 +503,7 @@ static void inflate_codes_setup(STATE_PARAM unsigned my_bl, unsigned my_bd)
|
||||
md = mask_bits[bd];
|
||||
}
|
||||
/* called once from inflate_get_next_window */
|
||||
static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
static int inflate_codes(STATE_PARAM_ONLY)
|
||||
{
|
||||
unsigned e; /* table entry flag/number of extra bits */
|
||||
huft_t *t; /* pointer to table entry */
|
||||
@@ -970,10 +970,10 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
|
||||
|
||||
|
||||
/* Called from unpack_gz_stream() and inflate_unzip() */
|
||||
static IF_DESKTOP(long long) int
|
||||
static USE_DESKTOP(long long) int
|
||||
inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n = 0;
|
||||
USE_DESKTOP(long long) int n = 0;
|
||||
ssize_t nwrote;
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
@@ -1008,7 +1008,7 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
n = -1;
|
||||
goto ret;
|
||||
}
|
||||
IF_DESKTOP(n += nwrote;)
|
||||
USE_DESKTOP(n += nwrote;)
|
||||
if (r == 0) break;
|
||||
}
|
||||
|
||||
@@ -1033,10 +1033,10 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
|
||||
|
||||
/* For unzip */
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
inflate_unzip(inflate_unzip_result *res, off_t compr_size, int in, int out)
|
||||
{
|
||||
IF_DESKTOP(long long) int n;
|
||||
USE_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
ALLOC_STATE;
|
||||
@@ -1083,7 +1083,8 @@ static uint16_t buffer_read_le_u16(STATE_PARAM_ONLY)
|
||||
{
|
||||
uint16_t res;
|
||||
#if BB_LITTLE_ENDIAN
|
||||
move_from_unaligned16(res, &bytebuffer[bytebuffer_offset]);
|
||||
/* gcc 4.2.1 is very clever */
|
||||
memcpy(&res, &bytebuffer[bytebuffer_offset], 2);
|
||||
#else
|
||||
res = bytebuffer[bytebuffer_offset];
|
||||
res |= bytebuffer[bytebuffer_offset + 1] << 8;
|
||||
@@ -1096,7 +1097,7 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
{
|
||||
uint32_t res;
|
||||
#if BB_LITTLE_ENDIAN
|
||||
move_from_unaligned32(res, &bytebuffer[bytebuffer_offset]);
|
||||
memcpy(&res, &bytebuffer[bytebuffer_offset], 4);
|
||||
#else
|
||||
res = bytebuffer[bytebuffer_offset];
|
||||
res |= bytebuffer[bytebuffer_offset + 1] << 8;
|
||||
@@ -1107,21 +1108,18 @@ static uint32_t buffer_read_le_u32(STATE_PARAM_ONLY)
|
||||
return res;
|
||||
}
|
||||
|
||||
static int check_header_gzip(STATE_PARAM unpack_info_t *info)
|
||||
static int check_header_gzip(STATE_PARAM_ONLY)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
struct {
|
||||
uint8_t gz_method;
|
||||
uint8_t flags;
|
||||
uint32_t mtime;
|
||||
uint8_t xtra_flags_UNUSED;
|
||||
uint8_t os_flags_UNUSED;
|
||||
} PACKED formatted;
|
||||
//uint32_t mtime; - unused fields
|
||||
//uint8_t xtra_flags;
|
||||
//uint8_t os_flags;
|
||||
} formatted; /* packed */
|
||||
} header;
|
||||
struct BUG_header {
|
||||
char BUG_header[sizeof(header) == 8 ? 1 : -1];
|
||||
};
|
||||
|
||||
/*
|
||||
* Rewind bytebuffer. We use the beginning because the header has 8
|
||||
@@ -1169,9 +1167,6 @@ static int check_header_gzip(STATE_PARAM unpack_info_t *info)
|
||||
}
|
||||
}
|
||||
|
||||
if (info)
|
||||
info->mtime = SWAP_LE32(header.formatted.mtime);
|
||||
|
||||
/* Read the header checksum */
|
||||
if (header.formatted.flags & 0x02) {
|
||||
if (!top_up(PASS_STATE 2))
|
||||
@@ -1181,11 +1176,11 @@ static int check_header_gzip(STATE_PARAM unpack_info_t *info)
|
||||
return 1;
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
|
||||
USE_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(int in, int out)
|
||||
{
|
||||
uint32_t v32;
|
||||
IF_DESKTOP(long long) int n;
|
||||
USE_DESKTOP(long long) int n;
|
||||
DECLARE_STATE;
|
||||
|
||||
n = 0;
|
||||
@@ -1197,7 +1192,7 @@ unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
|
||||
gunzip_src_fd = in;
|
||||
|
||||
again:
|
||||
if (!check_header_gzip(PASS_STATE info)) {
|
||||
if (!check_header_gzip(PASS_STATE_ONLY)) {
|
||||
bb_error_msg("corrupted data");
|
||||
n = -1;
|
||||
goto ret;
|
||||
@@ -1244,9 +1239,3 @@ unpack_gz_stream_with_info(int in, int out, unpack_info_t *info)
|
||||
DEALLOC_STATE;
|
||||
return n;
|
||||
}
|
||||
|
||||
IF_DESKTOP(long long) int FAST_FUNC
|
||||
unpack_gz_stream(int in, int out)
|
||||
{
|
||||
return unpack_gz_stream_with_info(in, out, NULL);
|
||||
}
|
||||
@@ -31,19 +31,19 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& strcmp(name_ptr, "bz2") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
|
||||
archive_handle->action_data_subarchive = get_header_tar_bz2;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
&& strcmp(name_ptr, "lzma") == 0
|
||||
) {
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
archive_handle->action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,20 +7,10 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static unsigned read_num(const char *str, int base)
|
||||
{
|
||||
/* This code works because
|
||||
* on misformatted numbers bb_strtou returns all-ones */
|
||||
int err = bb_strtou(str, NULL, base);
|
||||
if (err == -1)
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
}
|
||||
|
||||
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
int err;
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
unsigned size;
|
||||
union {
|
||||
char raw[60];
|
||||
struct {
|
||||
@@ -59,60 +49,57 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/* FIXME: more thorough routine would be in order here
|
||||
* (we have something like that in tar)
|
||||
* but for now we are lax. */
|
||||
typed->size = size = read_num(ar.formatted.size, 10);
|
||||
/* FIXME: more thorough routine would be in order here */
|
||||
/* (we have something like that in tar) */
|
||||
/* but for now we are lax. This code works because */
|
||||
/* on misformatted numbers bb_strtou returns all-ones */
|
||||
typed->mode = err = bb_strtou(ar.formatted.mode, NULL, 8);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->mtime = err = bb_strtou(ar.formatted.date, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->uid = err = bb_strtou(ar.formatted.uid, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->gid = err = bb_strtou(ar.formatted.gid, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->size = err = bb_strtou(ar.formatted.size, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/* special filenames have '/' as the first character */
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += size;
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
unsigned long_offset;
|
||||
|
||||
if (ar.formatted.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries
|
||||
*/
|
||||
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);
|
||||
* in static variable long_names for use in future entries */
|
||||
ar_long_name_size = typed->size;
|
||||
ar_long_names = xmalloc(ar_long_name_size);
|
||||
xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
|
||||
archive_handle->offset += ar_long_name_size;
|
||||
/* This ar entries data section only contained filenames for other records
|
||||
* they are stored in the static ar_long_names for future reference */
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
}
|
||||
/* Only size is always present, the rest may be missing in
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*/
|
||||
typed->mode = read_num(ar.formatted.mode, 8);
|
||||
typed->mtime = read_num(ar.formatted.date, 10);
|
||||
typed->uid = read_num(ar.formatted.uid, 10);
|
||||
typed->gid = read_num(ar.formatted.gid, 10);
|
||||
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
unsigned long_offset;
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += typed->size;
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in ar_long_names) that conatains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10);
|
||||
* (saved in variable long_name) that conatains the real filename */
|
||||
long_offset = atoi(&ar.formatted.name[1]);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
} else
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
/* short filenames */
|
||||
typed->name = xstrndup(ar.formatted.name, 16);
|
||||
}
|
||||
@@ -122,8 +109,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
#if ENABLE_DPKG || ENABLE_DPKG_DEB
|
||||
if (archive_handle->dpkg__sub_archive) {
|
||||
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
|
||||
if (archive_handle->sub_archive) {
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
|
||||
continue;
|
||||
} else
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
|
||||
#define hardlinks_to_create (*(hardlinks_t **)(&archive_handle->ah_priv[0]))
|
||||
#define created_hardlinks (*(hardlinks_t **)(&archive_handle->ah_priv[1]))
|
||||
// if (!archive_handle->ah_priv_inited) {
|
||||
// archive_handle->ah_priv_inited = 1;
|
||||
// hardlinks_to_create = NULL;
|
||||
// created_hardlinks = NULL;
|
||||
// }
|
||||
|
||||
/* There can be padding before archive header */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
@@ -61,15 +69,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
file_header->name = xzalloc(namesize + 1);
|
||||
/* Read in filename */
|
||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||
if (file_header->name[0] == '/') {
|
||||
/* Testcase: echo /etc/hosts | cpio -pvd /tmp
|
||||
* Without this code, it tries to unpack /etc/hosts
|
||||
* into "/etc/hosts", not "etc/hosts".
|
||||
*/
|
||||
char *p = file_header->name;
|
||||
do p++; while (*p == '/');
|
||||
overlapping_strcpy(file_header->name, p);
|
||||
}
|
||||
archive_handle->offset += namesize;
|
||||
|
||||
/* Update offset amount and skip padding before file contents */
|
||||
@@ -77,7 +76,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
|
||||
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
|
||||
/* Always round up. ">> 9" divides by 512 */
|
||||
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
|
||||
printf("%"OFF_FMT"u blocks\n", (archive_handle->offset + 511) >> 9);
|
||||
goto create_hardlinks;
|
||||
}
|
||||
|
||||
@@ -103,22 +102,18 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
strcpy(new->name, file_header->name);
|
||||
/* Put file on a linked list for later */
|
||||
if (size == 0) {
|
||||
new->next = archive_handle->cpio__hardlinks_to_create;
|
||||
archive_handle->cpio__hardlinks_to_create = new;
|
||||
new->next = hardlinks_to_create;
|
||||
hardlinks_to_create = new;
|
||||
return EXIT_SUCCESS; /* Skip this one */
|
||||
/* TODO: this breaks cpio -t (it does not show hardlinks) */
|
||||
}
|
||||
new->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = new;
|
||||
new->next = created_hardlinks;
|
||||
created_hardlinks = new;
|
||||
}
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
//TODO: run "echo /etc/hosts | cpio -pv /tmp" twice. On 2nd run:
|
||||
//cpio: etc/hosts not created: newer or same age file exists
|
||||
//etc/hosts <-- should NOT show it
|
||||
//2 blocks <-- should say "0 blocks"
|
||||
archive_handle->action_header(file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
@@ -137,11 +132,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
|
||||
while (archive_handle->cpio__hardlinks_to_create) {
|
||||
while (hardlinks_to_create) {
|
||||
hardlinks_t *cur;
|
||||
hardlinks_t *make_me = archive_handle->cpio__hardlinks_to_create;
|
||||
hardlinks_t *make_me = hardlinks_to_create;
|
||||
|
||||
archive_handle->cpio__hardlinks_to_create = make_me->next;
|
||||
hardlinks_to_create = make_me->next;
|
||||
|
||||
memset(file_header, 0, sizeof(*file_header));
|
||||
file_header->mtime = make_me->mtime;
|
||||
@@ -153,7 +148,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
/*file_header->link_target = NULL;*/
|
||||
|
||||
/* Try to find a file we are hardlinked to */
|
||||
cur = archive_handle->cpio__created_hardlinks;
|
||||
cur = created_hardlinks;
|
||||
while (cur) {
|
||||
/* TODO: must match maj/min too! */
|
||||
if (cur->inode == make_me->inode) {
|
||||
@@ -171,14 +166,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
/* Move to the list of created hardlinked files */
|
||||
make_me->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = make_me;
|
||||
make_me->next = created_hardlinks;
|
||||
created_hardlinks = make_me;
|
||||
next_link: ;
|
||||
}
|
||||
|
||||
while (archive_handle->cpio__created_hardlinks) {
|
||||
hardlinks_t *p = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = p->next;
|
||||
while (created_hardlinks) {
|
||||
hardlinks_t *p = created_hardlinks;
|
||||
created_hardlinks = p->next;
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,86 +14,16 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* GNU tar uses "base-256 encoding" for very large numbers (>8 billion).
|
||||
* Encoding is binary, with highest bit always set as a marker
|
||||
* and sign in next-highest bit:
|
||||
* 80 00 .. 00 - zero
|
||||
* bf ff .. ff - largest positive number
|
||||
* ff ff .. ff - minus 1
|
||||
* c0 00 .. 00 - smallest negative number
|
||||
*
|
||||
* We expect it only in size field, where negative numbers don't make sense.
|
||||
*/
|
||||
static off_t getBase256_len12(const char *str)
|
||||
{
|
||||
off_t value;
|
||||
int len;
|
||||
|
||||
/* if (*str & 0x40) error; - caller prevents this */
|
||||
|
||||
if (sizeof(off_t) >= 12) {
|
||||
/* Probably 128-bit (16 byte) off_t. Can be optimized. */
|
||||
len = 12;
|
||||
value = *str++ & 0x3f;
|
||||
while (--len)
|
||||
value = (value << 8) + (unsigned char) *str++;
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifdef CHECK_FOR_OVERFLOW
|
||||
/* Can be optimized to eat 32-bit chunks */
|
||||
char c = *str++ & 0x3f;
|
||||
len = 12;
|
||||
while (1) {
|
||||
if (c)
|
||||
bb_error_msg_and_die("overflow in base-256 encoded file size");
|
||||
if (--len == sizeof(off_t))
|
||||
break;
|
||||
c = *str++;
|
||||
}
|
||||
#else
|
||||
str += (12 - sizeof(off_t));
|
||||
#endif
|
||||
|
||||
/* Now str points to sizeof(off_t) least significant bytes.
|
||||
*
|
||||
* Example of tar file with 8914993153 (0x213600001) byte file.
|
||||
* Field starts at offset 7c:
|
||||
* 00070 30 30 30 00 30 30 30 30 30 30 30 00 80 00 00 00 |000.0000000.....|
|
||||
* 00080 00 00 00 02 13 60 00 01 31 31 31 32 30 33 33 36 |.....`..11120336|
|
||||
*
|
||||
* str is at offset 80 or 84 now (64-bit or 32-bit off_t).
|
||||
* We (ab)use the fact that value happens to be aligned,
|
||||
* and fetch it in one go:
|
||||
*/
|
||||
if (sizeof(off_t) == 8) {
|
||||
value = *(off_t*)str;
|
||||
value = SWAP_BE64(value);
|
||||
} else if (sizeof(off_t) == 4) {
|
||||
value = *(off_t*)str;
|
||||
value = SWAP_BE32(value);
|
||||
} else {
|
||||
value = 0;
|
||||
len = sizeof(off_t);
|
||||
while (--len)
|
||||
value = (value << 8) + (unsigned char) *str++;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/* NB: _DESTROYS_ str[len] character! */
|
||||
static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
unsigned long long v;
|
||||
/* NB: leading spaces are allowed. Using strtoull to handle that.
|
||||
* The downside is that we accept e.g. "-123" too :(
|
||||
* The downside is that we accept e.g. "-123" too :)
|
||||
*/
|
||||
str[len] = '\0';
|
||||
v = strtoull(str, &str, 8);
|
||||
/* std: "Each numeric field is terminated by one or more
|
||||
* <space> or NUL characters". We must support ' '! */
|
||||
if (*str != '\0' && *str != ' ')
|
||||
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
|
||||
bb_error_msg_and_die("corrupted octal value in tar header");
|
||||
return v;
|
||||
}
|
||||
@@ -135,13 +65,20 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
int parse_names;
|
||||
|
||||
/* Our "private data" */
|
||||
#define p_end (*(smallint *)(&archive_handle->ah_priv[0]))
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
# define p_longname (archive_handle->tar__longname)
|
||||
# define p_linkname (archive_handle->tar__linkname)
|
||||
#define p_longname (*(char* *)(&archive_handle->ah_priv[1]))
|
||||
#define p_linkname (*(char* *)(&archive_handle->ah_priv[2]))
|
||||
#else
|
||||
# define p_longname 0
|
||||
# define p_linkname 0
|
||||
#define p_longname 0
|
||||
#define p_linkname 0
|
||||
#endif
|
||||
// if (!archive_handle->ah_priv_inited) {
|
||||
// archive_handle->ah_priv_inited = 1;
|
||||
// p_end = 0;
|
||||
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_longname = NULL;)
|
||||
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_linkname = NULL;)
|
||||
// }
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
BUG_tar_header_size();
|
||||
@@ -154,7 +91,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
again_after_align:
|
||||
|
||||
#if ENABLE_DESKTOP || ENABLE_FEATURE_TAR_AUTODETECT
|
||||
#if ENABLE_DESKTOP
|
||||
/* to prevent misdetection of bz2 sig */
|
||||
*(uint32_t*)(&tar) = 0;
|
||||
i = full_read(archive_handle->src_fd, &tar, 512);
|
||||
@@ -171,7 +108,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("short read");
|
||||
}
|
||||
if (i != 512) {
|
||||
IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
|
||||
USE_FEATURE_TAR_AUTODETECT(goto autodetect;)
|
||||
goto short_read;
|
||||
}
|
||||
|
||||
@@ -183,7 +120,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
|
||||
if (archive_handle->tar__end) {
|
||||
if (p_end) {
|
||||
/* Second consecutive empty header - end of archive.
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
@@ -191,10 +128,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
continue;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
archive_handle->tar__end = 1;
|
||||
p_end = 1;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
archive_handle->tar__end = 0;
|
||||
p_end = 0;
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
@@ -205,7 +142,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
#if ENABLE_FEATURE_TAR_AUTODETECT
|
||||
char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
|
||||
|
||||
autodetect:
|
||||
USE_DESKTOP(autodetect:)
|
||||
/* tar gz/bz autodetect: check for gz/bz2 magic.
|
||||
* If we see the magic, and it is the very first block,
|
||||
* we can switch to get_header_tar_gz/bz2/lzma().
|
||||
@@ -257,21 +194,20 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
{
|
||||
char *endp; /* gcc likes temp var for &endp */
|
||||
sum = strtoul(tar.chksum, &endp, 8);
|
||||
if ((*endp != '\0' && *endp != ' ')
|
||||
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
}
|
||||
/* don't use xstrtoul, tar.chksum may have leading spaces */
|
||||
sum = strtoul(tar.chksum, NULL, 8);
|
||||
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
sum = strtoul(tar.chksum, &cp, 8);
|
||||
if ((*cp && *cp != ' ')
|
||||
|| (sum_u != sum USE_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
#else
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
sum = xstrtoul(tar.chksum, 8);
|
||||
if (sum_u != sum USE_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (!tar.typeflag) tar.typeflag = '0';
|
||||
@@ -294,18 +230,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
/* Will link_target be free()ed? */
|
||||
}
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
file_header->uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
#endif
|
||||
/* mtime: rudimentally handle GNU tar's "base256 encoding"
|
||||
* People report tarballs with NEGATIVE unix times encoded that way */
|
||||
file_header->mtime = (tar.mtime[0] & 0x80) /* base256? */
|
||||
? 0 /* bogus */
|
||||
: GET_OCTAL(tar.mtime);
|
||||
/* size: handle GNU tar's "base256 encoding" */
|
||||
file_header->size = (tar.size[0] & 0xc0) == 0x80 /* positive base256? */
|
||||
? getBase256_len12(tar.size)
|
||||
: GET_OCTAL(tar.size);
|
||||
file_header->mtime = GET_OCTAL(tar.mtime);
|
||||
file_header->size = GET_OCTAL(tar.size);
|
||||
file_header->gid = GET_OCTAL(tar.gid);
|
||||
file_header->uid = GET_OCTAL(tar.uid);
|
||||
/* Set bits 0-11 of the files mode */
|
||||
@@ -356,7 +285,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
file_header->mode |= S_IFBLK;
|
||||
goto size0;
|
||||
case '5':
|
||||
IF_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:)
|
||||
USE_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:)
|
||||
file_header->mode |= S_IFDIR;
|
||||
goto size0;
|
||||
case '6':
|
||||
@@ -442,8 +371,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
free(file_header->link_target);
|
||||
/* Do not free(file_header->name)! (why?) */
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
free(file_header->tar__uname);
|
||||
free(file_header->tar__gname);
|
||||
free(file_header->uname);
|
||||
free(file_header->gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -7,6 +7,5 @@
|
||||
|
||||
void FAST_FUNC header_list(const file_header_t *file_header)
|
||||
{
|
||||
//TODO: cpio -vp DIR should output "DIR/NAME", not just "NAME" */
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -8,57 +8,47 @@
|
||||
|
||||
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm tm_time;
|
||||
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
|
||||
struct tm *mtime = localtime(&(file_header->mtime));
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
char uid[sizeof(int)*3 + 2];
|
||||
/*char gid[sizeof(int)*3 + 2];*/
|
||||
char *user;
|
||||
char *group;
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char *user = file_header->uname;
|
||||
char *group = file_header->gname;
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
user = file_header->tar__uname;
|
||||
if (user == NULL) {
|
||||
sprintf(uid, "%u", (unsigned)file_header->uid);
|
||||
snprintf(uid, sizeof(uid), "%u", (unsigned)file_header->uid);
|
||||
user = uid;
|
||||
}
|
||||
group = file_header->tar__gname;
|
||||
if (group == NULL) {
|
||||
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
|
||||
group = utoa(file_header->gid);
|
||||
snprintf(gid, sizeof(gid), "%u", (unsigned)file_header->gid);
|
||||
group = gid;
|
||||
}
|
||||
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
printf("%s %s/%s %9u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
user,
|
||||
group,
|
||||
file_header->size,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
(unsigned int) file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
#else /* !FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
(unsigned)file_header->uid,
|
||||
(unsigned)file_header->gid,
|
||||
file_header->uid,
|
||||
file_header->gid,
|
||||
file_header->size,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
#endif /* FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
if (file_header->link_target) {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* in include/unarchive.h. On NOMMU, transformer is removed.
|
||||
*/
|
||||
void FAST_FUNC open_transformer(int fd,
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
|
||||
USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
|
||||
const char *transform_prog)
|
||||
{
|
||||
struct fd_pair fd_pipe;
|
||||
@@ -52,7 +52,7 @@ void FAST_FUNC open_transformer(int fd,
|
||||
argv[2] = (char*)"-";
|
||||
argv[3] = NULL;
|
||||
BB_EXECVP(transform_prog, argv);
|
||||
bb_perror_msg_and_die("can't execute '%s'", transform_prog);
|
||||
bb_perror_msg_and_die("can't exec %s", transform_prog);
|
||||
}
|
||||
#endif
|
||||
/* notreached */
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void FAST_FUNC seek_by_jump(int fd, off_t amount)
|
||||
void FAST_FUNC seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
|
||||
{
|
||||
if (amount
|
||||
&& lseek(fd, amount, SEEK_CUR) == (off_t) -1
|
||||
&& lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1
|
||||
) {
|
||||
if (errno == ESPIPE)
|
||||
seek_by_read(fd, amount);
|
||||
seek_by_read(archive_handle, amount);
|
||||
else
|
||||
bb_perror_msg_and_die("seek failure");
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
/* If we are reading through a pipe, or from stdin then we can't lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*/
|
||||
void FAST_FUNC seek_by_read(int fd, off_t amount)
|
||||
void FAST_FUNC seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
|
||||
{
|
||||
if (amount)
|
||||
bb_copyfd_exact_size(fd, -1, amount);
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/* LZO1X-1 compression
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
#define D_BITS 14
|
||||
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
|
||||
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
|
||||
|
||||
#define DO_COMPRESS lzo1x_1_compress
|
||||
|
||||
#include "lzo1x_c.c"
|
||||
@@ -1,35 +0,0 @@
|
||||
/* LZO1X-1(15) compression
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
#define D_BITS 15
|
||||
#define D_INDEX1(d,p) d = DM(DMUL(0x21,DX3(p,5,5,6)) >> 5)
|
||||
#define D_INDEX2(d,p) d = (d & (D_MASK & 0x7ff)) ^ (D_HIGH | 0x1f)
|
||||
|
||||
#define DO_COMPRESS lzo1x_1_15_compress
|
||||
|
||||
#include "lzo1x_c.c"
|
||||
@@ -1,920 +0,0 @@
|
||||
/* lzo1x_9x.c -- implementation of the LZO1X-999 compression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
|
||||
Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Markus F.X.J. Oberhumer
|
||||
<markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
*/
|
||||
#include "libbb.h"
|
||||
|
||||
/* The following is probably only safe on Intel-compatible processors ... */
|
||||
#define LZO_UNALIGNED_OK_2
|
||||
#define LZO_UNALIGNED_OK_4
|
||||
|
||||
#include "liblzo.h"
|
||||
|
||||
#define LZO_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define LZO_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define LZO_MAX3(a,b,c) ((a) >= (b) ? LZO_MAX(a,c) : LZO_MAX(b,c))
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define SWD_N M4_MAX_OFFSET /* size of ring buffer */
|
||||
#define SWD_F 2048 /* upper limit for match length */
|
||||
|
||||
#define SWD_BEST_OFF (LZO_MAX3(M2_MAX_LEN, M3_MAX_LEN, M4_MAX_LEN) + 1)
|
||||
|
||||
typedef struct {
|
||||
int init;
|
||||
|
||||
unsigned look; /* bytes in lookahead buffer */
|
||||
|
||||
unsigned m_len;
|
||||
unsigned m_off;
|
||||
|
||||
const uint8_t *bp;
|
||||
const uint8_t *ip;
|
||||
const uint8_t *in;
|
||||
const uint8_t *in_end;
|
||||
uint8_t *out;
|
||||
|
||||
unsigned r1_lit;
|
||||
|
||||
} lzo1x_999_t;
|
||||
|
||||
#define getbyte(c) ((c).ip < (c).in_end ? *((c).ip)++ : (-1))
|
||||
|
||||
/* lzo_swd.c -- sliding window dictionary */
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define SWD_UINT_MAX USHRT_MAX
|
||||
|
||||
#ifndef SWD_HSIZE
|
||||
# define SWD_HSIZE 16384
|
||||
#endif
|
||||
#ifndef SWD_MAX_CHAIN
|
||||
# define SWD_MAX_CHAIN 2048
|
||||
#endif
|
||||
|
||||
#define HEAD3(b, p) \
|
||||
( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) )
|
||||
|
||||
#if defined(LZO_UNALIGNED_OK_2)
|
||||
# define HEAD2(b,p) (* (uint16_t *) &(b[p]))
|
||||
#else
|
||||
# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
|
||||
#endif
|
||||
#define NIL2 SWD_UINT_MAX
|
||||
|
||||
typedef struct lzo_swd {
|
||||
/* public - "built-in" */
|
||||
|
||||
/* public - configuration */
|
||||
unsigned max_chain;
|
||||
int use_best_off;
|
||||
|
||||
/* public - output */
|
||||
unsigned m_len;
|
||||
unsigned m_off;
|
||||
unsigned look;
|
||||
int b_char;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
unsigned best_off[SWD_BEST_OFF];
|
||||
#endif
|
||||
|
||||
/* semi public */
|
||||
lzo1x_999_t *c;
|
||||
unsigned m_pos;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
unsigned best_pos[SWD_BEST_OFF];
|
||||
#endif
|
||||
|
||||
/* private */
|
||||
unsigned ip; /* input pointer (lookahead) */
|
||||
unsigned bp; /* buffer pointer */
|
||||
unsigned rp; /* remove pointer */
|
||||
|
||||
unsigned node_count;
|
||||
unsigned first_rp;
|
||||
|
||||
uint8_t b[SWD_N + SWD_F];
|
||||
uint8_t b_wrap[SWD_F]; /* must follow b */
|
||||
uint16_t head3[SWD_HSIZE];
|
||||
uint16_t succ3[SWD_N + SWD_F];
|
||||
uint16_t best3[SWD_N + SWD_F];
|
||||
uint16_t llen3[SWD_HSIZE];
|
||||
#ifdef HEAD2
|
||||
uint16_t head2[65536L];
|
||||
#endif
|
||||
} lzo_swd_t, *lzo_swd_p;
|
||||
|
||||
#define SIZEOF_LZO_SWD_T (sizeof(lzo_swd_t))
|
||||
|
||||
|
||||
/* Access macro for head3.
|
||||
* head3[key] may be uninitialized, but then its value will never be used.
|
||||
*/
|
||||
#define s_get_head3(s,key) s->head3[key]
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#define B_SIZE (SWD_N + SWD_F)
|
||||
|
||||
static int swd_init(lzo_swd_p s)
|
||||
{
|
||||
/* defaults */
|
||||
s->node_count = SWD_N;
|
||||
|
||||
memset(s->llen3, 0, sizeof(s->llen3[0]) * (unsigned)SWD_HSIZE);
|
||||
#ifdef HEAD2
|
||||
memset(s->head2, 0xff, sizeof(s->head2[0]) * 65536L);
|
||||
assert(s->head2[0] == NIL2);
|
||||
#endif
|
||||
|
||||
s->ip = 0;
|
||||
s->bp = s->ip;
|
||||
s->first_rp = s->ip;
|
||||
|
||||
assert(s->ip + SWD_F <= B_SIZE);
|
||||
s->look = (unsigned) (s->c->in_end - s->c->ip);
|
||||
if (s->look > 0) {
|
||||
if (s->look > SWD_F)
|
||||
s->look = SWD_F;
|
||||
memcpy(&s->b[s->ip],s->c->ip,s->look);
|
||||
s->c->ip += s->look;
|
||||
s->ip += s->look;
|
||||
}
|
||||
if (s->ip == B_SIZE)
|
||||
s->ip = 0;
|
||||
|
||||
s->rp = s->first_rp;
|
||||
if (s->rp >= s->node_count)
|
||||
s->rp -= s->node_count;
|
||||
else
|
||||
s->rp += B_SIZE - s->node_count;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
#define swd_pos2off(s,pos) \
|
||||
(s->bp > (pos) ? s->bp - (pos) : B_SIZE - ((pos) - s->bp))
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_getbyte(lzo_swd_p s)
|
||||
{
|
||||
int c;
|
||||
|
||||
if ((c = getbyte(*(s->c))) < 0) {
|
||||
if (s->look > 0)
|
||||
--s->look;
|
||||
} else {
|
||||
s->b[s->ip] = c;
|
||||
if (s->ip < SWD_F)
|
||||
s->b_wrap[s->ip] = c;
|
||||
}
|
||||
if (++s->ip == B_SIZE)
|
||||
s->ip = 0;
|
||||
if (++s->bp == B_SIZE)
|
||||
s->bp = 0;
|
||||
if (++s->rp == B_SIZE)
|
||||
s->rp = 0;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
// remove node from lists
|
||||
************************************************************************/
|
||||
static void swd_remove_node(lzo_swd_p s, unsigned node)
|
||||
{
|
||||
if (s->node_count == 0) {
|
||||
unsigned key;
|
||||
|
||||
key = HEAD3(s->b,node);
|
||||
assert(s->llen3[key] > 0);
|
||||
--s->llen3[key];
|
||||
|
||||
#ifdef HEAD2
|
||||
key = HEAD2(s->b,node);
|
||||
assert(s->head2[key] != NIL2);
|
||||
if ((unsigned) s->head2[key] == node)
|
||||
s->head2[key] = NIL2;
|
||||
#endif
|
||||
} else
|
||||
--s->node_count;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_accept(lzo_swd_p s, unsigned n)
|
||||
{
|
||||
assert(n <= s->look);
|
||||
|
||||
while (n--) {
|
||||
unsigned key;
|
||||
|
||||
swd_remove_node(s,s->rp);
|
||||
|
||||
/* add bp into HEAD3 */
|
||||
key = HEAD3(s->b,s->bp);
|
||||
s->succ3[s->bp] = s_get_head3(s,key);
|
||||
s->head3[key] = s->bp;
|
||||
s->best3[s->bp] = SWD_F + 1;
|
||||
s->llen3[key]++;
|
||||
assert(s->llen3[key] <= SWD_N);
|
||||
|
||||
#ifdef HEAD2
|
||||
/* add bp into HEAD2 */
|
||||
key = HEAD2(s->b,s->bp);
|
||||
s->head2[key] = s->bp;
|
||||
#endif
|
||||
|
||||
swd_getbyte(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_search(lzo_swd_p s, unsigned node, unsigned cnt)
|
||||
{
|
||||
const uint8_t *p1;
|
||||
const uint8_t *p2;
|
||||
const uint8_t *px;
|
||||
unsigned m_len = s->m_len;
|
||||
const uint8_t *b = s->b;
|
||||
const uint8_t *bp = s->b + s->bp;
|
||||
const uint8_t *bx = s->b + s->bp + s->look;
|
||||
unsigned char scan_end1;
|
||||
|
||||
assert(s->m_len > 0);
|
||||
|
||||
scan_end1 = bp[m_len - 1];
|
||||
for ( ; cnt-- > 0; node = s->succ3[node]) {
|
||||
p1 = bp;
|
||||
p2 = b + node;
|
||||
px = bx;
|
||||
|
||||
assert(m_len < s->look);
|
||||
|
||||
if (p2[m_len - 1] == scan_end1 &&
|
||||
p2[m_len] == p1[m_len] &&
|
||||
p2[0] == p1[0] &&
|
||||
p2[1] == p1[1]) {
|
||||
unsigned i;
|
||||
assert(lzo_memcmp(bp,&b[node],3) == 0);
|
||||
|
||||
p1 += 2; p2 += 2;
|
||||
do {} while (++p1 < px && *p1 == *++p2);
|
||||
i = p1-bp;
|
||||
|
||||
assert(lzo_memcmp(bp,&b[node],i) == 0);
|
||||
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (i < SWD_BEST_OFF) {
|
||||
if (s->best_pos[i] == 0)
|
||||
s->best_pos[i] = node + 1;
|
||||
}
|
||||
#endif
|
||||
if (i > m_len) {
|
||||
s->m_len = m_len = i;
|
||||
s->m_pos = node;
|
||||
if (m_len == s->look)
|
||||
return;
|
||||
if (m_len >= SWD_F)
|
||||
return;
|
||||
if (m_len > (unsigned) s->best3[node])
|
||||
return;
|
||||
scan_end1 = bp[m_len - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#ifdef HEAD2
|
||||
|
||||
static int swd_search2(lzo_swd_p s)
|
||||
{
|
||||
unsigned key;
|
||||
|
||||
assert(s->look >= 2);
|
||||
assert(s->m_len > 0);
|
||||
|
||||
key = s->head2[ HEAD2(s->b,s->bp) ];
|
||||
if (key == NIL2)
|
||||
return 0;
|
||||
assert(lzo_memcmp(&s->b[s->bp],&s->b[key],2) == 0);
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (s->best_pos[2] == 0)
|
||||
s->best_pos[2] = key + 1;
|
||||
#endif
|
||||
|
||||
if (s->m_len < 2) {
|
||||
s->m_len = 2;
|
||||
s->m_pos = key;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static void swd_findbest(lzo_swd_p s)
|
||||
{
|
||||
unsigned key;
|
||||
unsigned cnt, node;
|
||||
unsigned len;
|
||||
|
||||
assert(s->m_len > 0);
|
||||
|
||||
/* get current head, add bp into HEAD3 */
|
||||
key = HEAD3(s->b,s->bp);
|
||||
node = s->succ3[s->bp] = s_get_head3(s,key);
|
||||
cnt = s->llen3[key]++;
|
||||
assert(s->llen3[key] <= SWD_N + SWD_F);
|
||||
if (cnt > s->max_chain)
|
||||
cnt = s->max_chain;
|
||||
s->head3[key] = s->bp;
|
||||
|
||||
s->b_char = s->b[s->bp];
|
||||
len = s->m_len;
|
||||
if (s->m_len >= s->look) {
|
||||
if (s->look == 0)
|
||||
s->b_char = -1;
|
||||
s->m_off = 0;
|
||||
s->best3[s->bp] = SWD_F + 1;
|
||||
} else {
|
||||
#ifdef HEAD2
|
||||
if (swd_search2(s))
|
||||
#endif
|
||||
if (s->look >= 3)
|
||||
swd_search(s,node,cnt);
|
||||
if (s->m_len > len)
|
||||
s->m_off = swd_pos2off(s,s->m_pos);
|
||||
s->best3[s->bp] = s->m_len;
|
||||
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (s->use_best_off) {
|
||||
int i;
|
||||
for (i = 2; i < SWD_BEST_OFF; i++)
|
||||
if (s->best_pos[i] > 0)
|
||||
s->best_off[i] = swd_pos2off(s,s->best_pos[i]-1);
|
||||
else
|
||||
s->best_off[i] = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
swd_remove_node(s,s->rp);
|
||||
|
||||
#ifdef HEAD2
|
||||
/* add bp into HEAD2 */
|
||||
key = HEAD2(s->b,s->bp);
|
||||
s->head2[key] = s->bp;
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef HEAD3
|
||||
#undef HEAD2
|
||||
#undef s_get_head3
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int init_match(lzo1x_999_t *c, lzo_swd_p s, uint32_t use_best_off)
|
||||
{
|
||||
int r;
|
||||
|
||||
assert(!c->init);
|
||||
c->init = 1;
|
||||
|
||||
s->c = c;
|
||||
|
||||
r = swd_init(s);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
s->use_best_off = use_best_off;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int find_match(lzo1x_999_t *c, lzo_swd_p s,
|
||||
unsigned this_len, unsigned skip)
|
||||
{
|
||||
assert(c->init);
|
||||
|
||||
if (skip > 0) {
|
||||
assert(this_len >= skip);
|
||||
swd_accept(s, this_len - skip);
|
||||
} else {
|
||||
assert(this_len <= 1);
|
||||
}
|
||||
|
||||
s->m_len = 1;
|
||||
s->m_len = 1;
|
||||
#ifdef SWD_BEST_OFF
|
||||
if (s->use_best_off)
|
||||
memset(s->best_pos,0,sizeof(s->best_pos));
|
||||
#endif
|
||||
swd_findbest(s);
|
||||
c->m_len = s->m_len;
|
||||
c->m_off = s->m_off;
|
||||
|
||||
swd_getbyte(s);
|
||||
|
||||
if (s->b_char < 0) {
|
||||
c->look = 0;
|
||||
c->m_len = 0;
|
||||
} else {
|
||||
c->look = s->look + 1;
|
||||
}
|
||||
c->bp = c->ip - c->look;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
/* 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,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
unsigned max_lazy,
|
||||
unsigned max_chain,
|
||||
uint32_t use_best_off);
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static uint8_t *code_match(lzo1x_999_t *c,
|
||||
uint8_t *op, unsigned m_len, unsigned m_off)
|
||||
{
|
||||
assert(op > c->out);
|
||||
if (m_len == 2) {
|
||||
assert(m_off <= M1_MAX_OFFSET);
|
||||
assert(c->r1_lit > 0); assert(c->r1_lit < 4);
|
||||
m_off -= 1;
|
||||
*op++ = M1_MARKER | ((m_off & 3) << 2);
|
||||
*op++ = m_off >> 2;
|
||||
} else if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET) {
|
||||
assert(m_len >= 3);
|
||||
m_off -= 1;
|
||||
*op++ = ((m_len - 1) << 5) | ((m_off & 7) << 2);
|
||||
*op++ = m_off >> 3;
|
||||
assert(op[-2] >= M2_MARKER);
|
||||
} else if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && c->r1_lit >= 4) {
|
||||
assert(m_len == 3);
|
||||
assert(m_off > M2_MAX_OFFSET);
|
||||
m_off -= 1 + M2_MAX_OFFSET;
|
||||
*op++ = M1_MARKER | ((m_off & 3) << 2);
|
||||
*op++ = m_off >> 2;
|
||||
} else if (m_off <= M3_MAX_OFFSET) {
|
||||
assert(m_len >= 3);
|
||||
m_off -= 1;
|
||||
if (m_len <= M3_MAX_LEN)
|
||||
*op++ = M3_MARKER | (m_len - 2);
|
||||
else {
|
||||
m_len -= M3_MAX_LEN;
|
||||
*op++ = M3_MARKER | 0;
|
||||
while (m_len > 255)
|
||||
{
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = m_len;
|
||||
}
|
||||
*op++ = m_off << 2;
|
||||
*op++ = m_off >> 6;
|
||||
} else {
|
||||
unsigned k;
|
||||
|
||||
assert(m_len >= 3);
|
||||
assert(m_off > 0x4000); assert(m_off <= 0xbfff);
|
||||
m_off -= 0x4000;
|
||||
k = (m_off & 0x4000) >> 11;
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
*op++ = M4_MARKER | k | (m_len - 2);
|
||||
else {
|
||||
m_len -= M4_MAX_LEN;
|
||||
*op++ = M4_MARKER | k | 0;
|
||||
while (m_len > 255)
|
||||
{
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = m_len;
|
||||
}
|
||||
*op++ = m_off << 2;
|
||||
*op++ = m_off >> 6;
|
||||
}
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t *STORE_RUN(lzo1x_999_t *c, uint8_t *op,
|
||||
const uint8_t *ii, unsigned t)
|
||||
{
|
||||
if (op == c->out && t <= 238) {
|
||||
*op++ = 17 + t;
|
||||
} else if (t <= 3) {
|
||||
op[-2] |= t;
|
||||
} else if (t <= 18) {
|
||||
*op++ = t - 3;
|
||||
} else {
|
||||
unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = tt;
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t *code_run(lzo1x_999_t *c, uint8_t *op, const uint8_t *ii,
|
||||
unsigned lit)
|
||||
{
|
||||
if (lit > 0) {
|
||||
assert(m_len >= 2);
|
||||
op = STORE_RUN(c,op,ii,lit);
|
||||
} else {
|
||||
assert(m_len >= 3);
|
||||
}
|
||||
c->r1_lit = lit;
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int len_of_coded_match(unsigned m_len, unsigned m_off, unsigned lit)
|
||||
{
|
||||
int n = 4;
|
||||
|
||||
if (m_len < 2)
|
||||
return -1;
|
||||
if (m_len == 2)
|
||||
return (m_off <= M1_MAX_OFFSET && lit > 0 && lit < 4) ? 2 : -1;
|
||||
if (m_len <= M2_MAX_LEN && m_off <= M2_MAX_OFFSET)
|
||||
return 2;
|
||||
if (m_len == M2_MIN_LEN && m_off <= MX_MAX_OFFSET && lit >= 4)
|
||||
return 2;
|
||||
if (m_off <= M3_MAX_OFFSET) {
|
||||
if (m_len <= M3_MAX_LEN)
|
||||
return 3;
|
||||
m_len -= M3_MAX_LEN;
|
||||
} else if (m_off <= M4_MAX_OFFSET) {
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
return 3;
|
||||
m_len -= M4_MAX_LEN;
|
||||
} else
|
||||
return -1;
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
static int min_gain(unsigned ahead, unsigned lit1,
|
||||
unsigned lit2, int l1, int l2, int l3)
|
||||
{
|
||||
int lazy_match_min_gain = 0;
|
||||
|
||||
assert (ahead >= 1);
|
||||
lazy_match_min_gain += ahead;
|
||||
|
||||
if (lit1 <= 3)
|
||||
lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
|
||||
else if (lit1 <= 18)
|
||||
lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
|
||||
|
||||
lazy_match_min_gain += (l2 - l1) * 2;
|
||||
if (l3 > 0)
|
||||
lazy_match_min_gain -= (ahead - l3) * 2;
|
||||
|
||||
if (lazy_match_min_gain < 0)
|
||||
lazy_match_min_gain = 0;
|
||||
|
||||
return lazy_match_min_gain;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
#if defined(SWD_BEST_OFF)
|
||||
|
||||
static void better_match(const lzo_swd_p swd,
|
||||
unsigned *m_len, unsigned *m_off)
|
||||
{
|
||||
|
||||
if (*m_len <= M2_MIN_LEN)
|
||||
return;
|
||||
|
||||
if (*m_off <= M2_MAX_OFFSET)
|
||||
return;
|
||||
|
||||
/* M3/M4 -> M2 */
|
||||
if (*m_off > M2_MAX_OFFSET &&
|
||||
*m_len >= M2_MIN_LEN + 1 && *m_len <= M2_MAX_LEN + 1 &&
|
||||
swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M2_MAX_OFFSET)
|
||||
{
|
||||
*m_len = *m_len - 1;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
return;
|
||||
}
|
||||
|
||||
/* M4 -> M2 */
|
||||
if (*m_off > M3_MAX_OFFSET &&
|
||||
*m_len >= M4_MAX_LEN + 1 && *m_len <= M2_MAX_LEN + 2 &&
|
||||
swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= M2_MAX_OFFSET)
|
||||
{
|
||||
*m_len = *m_len - 2;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
return;
|
||||
}
|
||||
/* M4 -> M3 */
|
||||
if (*m_off > M3_MAX_OFFSET &&
|
||||
*m_len >= M4_MAX_LEN + 1 && *m_len <= M3_MAX_LEN + 1 &&
|
||||
swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= M3_MAX_OFFSET)
|
||||
{
|
||||
*m_len = *m_len - 1;
|
||||
*m_off = swd->best_off[*m_len];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
static int lzo1x_999_compress_internal(const uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
unsigned good_length,
|
||||
unsigned max_lazy,
|
||||
unsigned max_chain,
|
||||
uint32_t use_best_off)
|
||||
{
|
||||
uint8_t *op;
|
||||
const uint8_t *ii;
|
||||
unsigned lit;
|
||||
unsigned m_len, m_off;
|
||||
lzo1x_999_t cc;
|
||||
lzo1x_999_t * const c = &cc;
|
||||
lzo_swd_p const swd = (lzo_swd_p) wrkmem;
|
||||
int r;
|
||||
|
||||
c->init = 0;
|
||||
c->ip = c->in = in;
|
||||
c->in_end = in + in_len;
|
||||
c->out = out;
|
||||
|
||||
op = out;
|
||||
ii = c->ip; /* point to start of literal run */
|
||||
lit = 0;
|
||||
c->r1_lit = 0;
|
||||
|
||||
r = init_match(c, swd, use_best_off);
|
||||
if (r != 0)
|
||||
return r;
|
||||
swd->max_chain = max_chain;
|
||||
|
||||
r = find_match(c, swd, 0, 0);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
while (c->look > 0) {
|
||||
unsigned ahead;
|
||||
unsigned max_ahead;
|
||||
int l1, l2, l3;
|
||||
|
||||
m_len = c->m_len;
|
||||
m_off = c->m_off;
|
||||
|
||||
assert(c->bp == c->ip - c->look);
|
||||
assert(c->bp >= in);
|
||||
if (lit == 0)
|
||||
ii = c->bp;
|
||||
assert(ii + lit == c->bp);
|
||||
assert(swd->b_char == *(c->bp));
|
||||
|
||||
if ( m_len < 2 ||
|
||||
(m_len == 2 && (m_off > M1_MAX_OFFSET || lit == 0 || lit >= 4)) ||
|
||||
/* Do not accept this match for compressed-data compatibility
|
||||
* with LZO v1.01 and before
|
||||
* [ might be a problem for decompress() and optimize() ]
|
||||
*/
|
||||
(m_len == 2 && op == out) ||
|
||||
(op == out && lit == 0))
|
||||
{
|
||||
/* a literal */
|
||||
m_len = 0;
|
||||
}
|
||||
else if (m_len == M2_MIN_LEN) {
|
||||
/* compression ratio improves if we code a literal in some cases */
|
||||
if (m_off > MX_MAX_OFFSET && lit >= 4)
|
||||
m_len = 0;
|
||||
}
|
||||
|
||||
if (m_len == 0) {
|
||||
/* a literal */
|
||||
lit++;
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c,swd,1,0);
|
||||
assert(r == 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* a match */
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (swd->use_best_off)
|
||||
better_match(swd,&m_len,&m_off);
|
||||
#endif
|
||||
|
||||
/* shall we try a lazy match ? */
|
||||
ahead = 0;
|
||||
if (m_len >= max_lazy) {
|
||||
/* no */
|
||||
l1 = 0;
|
||||
max_ahead = 0;
|
||||
} else {
|
||||
/* yes, try a lazy match */
|
||||
l1 = len_of_coded_match(m_len,m_off,lit);
|
||||
assert(l1 > 0);
|
||||
max_ahead = LZO_MIN(2, (unsigned)l1 - 1);
|
||||
}
|
||||
|
||||
|
||||
while (ahead < max_ahead && c->look > m_len) {
|
||||
int lazy_match_min_gain;
|
||||
|
||||
if (m_len >= good_length)
|
||||
swd->max_chain = max_chain >> 2;
|
||||
else
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c,swd,1,0);
|
||||
ahead++;
|
||||
|
||||
assert(r == 0);
|
||||
assert(c->look > 0);
|
||||
assert(ii + lit + ahead == c->bp);
|
||||
|
||||
if (c->m_len < m_len)
|
||||
continue;
|
||||
if (c->m_len == m_len && c->m_off >= m_off)
|
||||
continue;
|
||||
#if defined(SWD_BEST_OFF)
|
||||
if (swd->use_best_off)
|
||||
better_match(swd,&c->m_len,&c->m_off);
|
||||
#endif
|
||||
l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
|
||||
if (l2 < 0)
|
||||
continue;
|
||||
|
||||
/* compressed-data compatibility [see above] */
|
||||
l3 = (op == out) ? -1 : len_of_coded_match(ahead,m_off,lit);
|
||||
|
||||
lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
|
||||
if (c->m_len >= m_len + lazy_match_min_gain) {
|
||||
if (l3 > 0) {
|
||||
/* code previous run */
|
||||
op = code_run(c,op,ii,lit);
|
||||
lit = 0;
|
||||
/* code shortened match */
|
||||
op = code_match(c,op,ahead,m_off);
|
||||
} else {
|
||||
lit += ahead;
|
||||
assert(ii + lit == c->bp);
|
||||
}
|
||||
goto lazy_match_done;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ii + lit + ahead == c->bp);
|
||||
|
||||
/* 1 - code run */
|
||||
op = code_run(c,op,ii,lit);
|
||||
lit = 0;
|
||||
|
||||
/* 2 - code match */
|
||||
op = code_match(c,op,m_len,m_off);
|
||||
swd->max_chain = max_chain;
|
||||
r = find_match(c,swd,m_len,1+ahead);
|
||||
assert(r == 0);
|
||||
|
||||
lazy_match_done: ;
|
||||
}
|
||||
|
||||
/* store final run */
|
||||
if (lit > 0)
|
||||
op = STORE_RUN(c,op,ii,lit);
|
||||
|
||||
#if defined(LZO_EOF_CODE)
|
||||
*op++ = M4_MARKER | 1;
|
||||
*op++ = 0;
|
||||
*op++ = 0;
|
||||
#endif
|
||||
|
||||
*out_len = op - out;
|
||||
|
||||
return LZO_E_OK;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
//
|
||||
************************************************************************/
|
||||
int lzo1x_999_compress_level(const uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void *wrkmem,
|
||||
int compression_level)
|
||||
{
|
||||
static const struct {
|
||||
uint16_t good_length;
|
||||
uint16_t max_lazy;
|
||||
uint16_t max_chain;
|
||||
uint16_t use_best_off;
|
||||
} c[3] = {
|
||||
{ 8, 32, 256, 0 },
|
||||
{ 32, 128, 2048, 1 },
|
||||
{ SWD_F, SWD_F, 4096, 1 } /* max. compression */
|
||||
};
|
||||
|
||||
if (compression_level < 7 || compression_level > 9)
|
||||
return LZO_E_ERROR;
|
||||
|
||||
compression_level -= 7;
|
||||
return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
|
||||
c[compression_level].good_length,
|
||||
c[compression_level].max_lazy,
|
||||
c[compression_level].max_chain,
|
||||
c[compression_level].use_best_off);
|
||||
}
|
||||
@@ -1,296 +0,0 @@
|
||||
/* implementation of the LZO1[XY]-1 compression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/***********************************************************************
|
||||
// compress a block of data.
|
||||
************************************************************************/
|
||||
static NOINLINE unsigned
|
||||
do_compress(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem)
|
||||
{
|
||||
register const uint8_t* ip;
|
||||
uint8_t* op;
|
||||
const uint8_t* const in_end = in + in_len;
|
||||
const uint8_t* const ip_end = in + in_len - M2_MAX_LEN - 5;
|
||||
const uint8_t* ii;
|
||||
const void* *const dict = (const void**) wrkmem;
|
||||
|
||||
op = out;
|
||||
ip = in;
|
||||
ii = ip;
|
||||
|
||||
ip += 4;
|
||||
for (;;) {
|
||||
register const uint8_t* m_pos;
|
||||
unsigned m_off;
|
||||
unsigned m_len;
|
||||
unsigned dindex;
|
||||
|
||||
D_INDEX1(dindex,ip);
|
||||
GINDEX(m_pos,m_off,dict,dindex,in);
|
||||
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
||||
goto literal;
|
||||
#if 1
|
||||
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
||||
goto try_match;
|
||||
D_INDEX2(dindex,ip);
|
||||
#endif
|
||||
GINDEX(m_pos,m_off,dict,dindex,in);
|
||||
if (LZO_CHECK_MPOS_NON_DET(m_pos,m_off,in,ip,M4_MAX_OFFSET))
|
||||
goto literal;
|
||||
if (m_off <= M2_MAX_OFFSET || m_pos[3] == ip[3])
|
||||
goto try_match;
|
||||
goto literal;
|
||||
|
||||
try_match:
|
||||
#if 1 && defined(LZO_UNALIGNED_OK_2)
|
||||
if (* (const lzo_ushortp) m_pos != * (const lzo_ushortp) ip)
|
||||
#else
|
||||
if (m_pos[0] != ip[0] || m_pos[1] != ip[1])
|
||||
#endif
|
||||
{
|
||||
} else {
|
||||
if (m_pos[2] == ip[2]) {
|
||||
#if 0
|
||||
if (m_off <= M2_MAX_OFFSET)
|
||||
goto match;
|
||||
if (lit <= 3)
|
||||
goto match;
|
||||
if (lit == 3) { /* better compression, but slower */
|
||||
assert(op - 2 > out); op[-2] |= (uint8_t)(3);
|
||||
*op++ = *ii++; *op++ = *ii++; *op++ = *ii++;
|
||||
goto code_match;
|
||||
}
|
||||
if (m_pos[3] == ip[3])
|
||||
#endif
|
||||
goto match;
|
||||
}
|
||||
else {
|
||||
/* still need a better way for finding M1 matches */
|
||||
#if 0
|
||||
/* a M1 match */
|
||||
#if 0
|
||||
if (m_off <= M1_MAX_OFFSET && lit > 0 && lit <= 3)
|
||||
#else
|
||||
if (m_off <= M1_MAX_OFFSET && lit == 3)
|
||||
#endif
|
||||
{
|
||||
register unsigned t;
|
||||
|
||||
t = lit;
|
||||
assert(op - 2 > out); op[-2] |= (uint8_t)(t);
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
assert(ii == ip);
|
||||
m_off -= 1;
|
||||
*op++ = (uint8_t)(M1_MARKER | ((m_off & 3) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 2);
|
||||
ip += 2;
|
||||
goto match_done;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* a literal */
|
||||
literal:
|
||||
UPDATE_I(dict, 0, dindex, ip, in);
|
||||
++ip;
|
||||
if (ip >= ip_end)
|
||||
break;
|
||||
continue;
|
||||
|
||||
/* a match */
|
||||
match:
|
||||
UPDATE_I(dict, 0, dindex, ip, in);
|
||||
/* store current literal run */
|
||||
if (pd(ip, ii) > 0) {
|
||||
register unsigned t = pd(ip, ii);
|
||||
|
||||
if (t <= 3) {
|
||||
assert(op - 2 > out);
|
||||
op[-2] |= (uint8_t)(t);
|
||||
}
|
||||
else if (t <= 18)
|
||||
*op++ = (uint8_t)(t - 3);
|
||||
else {
|
||||
register unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = (uint8_t)(tt);
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
}
|
||||
|
||||
/* code the match */
|
||||
assert(ii == ip);
|
||||
ip += 3;
|
||||
if (m_pos[3] != *ip++ || m_pos[4] != *ip++ || m_pos[5] != *ip++
|
||||
|| m_pos[6] != *ip++ || m_pos[7] != *ip++ || m_pos[8] != *ip++
|
||||
#ifdef LZO1Y
|
||||
|| m_pos[ 9] != *ip++ || m_pos[10] != *ip++ || m_pos[11] != *ip++
|
||||
|| m_pos[12] != *ip++ || m_pos[13] != *ip++ || m_pos[14] != *ip++
|
||||
#endif
|
||||
) {
|
||||
--ip;
|
||||
m_len = pd(ip, ii);
|
||||
assert(m_len >= 3);
|
||||
assert(m_len <= M2_MAX_LEN);
|
||||
|
||||
if (m_off <= M2_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
#if defined(LZO1X)
|
||||
*op++ = (uint8_t)(((m_len - 1) << 5) | ((m_off & 7) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 3);
|
||||
#elif defined(LZO1Y)
|
||||
*op++ = (uint8_t)(((m_len + 1) << 4) | ((m_off & 3) << 2));
|
||||
*op++ = (uint8_t)(m_off >> 2);
|
||||
#endif
|
||||
}
|
||||
else if (m_off <= M3_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
|
||||
goto m3_m4_offset;
|
||||
} else {
|
||||
#if defined(LZO1X)
|
||||
m_off -= 0x4000;
|
||||
assert(m_off > 0);
|
||||
assert(m_off <= 0x7fff);
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
||||
goto m3_m4_offset;
|
||||
#elif defined(LZO1Y)
|
||||
goto m4_match;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
{
|
||||
const uint8_t* end = in_end;
|
||||
const uint8_t* m = m_pos + M2_MAX_LEN + 1;
|
||||
while (ip < end && *m == *ip)
|
||||
m++, ip++;
|
||||
m_len = pd(ip, ii);
|
||||
}
|
||||
assert(m_len > M2_MAX_LEN);
|
||||
|
||||
if (m_off <= M3_MAX_OFFSET) {
|
||||
m_off -= 1;
|
||||
if (m_len <= 33)
|
||||
*op++ = (uint8_t)(M3_MARKER | (m_len - 2));
|
||||
else {
|
||||
m_len -= 33;
|
||||
*op++ = M3_MARKER | 0;
|
||||
goto m3_m4_len;
|
||||
}
|
||||
} else {
|
||||
#if defined(LZO1Y)
|
||||
m4_match:
|
||||
#endif
|
||||
m_off -= 0x4000;
|
||||
assert(m_off > 0);
|
||||
assert(m_off <= 0x7fff);
|
||||
if (m_len <= M4_MAX_LEN)
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11) | (m_len - 2));
|
||||
else {
|
||||
m_len -= M4_MAX_LEN;
|
||||
*op++ = (uint8_t)(M4_MARKER | ((m_off & 0x4000) >> 11));
|
||||
m3_m4_len:
|
||||
while (m_len > 255) {
|
||||
m_len -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(m_len > 0);
|
||||
*op++ = (uint8_t)(m_len);
|
||||
}
|
||||
}
|
||||
m3_m4_offset:
|
||||
*op++ = (uint8_t)((m_off & 63) << 2);
|
||||
*op++ = (uint8_t)(m_off >> 6);
|
||||
}
|
||||
#if 0
|
||||
match_done:
|
||||
#endif
|
||||
ii = ip;
|
||||
if (ip >= ip_end)
|
||||
break;
|
||||
}
|
||||
|
||||
*out_len = pd(op, out);
|
||||
return pd(in_end, ii);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
// public entry point
|
||||
************************************************************************/
|
||||
int DO_COMPRESS(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem)
|
||||
{
|
||||
uint8_t* op = out;
|
||||
unsigned t;
|
||||
|
||||
if (in_len <= M2_MAX_LEN + 5)
|
||||
t = in_len;
|
||||
else {
|
||||
t = do_compress(in,in_len,op,out_len,wrkmem);
|
||||
op += *out_len;
|
||||
}
|
||||
|
||||
if (t > 0) {
|
||||
const uint8_t* ii = in + in_len - t;
|
||||
|
||||
if (op == out && t <= 238)
|
||||
*op++ = (uint8_t)(17 + t);
|
||||
else if (t <= 3)
|
||||
op[-2] |= (uint8_t)(t);
|
||||
else if (t <= 18)
|
||||
*op++ = (uint8_t)(t - 3);
|
||||
else {
|
||||
unsigned tt = t - 18;
|
||||
|
||||
*op++ = 0;
|
||||
while (tt > 255) {
|
||||
tt -= 255;
|
||||
*op++ = 0;
|
||||
}
|
||||
assert(tt > 0);
|
||||
*op++ = (uint8_t)(tt);
|
||||
}
|
||||
do *op++ = *ii++; while (--t > 0);
|
||||
}
|
||||
|
||||
*op++ = M4_MARKER | 1;
|
||||
*op++ = 0;
|
||||
*op++ = 0;
|
||||
|
||||
*out_len = pd(op, out);
|
||||
return 0; /*LZO_E_OK*/
|
||||
}
|
||||
@@ -1,420 +0,0 @@
|
||||
/* implementation of the LZO1X decompression algorithm
|
||||
|
||||
This file is part of the LZO real-time data compression library.
|
||||
|
||||
Copyright (C) 1996..2008 Markus Franz Xaver Johannes Oberhumer
|
||||
All Rights Reserved.
|
||||
|
||||
Markus F.X.J. Oberhumer <markus@oberhumer.com>
|
||||
http://www.oberhumer.com/opensource/lzo/
|
||||
|
||||
The LZO library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
The LZO library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the LZO library; see the file COPYING.
|
||||
If not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "liblzo.h"
|
||||
|
||||
/***********************************************************************
|
||||
// decompress a block of data.
|
||||
************************************************************************/
|
||||
/* safe decompression with overrun testing */
|
||||
int lzo1x_decompress_safe(const uint8_t* in, unsigned in_len,
|
||||
uint8_t* out, unsigned* out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
register uint8_t* op;
|
||||
register const uint8_t* ip;
|
||||
register unsigned t;
|
||||
#if defined(COPY_DICT)
|
||||
unsigned m_off;
|
||||
const uint8_t* dict_end;
|
||||
#else
|
||||
register const uint8_t* m_pos = NULL; /* possibly not needed */
|
||||
#endif
|
||||
const uint8_t* const ip_end = in + in_len;
|
||||
#if defined(HAVE_ANY_OP)
|
||||
uint8_t* const op_end = out + *out_len;
|
||||
#endif
|
||||
#if defined(LZO1Z)
|
||||
unsigned last_m_off = 0;
|
||||
#endif
|
||||
|
||||
// LZO_UNUSED(wrkmem);
|
||||
|
||||
#if defined(COPY_DICT)
|
||||
if (dict) {
|
||||
if (dict_len > M4_MAX_OFFSET) {
|
||||
dict += dict_len - M4_MAX_OFFSET;
|
||||
dict_len = M4_MAX_OFFSET;
|
||||
}
|
||||
dict_end = dict + dict_len;
|
||||
} else {
|
||||
dict_len = 0;
|
||||
dict_end = NULL;
|
||||
}
|
||||
#endif /* COPY_DICT */
|
||||
|
||||
*out_len = 0;
|
||||
|
||||
op = out;
|
||||
ip = in;
|
||||
|
||||
if (*ip > 17) {
|
||||
t = *ip++ - 17;
|
||||
if (t < 4)
|
||||
goto match_next;
|
||||
assert(t > 0); NEED_OP(t); NEED_IP(t+1);
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
goto first_literal_run;
|
||||
}
|
||||
|
||||
while (TEST_IP && TEST_OP) {
|
||||
t = *ip++;
|
||||
if (t >= 16)
|
||||
goto match;
|
||||
/* a literal run */
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
t += 15 + *ip++;
|
||||
}
|
||||
/* copy literals */
|
||||
assert(t > 0);
|
||||
NEED_OP(t+3);
|
||||
NEED_IP(t+4);
|
||||
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
if (PTR_ALIGNED2_4(op, ip))
|
||||
# endif
|
||||
{
|
||||
COPY4(op, ip);
|
||||
op += 4;
|
||||
ip += 4;
|
||||
if (--t > 0) {
|
||||
if (t >= 4) {
|
||||
do {
|
||||
COPY4(op, ip);
|
||||
op += 4;
|
||||
ip += 4;
|
||||
t -= 4;
|
||||
} while (t >= 4);
|
||||
if (t > 0)
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
} else {
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
else
|
||||
# endif
|
||||
#endif
|
||||
#if !defined(LZO_UNALIGNED_OK_4)
|
||||
{
|
||||
*op++ = *ip++;
|
||||
*op++ = *ip++;
|
||||
*op++ = *ip++;
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
first_literal_run:
|
||||
t = *ip++;
|
||||
if (t >= 16)
|
||||
goto match;
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = (1 + M2_MAX_OFFSET) + (t >> 2) + (*ip++ << 2);
|
||||
#endif
|
||||
NEED_OP(3);
|
||||
t = 3; COPY_DICT(t,m_off)
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
t = (1 + M2_MAX_OFFSET) + (t << 6) + (*ip++ >> 2);
|
||||
m_pos = op - t;
|
||||
last_m_off = t;
|
||||
#else
|
||||
m_pos = op - (1 + M2_MAX_OFFSET);
|
||||
m_pos -= t >> 2;
|
||||
m_pos -= *ip++ << 2;
|
||||
#endif
|
||||
TEST_LB(m_pos); NEED_OP(3);
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos;
|
||||
#endif /* COPY_DICT */
|
||||
goto match_done;
|
||||
|
||||
/* handle matches */
|
||||
do {
|
||||
match:
|
||||
if (t >= 64) { /* a M2 match */
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1X)
|
||||
m_off = 1 + ((t >> 2) & 7) + (*ip++ << 3);
|
||||
t = (t >> 5) - 1;
|
||||
#elif defined(LZO1Y)
|
||||
m_off = 1 + ((t >> 2) & 3) + (*ip++ << 2);
|
||||
t = (t >> 4) - 3;
|
||||
#elif defined(LZO1Z)
|
||||
m_off = t & 0x1f;
|
||||
if (m_off >= 0x1c)
|
||||
m_off = last_m_off;
|
||||
else {
|
||||
m_off = 1 + (m_off << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
}
|
||||
t = (t >> 5) - 1;
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1X)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (t >> 2) & 7;
|
||||
m_pos -= *ip++ << 3;
|
||||
t = (t >> 5) - 1;
|
||||
#elif defined(LZO1Y)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (t >> 2) & 3;
|
||||
m_pos -= *ip++ << 2;
|
||||
t = (t >> 4) - 3;
|
||||
#elif defined(LZO1Z)
|
||||
{
|
||||
unsigned off = t & 0x1f;
|
||||
m_pos = op;
|
||||
if (off >= 0x1c) {
|
||||
assert(last_m_off > 0);
|
||||
m_pos -= last_m_off;
|
||||
} else {
|
||||
off = 1 + (off << 6) + (*ip++ >> 2);
|
||||
m_pos -= off;
|
||||
last_m_off = off;
|
||||
}
|
||||
}
|
||||
t = (t >> 5) - 1;
|
||||
#endif
|
||||
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
|
||||
goto copy_match;
|
||||
#endif /* COPY_DICT */
|
||||
}
|
||||
else if (t >= 32) { /* a M3 match */
|
||||
t &= 31;
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
t += 31 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = 1 + (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
{
|
||||
unsigned off = 1 + (ip[0] << 6) + (ip[1] >> 2);
|
||||
m_pos = op - off;
|
||||
last_m_off = off;
|
||||
}
|
||||
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
|
||||
m_pos = op - 1;
|
||||
m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
||||
#else
|
||||
m_pos = op - 1;
|
||||
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
#endif /* COPY_DICT */
|
||||
ip += 2;
|
||||
}
|
||||
else if (t >= 16) { /* a M4 match */
|
||||
#if defined(COPY_DICT)
|
||||
m_off = (t & 8) << 11;
|
||||
#else /* !COPY_DICT */
|
||||
m_pos = op;
|
||||
m_pos -= (t & 8) << 11;
|
||||
#endif /* COPY_DICT */
|
||||
t &= 7;
|
||||
if (t == 0) {
|
||||
NEED_IP(1);
|
||||
while (*ip == 0) {
|
||||
t += 255;
|
||||
ip++;
|
||||
NEED_IP(1);
|
||||
}
|
||||
t += 7 + *ip++;
|
||||
}
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off += (ip[0] << 6) + (ip[1] >> 2);
|
||||
#else
|
||||
m_off += (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
ip += 2;
|
||||
if (m_off == 0)
|
||||
goto eof_found;
|
||||
m_off += 0x4000;
|
||||
#if defined(LZO1Z)
|
||||
last_m_off = m_off;
|
||||
#endif
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
m_pos -= (ip[0] << 6) + (ip[1] >> 2);
|
||||
#elif defined(LZO_UNALIGNED_OK_2) && defined(LZO_ABI_LITTLE_ENDIAN)
|
||||
m_pos -= (* (const lzo_ushortp) ip) >> 2;
|
||||
#else
|
||||
m_pos -= (ip[0] >> 2) + (ip[1] << 6);
|
||||
#endif
|
||||
ip += 2;
|
||||
if (m_pos == op)
|
||||
goto eof_found;
|
||||
m_pos -= 0x4000;
|
||||
#if defined(LZO1Z)
|
||||
last_m_off = pd((const uint8_t*)op, m_pos);
|
||||
#endif
|
||||
#endif /* COPY_DICT */
|
||||
}
|
||||
else { /* a M1 match */
|
||||
#if defined(COPY_DICT)
|
||||
#if defined(LZO1Z)
|
||||
m_off = 1 + (t << 6) + (*ip++ >> 2);
|
||||
last_m_off = m_off;
|
||||
#else
|
||||
m_off = 1 + (t >> 2) + (*ip++ << 2);
|
||||
#endif
|
||||
NEED_OP(2);
|
||||
t = 2; COPY_DICT(t,m_off)
|
||||
#else /* !COPY_DICT */
|
||||
#if defined(LZO1Z)
|
||||
t = 1 + (t << 6) + (*ip++ >> 2);
|
||||
m_pos = op - t;
|
||||
last_m_off = t;
|
||||
#else
|
||||
m_pos = op - 1;
|
||||
m_pos -= t >> 2;
|
||||
m_pos -= *ip++ << 2;
|
||||
#endif
|
||||
TEST_LB(m_pos); NEED_OP(2);
|
||||
*op++ = *m_pos++;
|
||||
*op++ = *m_pos;
|
||||
#endif /* COPY_DICT */
|
||||
goto match_done;
|
||||
}
|
||||
|
||||
/* copy match */
|
||||
#if defined(COPY_DICT)
|
||||
|
||||
NEED_OP(t+3-1);
|
||||
t += 3-1; COPY_DICT(t,m_off)
|
||||
|
||||
#else /* !COPY_DICT */
|
||||
|
||||
TEST_LB(m_pos); assert(t > 0); NEED_OP(t+3-1);
|
||||
#if defined(LZO_UNALIGNED_OK_4) || defined(LZO_ALIGNED_OK_4)
|
||||
# if !defined(LZO_UNALIGNED_OK_4)
|
||||
if (t >= 2 * 4 - (3 - 1) && PTR_ALIGNED2_4(op,m_pos)) {
|
||||
assert((op - m_pos) >= 4); /* both pointers are aligned */
|
||||
# else
|
||||
if (t >= 2 * 4 - (3 - 1) && (op - m_pos) >= 4) {
|
||||
# endif
|
||||
COPY4(op,m_pos);
|
||||
op += 4; m_pos += 4; t -= 4 - (3 - 1);
|
||||
do {
|
||||
COPY4(op,m_pos);
|
||||
op += 4; m_pos += 4; t -= 4;
|
||||
} while (t >= 4);
|
||||
if (t > 0)
|
||||
do *op++ = *m_pos++; while (--t > 0);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
copy_match:
|
||||
*op++ = *m_pos++; *op++ = *m_pos++;
|
||||
do *op++ = *m_pos++; while (--t > 0);
|
||||
}
|
||||
|
||||
#endif /* COPY_DICT */
|
||||
|
||||
match_done:
|
||||
#if defined(LZO1Z)
|
||||
t = ip[-1] & 3;
|
||||
#else
|
||||
t = ip[-2] & 3;
|
||||
#endif
|
||||
if (t == 0)
|
||||
break;
|
||||
|
||||
/* copy literals */
|
||||
match_next:
|
||||
assert(t > 0);
|
||||
assert(t < 4);
|
||||
NEED_OP(t);
|
||||
NEED_IP(t+1);
|
||||
#if 0
|
||||
do *op++ = *ip++; while (--t > 0);
|
||||
#else
|
||||
*op++ = *ip++;
|
||||
if (t > 1) {
|
||||
*op++ = *ip++;
|
||||
if (t > 2)
|
||||
*op++ = *ip++;
|
||||
}
|
||||
#endif
|
||||
t = *ip++;
|
||||
} while (TEST_IP && TEST_OP);
|
||||
}
|
||||
|
||||
//#if defined(HAVE_TEST_IP) || defined(HAVE_TEST_OP)
|
||||
/* no EOF code was found */
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_EOF_NOT_FOUND;
|
||||
//#endif
|
||||
|
||||
eof_found:
|
||||
assert(t == 1);
|
||||
*out_len = pd(op, out);
|
||||
return (ip == ip_end ? LZO_E_OK :
|
||||
(ip < ip_end ? LZO_E_INPUT_NOT_CONSUMED : LZO_E_INPUT_OVERRUN));
|
||||
|
||||
//#if defined(HAVE_NEED_IP)
|
||||
input_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_INPUT_OVERRUN;
|
||||
//#endif
|
||||
|
||||
//#if defined(HAVE_NEED_OP)
|
||||
output_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_OUTPUT_OVERRUN;
|
||||
//#endif
|
||||
|
||||
//#if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
|
||||
lookbehind_overrun:
|
||||
*out_len = pd(op, out);
|
||||
return LZO_E_LOOKBEHIND_OVERRUN;
|
||||
//#endif
|
||||
}
|
||||
-1075
File diff suppressed because it is too large.
Load diff
+17
-29
@@ -115,10 +115,8 @@ int rpm_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
argc -= optind;
|
||||
if (!argc) bb_show_usage();
|
||||
|
||||
while (*argv) {
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
@@ -145,13 +143,13 @@ int rpm_main(int argc, char **argv)
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate_ptm;
|
||||
struct tm *bdate;
|
||||
char bdatestring[50];
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)");
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
bdate = localtime((time_t *) &bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate);
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0));
|
||||
@@ -192,7 +190,7 @@ static void extract_cpio_gz(int fd)
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned char magic[2];
|
||||
#if BB_MMU
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd);
|
||||
USE_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd);
|
||||
enum { xformer_prog = 0 };
|
||||
#else
|
||||
enum { xformer = 0 };
|
||||
@@ -204,12 +202,7 @@ static void extract_cpio_gz(int fd)
|
||||
archive_handle->seek = seek_by_read;
|
||||
//archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
* (TODO? real rpm creates "file;1234" and then renames it) */
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->ah_flags = ARCHIVE_PRESERVE_DATE | ARCHIVE_CREATE_LEADING_DIRS;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
@@ -226,7 +219,7 @@ static void extract_cpio_gz(int fd)
|
||||
|| magic[0] != 'B' || magic[1] != 'Z'
|
||||
) {
|
||||
bb_error_msg_and_die("no gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
USE_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
" magic");
|
||||
}
|
||||
#if BB_MMU
|
||||
@@ -253,7 +246,7 @@ static void extract_cpio_gz(int fd)
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
{
|
||||
/* We should never need mode than 200, and realloc later */
|
||||
rpm_index **tags = xzalloc(200 * sizeof(tags[0]));
|
||||
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *));
|
||||
int pass, tagindex = 0;
|
||||
|
||||
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
@@ -267,9 +260,6 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
uint32_t entries; /* Number of entries in header (4 bytes) */
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
} header;
|
||||
struct BUG_header {
|
||||
char BUG_header[sizeof(header) == 16 ? 1 : -1];
|
||||
};
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
@@ -283,8 +273,8 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
|
||||
while (header.entries--) {
|
||||
tmpindex = tags[tagindex++] = xmalloc(sizeof(*tmpindex));
|
||||
xread(fd, tmpindex, sizeof(*tmpindex));
|
||||
tmpindex = tags[tagindex++] = xmalloc(sizeof(rpm_index));
|
||||
xread(fd, tmpindex, sizeof(rpm_index));
|
||||
tmpindex->tag = ntohl(tmpindex->tag);
|
||||
tmpindex->type = ntohl(tmpindex->type);
|
||||
tmpindex->count = ntohl(tmpindex->count);
|
||||
@@ -297,7 +287,7 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
if (pass == 0)
|
||||
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
}
|
||||
tags = xrealloc(tags, tagindex * sizeof(tags[0])); /* realloc tags to save space */
|
||||
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
|
||||
*num_tags = tagindex;
|
||||
return tags; /* All done, leave the file at the start of the gzipped cpio archive */
|
||||
}
|
||||
@@ -326,7 +316,7 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) {
|
||||
int n;
|
||||
char *tmpstr = (char *) map + found[0]->offset;
|
||||
char *tmpstr = (char *) (map + found[0]->offset);
|
||||
for (n=0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
@@ -345,7 +335,7 @@ static int rpm_getint(int tag, int itemindex)
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (int *) ((char *) map + found[0]->offset);
|
||||
tmpint = (int *) (map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
@@ -388,11 +378,9 @@ static void fileaction_dobackup(char *filename, int fileref)
|
||||
|
||||
static void fileaction_setowngrp(char *filename, int fileref)
|
||||
{
|
||||
/* real rpm warns: "user foo does not exist - using <you>" */
|
||||
struct passwd *pw = getpwnam(rpm_getstr(TAG_FILEUSERNAME, fileref));
|
||||
int uid = pw ? pw->pw_uid : getuid(); /* or euid? */
|
||||
struct group *gr = getgrnam(rpm_getstr(TAG_FILEGROUPNAME, fileref));
|
||||
int gid = gr ? gr->gr_gid : getgid();
|
||||
int uid, gid;
|
||||
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
|
||||
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
|
||||
chown(filename, uid, gid);
|
||||
}
|
||||
|
||||
|
||||
+36
-57
@@ -9,11 +9,11 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_MAGIC 0xedabeedb
|
||||
#define RPM_MAGIC_STR "\355\253\356\333"
|
||||
#define RPM_MAGIC "\355\253\356\333"
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
|
||||
struct rpm_lead {
|
||||
uint32_t magic;
|
||||
unsigned char magic[4];
|
||||
uint8_t major, minor;
|
||||
uint16_t type;
|
||||
uint16_t archnum;
|
||||
@@ -23,88 +23,67 @@ struct rpm_lead {
|
||||
char reserved[16];
|
||||
};
|
||||
|
||||
#define RPM_HEADER_MAGICnVER 0x8eade801
|
||||
#define RPM_HEADER_MAGIC_STR "\216\255\350"
|
||||
|
||||
struct rpm_header {
|
||||
uint32_t magic_and_ver; /* 3 byte magic: 0x8e 0xad 0xe8; 1 byte version */
|
||||
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
uint32_t reserved; /* 4 bytes reserved */
|
||||
uint32_t entries; /* Number of entries in header (4 bytes) */
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
};
|
||||
|
||||
enum { rpm_fd = STDIN_FILENO };
|
||||
|
||||
static unsigned skip_header(void)
|
||||
static void skip_header(int rpm_fd)
|
||||
{
|
||||
struct rpm_header header;
|
||||
unsigned len;
|
||||
|
||||
xread(rpm_fd, &header, sizeof(header));
|
||||
// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
|
||||
// bb_error_msg_and_die("invalid RPM header magic");
|
||||
// }
|
||||
// if (header.version != 1) {
|
||||
// bb_error_msg_and_die("unsupported RPM header version");
|
||||
// }
|
||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
|
||||
bb_error_msg_and_die("invalid RPM header magic or unsupported version");
|
||||
// ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
|
||||
xread(rpm_fd, &header, sizeof(struct rpm_header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
|
||||
bb_error_msg_and_die("invalid RPM header magic"); /* Invalid magic */
|
||||
}
|
||||
|
||||
/* Seek past index entries, and past store */
|
||||
len = 16 * ntohl(header.entries) + ntohl(header.size);
|
||||
seek_by_jump(rpm_fd, len);
|
||||
|
||||
return sizeof(header) + len;
|
||||
if (header.version != 1) {
|
||||
bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
}
|
||||
header.entries = ntohl(header.entries);
|
||||
header.size = ntohl(header.size);
|
||||
lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
|
||||
lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
unsigned pos;
|
||||
int rpm_fd;
|
||||
unsigned char magic[2];
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
|
||||
|
||||
if (argv[1]) {
|
||||
xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
|
||||
}
|
||||
xread(rpm_fd, &lead, sizeof(lead));
|
||||
|
||||
/* Just check the magic, the rest is irrelevant */
|
||||
if (lead.magic != htonl(RPM_MAGIC)) {
|
||||
bb_error_msg_and_die("invalid RPM magic");
|
||||
if (argc == 1) {
|
||||
rpm_fd = STDIN_FILENO;
|
||||
} else {
|
||||
rpm_fd = xopen(argv[1], O_RDONLY);
|
||||
}
|
||||
|
||||
/* Skip the signature header, align to 8 bytes */
|
||||
pos = skip_header();
|
||||
seek_by_jump(rpm_fd, (8 - pos) & 7);
|
||||
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
|
||||
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
|
||||
bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
}
|
||||
|
||||
/* Skip the signature header */
|
||||
skip_header(rpm_fd);
|
||||
lseek(rpm_fd, (8 - (lseek(rpm_fd, 0, SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
|
||||
/* Skip the main header */
|
||||
skip_header();
|
||||
skip_header(rpm_fd);
|
||||
|
||||
xread(rpm_fd, &magic, 2);
|
||||
unpack = unpack_gz_stream;
|
||||
if (magic[0] != 0x1f || magic[1] != 0x8b) {
|
||||
if (!ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
|| magic[0] != 'B' || magic[1] != 'Z'
|
||||
) {
|
||||
bb_error_msg_and_die("invalid gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
" magic");
|
||||
}
|
||||
unpack = unpack_bz2_stream;
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
if (unpack(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(rpm_fd);
|
||||
}
|
||||
close(rpm_fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+121
-190
@@ -26,16 +26,13 @@
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* FIXME: Stop using this non-standard feature */
|
||||
#ifndef FNM_LEADING_DIR
|
||||
# define FNM_LEADING_DIR 0
|
||||
#define FNM_LEADING_DIR 0
|
||||
#endif
|
||||
|
||||
|
||||
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
|
||||
#define DBG(...) ((void)0)
|
||||
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
@@ -55,7 +52,8 @@
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
#define NAME_SIZE 100
|
||||
#define NAME_SIZE_STR "100"
|
||||
typedef struct TarHeader { /* byte offset */
|
||||
typedef struct TarHeader TarHeader;
|
||||
struct TarHeader { /* byte offset */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
@@ -77,38 +75,39 @@ typedef struct TarHeader { /* byte offset */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
|
||||
} TarHeader;
|
||||
};
|
||||
|
||||
/*
|
||||
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
|
||||
** the only functions that deal with the HardLinkInfo structure.
|
||||
** Even these functions use the xxxHardLinkInfo() functions.
|
||||
*/
|
||||
typedef struct HardLinkInfo {
|
||||
struct HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
// short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
} HardLinkInfo;
|
||||
typedef struct HardLinkInfo HardLinkInfo;
|
||||
struct HardLinkInfo {
|
||||
HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
};
|
||||
|
||||
/* Some info to be carried along when creating a new tarball */
|
||||
typedef struct TarBallInfo {
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
* for the tarball */
|
||||
struct stat statBuf; /* Stat info for the tarball, letting
|
||||
* us know the inode and device that the
|
||||
* tarball lives, so we can avoid trying
|
||||
* to include the tarball into itself */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
//TODO: save only st_dev + st_ino
|
||||
struct stat tarFileStatBuf; /* Stat info for the tarball, letting
|
||||
* us know the inode and device that the
|
||||
* tarball lives, so we can avoid trying
|
||||
* to include the tarball into itself */
|
||||
} TarBallInfo;
|
||||
};
|
||||
|
||||
/* A nice enum with all the possible tar file content types */
|
||||
enum {
|
||||
enum TarFileType {
|
||||
REGTYPE = '0', /* regular file */
|
||||
REGTYPE0 = '\0', /* regular file (ancient bug compat) */
|
||||
LNKTYPE = '1', /* hard link */
|
||||
@@ -121,6 +120,7 @@ enum {
|
||||
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
|
||||
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
|
||||
};
|
||||
typedef enum TarFileType TarFileType;
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
|
||||
@@ -135,7 +135,7 @@ static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
|
||||
*hlInfoHeadPtr = hlInfo;
|
||||
hlInfo->dev = statbuf->st_dev;
|
||||
hlInfo->ino = statbuf->st_ino;
|
||||
// hlInfo->linkCount = statbuf->st_nlink;
|
||||
hlInfo->linkCount = statbuf->st_nlink;
|
||||
strcpy(hlInfo->name, fileName);
|
||||
}
|
||||
|
||||
@@ -155,16 +155,12 @@ static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
|
||||
}
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order ;) */
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf)
|
||||
{
|
||||
while (hlInfo) {
|
||||
if (statbuf->st_ino == hlInfo->ino
|
||||
&& statbuf->st_dev == hlInfo->dev
|
||||
) {
|
||||
DBG("found hardlink:'%s'", hlInfo->name);
|
||||
if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev))
|
||||
break;
|
||||
}
|
||||
hlInfo = hlInfo->next;
|
||||
}
|
||||
return hlInfo;
|
||||
@@ -175,7 +171,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
|
||||
* Stores low-order bits only if whole value does not fit. */
|
||||
static void putOctal(char *cp, int len, off_t value)
|
||||
{
|
||||
char tempBuffer[sizeof(off_t)*3 + 1];
|
||||
char tempBuffer[sizeof(off_t)*3+1];
|
||||
char *tempString = tempBuffer;
|
||||
int width;
|
||||
|
||||
@@ -335,8 +331,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
if (sizeof(statbuf->st_size) > 4
|
||||
&& statbuf->st_size > (off_t)0777777777777LL
|
||||
) {
|
||||
bb_error_msg_and_die("can't store file '%s' "
|
||||
"of size %"OFF_FMT"u, aborting",
|
||||
bb_error_msg_and_die("cannot store file '%s' "
|
||||
"of size %"OFF_FMT"d, aborting",
|
||||
fileName, statbuf->st_size);
|
||||
}
|
||||
header.typeflag = REGTYPE;
|
||||
@@ -361,8 +357,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
if (tbInfo->verboseFlag) {
|
||||
FILE *vbFd = stdout;
|
||||
|
||||
/* If archive goes to stdout, verbose goes to stderr */
|
||||
if (tbInfo->tarFd == STDOUT_FILENO)
|
||||
if (tbInfo->tarFd == STDOUT_FILENO) /* If the archive goes to stdout, verbose to stderr */
|
||||
vbFd = stderr;
|
||||
/* GNU "tar cvvf" prints "extended" listing a-la "ls -l" */
|
||||
/* We don't have such excesses here: for us "v" == "vv" */
|
||||
@@ -380,19 +375,16 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
while (excluded_files) {
|
||||
if (excluded_files->data[0] == '/') {
|
||||
if (fnmatch(excluded_files->data, file,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
return 1;
|
||||
} else {
|
||||
const char *p;
|
||||
|
||||
for (p = file; p[0] != '\0'; p++) {
|
||||
if ((p == file || p[-1] == '/')
|
||||
&& p[0] != '/'
|
||||
&& fnmatch(excluded_files->data, p,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0
|
||||
) {
|
||||
if ((p == file || p[-1] == '/') && p[0] != '/' &&
|
||||
fnmatch(excluded_files->data, p,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
excluded_files = excluded_files->link;
|
||||
@@ -401,7 +393,7 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
# define exclude_file(excluded_files, file) 0
|
||||
#define exclude_file(excluded_files, file) 0
|
||||
#endif
|
||||
|
||||
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
@@ -411,8 +403,6 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
const char *header_name;
|
||||
int inputFileFd = -1;
|
||||
|
||||
DBG("writeFileToTarball('%s')", fileName);
|
||||
|
||||
/* Strip leading '/' (must be before memorizing hardlink's name) */
|
||||
header_name = fileName;
|
||||
while (header_name[0] == '/') {
|
||||
@@ -442,20 +432,17 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
if (!S_ISDIR(statbuf->st_mode) && statbuf->st_nlink > 1) {
|
||||
DBG("'%s': st_nlink > 1", header_name);
|
||||
if (statbuf->st_nlink > 1) {
|
||||
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
|
||||
if (tbInfo->hlInfo == NULL) {
|
||||
DBG("'%s': addHardLinkInfo", header_name);
|
||||
if (tbInfo->hlInfo == NULL)
|
||||
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* It is a bad idea to store the archive we are in the process of creating,
|
||||
* so check the device and inode to be sure that this particular file isn't
|
||||
* the new tarball */
|
||||
if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev
|
||||
&& tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino
|
||||
if (tbInfo->statBuf.st_dev == statbuf->st_dev
|
||||
&& tbInfo->statBuf.st_ino == statbuf->st_ino
|
||||
) {
|
||||
bb_error_msg("%s: file is the archive; skipping", fileName);
|
||||
return TRUE;
|
||||
@@ -517,37 +504,37 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
#if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
#define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
#endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
#elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
#else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
# endif
|
||||
#endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
# define WAIT_FOR_CHILD 0
|
||||
#define WAIT_FOR_CHILD 0
|
||||
volatile int vfork_exec_errno = 0;
|
||||
struct fd_pair gzipDataPipe;
|
||||
# if WAIT_FOR_CHILD
|
||||
#if WAIT_FOR_CHILD
|
||||
struct fd_pair gzipStatusPipe;
|
||||
xpiped_pair(gzipStatusPipe);
|
||||
# endif
|
||||
#endif
|
||||
xpiped_pair(gzipDataPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
gzipPid = vfork();
|
||||
if (gzipPid < 0)
|
||||
@@ -557,12 +544,12 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
/* child */
|
||||
/* NB: close _first_, then move fds! */
|
||||
close(gzipDataPipe.wr);
|
||||
# if WAIT_FOR_CHILD
|
||||
#if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.rd);
|
||||
/* gzipStatusPipe.wr will close only on exec -
|
||||
* parent waits for this close to happen */
|
||||
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
|
||||
# endif
|
||||
#endif
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
@@ -574,7 +561,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
/* parent */
|
||||
xmove_fd(gzipDataPipe.wr, tar_fd);
|
||||
close(gzipDataPipe.rd);
|
||||
# if WAIT_FOR_CHILD
|
||||
#if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.wr);
|
||||
while (1) {
|
||||
char buf;
|
||||
@@ -586,10 +573,10 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
continue; /* try it again */
|
||||
}
|
||||
close(gzipStatusPipe.rd);
|
||||
# endif
|
||||
#endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
bb_perror_msg_and_die("cannot exec %s", zip_exec);
|
||||
}
|
||||
}
|
||||
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
@@ -604,13 +591,15 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
struct TarBallInfo tbInfo;
|
||||
|
||||
tbInfo.hlInfoHead = NULL;
|
||||
|
||||
fchmod(tar_fd, 0644);
|
||||
tbInfo.tarFd = tar_fd;
|
||||
tbInfo.verboseFlag = verboseFlag;
|
||||
|
||||
/* Store the stat info for the tarball's file, so
|
||||
* can avoid including the tarball into itself.... */
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf) < 0)
|
||||
bb_perror_msg_and_die("can't stat tar file");
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
||||
bb_perror_msg_and_die("cannot stat tar file");
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip)
|
||||
@@ -623,8 +612,8 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, ACTION_RECURSE |
|
||||
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0)
|
||||
) {
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0))
|
||||
{
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
include = include->link;
|
||||
@@ -687,7 +676,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
# define append_file_list_to_list(x) 0
|
||||
#define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_Z
|
||||
@@ -712,7 +701,7 @@ static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
# define get_header_tar_Z NULL
|
||||
#define get_header_tar_Z NULL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
@@ -729,7 +718,7 @@ static void handle_SIGCHLD(int status)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
||||
/* child exited with 0 */
|
||||
return;
|
||||
/* Cannot happen?
|
||||
@@ -739,42 +728,35 @@ static void handle_SIGCHLD(int status)
|
||||
#endif
|
||||
|
||||
enum {
|
||||
OPTBIT_KEEP_OLD = 8,
|
||||
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
|
||||
IF_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
|
||||
IF_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
|
||||
IF_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
|
||||
IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
|
||||
IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
|
||||
IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
|
||||
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
OPTBIT_NUMERIC_OWNER,
|
||||
OPTBIT_KEEP_OLD = 7,
|
||||
USE_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
|
||||
USE_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
|
||||
USE_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
|
||||
USE_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
|
||||
USE_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
|
||||
USE_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
|
||||
USE_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
|
||||
USE_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
|
||||
OPTBIT_NOPRESERVE_OWN,
|
||||
OPTBIT_NOPRESERVE_PERM,
|
||||
OPTBIT_OVERWRITE,
|
||||
#endif
|
||||
OPT_TEST = 1 << 0, // t
|
||||
OPT_EXTRACT = 1 << 1, // x
|
||||
OPT_BASEDIR = 1 << 2, // C
|
||||
OPT_TARNAME = 1 << 3, // f
|
||||
OPT_2STDOUT = 1 << 4, // O
|
||||
OPT_NOPRESERVE_OWNER = 1 << 5, // o == no-same-owner
|
||||
OPT_P = 1 << 6, // p
|
||||
OPT_VERBOSE = 1 << 7, // v
|
||||
OPT_KEEP_OLD = 1 << 8, // k
|
||||
OPT_CREATE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
|
||||
OPT_DEREFERENCE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
|
||||
OPT_BZIP2 = IF_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
|
||||
OPT_LZMA = IF_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
|
||||
OPT_INCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
|
||||
OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
|
||||
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
|
||||
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
|
||||
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
|
||||
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
|
||||
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
|
||||
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
|
||||
OPT_P = 1 << 5, // p
|
||||
OPT_VERBOSE = 1 << 6, // v
|
||||
OPT_KEEP_OLD = 1 << 7, // k
|
||||
OPT_CREATE = USE_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
|
||||
OPT_DEREFERENCE = USE_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
|
||||
OPT_BZIP2 = USE_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
|
||||
OPT_LZMA = USE_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
|
||||
OPT_INCLUDE_FROM = USE_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
|
||||
OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
|
||||
OPT_GZIP = USE_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
|
||||
OPT_COMPRESS = USE_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
|
||||
OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
|
||||
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
|
||||
};
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
static const char tar_longopts[] ALIGN1 =
|
||||
@@ -783,10 +765,6 @@ static const char tar_longopts[] ALIGN1 =
|
||||
"directory\0" Required_argument "C"
|
||||
"file\0" Required_argument "f"
|
||||
"to-stdout\0" No_argument "O"
|
||||
/* do not restore owner */
|
||||
/* Note: GNU tar handles 'o' as no-same-owner only on extract,
|
||||
* on create, 'o' is --old-archive. We do not support --old-archive. */
|
||||
"no-same-owner\0" No_argument "o"
|
||||
"same-permissions\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
"keep-old\0" No_argument "k"
|
||||
@@ -810,17 +788,11 @@ static const char tar_longopts[] ALIGN1 =
|
||||
# if ENABLE_FEATURE_SEAMLESS_Z
|
||||
"compress\0" No_argument "Z"
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
|
||||
"touch\0" No_argument "m"
|
||||
# endif
|
||||
/* use numeric uid/gid from tar header, not textual */
|
||||
"numeric-owner\0" No_argument "\xfc"
|
||||
/* do not restore mode */
|
||||
"no-same-permissions\0" No_argument "\xfd"
|
||||
/* on unpack, open with O_TRUNC and !O_EXCL */
|
||||
"overwrite\0" No_argument "\xfe"
|
||||
"no-same-owner\0" No_argument "\xfd"
|
||||
"no-same-permissions\0" No_argument "\xfe"
|
||||
/* --exclude takes next bit position in option mask, */
|
||||
/* therefore we have to put it _after_ --no-same-permissions */
|
||||
/* therefore we have to either put it _after_ --no-same-perm */
|
||||
/* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
"exclude\0" Required_argument "\xff"
|
||||
# endif
|
||||
@@ -843,12 +815,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
|
||||
| ARCHIVE_RESTORE_DATE
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
|
||||
/* Apparently only root's tar preserves perms (see bug 3844) */
|
||||
if (getuid() != 0)
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
|
||||
| ARCHIVE_PRESERVE_DATE
|
||||
| ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:" // first arg is options
|
||||
@@ -858,59 +826,30 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
"\xff::" // cumulative lists for --exclude
|
||||
#endif
|
||||
IF_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
|
||||
IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
|
||||
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
|
||||
USE_FEATURE_TAR_CREATE("c:") "t:x:" // at least one of these is reqd
|
||||
USE_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive
|
||||
SKIP_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
applet_long_options = tar_longopts;
|
||||
#endif
|
||||
#if ENABLE_DESKTOP
|
||||
if (argv[1] && argv[1][0] != '-') {
|
||||
/* Compat:
|
||||
* 1st argument without dash handles options with parameters
|
||||
* differently from dashed one: it takes *next argv[i]*
|
||||
* as paramenter even if there are more chars in 1st argument:
|
||||
* "tar fx TARFILE" - "x" is not taken as f's param
|
||||
* but is interpreted as -x option
|
||||
* "tar -xf TARFILE" - dashed equivalent of the above
|
||||
* "tar -fx ..." - "x" is taken as f's param
|
||||
* getopt32 wouldn't handle 1st command correctly.
|
||||
* Unfortunately, people do use such commands.
|
||||
* We massage argv[1] to work around it by moving 'f'
|
||||
* to the end of the string.
|
||||
* More contrived "tar fCx TARFILE DIR" still fails,
|
||||
* but such commands are much less likely to be used.
|
||||
*/
|
||||
char *f = strchr(argv[1], 'f');
|
||||
if (f) {
|
||||
while (f[1] != '\0') {
|
||||
*f = f[1];
|
||||
f++;
|
||||
}
|
||||
*f = 'f';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
opt = getopt32(argv,
|
||||
"txC:f:Oopvk"
|
||||
IF_FEATURE_TAR_CREATE( "ch" )
|
||||
IF_FEATURE_SEAMLESS_BZ2( "j" )
|
||||
IF_FEATURE_SEAMLESS_LZMA("a" )
|
||||
IF_FEATURE_TAR_FROM( "T:X:")
|
||||
IF_FEATURE_SEAMLESS_GZ( "z" )
|
||||
IF_FEATURE_SEAMLESS_Z( "Z" )
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
"txC:f:Opvk"
|
||||
USE_FEATURE_TAR_CREATE( "ch" )
|
||||
USE_FEATURE_SEAMLESS_BZ2( "j" )
|
||||
USE_FEATURE_SEAMLESS_LZMA("a" )
|
||||
USE_FEATURE_TAR_FROM( "T:X:")
|
||||
USE_FEATURE_SEAMLESS_GZ( "z" )
|
||||
USE_FEATURE_SEAMLESS_Z( "Z" )
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
|
||||
IF_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
|
||||
USE_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
|
||||
USE_FEATURE_TAR_FROM(, &(tar_handle->reject)) // X
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
, &excludes // --exclude
|
||||
#endif
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
);
|
||||
//bb_error_msg("opt:%08x", opt);
|
||||
argv += optind;
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
@@ -923,21 +862,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->action_data = data_extract_to_stdout;
|
||||
|
||||
if (opt & OPT_KEEP_OLD)
|
||||
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
|
||||
tar_handle->ah_flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
if (opt & OPT_NUMERIC_OWNER)
|
||||
tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_OWNER)
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_OWNER;
|
||||
if (opt & OPT_NOPRESERVE_OWN)
|
||||
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_OWN;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_PERM)
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
|
||||
|
||||
if (opt & OPT_OVERWRITE) {
|
||||
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
|
||||
tar_handle->ah_flags |= ARCHIVE_O_TRUNC;
|
||||
}
|
||||
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
|
||||
|
||||
if (opt & OPT_GZIP)
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
@@ -951,12 +882,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_COMPRESS)
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_TIME)
|
||||
tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
@@ -964,12 +892,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
#endif
|
||||
|
||||
/* Setup an array of filenames to work with */
|
||||
/* TODO: This is the same as in ar, make a separate function? */
|
||||
/* TODO: This is the same as in ar, separate function ? */
|
||||
while (*argv) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
char *cp = last_char_is(*argv, '/');
|
||||
@@ -984,21 +912,24 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* Open the tar file */
|
||||
{
|
||||
int tar_fd = STDIN_FILENO;
|
||||
int flags = O_RDONLY;
|
||||
FILE *tar_stream;
|
||||
int flags;
|
||||
|
||||
if (opt & OPT_CREATE) {
|
||||
/* Make sure there is at least one file to tar up */
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
if (tar_handle->accept == NULL)
|
||||
bb_error_msg_and_die("empty archive");
|
||||
|
||||
tar_fd = STDOUT_FILENO;
|
||||
tar_stream = stdout;
|
||||
/* Mimicking GNU tar 1.15.1: */
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
} else {
|
||||
tar_stream = stdin;
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
|
||||
if (LONE_DASH(tar_filename)) {
|
||||
tar_handle->src_fd = tar_fd;
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) {
|
||||
@@ -1020,7 +951,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
signal(SIGCHLD, handle_SIGCHLD);
|
||||
#endif
|
||||
|
||||
/* Create an archive */
|
||||
/* create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
|
||||
+76
-315
@@ -16,7 +16,12 @@
|
||||
*/
|
||||
|
||||
/* TODO
|
||||
* Endian issues
|
||||
* Zip64 + other methods
|
||||
* Improve handling of zip format, ie.
|
||||
* - deferred CRC, comp. & uncomp. lengths (zip header flags bit 3)
|
||||
* - unix file permissions, etc.
|
||||
* - central directory
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -26,12 +31,12 @@ enum {
|
||||
#if BB_BIG_ENDIAN
|
||||
ZIP_FILEHEADER_MAGIC = 0x504b0304,
|
||||
ZIP_CDS_MAGIC = 0x504b0102,
|
||||
ZIP_CDE_MAGIC = 0x504b0506,
|
||||
ZIP_CDS_END_MAGIC = 0x504b0506,
|
||||
ZIP_DD_MAGIC = 0x504b0708,
|
||||
#else
|
||||
ZIP_FILEHEADER_MAGIC = 0x04034b50,
|
||||
ZIP_CDS_MAGIC = 0x02014b50,
|
||||
ZIP_CDE_MAGIC = 0x06054b50,
|
||||
ZIP_CDS_END_MAGIC = 0x06054b50,
|
||||
ZIP_DD_MAGIC = 0x08074b50,
|
||||
#endif
|
||||
};
|
||||
@@ -41,16 +46,16 @@ enum {
|
||||
typedef union {
|
||||
uint8_t raw[ZIP_HEADER_LEN];
|
||||
struct {
|
||||
uint16_t version; /* 0-1 */
|
||||
uint16_t flags; /* 2-3 */
|
||||
uint16_t method; /* 4-5 */
|
||||
uint16_t modtime; /* 6-7 */
|
||||
uint16_t moddate; /* 8-9 */
|
||||
uint32_t crc32 PACKED; /* 10-13 */
|
||||
uint32_t cmpsize PACKED; /* 14-17 */
|
||||
uint32_t ucmpsize PACKED; /* 18-21 */
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
uint16_t version; /* 0-1 */
|
||||
uint16_t flags; /* 2-3 */
|
||||
uint16_t method; /* 4-5 */
|
||||
uint16_t modtime; /* 6-7 */
|
||||
uint16_t moddate; /* 8-9 */
|
||||
uint32_t crc32 PACKED; /* 10-13 */
|
||||
uint32_t cmpsize PACKED; /* 14-17 */
|
||||
uint32_t ucmpsize PACKED; /* 18-21 */
|
||||
uint16_t filename_len; /* 22-23 */
|
||||
uint16_t extra_len; /* 24-25 */
|
||||
} formatted PACKED;
|
||||
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
|
||||
|
||||
@@ -60,11 +65,11 @@ typedef union {
|
||||
*/
|
||||
struct BUG_zip_header_must_be_26_bytes {
|
||||
char BUG_zip_header_must_be_26_bytes[
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2
|
||||
== ZIP_HEADER_LEN ? 1 : -1];
|
||||
offsetof(zip_header_t, formatted.extra_len) + 2 ==
|
||||
ZIP_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_ZIP(zip_header) do { \
|
||||
#define FIX_ENDIANNESS(zip_header) do { \
|
||||
(zip_header).formatted.version = SWAP_LE16((zip_header).formatted.version ); \
|
||||
(zip_header).formatted.flags = SWAP_LE16((zip_header).formatted.flags ); \
|
||||
(zip_header).formatted.method = SWAP_LE16((zip_header).formatted.method ); \
|
||||
@@ -77,139 +82,9 @@ struct BUG_zip_header_must_be_26_bytes {
|
||||
(zip_header).formatted.extra_len = SWAP_LE16((zip_header).formatted.extra_len ); \
|
||||
} while (0)
|
||||
|
||||
#define CDS_HEADER_LEN 42
|
||||
|
||||
typedef union {
|
||||
uint8_t raw[CDS_HEADER_LEN];
|
||||
struct {
|
||||
/* uint32_t signature; 50 4b 01 02 */
|
||||
uint16_t version_made_by; /* 0-1 */
|
||||
uint16_t version_needed; /* 2-3 */
|
||||
uint16_t cds_flags; /* 4-5 */
|
||||
uint16_t method; /* 6-7 */
|
||||
uint16_t mtime; /* 8-9 */
|
||||
uint16_t mdate; /* 10-11 */
|
||||
uint32_t crc32; /* 12-15 */
|
||||
uint32_t cmpsize; /* 16-19 */
|
||||
uint32_t ucmpsize; /* 20-23 */
|
||||
uint16_t file_name_length; /* 24-25 */
|
||||
uint16_t extra_field_length; /* 26-27 */
|
||||
uint16_t file_comment_length; /* 28-29 */
|
||||
uint16_t disk_number_start; /* 30-31 */
|
||||
uint16_t internal_file_attributes; /* 32-33 */
|
||||
uint32_t external_file_attributes PACKED; /* 34-37 */
|
||||
uint32_t relative_offset_of_local_header PACKED; /* 38-41 */
|
||||
} formatted PACKED;
|
||||
} cds_header_t;
|
||||
|
||||
struct BUG_cds_header_must_be_42_bytes {
|
||||
char BUG_cds_header_must_be_42_bytes[
|
||||
offsetof(cds_header_t, formatted.relative_offset_of_local_header) + 4
|
||||
== CDS_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_CDS(cds_header) do { \
|
||||
(cds_header).formatted.crc32 = SWAP_LE32((cds_header).formatted.crc32 ); \
|
||||
(cds_header).formatted.cmpsize = SWAP_LE32((cds_header).formatted.cmpsize ); \
|
||||
(cds_header).formatted.ucmpsize = SWAP_LE32((cds_header).formatted.ucmpsize ); \
|
||||
(cds_header).formatted.file_name_length = SWAP_LE16((cds_header).formatted.file_name_length); \
|
||||
(cds_header).formatted.extra_field_length = SWAP_LE16((cds_header).formatted.extra_field_length); \
|
||||
(cds_header).formatted.file_comment_length = SWAP_LE16((cds_header).formatted.file_comment_length); \
|
||||
} while (0)
|
||||
|
||||
#define CDE_HEADER_LEN 16
|
||||
|
||||
typedef union {
|
||||
uint8_t raw[CDE_HEADER_LEN];
|
||||
struct {
|
||||
/* uint32_t signature; 50 4b 05 06 */
|
||||
uint16_t this_disk_no;
|
||||
uint16_t disk_with_cds_no;
|
||||
uint16_t cds_entries_on_this_disk;
|
||||
uint16_t cds_entries_total;
|
||||
uint32_t cds_size;
|
||||
uint32_t cds_offset;
|
||||
/* uint16_t file_comment_length; */
|
||||
/* .ZIP file comment (variable size) */
|
||||
} formatted PACKED;
|
||||
} cde_header_t;
|
||||
|
||||
struct BUG_cde_header_must_be_16_bytes {
|
||||
char BUG_cde_header_must_be_16_bytes[
|
||||
sizeof(cde_header_t) == CDE_HEADER_LEN ? 1 : -1];
|
||||
};
|
||||
|
||||
#define FIX_ENDIANNESS_CDE(cde_header) do { \
|
||||
(cde_header).formatted.cds_offset = SWAP_LE32((cde_header).formatted.cds_offset); \
|
||||
} while (0)
|
||||
|
||||
enum { zip_fd = 3 };
|
||||
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
/* NB: does not preserve file position! */
|
||||
static uint32_t find_cds_offset(void)
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
cde_header_t cde_header;
|
||||
unsigned char *p;
|
||||
off_t end;
|
||||
|
||||
end = xlseek(zip_fd, 0, SEEK_END);
|
||||
if (end < 1024)
|
||||
end = 1024;
|
||||
end -= 1024;
|
||||
xlseek(zip_fd, end, SEEK_SET);
|
||||
full_read(zip_fd, buf, 1024);
|
||||
|
||||
p = buf;
|
||||
while (p <= buf + 1024 - CDE_HEADER_LEN - 4) {
|
||||
if (*p != 'P') {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
if (*++p != 'K')
|
||||
continue;
|
||||
if (*++p != 5)
|
||||
continue;
|
||||
if (*++p != 6)
|
||||
continue;
|
||||
/* we found CDE! */
|
||||
memcpy(cde_header.raw, p + 1, CDE_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDE(cde_header);
|
||||
return cde_header.formatted.cds_offset;
|
||||
}
|
||||
bb_error_msg_and_die("can't find file table");
|
||||
};
|
||||
|
||||
static uint32_t read_next_cds(int count_m1, uint32_t cds_offset, cds_header_t *cds_ptr)
|
||||
{
|
||||
off_t org;
|
||||
|
||||
org = xlseek(zip_fd, 0, SEEK_CUR);
|
||||
|
||||
if (!cds_offset)
|
||||
cds_offset = find_cds_offset();
|
||||
|
||||
while (count_m1-- >= 0) {
|
||||
xlseek(zip_fd, cds_offset + 4, SEEK_SET);
|
||||
xread(zip_fd, cds_ptr->raw, CDS_HEADER_LEN);
|
||||
FIX_ENDIANNESS_CDS(*cds_ptr);
|
||||
cds_offset += 4 + CDS_HEADER_LEN
|
||||
+ cds_ptr->formatted.file_name_length
|
||||
+ cds_ptr->formatted.extra_field_length
|
||||
+ cds_ptr->formatted.file_comment_length;
|
||||
}
|
||||
|
||||
xlseek(zip_fd, org, SEEK_SET);
|
||||
return cds_offset;
|
||||
};
|
||||
#endif
|
||||
|
||||
static void unzip_skip(off_t skip)
|
||||
{
|
||||
if (lseek(zip_fd, skip, SEEK_CUR) == (off_t)-1)
|
||||
bb_copyfd_exact_size(zip_fd, -1, skip);
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
|
||||
static void unzip_create_leading_dirs(const char *fn)
|
||||
@@ -222,17 +97,17 @@ static void unzip_create_leading_dirs(const char *fn)
|
||||
free(name);
|
||||
}
|
||||
|
||||
static void unzip_extract(zip_header_t *zip_header, int dst_fd)
|
||||
static void unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
{
|
||||
if (zip_header->formatted.method == 0) {
|
||||
/* Method 0 - stored (not compressed) */
|
||||
off_t size = zip_header->formatted.ucmpsize;
|
||||
if (size)
|
||||
bb_copyfd_exact_size(zip_fd, dst_fd, size);
|
||||
bb_copyfd_exact_size(src_fd, dst_fd, size);
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_unzip_result res;
|
||||
if (inflate_unzip(&res, zip_header->formatted.cmpsize, zip_fd, dst_fd) < 0)
|
||||
if (inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd) < 0)
|
||||
bb_error_msg_and_die("inflate error");
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
|
||||
@@ -253,17 +128,12 @@ int unzip_main(int argc, char **argv)
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
smallint quiet = 0;
|
||||
IF_NOT_DESKTOP(const) smallint verbose = 0;
|
||||
smallint verbose = 1;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
#if ENABLE_DESKTOP
|
||||
uint32_t cds_offset;
|
||||
unsigned cds_entries;
|
||||
#endif
|
||||
unsigned long total_usize;
|
||||
unsigned long total_size;
|
||||
unsigned total_size;
|
||||
unsigned total_entries;
|
||||
int src_fd = -1;
|
||||
int dst_fd = -1;
|
||||
char *src_fn = NULL;
|
||||
char *dst_fn = NULL;
|
||||
@@ -275,49 +145,8 @@ int unzip_main(int argc, char **argv)
|
||||
char key_buf[80];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
|
||||
*
|
||||
* # /usr/bin/unzip -qq -v decompress_unlzma.i.zip
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* # /usr/bin/unzip -q -v decompress_unlzma.i.zip
|
||||
* Length Method Size Ratio Date Time CRC-32 Name
|
||||
* -------- ------ ------- ----- ---- ---- ------ ----
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* -------- ------- --- -------
|
||||
* 204372 35278 83% 1 file
|
||||
* # /usr/bin/unzip -v decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Method Size Ratio Date Time CRC-32 Name
|
||||
* -------- ------ ------- ----- ---- ---- ------ ----
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* -------- ------- --- -------
|
||||
* 204372 35278 83% 1 file
|
||||
* # unzip -v decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 files
|
||||
* # /usr/bin/unzip -l -qq decompress_unlzma.i.zip
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* # /usr/bin/unzip -l -q decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 file
|
||||
* # /usr/bin/unzip -l decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 file
|
||||
*/
|
||||
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
@@ -337,12 +166,7 @@ int unzip_main(int argc, char **argv)
|
||||
dst_fd = STDOUT_FILENO;
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
quiet++;
|
||||
break;
|
||||
|
||||
case 'v': /* Verbose list */
|
||||
IF_DESKTOP(verbose++;)
|
||||
listing = 1;
|
||||
verbose = 0;
|
||||
break;
|
||||
|
||||
case 1: /* The zip file */
|
||||
@@ -397,14 +221,13 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
/* Open input file */
|
||||
if (LONE_DASH(src_fn)) {
|
||||
xdup2(STDIN_FILENO, zip_fd);
|
||||
src_fd = STDIN_FILENO;
|
||||
/* Cannot use prompt mode since zip data is arriving on STDIN */
|
||||
if (overwrite == O_PROMPT)
|
||||
overwrite = O_NEVER;
|
||||
} else {
|
||||
static const char extn[][5] = {"", ".zip", ".ZIP"};
|
||||
int orig_src_fn_len = strlen(src_fn);
|
||||
int src_fd = -1;
|
||||
|
||||
for (i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
strcpy(src_fn + orig_src_fn_len, extn[i]);
|
||||
@@ -414,87 +237,53 @@ int unzip_main(int argc, char **argv)
|
||||
src_fn[orig_src_fn_len] = '\0';
|
||||
bb_error_msg_and_die("can't open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
|
||||
}
|
||||
xmove_fd(src_fd, zip_fd);
|
||||
}
|
||||
|
||||
/* Change dir if necessary */
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
if (quiet <= 1) { /* not -qq */
|
||||
if (quiet == 0)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing) {
|
||||
puts(verbose ?
|
||||
" Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
"-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
:
|
||||
" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----"
|
||||
);
|
||||
if (verbose) {
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
}
|
||||
}
|
||||
|
||||
total_usize = 0;
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
#if ENABLE_DESKTOP
|
||||
cds_entries = 0;
|
||||
cds_offset = 0;
|
||||
#endif
|
||||
while (1) {
|
||||
uint32_t magic;
|
||||
|
||||
/* Check magic number */
|
||||
xread(zip_fd, &magic, 4);
|
||||
xread(src_fd, &magic, 4);
|
||||
/* Central directory? It's at the end, so exit */
|
||||
if (magic == ZIP_CDS_MAGIC)
|
||||
break;
|
||||
#if ENABLE_DESKTOP
|
||||
/* Data descriptor? It was a streaming file, go on */
|
||||
if (magic == ZIP_DD_MAGIC) {
|
||||
/* skip over duplicate crc32, cmpsize and ucmpsize */
|
||||
unzip_skip(3 * 4);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (magic != ZIP_FILEHEADER_MAGIC)
|
||||
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
|
||||
|
||||
/* Read the file header */
|
||||
xread(zip_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS_ZIP(zip_header);
|
||||
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
|
||||
FIX_ENDIANNESS(zip_header);
|
||||
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
|
||||
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
|
||||
}
|
||||
#if !ENABLE_DESKTOP
|
||||
if (zip_header.formatted.flags & 0x0009) {
|
||||
bb_error_msg_and_die("zip flags 1 and 8 are not supported");
|
||||
}
|
||||
#else
|
||||
if (zip_header.formatted.flags & 0x0001) {
|
||||
if (zip_header.formatted.flags & (0x0008|0x0001)) {
|
||||
/* 0x0001 - encrypted */
|
||||
bb_error_msg_and_die("zip flag 1 (encryption) is not supported");
|
||||
}
|
||||
if (zip_header.formatted.flags & 0x0008) {
|
||||
cds_header_t cds_header;
|
||||
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
|
||||
* only from Central Directory. See unzip_doc.txt */
|
||||
cds_offset = read_next_cds(total_entries - cds_entries, cds_offset, &cds_header);
|
||||
cds_entries = total_entries + 1;
|
||||
zip_header.formatted.crc32 = cds_header.formatted.crc32;
|
||||
zip_header.formatted.cmpsize = cds_header.formatted.cmpsize;
|
||||
zip_header.formatted.ucmpsize = cds_header.formatted.ucmpsize;
|
||||
bb_error_msg_and_die("zip flags 8 and 1 are not supported");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read filename */
|
||||
free(dst_fn);
|
||||
dst_fn = xzalloc(zip_header.formatted.filename_len + 1);
|
||||
xread(zip_fd, dst_fn, zip_header.formatted.filename_len);
|
||||
xread(src_fd, dst_fn, zip_header.formatted.filename_len);
|
||||
|
||||
/* Skip extra header bytes */
|
||||
unzip_skip(zip_header.formatted.extra_len);
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
/* Filter zip entries */
|
||||
if (find_list_entry(zreject, dst_fn)
|
||||
@@ -504,39 +293,21 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
if (verbose) {
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
zip_header.formatted.ucmpsize,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_size += zip_header.formatted.ucmpsize;
|
||||
total_entries++;
|
||||
} else {
|
||||
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
|
||||
percents = percents * 100;
|
||||
if (zip_header.formatted.ucmpsize)
|
||||
percents /= zip_header.formatted.ucmpsize;
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)percents,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
zip_header.formatted.crc32,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
/* short listing -- filenames only */
|
||||
puts(dst_fn);
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
@@ -544,9 +315,9 @@ int unzip_main(int argc, char **argv)
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
bb_perror_msg_and_die("cannot stat '%s'", dst_fn);
|
||||
}
|
||||
if (!quiet) {
|
||||
if (verbose) {
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
@@ -564,7 +335,7 @@ int unzip_main(int argc, char **argv)
|
||||
check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
bb_perror_msg_and_die("cannot stat '%s'", dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
} else { /* File already exists */
|
||||
@@ -576,7 +347,7 @@ int unzip_main(int argc, char **argv)
|
||||
} else {
|
||||
printf("replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ", dst_fn);
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
bb_perror_msg_and_die("cannot read input");
|
||||
}
|
||||
i = key_buf[0];
|
||||
}
|
||||
@@ -594,10 +365,10 @@ int unzip_main(int argc, char **argv)
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
case -1: /* Unzip */
|
||||
if (!quiet) {
|
||||
if (verbose) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_extract(&zip_header, dst_fd);
|
||||
unzip_extract(&zip_header, src_fd, dst_fd);
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
close(dst_fd);
|
||||
@@ -608,14 +379,14 @@ int unzip_main(int argc, char **argv)
|
||||
overwrite = O_NEVER;
|
||||
case 'n':
|
||||
/* Skip entry data */
|
||||
unzip_skip(zip_header.formatted.cmpsize);
|
||||
unzip_skip(src_fd, zip_header.formatted.cmpsize);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
/* Prompt for new name */
|
||||
printf("new name: ");
|
||||
if (!fgets(key_buf, sizeof(key_buf), stdin)) {
|
||||
bb_perror_msg_and_die("can't read input");
|
||||
bb_perror_msg_and_die("cannot read input");
|
||||
}
|
||||
free(dst_fn);
|
||||
dst_fn = xstrdup(key_buf);
|
||||
@@ -623,32 +394,22 @@ int unzip_main(int argc, char **argv)
|
||||
goto check_file;
|
||||
|
||||
default:
|
||||
printf("error: invalid response [%c]\n", (char)i);
|
||||
printf("error: invalid response [%c]\n",(char)i);
|
||||
goto check_file;
|
||||
}
|
||||
|
||||
total_entries++;
|
||||
// Looks like bug (data descriptor cannot be identified this way)
|
||||
// /* Data descriptor section */
|
||||
// if (zip_header.formatted.flags & 4) {
|
||||
// /* skip over duplicate crc, compressed size and uncompressed size */
|
||||
// unzip_skip(src_fd, 12);
|
||||
// }
|
||||
}
|
||||
|
||||
if (listing && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( " -------- -------\n"
|
||||
"%9lu" " %u files\n",
|
||||
total_usize, total_entries);
|
||||
} else {
|
||||
unsigned long percents = total_usize - total_size;
|
||||
percents = percents * 100;
|
||||
if (total_usize)
|
||||
percents /= total_usize;
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "-------- ------- --- -------\n"
|
||||
"%8lu" "%17lu%4u%% %u files\n",
|
||||
total_usize, total_size, (unsigned)percents,
|
||||
total_entries);
|
||||
}
|
||||
if (listing && verbose) {
|
||||
printf(" -------- -------\n"
|
||||
"%9d %d files\n",
|
||||
total_size, total_entries);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Binary file not shown.
+1
-16
@@ -91,7 +91,7 @@ config SETCONSOLE
|
||||
config FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on SETCONSOLE && LONG_OPTS
|
||||
depends on SETCONSOLE && GETOPT_LONG
|
||||
help
|
||||
Support long options for the setconsole applet.
|
||||
|
||||
@@ -101,21 +101,6 @@ config SETFONT
|
||||
help
|
||||
Allows to load console screen map. Useful for i18n.
|
||||
|
||||
config FEATURE_SETFONT_TEXTUAL_MAP
|
||||
bool "Support reading textual screen maps"
|
||||
default n
|
||||
depends on SETFONT
|
||||
help
|
||||
Support reading textual screen maps.
|
||||
|
||||
config DEFAULT_SETFONT_DIR
|
||||
string "Default directory for console-tools files"
|
||||
default ""
|
||||
depends on SETFONT
|
||||
help
|
||||
Directory to use if setfont's params are simple filenames
|
||||
(not /path/to/file or ./file). Default is "" (no default directory).
|
||||
|
||||
config SETKEYCODES
|
||||
bool "setkeycodes"
|
||||
default n
|
||||
|
||||
@@ -6,12 +6,19 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chvt_main(int argc UNUSED_PARAM, char **argv)
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int num = xatou_range(single_argv(argv), 1, 63);
|
||||
int num;
|
||||
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
console_make_active(get_console_fd_or_die(), num);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -28,9 +28,9 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
|
||||
/* bb_warn_ignoring_args(argv[1]);*/
|
||||
/* bb_warn_ignoring_args(argc>=2);*/
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
|
||||
+10
-11
@@ -2,37 +2,37 @@
|
||||
/*
|
||||
* Mini kbd_mode implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
|
||||
* Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
|
||||
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
|
||||
* console-utils v0.2.3, licensed under GNU GPLv2
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <linux/kd.h>
|
||||
|
||||
int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int fd;
|
||||
unsigned opt;
|
||||
enum {
|
||||
SCANCODE = (1 << 0),
|
||||
ASCII = (1 << 1),
|
||||
MEDIUMRAW = (1 << 2),
|
||||
UNICODE = (1 << 3),
|
||||
UNICODE = (1 << 3)
|
||||
};
|
||||
int fd;
|
||||
unsigned opt;
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
|
||||
opt = getopt32(argv, "sakuC:", &tty_name);
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
opt &= 0xf; /* clear -C bit, see (*) */
|
||||
static const char KD_xxx[] ALIGN1 = "saku";
|
||||
opt = getopt32(argv, KD_xxx);
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
if (!opt) { /* print current setting */
|
||||
const char *mode = "unknown";
|
||||
int m;
|
||||
|
||||
xioctl(fd, KDGKBMODE, &m);
|
||||
ioctl(fd, KDGKBMODE, &m);
|
||||
if (m == K_RAW)
|
||||
mode = "raw (scancode)";
|
||||
else if (m == K_XLATE)
|
||||
@@ -43,7 +43,6 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
|
||||
mode = "Unicode (UTF-8)";
|
||||
printf("The keyboard is in %s mode\n", mode);
|
||||
} else {
|
||||
/* here we depend on specific bits assigned to options (*) */
|
||||
opt = opt & UNICODE ? 3 : opt >> 1;
|
||||
/* double cast prevents warnings about widening conversion */
|
||||
xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
|
||||
|
||||
+10
-186
@@ -6,34 +6,10 @@
|
||||
*
|
||||
* Loads the console font, and possibly the corresponding screen map(s).
|
||||
* (Adapted for busybox by Matej Vela.)
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include <sys/kd.h>
|
||||
|
||||
#ifndef KDFONTOP
|
||||
#define KDFONTOP 0x4B72
|
||||
struct console_font_op {
|
||||
unsigned op; /* KD_FONT_OP_* */
|
||||
unsigned flags; /* KD_FONT_FLAG_* */
|
||||
unsigned width, height;
|
||||
unsigned charcount;
|
||||
unsigned char *data; /* font data with height fixed to 32 */
|
||||
};
|
||||
|
||||
#define KD_FONT_OP_SET 0 /* Set font */
|
||||
#define KD_FONT_OP_GET 1 /* Get font */
|
||||
#define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default,
|
||||
data points to name / NULL */
|
||||
#define KD_FONT_OP_COPY 3 /* Copy from another console */
|
||||
|
||||
#define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
|
||||
#define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
|
||||
/* (Used internally for PIO_FONT support) */
|
||||
#endif /* KDFONTOP */
|
||||
|
||||
|
||||
enum {
|
||||
PSF_MAGIC1 = 0x36,
|
||||
PSF_MAGIC2 = 0x04,
|
||||
@@ -41,7 +17,7 @@ enum {
|
||||
PSF_MODE512 = 0x01,
|
||||
PSF_MODEHASTAB = 0x02,
|
||||
PSF_MAXMODE = 0x03,
|
||||
PSF_SEPARATOR = 0xffff
|
||||
PSF_SEPARATOR = 0xFFFF
|
||||
};
|
||||
|
||||
struct psf_header {
|
||||
@@ -64,28 +40,6 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
|
||||
for (i = 0; i < fontsize; i++)
|
||||
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
|
||||
|
||||
{ /* KDFONTOP */
|
||||
struct console_font_op cfo;
|
||||
|
||||
cfo.op = KD_FONT_OP_SET;
|
||||
cfo.flags = 0;
|
||||
cfo.width = 8;
|
||||
cfo.height = unit;
|
||||
cfo.charcount = fontsize;
|
||||
cfo.data = (void*)buf;
|
||||
#if 0
|
||||
if (!ioctl_or_perror(fd, KDFONTOP, &cfo, "KDFONTOP ioctl failed (will try PIO_FONTX)"))
|
||||
goto ret; /* success */
|
||||
#else
|
||||
xioctl(fd, KDFONTOP, &cfo);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* These ones do not honour -C tty (they set font on current tty regardless)
|
||||
* On x86, this distinction is visible on framebuffer consoles
|
||||
* (regular character consoles may have only one shared font anyway)
|
||||
*/
|
||||
#if defined(PIO_FONTX) && !defined(__sparc__)
|
||||
{
|
||||
struct consolefontdesc cfd;
|
||||
@@ -95,12 +49,11 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
|
||||
cfd.chardata = buf;
|
||||
|
||||
if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
|
||||
goto ret; /* success */
|
||||
goto ret; /* success */
|
||||
}
|
||||
#endif
|
||||
xioctl(fd, PIO_FONT, buf);
|
||||
ret:
|
||||
#endif /* 0 */
|
||||
free(buf);
|
||||
}
|
||||
|
||||
@@ -202,7 +155,7 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
* just read the entire file.
|
||||
*/
|
||||
len = 32*1024; // can't be larger
|
||||
psfhdr = xmalloc_read(STDIN_FILENO, &len);
|
||||
psfhdr = (struct psf_header *) xmalloc_read(STDIN_FILENO, &len);
|
||||
// xmalloc_open_zipped_read_close(filename, &len);
|
||||
if (!psfhdr)
|
||||
bb_perror_msg_and_die("error reading input font");
|
||||
@@ -213,159 +166,30 @@ int loadfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
#endif
|
||||
|
||||
#if ENABLE_SETFONT
|
||||
|
||||
/*
|
||||
kbd-1.12:
|
||||
|
||||
setfont [-O font+umap.orig] [-o font.orig] [-om cmap.orig]
|
||||
[-ou umap.orig] [-N] [font.new ...] [-m cmap] [-u umap] [-C console]
|
||||
[-hNN] [-v] [-V]
|
||||
|
||||
-h NN Override font height
|
||||
-o file
|
||||
Save previous font in file
|
||||
-O file
|
||||
Save previous font and Unicode map in file
|
||||
-om file
|
||||
Store console map in file
|
||||
-ou file
|
||||
Save previous Unicode map in file
|
||||
-m file
|
||||
Load console map or Unicode console map from file
|
||||
-u file
|
||||
Load Unicode table describing the font from file
|
||||
Example:
|
||||
# cp866
|
||||
0x00-0x7f idem
|
||||
#
|
||||
0x80 U+0410 # CYRILLIC CAPITAL LETTER A
|
||||
0x81 U+0411 # CYRILLIC CAPITAL LETTER BE
|
||||
0x82 U+0412 # CYRILLIC CAPITAL LETTER VE
|
||||
-C console
|
||||
Set the font for the indicated console
|
||||
-v Verbose
|
||||
-V Version
|
||||
*/
|
||||
|
||||
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
static int ctoi(char *s)
|
||||
{
|
||||
if (s[0] == '\'' && s[1] != '\0' && s[2] == '\'' && s[3] == '\0')
|
||||
return s[1];
|
||||
// U+ means 0x
|
||||
if (s[0] == 'U' && s[1] == '+') {
|
||||
s[0] = '0';
|
||||
s[1] = 'x';
|
||||
}
|
||||
if (!isdigit(s[0]))
|
||||
return -1;
|
||||
return xstrtoul(s, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
size_t len;
|
||||
unsigned opts;
|
||||
int fd;
|
||||
struct psf_header *psfhdr;
|
||||
char *mapfilename;
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
int fd;
|
||||
|
||||
opt_complementary = "=1";
|
||||
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
|
||||
getopt32(argv, "m:", &mapfilename);
|
||||
argv += optind;
|
||||
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
|
||||
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
|
||||
if (*argv[0] != '/') {
|
||||
// goto default fonts location. don't die if doesn't exist
|
||||
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consolefonts");
|
||||
}
|
||||
}
|
||||
// load font
|
||||
len = 32*1024; // can't be larger
|
||||
psfhdr = xmalloc_open_zipped_read_close(*argv, &len);
|
||||
if (!psfhdr)
|
||||
bb_simple_perror_msg_and_die(*argv);
|
||||
psfhdr = (struct psf_header *) xmalloc_open_zipped_read_close(*argv, &len);
|
||||
fd = get_console_fd_or_die();
|
||||
do_load(fd, psfhdr, len);
|
||||
|
||||
// load the screen map, if any
|
||||
if (opts & 1) { // -m
|
||||
unsigned mode = PIO_SCRNMAP;
|
||||
void *map;
|
||||
|
||||
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
|
||||
if (mapfilename[0] != '/') {
|
||||
// goto default keymaps location
|
||||
chdir(CONFIG_DEFAULT_SETFONT_DIR "/consoletrans");
|
||||
}
|
||||
}
|
||||
// fetch keymap
|
||||
map = xmalloc_open_zipped_read_close(mapfilename, &len);
|
||||
if (!map)
|
||||
bb_simple_perror_msg_and_die(mapfilename);
|
||||
// file size is 256 or 512 bytes? -> assume binary map
|
||||
if (option_mask32 & 1) { // -m
|
||||
void *map = xmalloc_open_zipped_read_close(mapfilename, &len);
|
||||
if (len == E_TABSZ || len == 2*E_TABSZ) {
|
||||
if (len == 2*E_TABSZ)
|
||||
mode = PIO_UNISCRNMAP;
|
||||
xioctl(fd, (len == 2*E_TABSZ) ? PIO_UNISCRNMAP : PIO_SCRNMAP, map);
|
||||
}
|
||||
#if ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
// assume textual Unicode console maps:
|
||||
// 0x00 U+0000 # NULL (NUL)
|
||||
// 0x01 U+0001 # START OF HEADING (SOH)
|
||||
// 0x02 U+0002 # START OF TEXT (STX)
|
||||
// 0x03 U+0003 # END OF TEXT (ETX)
|
||||
else {
|
||||
int i;
|
||||
char *token[2];
|
||||
parser_t *parser;
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(map);
|
||||
map = xmalloc(E_TABSZ * sizeof(unsigned short));
|
||||
|
||||
#define unicodes ((unsigned short *)map)
|
||||
// fill vanilla map
|
||||
for (i = 0; i < E_TABSZ; i++)
|
||||
unicodes[i] = 0xf000 + i;
|
||||
|
||||
parser = config_open(mapfilename);
|
||||
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL | PARSE_MIN_DIE)) {
|
||||
// parse code/value pair
|
||||
int a = ctoi(token[0]);
|
||||
int b = ctoi(token[1]);
|
||||
if (a < 0 || a >= E_TABSZ
|
||||
|| b < 0 || b > 65535
|
||||
) {
|
||||
bb_error_msg_and_die("map format");
|
||||
}
|
||||
// patch map
|
||||
unicodes[a] = b;
|
||||
// unicode character is met?
|
||||
if (b > 255)
|
||||
mode = PIO_UNISCRNMAP;
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
config_close(parser);
|
||||
|
||||
if (mode != PIO_UNISCRNMAP) {
|
||||
#define asciis ((unsigned char *)map)
|
||||
for (i = 0; i < E_TABSZ; i++)
|
||||
asciis[i] = unicodes[i];
|
||||
#undef asciis
|
||||
}
|
||||
#undef unicodes
|
||||
}
|
||||
#endif // ENABLE_FEATURE_SETFONT_TEXTUAL_MAP
|
||||
|
||||
// do set screen map
|
||||
xioctl(fd, mode, map);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(map);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
||||
@@ -29,15 +31,11 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
uint16_t ibuff[NR_KEYS];
|
||||
/* const char *tty_name = CURRENT_TTY; */
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
|
||||
/* bb_warn_ignoring_args(argc>=2);*/
|
||||
|
||||
/* bb_warn_ignoring_args(argv[1]); */
|
||||
fd = get_console_fd_or_die();
|
||||
/* or maybe:
|
||||
opt = getopt32(argv, "C:", &tty_name);
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
*/
|
||||
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
|
||||
|
||||
@@ -61,7 +61,9 @@ static int get_vt_fd(void)
|
||||
for (fd = 0; fd < 3; fd++)
|
||||
if (!not_vt_fd(fd))
|
||||
return fd;
|
||||
fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
|
||||
/* _only_ O_NONBLOCK: ask for neither read nor write perms */
|
||||
/*FIXME: use? device_open(DEV_CONSOLE,0); */
|
||||
fd = open(DEV_CONSOLE, O_NONBLOCK);
|
||||
if (fd >= 0 && !not_vt_fd(fd))
|
||||
return fd;
|
||||
bb_error_msg_and_die("can't find open VT");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* resize - set terminal width and height.
|
||||
*
|
||||
* Copyright 2006 Bernhard Reutner-Fischer
|
||||
* Copyright 2006 Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* setconsole.c - redirect system console output
|
||||
*
|
||||
* Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de>
|
||||
* Copyright (C) 2008 Bernhard Reutner-Fischer
|
||||
* Copyright (C) 2008 Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
@@ -72,9 +72,9 @@ int showkey_main(int argc UNUSED_PARAM, char **argv)
|
||||
// get keyboard settings
|
||||
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
|
||||
printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",
|
||||
kbmode == K_RAW ? "RAW" :
|
||||
(kbmode == K_XLATE ? "XLATE" :
|
||||
(kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
|
||||
kbmode == K_RAW ? "RAW" :
|
||||
(kbmode == K_XLATE ? "XLATE" :
|
||||
(kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
|
||||
(kbmode == K_UNICODE ? "UNICODE" : "?UNKNOWN?")))
|
||||
, (option_mask32 & OPT_a) ? "when CTRL+D pressed" : "10s after last keypress"
|
||||
);
|
||||
|
||||
+20
-78
@@ -52,13 +52,6 @@ config CHOWN
|
||||
chown is used to change the user and/or group ownership
|
||||
of files.
|
||||
|
||||
config FEATURE_CHOWN_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on CHOWN && LONG_OPTS
|
||||
help
|
||||
Enable use of long options
|
||||
|
||||
config CHROOT
|
||||
bool "chroot"
|
||||
default n
|
||||
@@ -85,14 +78,6 @@ config CP
|
||||
help
|
||||
cp is used to copy files and directories.
|
||||
|
||||
config FEATURE_CP_LONG_OPTIONS
|
||||
bool "Enable long options for cp"
|
||||
default n
|
||||
depends on CP && LONG_OPTS
|
||||
help
|
||||
Enable long options for cp.
|
||||
Also add support for --parents option.
|
||||
|
||||
config CUT
|
||||
bool "cut"
|
||||
default n
|
||||
@@ -115,22 +100,6 @@ config FEATURE_DATE_ISOFMT
|
||||
Enable option (-I) to output an ISO-8601 compliant
|
||||
date/time string.
|
||||
|
||||
config FEATURE_DATE_COMPAT
|
||||
bool "Support weird 'date MMDDhhmm[[YY]YY][.ss]' format"
|
||||
default y
|
||||
depends on DATE
|
||||
help
|
||||
System time can be set by 'date -s DATE' and simply 'date DATE',
|
||||
but formats of DATE string are different. 'date DATE' accepts
|
||||
a rather weird MMDDhhmm[[YY]YY][.ss] format with completely
|
||||
unnatural placement of year between minutes and seconds.
|
||||
date -s (and other commands like touch -d) use more sensible
|
||||
formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
|
||||
|
||||
With this option off, 'date DATE' is 'date -s DATE' support
|
||||
the same format. With it on, 'date DATE' additionally supports
|
||||
MMDDhhmm[[YY]YY][.ss] format.
|
||||
|
||||
config DD
|
||||
bool "dd"
|
||||
default n
|
||||
@@ -144,22 +113,13 @@ config FEATURE_DD_SIGNAL_HANDLING
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null&
|
||||
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in
|
||||
10899206+0 records out
|
||||
|
||||
config FEATURE_DD_THIRD_STATUS_LINE
|
||||
bool "Enable the third status line upon signal"
|
||||
default n
|
||||
depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
help
|
||||
Displays a coreutils-like third status line with transferred bytes,
|
||||
elapsed time and speed.
|
||||
10899206+0 records in 10899206+0 records out
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
@@ -176,12 +136,12 @@ config DF
|
||||
df reports the amount of disk space used and available
|
||||
on filesystems.
|
||||
|
||||
config FEATURE_DF_FANCY
|
||||
bool "Enable -a, -i, -B"
|
||||
config FEATURE_DF_INODE
|
||||
bool "Enable -i (inode information)"
|
||||
default n
|
||||
depends on DF
|
||||
help
|
||||
This option enables -a, -i and -B.
|
||||
This option enables support for df -i.
|
||||
|
||||
config DIRNAME
|
||||
bool "dirname"
|
||||
@@ -229,7 +189,7 @@ config ECHO
|
||||
config FEATURE_FANCY_ECHO
|
||||
bool "Enable echo options (-n and -e)"
|
||||
default y
|
||||
depends on ECHO || ASH_BUILTIN_ECHO || HUSH
|
||||
depends on ECHO
|
||||
help
|
||||
This adds options (-n and -e) to echo.
|
||||
|
||||
@@ -244,7 +204,7 @@ config ENV
|
||||
config FEATURE_ENV_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on ENV && LONG_OPTS
|
||||
depends on ENV && GETOPT_LONG
|
||||
help
|
||||
Support long options for the env applet.
|
||||
|
||||
@@ -257,7 +217,7 @@ config EXPAND
|
||||
config FEATURE_EXPAND_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on EXPAND && LONG_OPTS
|
||||
depends on EXPAND && GETOPT_LONG
|
||||
help
|
||||
Support long options for the expand applet.
|
||||
|
||||
@@ -289,12 +249,6 @@ config FOLD
|
||||
help
|
||||
Wrap text to fit a specific width.
|
||||
|
||||
config FSYNC
|
||||
bool "fsync"
|
||||
default n
|
||||
help
|
||||
fsync is used to flush file-related cached blocks to disk.
|
||||
|
||||
config HEAD
|
||||
bool "head"
|
||||
default n
|
||||
@@ -331,7 +285,7 @@ config INSTALL
|
||||
config FEATURE_INSTALL_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on INSTALL && LONG_OPTS
|
||||
depends on INSTALL && GETOPT_LONG
|
||||
help
|
||||
Support long options for the install applet.
|
||||
|
||||
@@ -404,7 +358,7 @@ config FEATURE_LS_USERNAME
|
||||
config FEATURE_LS_COLOR
|
||||
bool "Allow use of color to identify file types"
|
||||
default y
|
||||
depends on LS && LONG_OPTS
|
||||
depends on LS && GETOPT_LONG
|
||||
help
|
||||
This enables the --color option to ls.
|
||||
|
||||
@@ -434,7 +388,7 @@ config MKDIR
|
||||
config FEATURE_MKDIR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on MKDIR && LONG_OPTS
|
||||
depends on MKDIR && GETOPT_LONG
|
||||
help
|
||||
Support long options for the mkdir applet.
|
||||
|
||||
@@ -461,7 +415,7 @@ config MV
|
||||
config FEATURE_MV_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on MV && LONG_OPTS
|
||||
depends on MV && GETOPT_LONG
|
||||
help
|
||||
Support long options for the mv applet.
|
||||
|
||||
@@ -538,7 +492,7 @@ config RMDIR
|
||||
config FEATURE_RMDIR_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on RMDIR && LONG_OPTS
|
||||
depends on RMDIR && GETOPT_LONG
|
||||
help
|
||||
Support long options for the rmdir applet, including
|
||||
--ignore-fail-on-non-empty for compatibility with GNU rmdir.
|
||||
@@ -555,18 +509,6 @@ config SHA1SUM
|
||||
help
|
||||
Compute and check SHA1 message digest
|
||||
|
||||
config SHA256SUM
|
||||
bool "sha256sum"
|
||||
default n
|
||||
help
|
||||
Compute and check SHA256 message digest
|
||||
|
||||
config SHA512SUM
|
||||
bool "sha512sum"
|
||||
default n
|
||||
help
|
||||
Compute and check SHA512 message digest
|
||||
|
||||
config SLEEP
|
||||
bool "sleep"
|
||||
default n
|
||||
@@ -675,7 +617,7 @@ config TAIL
|
||||
from files.
|
||||
|
||||
config FEATURE_FANCY_TAIL
|
||||
bool "Enable extra tail options (-q, -s, -v, and -F)"
|
||||
bool "Enable extra tail options (-q, -s, and -v)"
|
||||
default y
|
||||
depends on TAIL
|
||||
help
|
||||
@@ -707,7 +649,7 @@ config TEST
|
||||
config FEATURE_TEST_64
|
||||
bool "Extend test to 64 bit"
|
||||
default n
|
||||
depends on TEST || ASH_BUILTIN_TEST || HUSH
|
||||
depends on TEST
|
||||
help
|
||||
Enable 64-bit support in test.
|
||||
|
||||
@@ -772,7 +714,7 @@ config UNEXPAND
|
||||
config FEATURE_UNEXPAND_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on UNEXPAND && LONG_OPTS
|
||||
depends on UNEXPAND && GETOPT_LONG
|
||||
help
|
||||
Support long options for the unexpand applet.
|
||||
|
||||
@@ -812,7 +754,7 @@ config FEATURE_WC_LARGE
|
||||
default n
|
||||
depends on WC
|
||||
help
|
||||
Use "unsigned long long" in wc for counter variables.
|
||||
Use "unsigned long long" in wc for count variables.
|
||||
|
||||
config WHO
|
||||
bool "who"
|
||||
@@ -869,13 +811,13 @@ config FEATURE_HUMAN_READABLE
|
||||
help
|
||||
Allow df, du, and ls to have human readable output.
|
||||
|
||||
comment "Common options for md5sum, sha1sum, sha256sum, sha512sum"
|
||||
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
|
||||
comment "Common options for md5sum, sha1sum"
|
||||
depends on MD5SUM || SHA1SUM
|
||||
|
||||
config FEATURE_MD5_SHA1_SUM_CHECK
|
||||
bool "Enable -c, -s and -w options"
|
||||
default n
|
||||
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
|
||||
depends on MD5SUM || SHA1SUM
|
||||
help
|
||||
Enabling the -c options allows files to be checked
|
||||
against pre-calculated hash values.
|
||||
|
||||
@@ -36,7 +36,6 @@ lib-$(CONFIG_EXPR) += expr.o
|
||||
lib-$(CONFIG_EXPAND) += expand.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
lib-$(CONFIG_FOLD) += fold.o
|
||||
lib-$(CONFIG_FSYNC) += fsync.o
|
||||
lib-$(CONFIG_HEAD) += head.o
|
||||
lib-$(CONFIG_HOSTID) += hostid.o
|
||||
lib-$(CONFIG_ID) += id.o
|
||||
@@ -45,7 +44,6 @@ lib-$(CONFIG_LENGTH) += length.o
|
||||
lib-$(CONFIG_LN) += ln.o
|
||||
lib-$(CONFIG_LOGNAME) += logname.o
|
||||
lib-$(CONFIG_LS) += ls.o
|
||||
lib-$(CONFIG_FTPD) += ls.o
|
||||
lib-$(CONFIG_MD5SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_MKDIR) += mkdir.o
|
||||
lib-$(CONFIG_MKFIFO) += mkfifo.o
|
||||
@@ -64,8 +62,6 @@ lib-$(CONFIG_RM) += rm.o
|
||||
lib-$(CONFIG_RMDIR) += rmdir.o
|
||||
lib-$(CONFIG_SEQ) += seq.o
|
||||
lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_SLEEP) += sleep.o
|
||||
lib-$(CONFIG_SPLIT) += split.o
|
||||
lib-$(CONFIG_SORT) += sort.o
|
||||
|
||||
@@ -48,6 +48,5 @@ int basename_main(int argc, char **argv)
|
||||
|
||||
/* puts(s) will do, but we can do without stdio this way: */
|
||||
s[m++] = '\n';
|
||||
/* NB: != is correct here: */
|
||||
return full_write(STDOUT_FILENO, s, m) != (ssize_t)m;
|
||||
}
|
||||
+15
-36
@@ -16,8 +16,8 @@
|
||||
*
|
||||
* Major size reduction... over 50% (>1.5k) on i386.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
|
||||
|
||||
@@ -77,42 +77,36 @@ static char *build_row(char *p, unsigned *dp);
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
|
||||
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
int cal_main(int argc, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
struct tm zero_tm;
|
||||
time_t now;
|
||||
unsigned month, year, flags, i;
|
||||
char *month_names[12];
|
||||
/* normal heading: */
|
||||
/* "Su Mo Tu We Th Fr Sa" */
|
||||
/* -j heading: */
|
||||
/* " Su Mo Tu We Th Fr Sa" */
|
||||
char day_headings[ENABLE_FEATURE_ASSUME_UNICODE ? 28 * 6 : 28];
|
||||
IF_FEATURE_ASSUME_UNICODE(char *hp = day_headings;)
|
||||
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
|
||||
char buf[40];
|
||||
|
||||
init_unicode();
|
||||
|
||||
flags = getopt32(argv, "jy");
|
||||
/* This sets julian = flags & 1: */
|
||||
option_mask32 &= 1;
|
||||
month = 0;
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (!argv[0]) {
|
||||
struct tm *ptm;
|
||||
if (argc > 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
if (!argc) {
|
||||
time(&now);
|
||||
ptm = localtime(&now);
|
||||
year = ptm->tm_year + 1900;
|
||||
local_time = localtime(&now);
|
||||
year = local_time->tm_year + 1900;
|
||||
if (!(flags & 2)) { /* no -y */
|
||||
month = ptm->tm_mon + 1;
|
||||
month = local_time->tm_mon + 1;
|
||||
}
|
||||
} else {
|
||||
if (argv[1]) {
|
||||
if (argv[2]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
if (argc == 2) {
|
||||
month = xatou_range(*argv++, 1, 12);
|
||||
}
|
||||
year = xatou_range(*argv, 1, 9999);
|
||||
@@ -123,30 +117,15 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
i = 0;
|
||||
do {
|
||||
zero_tm.tm_mon = i;
|
||||
/* full month name according to locale */
|
||||
strftime(buf, sizeof(buf), "%B", &zero_tm);
|
||||
month_names[i] = xstrdup(buf);
|
||||
|
||||
if (i < 7) {
|
||||
zero_tm.tm_wday = i;
|
||||
/* abbreviated weekday name according to locale */
|
||||
strftime(buf, sizeof(buf), "%a", &zero_tm);
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
if (julian)
|
||||
*hp++ = ' ';
|
||||
{
|
||||
char *two_wchars = unicode_cut_nchars(2, buf);
|
||||
strcpy(hp, two_wchars);
|
||||
free(two_wchars);
|
||||
}
|
||||
hp += strlen(hp);
|
||||
*hp++ = ' ';
|
||||
#else
|
||||
strncpy(day_headings + i * (3+julian) + julian, buf, 2);
|
||||
#endif
|
||||
}
|
||||
} while (++i < 12);
|
||||
IF_FEATURE_ASSUME_UNICODE(hp[-1] = '\0';)
|
||||
|
||||
if (month) {
|
||||
unsigned row, len, days[MAXDAYS];
|
||||
@@ -168,7 +147,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned *dp;
|
||||
char lineout[80];
|
||||
|
||||
sprintf(lineout, "%u", year);
|
||||
sprintf(lineout, "%d", year);
|
||||
center(lineout,
|
||||
(WEEK_LEN * 3 + HEAD_SEP * 2)
|
||||
+ julian * (J_WEEK_LEN * 2 + HEAD_SEP
|
||||
@@ -283,7 +262,7 @@ static void trim_trailing_spaces_and_print(char *s)
|
||||
}
|
||||
while (p != s) {
|
||||
--p;
|
||||
if (!isspace(*p)) {
|
||||
if (!(isspace)(*p)) { /* We want the function... not the inline. */
|
||||
p[1] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-4
@@ -20,10 +20,10 @@
|
||||
|
||||
|
||||
#define OPT_RECURSE (option_mask32 & 1)
|
||||
#define OPT_VERBOSE (IF_DESKTOP(option_mask32 & 2) IF_NOT_DESKTOP(0))
|
||||
#define OPT_CHANGED (IF_DESKTOP(option_mask32 & 4) IF_NOT_DESKTOP(0))
|
||||
#define OPT_QUIET (IF_DESKTOP(option_mask32 & 8) IF_NOT_DESKTOP(0))
|
||||
#define OPT_STR "R" IF_DESKTOP("vcf")
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
|
||||
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
|
||||
#define OPT_STR "R" USE_DESKTOP("vcf")
|
||||
|
||||
/* coreutils:
|
||||
* chmod never changes the permissions of symbolic links; the chmod
|
||||
|
||||
+12
-27
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -15,13 +16,13 @@
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
#define OPT_STR ("Rh" IF_DESKTOP("vcfLHP"))
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
|
||||
#define BIT_RECURSE 1
|
||||
#define OPT_RECURSE (opt & 1)
|
||||
#define OPT_NODEREF (opt & 2)
|
||||
#define OPT_VERBOSE (IF_DESKTOP(opt & 0x04) IF_NOT_DESKTOP(0))
|
||||
#define OPT_CHANGED (IF_DESKTOP(opt & 0x08) IF_NOT_DESKTOP(0))
|
||||
#define OPT_QUIET (IF_DESKTOP(opt & 0x10) IF_NOT_DESKTOP(0))
|
||||
#define OPT_VERBOSE (USE_DESKTOP(opt & 0x04) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(opt & 0x08) SKIP_DESKTOP(0))
|
||||
#define OPT_QUIET (USE_DESKTOP(opt & 0x10) SKIP_DESKTOP(0))
|
||||
/* POSIX options
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
* -H if a command line argument is a symbolic link to a directory, traverse it
|
||||
@@ -31,24 +32,10 @@
|
||||
* The last option specified shall determine the behavior of the utility." */
|
||||
/* -L */
|
||||
#define BIT_TRAVERSE 0x20
|
||||
#define OPT_TRAVERSE (IF_DESKTOP(opt & BIT_TRAVERSE) IF_NOT_DESKTOP(0))
|
||||
#define OPT_TRAVERSE (USE_DESKTOP(opt & BIT_TRAVERSE) SKIP_DESKTOP(0))
|
||||
/* -H or -L */
|
||||
#define BIT_TRAVERSE_TOP (0x20|0x40)
|
||||
#define OPT_TRAVERSE_TOP (IF_DESKTOP(opt & BIT_TRAVERSE_TOP) IF_NOT_DESKTOP(0))
|
||||
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
static const char chown_longopts[] ALIGN1 =
|
||||
"recursive\0" No_argument "R"
|
||||
"dereference\0" No_argument "\xff"
|
||||
"no-dereference\0" No_argument "h"
|
||||
# if ENABLE_DESKTOP
|
||||
"changes\0" No_argument "c"
|
||||
"silent\0" No_argument "f"
|
||||
"quiet\0" No_argument "f"
|
||||
"verbose\0" No_argument "v"
|
||||
# endif
|
||||
;
|
||||
#endif
|
||||
#define OPT_TRAVERSE_TOP (USE_DESKTOP(opt & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
|
||||
|
||||
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
|
||||
|
||||
@@ -89,19 +76,16 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
param.ugid.uid = -1;
|
||||
param.ugid.gid = -1;
|
||||
param.chown_func = chown;
|
||||
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
applet_long_options = chown_longopts;
|
||||
#endif
|
||||
opt_complementary = "-2";
|
||||
opt = getopt32(argv, OPT_STR);
|
||||
argv += optind;
|
||||
|
||||
/* This matches coreutils behavior (almost - see below) */
|
||||
param.chown_func = chown;
|
||||
if (OPT_NODEREF
|
||||
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
|
||||
IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
|
||||
USE_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
|
||||
) {
|
||||
param.chown_func = lchown;
|
||||
}
|
||||
@@ -117,7 +101,8 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
parse_chown_usergroup_or_die(¶m.ugid, argv[0]);
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
while (*++argv) {
|
||||
argv++;
|
||||
do {
|
||||
if (!recursive_action(*argv,
|
||||
flags, /* flags */
|
||||
fileAction, /* file action */
|
||||
@@ -127,7 +112,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
} while (*++argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
+7
-5
@@ -12,16 +12,18 @@
|
||||
#include "libbb.h"
|
||||
|
||||
int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chroot_main(int argc UNUSED_PARAM, char **argv)
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
++argv;
|
||||
if (!*argv)
|
||||
if (argc < 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
++argv;
|
||||
xchroot(*argv);
|
||||
xchdir("/");
|
||||
|
||||
++argv;
|
||||
if (!*argv) { /* no 2nd param (PROG), use shell */
|
||||
if (argc == 2) {
|
||||
argv -= 2;
|
||||
argv[0] = getenv("SHELL");
|
||||
if (!argv[0]) {
|
||||
@@ -31,5 +33,5 @@ int chroot_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
BB_EXECVP(*argv, argv);
|
||||
bb_perror_msg_and_die("can't execute '%s'", *argv);
|
||||
bb_perror_msg_and_die("cannot execute %s", *argv);
|
||||
}
|
||||
+9
-20
@@ -4,8 +4,8 @@
|
||||
*
|
||||
* Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -13,9 +13,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, 1);
|
||||
uint32_t crc;
|
||||
off_t length, filesize;
|
||||
long length, filesize;
|
||||
int bytes_read;
|
||||
int exit_code = EXIT_SUCCESS;
|
||||
uint8_t *cp;
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
@@ -28,10 +27,8 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
do {
|
||||
int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
|
||||
|
||||
if (fd < 0) {
|
||||
exit_code = EXIT_FAILURE;
|
||||
if (fd < 0)
|
||||
continue;
|
||||
}
|
||||
crc = 0;
|
||||
length = 0;
|
||||
|
||||
@@ -47,21 +44,13 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
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;
|
||||
for (; length; length >>= 8)
|
||||
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ length) & 0xff];
|
||||
crc ^= 0xffffffffL;
|
||||
|
||||
printf((*argv ? "%"PRIu32" %"OFF_FMT"i %s\n" : "%"PRIu32" %"OFF_FMT"i\n"),
|
||||
printf((*argv ? "%" PRIu32 " %li %s\n" : "%" PRIu32 " %li\n"),
|
||||
crc, filesize, *argv);
|
||||
} while (*argv && *++argv);
|
||||
|
||||
fflush_stdout_and_exit(exit_code);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+17
-101
@@ -20,6 +20,7 @@
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cp_main(int argc, char **argv)
|
||||
{
|
||||
@@ -30,15 +31,12 @@ int cp_main(int argc, char **argv)
|
||||
int s_flags;
|
||||
int d_flags;
|
||||
int flags;
|
||||
int status;
|
||||
int status = 0;
|
||||
enum {
|
||||
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
|
||||
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
|
||||
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
|
||||
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
|
||||
#endif
|
||||
OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
};
|
||||
|
||||
// Need at least two arguments
|
||||
@@ -47,79 +45,21 @@ int cp_main(int argc, char **argv)
|
||||
// -r and -R are the same
|
||||
// -R (and therefore -r) turns on -d (coreutils does this)
|
||||
// -a = -pdR
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
applet_long_options =
|
||||
"archive\0" No_argument "a"
|
||||
"force\0" No_argument "f"
|
||||
"interactive\0" No_argument "i"
|
||||
"link\0" No_argument "l"
|
||||
"dereference\0" No_argument "L"
|
||||
"no-dereference\0" No_argument "P"
|
||||
"recursive\0" No_argument "R"
|
||||
"symbolic-link\0" No_argument "s"
|
||||
"verbose\0" No_argument "v"
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
* -f, --force
|
||||
* -i, --interactive
|
||||
* -l, --link
|
||||
* -L, --dereference
|
||||
* -P, --no-dereference
|
||||
* -R, -r, --recursive
|
||||
* -s, --symbolic-link
|
||||
* -v, --verbose
|
||||
* -H follow command-line symbolic links in SOURCE
|
||||
* -d same as --no-dereference --preserve=links
|
||||
* -p same as --preserve=mode,ownership,timestamps
|
||||
* -c same as --preserve=context
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* NOT SUPPORTED IN BBOX:
|
||||
* --backup[=CONTROL]
|
||||
* make a backup of each existing destination file
|
||||
* -b like --backup but does not accept an argument
|
||||
* --copy-contents
|
||||
* copy contents of special files when recursive
|
||||
* --preserve[=ATTR_LIST]
|
||||
* preserve attributes (default: mode,ownership,timestamps),
|
||||
* if possible additional attributes: security context,links,all
|
||||
* --no-preserve=ATTR_LIST
|
||||
* --remove-destination
|
||||
* remove each existing destination file before attempting to open
|
||||
* --sparse=WHEN
|
||||
* control creation of sparse files
|
||||
* --strip-trailing-slashes
|
||||
* remove any trailing slashes from each SOURCE argument
|
||||
* -S, --suffix=SUFFIX
|
||||
* override the usual backup suffix
|
||||
* -t, --target-directory=DIRECTORY
|
||||
* copy all SOURCE arguments into DIRECTORY
|
||||
* -T, --no-target-directory
|
||||
* treat DEST as a normal file
|
||||
* -u, --update
|
||||
* copy only when the SOURCE file is newer than the destination
|
||||
* file or when the destination file is missing
|
||||
* -x, --one-file-system
|
||||
* stay on this file system
|
||||
* -Z, --context=CONTEXT
|
||||
* (SELinux) set SELinux security context of copy to CONTEXT
|
||||
*/
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPH");
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
/* Reverse this bit. If there is -d, bit is not set: */
|
||||
flags ^= FILEUTILS_DEREFERENCE;
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
|
||||
/* coreutils 6.9 compat:
|
||||
* by default, "cp" derefs symlinks (creates regular dest files),
|
||||
* but "cp -R" does not. We switch off deref if -r or -R (see above).
|
||||
* However, "cp -RL" must still deref symlinks: */
|
||||
if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
|
||||
flags |= FILEUTILS_DEREFERENCE;
|
||||
/* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||
* just ignore it too for fun. TODO.
|
||||
if (flags & OPT_H) ... // deref command-line params only
|
||||
*/
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
|
||||
@@ -127,62 +67,38 @@ int cp_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
status = EXIT_SUCCESS;
|
||||
last = argv[argc - 1];
|
||||
/* If there are only two arguments and... */
|
||||
if (argc == 2) {
|
||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
if (s_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
d_flags = cp_mv_stat(last, &dest_stat);
|
||||
if (d_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & OPT_parents) {
|
||||
if (!(d_flags & 2)) {
|
||||
bb_error_msg_and_die("with --parents, the destination must be a directory");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ...if neither is a directory... */
|
||||
if (!((s_flags | d_flags) & 2)
|
||||
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
/* ...if neither is a directory or... */
|
||||
if ( !((s_flags | d_flags) & 2) ||
|
||||
/* ...recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
) {
|
||||
/* Do a simple copy */
|
||||
/* ...do a simple copy. */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & OPT_parents) {
|
||||
char *dest_dup;
|
||||
char *dest_dir;
|
||||
dest = concat_path_file(last, *argv);
|
||||
dest_dup = xstrdup(dest);
|
||||
dest_dir = dirname(dest_dup);
|
||||
if (bb_make_directory(dest_dir, -1, FILEUTILS_RECUR)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
free(dest_dup);
|
||||
goto DO_COPY;
|
||||
}
|
||||
#endif
|
||||
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
|
||||
DO_COPY:
|
||||
if (copy_file(*argv, dest, flags) < 0) {
|
||||
status = EXIT_FAILURE;
|
||||
status = 1;
|
||||
}
|
||||
if (*++argv == last) {
|
||||
/* possibly leaking dest... */
|
||||
break;
|
||||
}
|
||||
/* don't move up: dest may be == last and not malloced! */
|
||||
free((void*)dest);
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 1999,2000,2001 by Lineo, inc.
|
||||
* Written by Mark Whitley <markw@codepoet.org>
|
||||
* debloated by Bernhard Reutner-Fischer
|
||||
* debloated by Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
@@ -111,10 +111,7 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
|
||||
int ndelim = -1; /* zero-based / one-based problem */
|
||||
int nfields_printed = 0;
|
||||
char *field = NULL;
|
||||
char delimiter[2];
|
||||
|
||||
delimiter[0] = delim;
|
||||
delimiter[1] = 0;
|
||||
const char delimiter[2] = { delim, 0 };
|
||||
|
||||
/* does this line contain any delimiters? */
|
||||
if (strchr(line, delim) == NULL) {
|
||||
@@ -264,7 +261,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* now that the lists are parsed, we need to sort them to make life
|
||||
* easier on us when it comes time to print the chars / fields / lines
|
||||
*/
|
||||
qsort(cut_lists, nlists, sizeof(cut_lists[0]), cmpfunc);
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
+115
-117
@@ -5,11 +5,13 @@
|
||||
* by Matthew Grant <grantma@anathoth.gen.nz>
|
||||
*
|
||||
* iso-format handling added by Robert Griebl <griebl@gmx.de>
|
||||
* bugfixes and cleanup by Bernhard Reutner-Fischer
|
||||
* bugfixes and cleanup by Bernhard Fischer
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
all the GNU strftime stuff (its in libc, lets use it),
|
||||
setting time using UTC and displaying it, as well as
|
||||
@@ -21,71 +23,25 @@
|
||||
|
||||
/* Default input handling to save surprising some people */
|
||||
|
||||
/* GNU coreutils 6.9 man page:
|
||||
* date [OPTION]... [+FORMAT]
|
||||
* date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
|
||||
* -d, --date=STRING
|
||||
* display time described by STRING, not `now'
|
||||
* -f, --file=DATEFILE
|
||||
* like --date once for each line of DATEFILE
|
||||
* -r, --reference=FILE
|
||||
* display the last modification time of FILE
|
||||
* -R, --rfc-2822
|
||||
* output date and time in RFC 2822 format.
|
||||
* Example: Mon, 07 Aug 2006 12:34:56 -0600
|
||||
* --rfc-3339=TIMESPEC
|
||||
* output date and time in RFC 3339 format.
|
||||
* TIMESPEC='date', 'seconds', or 'ns'
|
||||
* Date and time components are separated by a single space:
|
||||
* 2006-08-07 12:34:56-06:00
|
||||
* -s, --set=STRING
|
||||
* set time described by STRING
|
||||
* -u, --utc, --universal
|
||||
* print or set Coordinated Universal Time
|
||||
*
|
||||
* Busybox:
|
||||
* long options are not supported
|
||||
* -f is not supported
|
||||
* -I seems to roughly match --rfc-3339, but -I has _optional_ param
|
||||
* (thus "-I seconds" doesn't work, only "-Iseconds"),
|
||||
* and does not support -Ins
|
||||
* -D FMT is a bbox extension for _input_ conversion of -d DATE
|
||||
*/
|
||||
#include "libbb.h"
|
||||
|
||||
enum {
|
||||
OPT_RFC2822 = (1 << 0), /* R */
|
||||
OPT_SET = (1 << 1), /* s */
|
||||
OPT_UTC = (1 << 2), /* u */
|
||||
OPT_DATE = (1 << 3), /* d */
|
||||
OPT_REFERENCE = (1 << 4), /* r */
|
||||
OPT_TIMESPEC = (1 << 5) * ENABLE_FEATURE_DATE_ISOFMT, /* I */
|
||||
OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */
|
||||
};
|
||||
#define DATE_OPT_RFC2822 0x01
|
||||
#define DATE_OPT_SET 0x02
|
||||
#define DATE_OPT_UTC 0x04
|
||||
#define DATE_OPT_DATE 0x08
|
||||
#define DATE_OPT_REFERENCE 0x10
|
||||
#define DATE_OPT_TIMESPEC 0x20
|
||||
#define DATE_OPT_HINT 0x40
|
||||
|
||||
static void maybe_set_utc(int opt)
|
||||
{
|
||||
if (opt & OPT_UTC)
|
||||
if (opt & DATE_OPT_UTC)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
}
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char date_longopts[] ALIGN1 =
|
||||
"rfc-822\0" No_argument "R"
|
||||
"rfc-2822\0" No_argument "R"
|
||||
"set\0" Required_argument "s"
|
||||
"utc\0" No_argument "u"
|
||||
/* "universal\0" No_argument "u" */
|
||||
"date\0" Required_argument "d"
|
||||
"reference\0" Required_argument "r"
|
||||
;
|
||||
#endif
|
||||
|
||||
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct tm tm_time;
|
||||
char buf_fmt_dt2str[64];
|
||||
time_t tm;
|
||||
unsigned opt;
|
||||
int ifmt = -1;
|
||||
@@ -96,21 +52,20 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
char *isofmt_arg = NULL;
|
||||
|
||||
opt_complementary = "d--s:s--d"
|
||||
IF_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
IF_LONG_OPTS(applet_long_options = date_longopts;)
|
||||
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
opt = getopt32(argv, "Rs:ud:r:"
|
||||
IF_FEATURE_DATE_ISOFMT("I::D:"),
|
||||
USE_FEATURE_DATE_ISOFMT("I::D:"),
|
||||
&date_str, &date_str, &filename
|
||||
IF_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
|
||||
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
|
||||
argv += optind;
|
||||
maybe_set_utc(opt);
|
||||
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_TIMESPEC)) {
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) {
|
||||
ifmt = 0; /* default is date */
|
||||
if (isofmt_arg) {
|
||||
static const char isoformats[] ALIGN1 =
|
||||
"date\0""hours\0""minutes\0""seconds\0"; /* ns? */
|
||||
ifmt = index_in_substrings(isoformats, isofmt_arg);
|
||||
"date\0""hours\0""minutes\0""seconds\0";
|
||||
ifmt = index_in_strings(isoformats, isofmt_arg);
|
||||
if (ifmt < 0)
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -118,54 +73,28 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
fmt_dt2str = NULL;
|
||||
if (argv[0] && argv[0][0] == '+') {
|
||||
fmt_dt2str = &argv[0][1]; /* skip over the '+' */
|
||||
fmt_dt2str = &argv[0][1]; /* Skip over the '+' */
|
||||
argv++;
|
||||
}
|
||||
if (!(opt & (OPT_SET | OPT_DATE))) {
|
||||
opt |= OPT_SET;
|
||||
if (!(opt & (DATE_OPT_SET | DATE_OPT_DATE))) {
|
||||
opt |= DATE_OPT_SET;
|
||||
date_str = argv[0]; /* can be NULL */
|
||||
if (date_str) {
|
||||
#if ENABLE_FEATURE_DATE_COMPAT
|
||||
int len = strspn(date_str, "0123456789");
|
||||
if (date_str[len] == '\0'
|
||||
|| (date_str[len] == '.'
|
||||
&& isdigit(date_str[len+1])
|
||||
&& isdigit(date_str[len+2])
|
||||
&& date_str[len+3] == '\0'
|
||||
)
|
||||
) {
|
||||
/* Dreaded MMDDhhmm[[CC]YY][.ss] format!
|
||||
* It does not match -d or -s format.
|
||||
* Some users actually do use it.
|
||||
*/
|
||||
len -= 8;
|
||||
if (len < 0 || len > 4 || (len & 1))
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
if (len != 0) { /* move YY or CCYY to front */
|
||||
char buf[4];
|
||||
memcpy(buf, date_str + 8, len);
|
||||
memmove(date_str + len, date_str, 8);
|
||||
memcpy(date_str, buf, len);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (date_str)
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
if (*argv)
|
||||
bb_show_usage();
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
* which depends on whether the clock is being set or read */
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
if (opt & OPT_REFERENCE) {
|
||||
if (opt & DATE_OPT_REFERENCE) {
|
||||
struct stat statbuf;
|
||||
xstat(filename, &statbuf);
|
||||
tm = statbuf.st_mtime;
|
||||
} else {
|
||||
} else
|
||||
time(&tm);
|
||||
}
|
||||
localtime_r(&tm, &tm_time);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
|
||||
/* If date string is given, update tm_time, and maybe set date */
|
||||
if (date_str != NULL) {
|
||||
@@ -175,22 +104,81 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
tm_time.tm_hour = 0;
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & OPT_HINT)) {
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_HINT)) {
|
||||
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
} else {
|
||||
parse_datestr(date_str, &tm_time);
|
||||
char end = '\0';
|
||||
const char *last_colon = strrchr(date_str, ':');
|
||||
|
||||
if (last_colon != NULL) {
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (sscanf(date_str, "%u:%u%c",
|
||||
&tm_time.tm_hour,
|
||||
&tm_time.tm_min,
|
||||
&end) >= 2) {
|
||||
/* no adjustments needed */
|
||||
} else if (sscanf(date_str, "%u.%u-%u:%u%c",
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&end) >= 4) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
tm_time.tm_mon -= 1;
|
||||
} else if (sscanf(date_str, "%u.%u.%u-%u:%u%c", &tm_time.tm_year,
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&end) >= 5) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
} else if (sscanf(date_str, "%u-%u-%u %u:%u%c", &tm_time.tm_year,
|
||||
&tm_time.tm_mon, &tm_time.tm_mday,
|
||||
&tm_time.tm_hour, &tm_time.tm_min,
|
||||
&end) >= 5) {
|
||||
tm_time.tm_year -= 1900; /* Adjust years */
|
||||
tm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
//TODO: coreutils 6.9 also accepts "YYYY-MM-DD HH" (no minutes)
|
||||
} else {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
if (end == ':') {
|
||||
if (sscanf(last_colon + 1, "%u%c", &tm_time.tm_sec, &end) == 1)
|
||||
end = '\0';
|
||||
/* else end != NUL and we error out */
|
||||
}
|
||||
} else {
|
||||
if (sscanf(date_str, "%2u%2u%2u%2u%u%c", &tm_time.tm_mon,
|
||||
&tm_time.tm_mday, &tm_time.tm_hour, &tm_time.tm_min,
|
||||
&tm_time.tm_year, &end) < 4)
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time.tm_year >= 1900) {
|
||||
tm_time.tm_year -= 1900;
|
||||
}
|
||||
/* adjust date */
|
||||
tm_time.tm_mon -= 1;
|
||||
if (end == '.') {
|
||||
if (sscanf(strchr(date_str, '.') + 1, "%u%c",
|
||||
&tm_time.tm_sec, &end) == 1)
|
||||
end = '\0';
|
||||
/* else end != NUL and we error out */
|
||||
}
|
||||
}
|
||||
if (end != '\0') {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst */
|
||||
tm = validate_tm_time(date_str, &tm_time);
|
||||
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst. */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0) {
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
}
|
||||
maybe_set_utc(opt);
|
||||
|
||||
/* if setting time, set it */
|
||||
if ((opt & OPT_SET) && stime(&tm) < 0) {
|
||||
bb_perror_msg("can't set date");
|
||||
if ((opt & DATE_OPT_SET) && stime(&tm) < 0) {
|
||||
bb_perror_msg("cannot set date");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,28 +187,37 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Deal with format string */
|
||||
if (fmt_dt2str == NULL) {
|
||||
int i;
|
||||
fmt_dt2str = buf_fmt_dt2str;
|
||||
fmt_dt2str = xzalloc(32);
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
||||
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */
|
||||
strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
|
||||
i = 8 + 3 * ifmt;
|
||||
if (ifmt != 0) {
|
||||
/* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */
|
||||
strcpy(fmt_dt2str, "%Y-%m-%d");
|
||||
if (ifmt > 0) {
|
||||
i = 8;
|
||||
fmt_dt2str[i++] = 'T';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'H';
|
||||
if (ifmt > 1) {
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'M';
|
||||
if (ifmt > 2) {
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'S';
|
||||
}
|
||||
}
|
||||
format_utc:
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = (opt & OPT_UTC) ? 'Z' : 'z';
|
||||
fmt_dt2str[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
||||
}
|
||||
fmt_dt2str[i] = '\0';
|
||||
} else if (opt & OPT_RFC2822) {
|
||||
/* -R. undo busybox.c setlocale */
|
||||
} else if (opt & DATE_OPT_RFC2822) {
|
||||
/* Undo busybox.c for date -R */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = sizeof("%a, %d %b %Y %H:%M:%S ")-1;
|
||||
i = 22;
|
||||
goto format_utc;
|
||||
} else { /* default case */
|
||||
} else /* default case */
|
||||
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
}
|
||||
|
||||
#define date_buf bb_common_bufsiz1
|
||||
@@ -232,6 +229,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
|
||||
}
|
||||
|
||||
+15
-57
@@ -8,6 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
@@ -29,57 +30,24 @@ static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ "", 0 }
|
||||
{ }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
unsigned long long total_bytes;
|
||||
unsigned long long begin_time_us;
|
||||
#endif
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#define INIT_G() do { \
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
} while (0)
|
||||
/* We have to zero it out because of NOEXEC */
|
||||
#define INIT_G() memset(&G, 0, sizeof(G))
|
||||
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
{
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
double seconds;
|
||||
unsigned long long bytes_sec;
|
||||
unsigned long long now_us = monotonic_us(); /* before fprintf */
|
||||
#endif
|
||||
|
||||
/* Deliberately using %u, not %d */
|
||||
fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
|
||||
"%"OFF_FMT"u+%"OFF_FMT"u records out\n",
|
||||
G.in_full, G.in_part,
|
||||
G.out_full, G.out_part);
|
||||
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
make_human_readable_str(G.total_bytes, 1, 0)
|
||||
);
|
||||
/* Corner cases:
|
||||
* ./busybox dd </dev/null >/dev/null
|
||||
* ./busybox dd bs=1M count=2000 </dev/zero >/dev/null
|
||||
* (echo DONE) | ./busybox dd >/dev/null
|
||||
* (sleep 1; echo DONE) | ./busybox dd >/dev/null
|
||||
*/
|
||||
seconds = (now_us - G.begin_time_us) / 1000000.0;
|
||||
bytes_sec = G.total_bytes / seconds;
|
||||
fprintf(stderr, "%f seconds, %sB/s\n",
|
||||
seconds,
|
||||
/* show fractional digit, use suffixes */
|
||||
make_human_readable_str(bytes_sec, 1, 0)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
static ssize_t full_write_or_warn(const void *buf, size_t len,
|
||||
@@ -101,16 +69,13 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
G.out_full++;
|
||||
else if (n) /* > 0 */
|
||||
G.out_part++;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
G.total_bytes += n;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_LFS
|
||||
# define XATOU_SFX xatoull_sfx
|
||||
#define XATOU_SFX xatoull_sfx
|
||||
#else
|
||||
# define XATOU_SFX xatoul_sfx
|
||||
#define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -189,7 +154,11 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
memset(&Z, 0, sizeof(Z));
|
||||
INIT_G();
|
||||
//fflush_all(); - is this needed because of NOEXEC?
|
||||
//fflush(NULL); - is this needed because of NOEXEC?
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
#endif
|
||||
|
||||
for (n = 1; argv[n]; n++) {
|
||||
int what;
|
||||
@@ -276,14 +245,6 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
G.begin_time_us = monotonic_us();
|
||||
#endif
|
||||
|
||||
if (infile != NULL)
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
else {
|
||||
@@ -326,26 +287,23 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */
|
||||
memset(ibuf, 0, ibs);
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
/* "Bad block" */
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
n = ibs;
|
||||
bb_simple_perror_msg(infile);
|
||||
/* GNU dd with conv=noerror skips over bad blocks */
|
||||
xlseek(ifd, ibs, SEEK_CUR);
|
||||
/* conv=noerror,sync writes NULs,
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (flags & FLAG_SYNC) {
|
||||
memset(ibuf + n, 0, ibs - n);
|
||||
memset(ibuf + n, '\0', ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-95
@@ -8,7 +8,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- option -t missing. */
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- options -P and -t missing. Also blocksize. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/df.html */
|
||||
|
||||
/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
|
||||
@@ -16,16 +16,11 @@
|
||||
* Size reduction. Removed floating point dependency. Added error checking
|
||||
* on output. Output stats on 0-sized filesystems if specifically listed on
|
||||
* the command line. Properly round *-blocks, Used, and Available quantities.
|
||||
*
|
||||
* Aug 28, 2008 Bernhard Reutner-Fischer
|
||||
*
|
||||
* Implement -P and -B; better coreutils compat; cleanup
|
||||
*/
|
||||
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#if !ENABLE_FEATURE_HUMAN_READABLE
|
||||
static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
@@ -35,88 +30,60 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
int df_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long blocks_used;
|
||||
unsigned blocks_percent_used;
|
||||
unsigned long df_disp_hr = 1024;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned df_disp_hr = 1024;
|
||||
#endif
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned opt;
|
||||
FILE *mount_table;
|
||||
struct mntent *mount_entry;
|
||||
struct statfs s;
|
||||
/* default display is kilobytes */
|
||||
const char *disp_units_hdr = "1k-blocks";
|
||||
|
||||
enum {
|
||||
OPT_KILO = (1 << 0),
|
||||
OPT_POSIX = (1 << 1),
|
||||
OPT_ALL = (1 << 2) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_INODE = (1 << 3) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_BSIZE = (1 << 4) * ENABLE_FEATURE_DF_FANCY,
|
||||
OPT_HUMAN = (1 << (2 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_MEGA = (1 << (3 + 3*ENABLE_FEATURE_DF_FANCY)) * ENABLE_FEATURE_HUMAN_READABLE,
|
||||
OPT_ALL = (1 << 0),
|
||||
OPT_INODE = (ENABLE_FEATURE_HUMAN_READABLE ? (1 << 4) : (1 << 2))
|
||||
* ENABLE_FEATURE_DF_INODE
|
||||
};
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
|
||||
init_unicode();
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
|
||||
opt_complementary = "k-mB:m-Bk:B-km";
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "k-m:m-k";
|
||||
#endif
|
||||
opt = getopt32(argv, "kP"
|
||||
IF_FEATURE_DF_FANCY("aiB:")
|
||||
IF_FEATURE_HUMAN_READABLE("hm")
|
||||
IF_FEATURE_DF_FANCY(, &chp));
|
||||
if (opt & OPT_MEGA)
|
||||
df_disp_hr = 1024*1024;
|
||||
|
||||
if (opt & OPT_BSIZE)
|
||||
df_disp_hr = xatoul_range(chp, 1, ULONG_MAX); /* disallow 0 */
|
||||
|
||||
/* From the manpage of df from coreutils-6.10:
|
||||
Disk space is shown in 1K blocks by default, unless the environment
|
||||
variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
|
||||
*/
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
df_disp_hr = 512;
|
||||
|
||||
if (opt & OPT_HUMAN) {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk";
|
||||
opt = getopt32(argv, "ahmk" USE_FEATURE_DF_INODE("i"));
|
||||
if (opt & (1 << 1)) { // -h
|
||||
df_disp_hr = 0;
|
||||
disp_units_hdr = " Size";
|
||||
}
|
||||
if (opt & OPT_INODE)
|
||||
disp_units_hdr = " Inodes";
|
||||
|
||||
if (disp_units_hdr == NULL) {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
disp_units_hdr = xasprintf("%s-blocks",
|
||||
/* print df_disp_hr, show no fractionals,
|
||||
* use suffixes if OPT_POSIX is set in opt */
|
||||
make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX))
|
||||
);
|
||||
#else
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
if (opt & (1 << 2)) { // -m
|
||||
df_disp_hr = 1024*1024;
|
||||
disp_units_hdr = "1M-blocks";
|
||||
}
|
||||
printf("Filesystem %-15sUsed Available %s Mounted on\n",
|
||||
disp_units_hdr, (opt & OPT_POSIX) ? "Capacity" : "Use%");
|
||||
if (opt & OPT_INODE) {
|
||||
disp_units_hdr = " Inodes";
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "ak" USE_FEATURE_DF_INODE("i"));
|
||||
#endif
|
||||
|
||||
printf("Filesystem %-15sUsed Available Use%% Mounted on\n",
|
||||
disp_units_hdr);
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
if (!argv[0]) {
|
||||
if (optind >= argc) {
|
||||
mount_table = setmntent(bb_path_mtab_file, "r");
|
||||
if (!mount_table)
|
||||
if (!mount_table) {
|
||||
bb_perror_msg_and_die(bb_path_mtab_file);
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
size_t dev_len;
|
||||
#endif
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -126,12 +93,13 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
} else {
|
||||
mount_point = *argv++;
|
||||
if (!mount_point)
|
||||
if (!mount_point) {
|
||||
break;
|
||||
mount_entry = find_mount_point(mount_point, 1);
|
||||
}
|
||||
mount_entry = find_mount_point(mount_point, bb_path_mtab_file);
|
||||
if (!mount_entry) {
|
||||
bb_error_msg("%s: can't find mount point", mount_point);
|
||||
set_error:
|
||||
SET_ERROR:
|
||||
status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
@@ -142,7 +110,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
bb_simple_perror_msg(mount_point);
|
||||
goto set_error;
|
||||
goto SET_ERROR;
|
||||
}
|
||||
|
||||
if ((s.f_blocks > 0) || !mount_table || (opt & OPT_ALL)) {
|
||||
@@ -150,9 +118,10 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
s.f_blocks = s.f_files;
|
||||
s.f_bavail = s.f_bfree = s.f_ffree;
|
||||
s.f_bsize = 1;
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
if (df_disp_hr)
|
||||
df_disp_hr = 1;
|
||||
#endif
|
||||
}
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
@@ -162,59 +131,45 @@ int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
|
||||
/* GNU coreutils 6.10 skips certain mounts, try to be compatible. */
|
||||
if (strcmp(device, "rootfs") == 0)
|
||||
#ifdef WHY_IT_SHOULD_BE_HIDDEN
|
||||
if (strcmp(device, "rootfs") == 0) {
|
||||
continue;
|
||||
|
||||
}
|
||||
#endif
|
||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||
/* ... and also this is the only user of find_block_device */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
* or leaves device alone if it can't find it */
|
||||
device = find_block_device("/");
|
||||
if (!device) {
|
||||
goto set_error;
|
||||
goto SET_ERROR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
dev_len = unicode_strlen(device);
|
||||
if (dev_len > 20) {
|
||||
printf("%s\n%20s", device, "");
|
||||
} else {
|
||||
printf("%s%*s", device, 20 - (int)dev_len, "");
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf(" %9s ",
|
||||
/* f_blocks x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
printf(" %9s " + 1,
|
||||
/* EXPR x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str((s.f_blocks - s.f_bfree),
|
||||
s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s %3u%% %s\n",
|
||||
/* f_bavail x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
#else
|
||||
printf(" %9lu %9lu %9lu %3u%% %s\n",
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks - s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks-s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
+8
-3
@@ -15,8 +15,13 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dirname_main(int argc UNUSED_PARAM, char **argv)
|
||||
int dirname_main(int argc, char **argv)
|
||||
{
|
||||
puts(dirname(single_argv(argv)));
|
||||
return fflush_all();
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
puts(dirname(argv[1]));
|
||||
|
||||
return fflush(stdout);
|
||||
}
|
||||
@@ -42,10 +42,10 @@ static void convert(char *fn, int conv_type)
|
||||
i = mkstemp(temp_fn);
|
||||
if (i == -1
|
||||
|| fchmod(i, st.st_mode) == -1
|
||||
|| !(out = fdopen(i, "w+"))
|
||||
) {
|
||||
bb_simple_perror_msg_and_die(temp_fn);
|
||||
}
|
||||
out = xfdopen_for_write(i);
|
||||
}
|
||||
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
@@ -69,7 +69,7 @@ static void convert(char *fn, int conv_type)
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dos2unix_main(int argc UNUSED_PARAM, char **argv)
|
||||
int dos2unix_main(int argc, char **argv)
|
||||
{
|
||||
int o, conv_type;
|
||||
|
||||
@@ -88,11 +88,11 @@ int dos2unix_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (o)
|
||||
conv_type = o;
|
||||
|
||||
argv += optind;
|
||||
do {
|
||||
/* might be convert(NULL) if there is no filename given */
|
||||
convert(*argv, conv_type);
|
||||
} while (*++argv);
|
||||
convert(argv[optind], conv_type);
|
||||
optind++;
|
||||
} while (optind < argc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+53
-44
@@ -25,28 +25,19 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
enum {
|
||||
OPT_a_files_too = (1 << 0),
|
||||
OPT_H_follow_links = (1 << 1),
|
||||
OPT_k_kbytes = (1 << 2),
|
||||
OPT_L_follow_links = (1 << 3),
|
||||
OPT_s_total_norecurse = (1 << 4),
|
||||
OPT_x_one_FS = (1 << 5),
|
||||
OPT_d_maxdepth = (1 << 6),
|
||||
OPT_l_hardlinks = (1 << 7),
|
||||
OPT_c_total = (1 << 8),
|
||||
OPT_h_for_humans = (1 << 9),
|
||||
OPT_m_mbytes = (1 << 10),
|
||||
};
|
||||
|
||||
struct globals {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned long disp_hr;
|
||||
#else
|
||||
unsigned disp_k;
|
||||
#endif
|
||||
|
||||
int max_print_depth;
|
||||
nlink_t count_hardlinks;
|
||||
|
||||
bool status;
|
||||
bool one_file_system;
|
||||
int print_files;
|
||||
int slink_depth;
|
||||
int du_depth;
|
||||
dev_t dir_dev;
|
||||
@@ -58,17 +49,14 @@ static void print(unsigned long size, const char *filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n",
|
||||
/* size x 512 / G.disp_hr, show one fractional,
|
||||
* use suffixes if G.disp_hr == 0 */
|
||||
make_human_readable_str(size, 512, G.disp_hr),
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr),
|
||||
filename);
|
||||
#else
|
||||
if (G.disp_k) {
|
||||
size++;
|
||||
size >>= 1;
|
||||
}
|
||||
printf("%lu\t%s\n", size, filename);
|
||||
printf("%ld\t%s\n", size, filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -84,7 +72,7 @@ static unsigned long du(const char *filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (option_mask32 & OPT_x_one_FS) {
|
||||
if (G.one_file_system) {
|
||||
if (G.du_depth == 0) {
|
||||
G.dir_dev = statbuf.st_dev;
|
||||
} else if (G.dir_dev != statbuf.st_dev) {
|
||||
@@ -95,7 +83,7 @@ static unsigned long du(const char *filename)
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (G.slink_depth > G.du_depth) { /* -H or -L */
|
||||
if (G.slink_depth > G.du_depth) { /* -H or -L */
|
||||
if (stat(filename, &statbuf) != 0) {
|
||||
bb_simple_perror_msg(filename);
|
||||
G.status = EXIT_FAILURE;
|
||||
@@ -103,15 +91,12 @@ static unsigned long du(const char *filename)
|
||||
}
|
||||
sum = statbuf.st_blocks;
|
||||
if (G.slink_depth == 1) {
|
||||
/* Convert -H to -L */
|
||||
G.slink_depth = INT_MAX;
|
||||
G.slink_depth = INT_MAX; /* Convert -H to -L. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!(option_mask32 & OPT_l_hardlinks)
|
||||
&& statbuf.st_nlink > 1
|
||||
) {
|
||||
if (statbuf.st_nlink > G.count_hardlinks) {
|
||||
/* Add files/directories with links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf)) {
|
||||
return 0;
|
||||
@@ -130,8 +115,14 @@ static unsigned long du(const char *filename)
|
||||
return sum;
|
||||
}
|
||||
|
||||
newfile = last_char_is(filename, '/');
|
||||
if (newfile)
|
||||
*newfile = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
newfile = concat_subpath_file(filename, entry->d_name);
|
||||
char *name = entry->d_name;
|
||||
|
||||
newfile = concat_subpath_file(filename, name);
|
||||
if (newfile == NULL)
|
||||
continue;
|
||||
++G.du_depth;
|
||||
@@ -140,9 +131,8 @@ static unsigned long du(const char *filename)
|
||||
free(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
} else {
|
||||
if (!(option_mask32 & OPT_a_files_too) && G.du_depth != 0)
|
||||
return sum;
|
||||
} else if (G.du_depth > G.print_files) {
|
||||
return sum;
|
||||
}
|
||||
if (G.du_depth <= G.max_print_depth) {
|
||||
print(sum, filename);
|
||||
@@ -155,18 +145,20 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned long total;
|
||||
int slink_depth_save;
|
||||
bool print_final_total;
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
|
||||
IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
|
||||
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 1024;)
|
||||
SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_hr = 512;)
|
||||
if (getenv("POSIXLY_CORRECT")) /* TODO - a new libbb function? */
|
||||
G.disp_hr = 512;
|
||||
#else
|
||||
IF_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
|
||||
/* IF_NOT_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
|
||||
USE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 1;)
|
||||
/* SKIP_FEATURE_DU_DEFAULT_BLOCKSIZE_1K(G.disp_k = 0;) - G is pre-zeroed */
|
||||
#endif
|
||||
G.max_print_depth = INT_MAX;
|
||||
G.count_hardlinks = 1;
|
||||
|
||||
/* Note: SUSv3 specifies that -a and -s options cannot be used together
|
||||
* in strictly conforming applications. However, it also says that some
|
||||
@@ -178,13 +170,16 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s:d+";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &G.max_print_depth);
|
||||
argv += optind;
|
||||
if (opt & OPT_h_for_humans) {
|
||||
if (opt & (1 << 9)) {
|
||||
/* -h opt */
|
||||
G.disp_hr = 0;
|
||||
}
|
||||
if (opt & OPT_m_mbytes) {
|
||||
if (opt & (1 << 10)) {
|
||||
/* -m opt */
|
||||
G.disp_hr = 1024*1024;
|
||||
}
|
||||
if (opt & OPT_k_kbytes) {
|
||||
if (opt & (1 << 2)) {
|
||||
/* -k opt */
|
||||
G.disp_hr = 1024;
|
||||
}
|
||||
#else
|
||||
@@ -192,20 +187,34 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc", &G.max_print_depth);
|
||||
argv += optind;
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & OPT_k_kbytes) {
|
||||
if (opt & (1 << 2)) {
|
||||
/* -k opt */
|
||||
G.disp_k = 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (opt & OPT_H_follow_links) {
|
||||
if (opt & (1 << 0)) {
|
||||
/* -a opt */
|
||||
G.print_files = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 1)) {
|
||||
/* -H opt */
|
||||
G.slink_depth = 1;
|
||||
}
|
||||
if (opt & OPT_L_follow_links) {
|
||||
if (opt & (1 << 3)) {
|
||||
/* -L opt */
|
||||
G.slink_depth = INT_MAX;
|
||||
}
|
||||
if (opt & OPT_s_total_norecurse) {
|
||||
if (opt & (1 << 4)) {
|
||||
/* -s opt */
|
||||
G.max_print_depth = 0;
|
||||
}
|
||||
G.one_file_system = opt & (1 << 5); /* -x opt */
|
||||
if (opt & (1 << 7)) {
|
||||
/* -l opt */
|
||||
G.count_hardlinks = MAXINT(nlink_t);
|
||||
}
|
||||
print_final_total = opt & (1 << 8); /* -c opt */
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (!*argv) {
|
||||
@@ -219,12 +228,12 @@ int du_main(int argc UNUSED_PARAM, char **argv)
|
||||
total = 0;
|
||||
do {
|
||||
total += du(*argv);
|
||||
/* otherwise du /dir /dir won't show /dir twice: */
|
||||
reset_ino_dev_hashtable();
|
||||
G.slink_depth = slink_depth_save;
|
||||
} while (*++argv);
|
||||
|
||||
if (opt & OPT_c_total)
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
reset_ino_dev_hashtable();
|
||||
if (print_final_total)
|
||||
print(total, "total");
|
||||
|
||||
fflush_stdout_and_exit(G.status);
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_putchar('\n');
|
||||
}
|
||||
ret:
|
||||
return fflush_all();
|
||||
return fflush(stdout);
|
||||
}
|
||||
|
||||
/*-
|
||||
|
||||
+16
-20
@@ -43,30 +43,29 @@ static const char env_longopts[] ALIGN1 =
|
||||
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opts;
|
||||
/* cleanenv was static - why? */
|
||||
char *cleanenv[1];
|
||||
char **ep;
|
||||
unsigned opt;
|
||||
llist_t *unset_env = NULL;
|
||||
|
||||
opt_complementary = "u::";
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
applet_long_options = env_longopts;
|
||||
#endif
|
||||
opts = getopt32(argv, "+iu:", &unset_env);
|
||||
opt = getopt32(argv, "+iu:", &unset_env);
|
||||
argv += optind;
|
||||
if (argv[0] && LONE_DASH(argv[0])) {
|
||||
opts |= 1;
|
||||
if (*argv && LONE_DASH(argv[0])) {
|
||||
opt |= 1;
|
||||
++argv;
|
||||
}
|
||||
if (opts & 1) {
|
||||
clearenv();
|
||||
}
|
||||
while (unset_env) {
|
||||
char *var = llist_pop(&unset_env);
|
||||
/* This does not handle -uVAR=VAL
|
||||
* (coreutils _sets_ the variable in that case): */
|
||||
/*unsetenv(var);*/
|
||||
/* This does, but uses somewhan undocumented feature that
|
||||
* putenv("name_without_equal_sign") unsets the variable: */
|
||||
putenv(var);
|
||||
if (opt & 1) {
|
||||
cleanenv[0] = NULL;
|
||||
environ = cleanenv;
|
||||
} else {
|
||||
while (unset_env) {
|
||||
unsetenv(llist_pop(&unset_env));
|
||||
}
|
||||
}
|
||||
|
||||
while (*argv && (strchr(*argv, '=') != NULL)) {
|
||||
@@ -83,11 +82,8 @@ int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_simple_perror_msg_and_die(*argv);
|
||||
}
|
||||
|
||||
if (environ) { /* clearenv() may set environ == NULL! */
|
||||
char **ep;
|
||||
for (ep = environ; *ep; ep++) {
|
||||
puts(*ep);
|
||||
}
|
||||
for (ep = environ; *ep; ep++) {
|
||||
puts(*ep);
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
|
||||
+75
-70
@@ -20,8 +20,8 @@
|
||||
*
|
||||
* Caveat: this versions of expand and unexpand don't accept tab lists.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
enum {
|
||||
OPT_INITIAL = 1 << 0,
|
||||
@@ -29,92 +29,98 @@ enum {
|
||||
OPT_ALL = 1 << 2,
|
||||
};
|
||||
|
||||
static void xputchar(char c)
|
||||
{
|
||||
if (putchar(c) < 0)
|
||||
bb_error_msg_and_die(bb_msg_write_error);
|
||||
}
|
||||
|
||||
#if ENABLE_EXPAND
|
||||
static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
{
|
||||
char *line;
|
||||
char *ptr;
|
||||
int convert;
|
||||
unsigned pos;
|
||||
|
||||
/* Increment tab_size by 1 locally.*/
|
||||
tab_size++;
|
||||
|
||||
while ((line = xmalloc_fgets(file)) != NULL) {
|
||||
unsigned char c;
|
||||
char *ptr;
|
||||
char *ptr_strbeg;
|
||||
|
||||
ptr = ptr_strbeg = line;
|
||||
while ((c = *ptr) != '\0') {
|
||||
if ((opt & OPT_INITIAL) && !isblank(c)) {
|
||||
/* not space or tab */
|
||||
break;
|
||||
convert = 1;
|
||||
pos = 0;
|
||||
ptr = line;
|
||||
while (*line) {
|
||||
pos++;
|
||||
if (*line == '\t' && convert) {
|
||||
for (; pos < tab_size; pos++) {
|
||||
xputchar(' ');
|
||||
}
|
||||
} else {
|
||||
if ((opt & OPT_INITIAL) && !isblank(*line)) {
|
||||
convert = 0;
|
||||
}
|
||||
xputchar(*line);
|
||||
}
|
||||
if (c == '\t') {
|
||||
unsigned len;
|
||||
*ptr = '\0';
|
||||
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
len = unicode_strlen(ptr_strbeg);
|
||||
# else
|
||||
len = ptr - ptr_strbeg;
|
||||
# endif
|
||||
len = tab_size - (len % tab_size);
|
||||
/*while (ptr[1] == '\t') { ptr++; len += tab_size; } - can handle many tabs at once */
|
||||
printf("%s%*s", ptr_strbeg, len, "");
|
||||
ptr_strbeg = ptr + 1;
|
||||
if (pos == tab_size) {
|
||||
pos = 0;
|
||||
}
|
||||
ptr++;
|
||||
line++;
|
||||
}
|
||||
fputs(ptr_strbeg, stdout);
|
||||
free(line);
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_UNEXPAND
|
||||
static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
|
||||
{
|
||||
char *line;
|
||||
char *ptr;
|
||||
int convert;
|
||||
int pos;
|
||||
int i = 0;
|
||||
unsigned column = 0;
|
||||
|
||||
while ((line = xmalloc_fgets(file)) != NULL) {
|
||||
char *ptr = line;
|
||||
unsigned column = 0;
|
||||
|
||||
while (*ptr) {
|
||||
unsigned n;
|
||||
unsigned len;
|
||||
|
||||
while (*ptr == ' ') {
|
||||
convert = 1;
|
||||
pos = 0;
|
||||
ptr = line;
|
||||
while (*line) {
|
||||
while ((*line == ' ' || *line == '\t') && convert) {
|
||||
pos += (*line == ' ') ? 1 : tab_size;
|
||||
line++;
|
||||
column++;
|
||||
ptr++;
|
||||
if ((opt & OPT_ALL) && column == tab_size) {
|
||||
column = 0;
|
||||
goto put_tab;
|
||||
}
|
||||
}
|
||||
if (*ptr == '\t') {
|
||||
column += tab_size - (column % tab_size);
|
||||
ptr++;
|
||||
continue;
|
||||
if (pos) {
|
||||
i = pos / tab_size;
|
||||
if (i) {
|
||||
for (; i > 0; i--) {
|
||||
put_tab:
|
||||
xputchar('\t');
|
||||
}
|
||||
} else {
|
||||
for (i = pos % tab_size; i > 0; i--) {
|
||||
xputchar(' ');
|
||||
}
|
||||
}
|
||||
pos = 0;
|
||||
} else {
|
||||
if (opt & OPT_INITIAL) {
|
||||
convert = 0;
|
||||
}
|
||||
if (opt & OPT_ALL) {
|
||||
column++;
|
||||
}
|
||||
xputchar(*line);
|
||||
line++;
|
||||
}
|
||||
|
||||
n = column / tab_size;
|
||||
column = column % tab_size;
|
||||
while (n--)
|
||||
putchar('\t');
|
||||
|
||||
if ((opt & OPT_INITIAL) && ptr != line) {
|
||||
printf("%*s%s", column, "", ptr);
|
||||
break;
|
||||
}
|
||||
n = strcspn(ptr, "\t ");
|
||||
printf("%*s%.*s", column, "", n, ptr);
|
||||
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
{
|
||||
char c;
|
||||
c = ptr[n];
|
||||
ptr[n] = '\0';
|
||||
len = unicode_strlen(ptr);
|
||||
ptr[n] = c;
|
||||
}
|
||||
# else
|
||||
len = n;
|
||||
# endif
|
||||
ptr += n;
|
||||
column = (column + len) % tab_size;
|
||||
}
|
||||
free(line);
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -144,13 +150,12 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
|
||||
"all\0" No_argument "a"
|
||||
;
|
||||
#endif
|
||||
init_unicode();
|
||||
|
||||
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
|
||||
IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
|
||||
USE_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
|
||||
opt = getopt32(argv, "it:", &opt_t);
|
||||
} else {
|
||||
IF_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
|
||||
USE_FEATURE_UNEXPAND_LONG_OPTIONS(applet_long_options = unexpand_longopts);
|
||||
/* -t NUM sets also -a */
|
||||
opt_complementary = "ta";
|
||||
opt = getopt32(argv, "ft:a", &opt_t);
|
||||
@@ -172,9 +177,9 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e'))
|
||||
IF_EXPAND(expand(file, tab_size, opt));
|
||||
USE_EXPAND(expand(file, tab_size, opt));
|
||||
else
|
||||
IF_UNEXPAND(unexpand(file, tab_size, opt));
|
||||
USE_UNEXPAND(unexpand(file, tab_size, opt));
|
||||
|
||||
/* Check and close the file */
|
||||
if (fclose_if_not_stdin(file)) {
|
||||
|
||||
+14
-11
@@ -214,22 +214,22 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
|
||||
|
||||
static VALUE *docolon(VALUE *sv, VALUE *pv)
|
||||
{
|
||||
enum { NMATCH = 2 };
|
||||
VALUE *v;
|
||||
regex_t re_buffer;
|
||||
const int NMATCH = 2;
|
||||
regmatch_t re_regs[NMATCH];
|
||||
|
||||
tostring(sv);
|
||||
tostring(pv);
|
||||
|
||||
if (pv->u.s[0] == '^') {
|
||||
bb_error_msg(
|
||||
"warning: '%s': using '^' as the first character\n"
|
||||
"of a basic regular expression is not portable; it is ignored", pv->u.s);
|
||||
bb_error_msg("\
|
||||
warning: unportable BRE: `%s': using `^' as the first character\n\
|
||||
of a basic regular expression is not portable; it is being ignored", pv->u.s);
|
||||
}
|
||||
|
||||
memset(&re_buffer, 0, sizeof(re_buffer));
|
||||
memset(re_regs, 0, sizeof(re_regs));
|
||||
memset(re_regs, 0, sizeof(*re_regs));
|
||||
xregcomp(&re_buffer, pv->u.s, 0);
|
||||
|
||||
/* expr uses an anchored pattern match, so check that there was a
|
||||
@@ -238,7 +238,7 @@ static VALUE *docolon(VALUE *sv, VALUE *pv)
|
||||
&& re_regs[0].rm_so == 0
|
||||
) {
|
||||
/* Were \(...\) used? */
|
||||
if (re_buffer.re_nsub > 0 && re_regs[1].rm_so >= 0) {
|
||||
if (re_buffer.re_nsub > 0) {
|
||||
sv->u.s[re_regs[1].rm_eo] = '\0';
|
||||
v = str_value(sv->u.s + re_regs[1].rm_so);
|
||||
} else {
|
||||
@@ -251,7 +251,7 @@ static VALUE *docolon(VALUE *sv, VALUE *pv)
|
||||
else
|
||||
v = int_value(0);
|
||||
}
|
||||
regfree(&re_buffer);
|
||||
//FIXME: sounds like here is a bit missing: regfree(&re_buffer);
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -481,21 +481,24 @@ static VALUE *eval(void)
|
||||
}
|
||||
|
||||
int expr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int expr_main(int argc UNUSED_PARAM, char **argv)
|
||||
int expr_main(int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
xfunc_error_retval = 2; /* coreutils compat */
|
||||
G.args = argv + 1;
|
||||
if (*G.args == NULL) {
|
||||
if (argc == 1) {
|
||||
bb_error_msg_and_die("too few arguments");
|
||||
}
|
||||
|
||||
G.args = argv + 1;
|
||||
|
||||
v = eval();
|
||||
if (*G.args)
|
||||
bb_error_msg_and_die("syntax error");
|
||||
|
||||
if (v->type == INTEGER)
|
||||
printf("%" PF_REZ "d\n", PF_REZ_TYPE v->u.i);
|
||||
else
|
||||
puts(v->u.s);
|
||||
|
||||
fflush_stdout_and_exit(null(v));
|
||||
}
|
||||
+74
-88
@@ -9,8 +9,8 @@
|
||||
|
||||
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
/* Must match getopt32 call */
|
||||
#define FLAG_COUNT_BYTES 1
|
||||
@@ -20,53 +20,39 @@
|
||||
/* Assuming the current column is COLUMN, return the column that
|
||||
printing C will move the cursor to.
|
||||
The first column is 0. */
|
||||
static int adjust_column(unsigned column, char c)
|
||||
static int adjust_column(int column, char c)
|
||||
{
|
||||
if (option_mask32 & FLAG_COUNT_BYTES)
|
||||
return ++column;
|
||||
|
||||
if (c == '\t')
|
||||
return column + 8 - column % 8;
|
||||
|
||||
if (c == '\b') {
|
||||
if ((int)--column < 0)
|
||||
if (!(option_mask32 & FLAG_COUNT_BYTES)) {
|
||||
if (c == '\b') {
|
||||
if (column > 0)
|
||||
column--;
|
||||
} else if (c == '\r')
|
||||
column = 0;
|
||||
}
|
||||
else if (c == '\r')
|
||||
column = 0;
|
||||
else { /* just a printable char */
|
||||
if (unicode_status != UNICODE_ON /* every byte is a new char */
|
||||
|| (c & 0xc0) != 0x80 /* it isn't a 2nd+ byte of a Unicode char */
|
||||
) {
|
||||
else if (c == '\t')
|
||||
column = column + 8 - column % 8;
|
||||
else /* if (isprint (c)) */
|
||||
column++;
|
||||
}
|
||||
}
|
||||
} else
|
||||
column++;
|
||||
return column;
|
||||
}
|
||||
|
||||
/* Note that this function can write NULs, unlike fputs etc. */
|
||||
static void write2stdout(const void *buf, unsigned size)
|
||||
{
|
||||
fwrite(buf, 1, size, stdout);
|
||||
}
|
||||
|
||||
int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int fold_main(int argc UNUSED_PARAM, char **argv)
|
||||
int fold_main(int argc, char **argv)
|
||||
{
|
||||
char *line_out = NULL;
|
||||
const char *w_opt = "80";
|
||||
unsigned width;
|
||||
smallint exitcode = EXIT_SUCCESS;
|
||||
|
||||
init_unicode();
|
||||
int allocated_out = 0;
|
||||
char *w_opt;
|
||||
int width = 80;
|
||||
int i;
|
||||
int errs = 0;
|
||||
|
||||
if (ENABLE_INCLUDE_SUSv2) {
|
||||
/* Turn any numeric options into -w options. */
|
||||
int i;
|
||||
for (i = 1; argv[i]; i++) {
|
||||
const char *a = argv[i];
|
||||
if (*a == '-') {
|
||||
a++;
|
||||
for (i = 1; i < argc; i++) {
|
||||
char const *a = argv[i];
|
||||
|
||||
if (*a++ == '-') {
|
||||
if (*a == '-' && !a[1]) /* "--" */
|
||||
break;
|
||||
if (isdigit(*a))
|
||||
@@ -76,7 +62,8 @@ int fold_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
getopt32(argv, "bsw:", &w_opt);
|
||||
width = xatou_range(w_opt, 1, 10000);
|
||||
if (option_mask32 & FLAG_WIDTH)
|
||||
width = xatoul_range(w_opt, 1, 10000);
|
||||
|
||||
argv += optind;
|
||||
if (!*argv)
|
||||
@@ -85,81 +72,80 @@ int fold_main(int argc UNUSED_PARAM, char **argv)
|
||||
do {
|
||||
FILE *istream = fopen_or_warn_stdin(*argv);
|
||||
int c;
|
||||
unsigned column = 0; /* Screen column where next char will go */
|
||||
unsigned offset_out = 0; /* Index in 'line_out' for next char */
|
||||
int column = 0; /* Screen column where next char will go. */
|
||||
int offset_out = 0; /* Index in 'line_out' for next char. */
|
||||
|
||||
if (istream == NULL) {
|
||||
exitcode = EXIT_FAILURE;
|
||||
errs |= EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((c = getc(istream)) != EOF) {
|
||||
/* We grow line_out in chunks of 0x1000 bytes */
|
||||
if ((offset_out & 0xfff) == 0) {
|
||||
line_out = xrealloc(line_out, offset_out + 0x1000);
|
||||
if (offset_out + 1 >= allocated_out) {
|
||||
allocated_out += 1024;
|
||||
line_out = xrealloc(line_out, allocated_out);
|
||||
}
|
||||
rescan:
|
||||
line_out[offset_out] = c;
|
||||
|
||||
if (c == '\n') {
|
||||
write2stdout(line_out, offset_out + 1);
|
||||
line_out[offset_out++] = c;
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
continue;
|
||||
}
|
||||
rescan:
|
||||
column = adjust_column(column, c);
|
||||
if (column <= width || offset_out == 0) {
|
||||
/* offset_out == 0 case happens
|
||||
* with small width (say, 1) and tabs.
|
||||
* The very first tab already goes to column 8,
|
||||
* but we must not wrap it */
|
||||
offset_out++;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This character would make the line too long.
|
||||
* Print the line plus a newline, and make this character
|
||||
* start the next line */
|
||||
if (option_mask32 & FLAG_BREAK_SPACES) {
|
||||
unsigned i;
|
||||
unsigned logical_end;
|
||||
if (column > width) {
|
||||
/* This character would make the line too long.
|
||||
Print the line plus a newline, and make this character
|
||||
start the next line. */
|
||||
if (option_mask32 & FLAG_BREAK_SPACES) {
|
||||
/* Look for the last blank. */
|
||||
int logical_end;
|
||||
|
||||
/* Look for the last blank. */
|
||||
for (logical_end = offset_out - 1; (int)logical_end >= 0; logical_end--) {
|
||||
if (!isblank(line_out[logical_end]))
|
||||
for (logical_end = offset_out - 1; logical_end >= 0; logical_end--) {
|
||||
if (isblank(line_out[logical_end])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (logical_end >= 0) {
|
||||
/* Found a blank. Don't output the part after it. */
|
||||
logical_end++;
|
||||
fwrite(line_out, sizeof(char), (size_t) logical_end, stdout);
|
||||
bb_putchar('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
The areas being copied here might overlap. */
|
||||
memmove(line_out, line_out + logical_end, offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++) {
|
||||
column = adjust_column(column, line_out[i]);
|
||||
}
|
||||
goto rescan;
|
||||
}
|
||||
} else {
|
||||
if (offset_out == 0) {
|
||||
line_out[offset_out++] = c;
|
||||
continue;
|
||||
|
||||
/* Found a space or tab.
|
||||
* Output up to and including it, and start a new line */
|
||||
logical_end++;
|
||||
/*line_out[logical_end] = '\n'; - NO! this nukes one buffered character */
|
||||
write2stdout(line_out, logical_end);
|
||||
putchar('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
* The areas being copied here might overlap. */
|
||||
memmove(line_out, line_out + logical_end, offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++) {
|
||||
column = adjust_column(column, line_out[i]);
|
||||
}
|
||||
goto rescan;
|
||||
}
|
||||
/* No blank found, wrap will split the overlong word */
|
||||
line_out[offset_out++] = '\n';
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
}
|
||||
/* Output what we accumulated up to now, and start a new line */
|
||||
line_out[offset_out] = '\n';
|
||||
write2stdout(line_out, offset_out + 1);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
} /* while (not EOF) */
|
||||
|
||||
line_out[offset_out++] = c;
|
||||
}
|
||||
|
||||
if (offset_out) {
|
||||
write2stdout(line_out, offset_out);
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
}
|
||||
|
||||
if (fclose_if_not_stdin(istream)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
exitcode = EXIT_FAILURE;
|
||||
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
|
||||
errs |= EXIT_FAILURE;
|
||||
}
|
||||
} while (*++argv);
|
||||
|
||||
fflush_stdout_and_exit(exitcode);
|
||||
fflush_stdout_and_exit(errs);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini fsync implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2008 Nokia Corporation. All rights reserved.
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int fsync_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int status;
|
||||
int opts;
|
||||
|
||||
opts = getopt32(argv, "d"); /* fdatasync */
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
status = EXIT_SUCCESS;
|
||||
do {
|
||||
int fd = open3_or_warn(*argv, O_NOATIME | O_NOCTTY | O_RDONLY, 0);
|
||||
|
||||
if (fd == -1) {
|
||||
status = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
if ((opts ? fdatasync(fd) : fsync(fd))) {
|
||||
//status = EXIT_FAILURE; - do we want this?
|
||||
bb_simple_perror_msg(*argv);
|
||||
}
|
||||
close(fd);
|
||||
} while (*++argv);
|
||||
|
||||
return status;
|
||||
}
|
||||
+5
-5
@@ -25,7 +25,7 @@ static const struct suffix_mult head_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ "", 0 }
|
||||
{ }
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -40,6 +40,7 @@ int head_main(int argc, char **argv)
|
||||
int count_bytes = 0;
|
||||
int header_threshhold = 1;
|
||||
#endif
|
||||
|
||||
FILE *fp;
|
||||
const char *fmt;
|
||||
char *p;
|
||||
@@ -49,7 +50,7 @@ int head_main(int argc, char **argv)
|
||||
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
/* Allow legacy syntax of an initial numeric option without -n. */
|
||||
if (argv[1] && argv[1][0] == '-'
|
||||
if (argc > 1 && argv[1][0] == '-'
|
||||
&& isdigit(argv[1][1])
|
||||
) {
|
||||
--argc;
|
||||
@@ -78,6 +79,7 @@ int head_main(int argc, char **argv)
|
||||
#if ENABLE_INCLUDE_SUSv2 || ENABLE_FEATURE_FANCY_HEAD
|
||||
GET_COUNT:
|
||||
#endif
|
||||
|
||||
#if !ENABLE_FEATURE_FANCY_HEAD
|
||||
count = xatoul(p);
|
||||
#else
|
||||
@@ -126,12 +128,10 @@ int head_main(int argc, char **argv)
|
||||
putchar(c);
|
||||
}
|
||||
if (fclose_if_not_stdin(fp)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
die_if_ferror_stdout();
|
||||
} else {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
fmt = header_fmt_str;
|
||||
} while (*++argv);
|
||||
|
||||
+3
-3
@@ -14,13 +14,13 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int hostid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
int hostid_main(int argc, char **argv UNUSED_PARAM)
|
||||
{
|
||||
if (argv[1]) {
|
||||
if (argc > 1) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
printf("%lx\n", gethostid());
|
||||
|
||||
return fflush_all();
|
||||
return fflush(stdout);
|
||||
}
|
||||
+80
-168
@@ -3,212 +3,124 @@
|
||||
* Mini id implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
|
||||
* Copyright (C) 2008 by Tito Ragusa <farmatito@tiscali.it>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 compliant. */
|
||||
/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever
|
||||
* length and to be more similar to GNU id.
|
||||
/* BB_AUDIT SUSv3 _NOT_ compliant -- option -G is not currently supported. */
|
||||
/* Hacked by Tito Ragusa (C) 2004 to handle usernames of whatever length and to
|
||||
* be more similar to GNU id.
|
||||
* -Z option support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
* Added -G option Tito Ragusa (C) 2008 for SUSv3.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if !ENABLE_USE_BB_PWD_GRP
|
||||
#if defined(__UCLIBC_MAJOR__) && (__UCLIBC_MAJOR__ == 0)
|
||||
#if (__UCLIBC_MINOR__ < 9) || (__UCLIBC_MINOR__ == 9 && __UCLIBC_SUBLEVEL__ < 30)
|
||||
#error "Sorry, you need at least uClibc version 0.9.30 for id applet to build"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
enum {
|
||||
PRINT_REAL = (1 << 0),
|
||||
NAME_NOT_NUMBER = (1 << 1),
|
||||
JUST_USER = (1 << 2),
|
||||
JUST_GROUP = (1 << 3),
|
||||
JUST_ALL_GROUPS = (1 << 4),
|
||||
#define PRINT_REAL 1
|
||||
#define NAME_NOT_NUMBER 2
|
||||
#define JUST_USER 4
|
||||
#define JUST_GROUP 8
|
||||
#if ENABLE_SELINUX
|
||||
JUST_CONTEXT = (1 << 5),
|
||||
#define JUST_CONTEXT 16
|
||||
#endif
|
||||
};
|
||||
|
||||
static int print_common(unsigned id, const char *name, const char *prefix)
|
||||
static int printf_full(unsigned int id, const char *arg, const char prefix)
|
||||
{
|
||||
if (prefix) {
|
||||
printf("%s", prefix);
|
||||
}
|
||||
if (!(option_mask32 & NAME_NOT_NUMBER) || !name) {
|
||||
printf("%u", id);
|
||||
}
|
||||
if (!option_mask32 || (option_mask32 & NAME_NOT_NUMBER)) {
|
||||
if (name) {
|
||||
printf(option_mask32 ? "%s" : "(%s)", name);
|
||||
} else {
|
||||
/* Don't set error status flag in default mode */
|
||||
if (option_mask32) {
|
||||
if (ENABLE_DESKTOP)
|
||||
bb_error_msg("unknown ID %u", id);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
const char *fmt = "%cid=%u";
|
||||
int status = EXIT_FAILURE;
|
||||
|
||||
static int print_group(gid_t id, const char *prefix)
|
||||
{
|
||||
return print_common(id, gid2group(id), prefix);
|
||||
}
|
||||
|
||||
static int print_user(uid_t id, const char *prefix)
|
||||
{
|
||||
return print_common(id, uid2uname(id), prefix);
|
||||
}
|
||||
|
||||
/* On error set *n < 0 and return >= 0
|
||||
* If *n is too small, update it and return < 0
|
||||
* (ok to trash groups[] in both cases)
|
||||
* Otherwise fill in groups[] and return >= 0
|
||||
*/
|
||||
static int get_groups(const char *username, gid_t rgid, gid_t *groups, int *n)
|
||||
{
|
||||
int m;
|
||||
|
||||
if (username) {
|
||||
/* If the user is a member of more than
|
||||
* *n groups, then -1 is returned. Otherwise >= 0.
|
||||
* (and no defined way of detecting errors?!) */
|
||||
m = getgrouplist(username, rgid, groups, n);
|
||||
/* I guess *n < 0 might indicate error. Anyway,
|
||||
* malloc'ing -1 bytes won't be good, so: */
|
||||
//if (*n < 0)
|
||||
// return 0;
|
||||
//return m;
|
||||
//commented out here, happens below anyway
|
||||
} else {
|
||||
/* On error -1 is returned, which ends up in *n */
|
||||
int nn = getgroups(*n, groups);
|
||||
/* 0: nn <= *n, groups[] was big enough; -1 otherwise */
|
||||
m = - (nn > *n);
|
||||
*n = nn;
|
||||
if (arg) {
|
||||
fmt = "%cid=%u(%s)";
|
||||
status = EXIT_SUCCESS;
|
||||
}
|
||||
if (*n < 0)
|
||||
return 0; /* error, don't return < 0! */
|
||||
return m;
|
||||
printf(fmt, prefix, id, arg);
|
||||
return status;
|
||||
}
|
||||
|
||||
int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int id_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
uid_t ruid;
|
||||
gid_t rgid;
|
||||
uid_t euid;
|
||||
gid_t egid;
|
||||
unsigned opt;
|
||||
int i;
|
||||
int status = EXIT_SUCCESS;
|
||||
const char *prefix;
|
||||
const char *username;
|
||||
struct passwd *p;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
unsigned long flags;
|
||||
short status;
|
||||
#if ENABLE_SELINUX
|
||||
security_context_t scontext = NULL;
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
/* Don't allow -n -r -nr -ug -rug -nug -rnug -uZ -gZ -GZ*/
|
||||
/* Don't allow -n -r -nr -ug -rug -nug -rnug */
|
||||
/* Don't allow more than one username */
|
||||
opt_complementary = "?1:u--g:g--u:G--u:u--G:g--G:G--g:r?ugG:n?ugG"
|
||||
IF_SELINUX(":u--Z:Z--u:g--Z:Z--g:G--Z:Z--G");
|
||||
opt = getopt32(argv, "rnugG" IF_SELINUX("Z"));
|
||||
opt_complementary = "?1:u--g:g--u:r?ug:n?ug" USE_SELINUX(":u--Z:Z--u:g--Z:Z--g");
|
||||
flags = getopt32(argv, "rnug" USE_SELINUX("Z"));
|
||||
|
||||
username = argv[optind];
|
||||
if (username) {
|
||||
struct passwd *p = xgetpwnam(username);
|
||||
euid = ruid = p->pw_uid;
|
||||
egid = rgid = p->pw_gid;
|
||||
} else {
|
||||
egid = getegid();
|
||||
rgid = getgid();
|
||||
euid = geteuid();
|
||||
ruid = getuid();
|
||||
/* This values could be overwritten later */
|
||||
uid = geteuid();
|
||||
gid = getegid();
|
||||
if (flags & PRINT_REAL) {
|
||||
uid = getuid();
|
||||
gid = getgid();
|
||||
}
|
||||
/* JUST_ALL_GROUPS ignores -r PRINT_REAL flag even if man page for */
|
||||
/* id says: print the real ID instead of the effective ID, with -ugG */
|
||||
/* in fact in this case egid is always printed if egid != rgid */
|
||||
if (!opt || (opt & JUST_ALL_GROUPS)) {
|
||||
gid_t *groups;
|
||||
int n;
|
||||
|
||||
if (!opt) {
|
||||
/* Default Mode */
|
||||
status |= print_user(ruid, "uid=");
|
||||
status |= print_group(rgid, " gid=");
|
||||
if (euid != ruid)
|
||||
status |= print_user(euid, " euid=");
|
||||
if (egid != rgid)
|
||||
status |= print_group(egid, " egid=");
|
||||
if (argv[optind]) {
|
||||
p = getpwnam(argv[optind]);
|
||||
/* xuname2uid is needed because it exits on failure */
|
||||
uid = xuname2uid(argv[optind]);
|
||||
gid = p->pw_gid;
|
||||
/* in this case PRINT_REAL is the same */
|
||||
}
|
||||
|
||||
if (flags & (JUST_GROUP | JUST_USER USE_SELINUX(| JUST_CONTEXT))) {
|
||||
/* JUST_GROUP and JUST_USER are mutually exclusive */
|
||||
if (flags & NAME_NOT_NUMBER) {
|
||||
/* bb_getXXXid(-1) exit on failure, puts cannot segfault */
|
||||
puts((flags & JUST_USER) ? bb_getpwuid(NULL, -1, uid) : bb_getgrgid(NULL, -1, gid));
|
||||
} else {
|
||||
/* JUST_ALL_GROUPS */
|
||||
status |= print_group(rgid, NULL);
|
||||
if (egid != rgid)
|
||||
status |= print_group(egid, " ");
|
||||
}
|
||||
/* We are supplying largish buffer, trying
|
||||
* to not run get_groups() twice. That might be slow
|
||||
* ("user database in remote SQL server" case) */
|
||||
groups = xmalloc(64 * sizeof(gid_t));
|
||||
n = 64;
|
||||
if (get_groups(username, rgid, groups, &n) < 0) {
|
||||
/* Need bigger buffer after all */
|
||||
groups = xrealloc(groups, n * sizeof(gid_t));
|
||||
get_groups(username, rgid, groups, &n);
|
||||
}
|
||||
if (n > 0) {
|
||||
/* Print the list */
|
||||
prefix = " groups=";
|
||||
for (i = 0; i < n; i++) {
|
||||
if (opt && (groups[i] == rgid || groups[i] == egid))
|
||||
continue;
|
||||
status |= print_group(groups[i], opt ? " " : prefix);
|
||||
prefix = ",";
|
||||
if (flags & JUST_USER) {
|
||||
printf("%u\n", uid);
|
||||
}
|
||||
if (flags & JUST_GROUP) {
|
||||
printf("%u\n", gid);
|
||||
}
|
||||
} else if (n < 0) { /* error in get_groups() */
|
||||
if (!ENABLE_DESKTOP)
|
||||
bb_error_msg_and_die("can't get groups");
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(groups);
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (is_selinux_enabled()) {
|
||||
if (getcon(&scontext) == 0)
|
||||
printf(" context=%s", scontext);
|
||||
if (flags & JUST_CONTEXT) {
|
||||
selinux_or_die();
|
||||
if (argc - optind == 1) {
|
||||
bb_error_msg_and_die("user name can't be passed with -Z");
|
||||
}
|
||||
|
||||
if (getcon(&scontext)) {
|
||||
bb_error_msg_and_die("can't get process context");
|
||||
}
|
||||
puts(scontext);
|
||||
}
|
||||
#endif
|
||||
} else if (opt & PRINT_REAL) {
|
||||
euid = ruid;
|
||||
egid = rgid;
|
||||
/* exit */
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
if (opt & JUST_USER)
|
||||
status |= print_user(euid, NULL);
|
||||
else if (opt & JUST_GROUP)
|
||||
status |= print_group(egid, NULL);
|
||||
/* Print full info like GNU id */
|
||||
/* bb_getpwuid(0) doesn't exit on failure (returns NULL) */
|
||||
status = printf_full(uid, bb_getpwuid(NULL, 0, uid), 'u');
|
||||
bb_putchar(' ');
|
||||
status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), 'g');
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
else if (opt & JUST_CONTEXT) {
|
||||
selinux_or_die();
|
||||
if (username || getcon(&scontext)) {
|
||||
bb_error_msg_and_die("can't get process context%s",
|
||||
username ? " for a different user" : "");
|
||||
if (is_selinux_enabled()) {
|
||||
security_context_t mysid;
|
||||
const char *context;
|
||||
|
||||
context = "unknown";
|
||||
getcon(&mysid);
|
||||
if (mysid) {
|
||||
context = alloca(strlen(mysid) + 1);
|
||||
strcpy((char*)context, mysid);
|
||||
freecon(mysid);
|
||||
}
|
||||
fputs(scontext, stdout);
|
||||
printf(" context=%s", context);
|
||||
}
|
||||
/* freecon(NULL) seems to be harmless */
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
freecon(scontext);
|
||||
#endif
|
||||
|
||||
bb_putchar('\n');
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
#!/bin/bash
|
||||
# Test script for busybox id vs. coreutils id.
|
||||
# Needs root privileges for some tests.
|
||||
|
||||
cp /usr/bin/id .
|
||||
BUSYBOX=./busybox
|
||||
ID=./id
|
||||
LIST=`awk -F: '{ printf "%s\n", $1 }' /etc/passwd`
|
||||
FLAG_USER_EXISTS="no"
|
||||
TEST_USER="f583ca884c1d93458fb61ed137ff44f6"
|
||||
|
||||
echo "test 1: id [options] nousername"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
|
||||
echo "test 2: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
if test "$i" = "$TEST_USER"; then
|
||||
FLAG_USER_EXISTS="yes"
|
||||
fi
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
if test $FLAG_USER_EXISTS = "yes"; then
|
||||
echo "test 3,4,5,6,7,8,9,10,11,12 skipped because test user $TEST_USER already exists"
|
||||
rm -f foo bar
|
||||
exit 1
|
||||
fi
|
||||
|
||||
adduser -s /bin/true -g "" -H -D "$TEST_USER" || exit 1
|
||||
|
||||
chown $TEST_USER.$TEST_USER $BUSYBOX
|
||||
chmod u+s $BUSYBOX 2>&1 /dev/null
|
||||
chown $TEST_USER.$TEST_USER $ID
|
||||
chmod u+s $ID 2>&1 /dev/null
|
||||
|
||||
echo "test 3 setuid, existing user: id [options] no username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
#done
|
||||
done
|
||||
|
||||
echo "test 4 setuid, existing user: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
chown $TEST_USER.$TEST_USER $BUSYBOX
|
||||
chmod g+s $BUSYBOX 2>&1 /dev/null
|
||||
chown $TEST_USER.$TEST_USER $ID
|
||||
chmod g+s $ID 2>&1 /dev/null
|
||||
|
||||
echo "test 5 setgid, existing user: id [options] no username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
#done
|
||||
done
|
||||
|
||||
echo "test 6 setgid, existing user: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
chown $TEST_USER.$TEST_USER $BUSYBOX
|
||||
chmod u+s,g+s $BUSYBOX 2>&1 /dev/null
|
||||
chown $TEST_USER.$TEST_USER $ID
|
||||
chmod u+s,g+s $ID 2>&1 /dev/null
|
||||
|
||||
echo "test 7 setuid, setgid, existing user: id [options] no username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
#done
|
||||
done
|
||||
|
||||
echo "test 8 setuid, setgid, existing user: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
deluser $TEST_USER || exit 1
|
||||
|
||||
echo "test 9 setuid, setgid, not existing user: id [options] no username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
|
||||
echo "test 10 setuid, setgid, not existing user: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
chown .root $BUSYBOX 2>&1 /dev/null
|
||||
chown .root $ID 2>&1 /dev/null
|
||||
chmod g+s $BUSYBOX 2>&1 /dev/null
|
||||
chmod g+s $ID 2>&1 /dev/null
|
||||
|
||||
echo "test 11 setgid, not existing group: id [options] no username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
$BUSYBOX id $OPTIONS >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
#done
|
||||
done
|
||||
|
||||
echo "test 12 setgid, not existing group: id [options] username"
|
||||
rm -f foo bar
|
||||
for OPTIONS in "" "-u" "-un" "-unr" "-g" "-gn" "-gnr" "-G" "-Gn" "-Gnr"
|
||||
do
|
||||
#echo "$OPTIONS"
|
||||
for i in $LIST ; do
|
||||
$BUSYBOX id $OPTIONS $i >foo 2>/dev/null
|
||||
RET1=$?
|
||||
$ID $OPTIONS $i >bar 2>/dev/null
|
||||
RET2=$?
|
||||
if test "$RET1" != "$RET2"; then
|
||||
echo "Return Values differ ($RET1 != $RET2): options $OPTIONS"
|
||||
fi
|
||||
diff foo bar
|
||||
done
|
||||
done
|
||||
|
||||
chown root.root $BUSYBOX 2>&1 /dev/null
|
||||
chown root.root $ID 2>&1 /dev/null
|
||||
rm -f $ID
|
||||
rm -f foo bar
|
||||
+31
-39
@@ -4,6 +4,9 @@
|
||||
* SELinux support: by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* TODO: -d option, need a way of recursively making directories and changing
|
||||
* owner/group, will probably modify bb_make_directory(...)
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -50,8 +53,7 @@ static void setdefaultfilecon(const char *path)
|
||||
|
||||
if (lsetfilecon(path, scontext) < 0) {
|
||||
if (errno != ENOTSUP) {
|
||||
bb_perror_msg("warning: failed to change context"
|
||||
" of %s to %s", path, scontext);
|
||||
bb_perror_msg("warning: failed to change context of %s to %s", path, scontext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +75,7 @@ int install_main(int argc, char **argv)
|
||||
const char *uid_str;
|
||||
const char *mode_str;
|
||||
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
|
||||
int opts;
|
||||
int flags;
|
||||
int min_args = 1;
|
||||
int ret = EXIT_SUCCESS;
|
||||
int isdir = 0;
|
||||
@@ -85,58 +87,56 @@ int install_main(int argc, char **argv)
|
||||
OPT_c = 1 << 0,
|
||||
OPT_v = 1 << 1,
|
||||
OPT_b = 1 << 2,
|
||||
OPT_MKDIR_LEADING = 1 << 3,
|
||||
OPT_DIRECTORY = 1 << 4,
|
||||
OPT_PRESERVE_TIME = 1 << 5,
|
||||
OPT_STRIP = 1 << 6,
|
||||
OPT_GROUP = 1 << 7,
|
||||
OPT_MODE = 1 << 8,
|
||||
OPT_OWNER = 1 << 9,
|
||||
OPT_DIRECTORY = 1 << 3,
|
||||
OPT_PRESERVE_TIME = 1 << 4,
|
||||
OPT_STRIP = 1 << 5,
|
||||
OPT_GROUP = 1 << 6,
|
||||
OPT_MODE = 1 << 7,
|
||||
OPT_OWNER = 1 << 8,
|
||||
#if ENABLE_SELINUX
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 10,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 11,
|
||||
OPT_SET_SECURITY_CONTEXT = 1 << 9,
|
||||
OPT_PRESERVE_SECURITY_CONTEXT = 1 << 10,
|
||||
#endif
|
||||
};
|
||||
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
opt_complementary = "s--d:d--s" USE_SELINUX(":Z--\xff:\xff--Z");
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
opts = getopt32(argv, "cvb" "Ddpsg:m:o:" IF_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str IF_SELINUX(, &scontext));
|
||||
flags = getopt32(argv, "cvb" "dpsg:m:o:" USE_SELINUX("Z:"),
|
||||
&gid_str, &mode_str, &uid_str USE_SELINUX(, &scontext));
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (opts & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
|
||||
if (flags & (OPT_PRESERVE_SECURITY_CONTEXT|OPT_SET_SECURITY_CONTEXT)) {
|
||||
selinux_or_die();
|
||||
use_default_selinux_context = 0;
|
||||
if (opts & OPT_PRESERVE_SECURITY_CONTEXT) {
|
||||
if (flags & OPT_PRESERVE_SECURITY_CONTEXT) {
|
||||
copy_flags |= FILEUTILS_PRESERVE_SECURITY_CONTEXT;
|
||||
}
|
||||
if (opts & OPT_SET_SECURITY_CONTEXT) {
|
||||
if (flags & OPT_SET_SECURITY_CONTEXT) {
|
||||
setfscreatecon_or_die(scontext);
|
||||
copy_flags |= FILEUTILS_SET_SECURITY_CONTEXT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* preserve access and modification time, this is GNU behaviour,
|
||||
* BSD only preserves modification time */
|
||||
if (opts & OPT_PRESERVE_TIME) {
|
||||
/* preserve access and modification time, this is GNU behaviour, BSD only preserves modification time */
|
||||
if (flags & OPT_PRESERVE_TIME) {
|
||||
copy_flags |= FILEUTILS_PRESERVE_STATUS;
|
||||
}
|
||||
mode = 0755; /* GNU coreutils 6.10 compat */
|
||||
if (opts & OPT_MODE)
|
||||
mode = 0666;
|
||||
if (flags & OPT_MODE)
|
||||
bb_parse_mode(mode_str, &mode);
|
||||
uid = (opts & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (opts & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
|
||||
gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
|
||||
|
||||
last = argv[argc - 1];
|
||||
if (!(opts & OPT_DIRECTORY)) {
|
||||
if (!(flags & OPT_DIRECTORY)) {
|
||||
argv[argc - 1] = NULL;
|
||||
min_args++;
|
||||
|
||||
@@ -149,7 +149,7 @@ int install_main(int argc, char **argv)
|
||||
|
||||
while ((arg = *argv++) != NULL) {
|
||||
char *dest = last;
|
||||
if (opts & OPT_DIRECTORY) {
|
||||
if (flags & OPT_DIRECTORY) {
|
||||
dest = arg;
|
||||
/* GNU coreutils 6.9 does not set uid:gid
|
||||
* on intermediate created directories
|
||||
@@ -159,13 +159,6 @@ int install_main(int argc, char **argv)
|
||||
goto next;
|
||||
}
|
||||
} else {
|
||||
if (opts & OPT_MKDIR_LEADING) {
|
||||
char *ddir = xstrdup(dest);
|
||||
bb_make_directory(dirname(ddir), 0755, FILEUTILS_RECUR);
|
||||
/* errors are not checked. copy_file
|
||||
* will fail if dir is not created. */
|
||||
free(ddir);
|
||||
}
|
||||
if (isdir)
|
||||
dest = concat_path_file(last, basename(arg));
|
||||
if (copy_file(arg, dest, copy_flags)) {
|
||||
@@ -175,9 +168,8 @@ int install_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
/* Set the file mode (always, not only with -m).
|
||||
* GNU coreutils 6.10 is not affected by umask. */
|
||||
if (chmod(dest, mode) == -1) {
|
||||
/* Set the file mode */
|
||||
if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
|
||||
bb_perror_msg("can't change %s of %s", "permissions", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
@@ -186,13 +178,13 @@ int install_main(int argc, char **argv)
|
||||
setdefaultfilecon(dest);
|
||||
#endif
|
||||
/* Set the user and group id */
|
||||
if ((opts & (OPT_OWNER|OPT_GROUP))
|
||||
if ((flags & (OPT_OWNER|OPT_GROUP))
|
||||
&& lchown(dest, uid, gid) == -1
|
||||
) {
|
||||
bb_perror_msg("can't change %s of %s", "ownership", dest);
|
||||
ret = EXIT_FAILURE;
|
||||
}
|
||||
if (opts & OPT_STRIP) {
|
||||
if (flags & OPT_STRIP) {
|
||||
char *args[3];
|
||||
args[0] = (char*)"strip";
|
||||
args[1] = dest;
|
||||
|
||||
+1
-4
@@ -1,7 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */
|
||||
|
||||
@@ -18,5 +15,5 @@ int length_main(int argc, char **argv)
|
||||
|
||||
printf("%u\n", (unsigned)strlen(*argv));
|
||||
|
||||
return fflush_all();
|
||||
return fflush(stdout);
|
||||
}
|
||||
@@ -4,9 +4,11 @@
|
||||
*/
|
||||
|
||||
#ifndef COREUTILS_H
|
||||
#define COREUTILS_H 1
|
||||
#define COREUTILS_H 1
|
||||
|
||||
PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
|
||||
#if __GNUC_PREREQ(4,1)
|
||||
# pragma GCC visibility push(hidden)
|
||||
#endif
|
||||
|
||||
typedef int (*stat_func)(const char *fn, struct stat *ps);
|
||||
|
||||
@@ -15,6 +17,8 @@ int cp_mv_stat(const char *fn, struct stat *fn_stat) FAST_FUNC;
|
||||
|
||||
mode_t getopt_mk_fifo_nod(char **argv) FAST_FUNC;
|
||||
|
||||
POP_SAVED_FUNCTION_VISIBILITY
|
||||
#if __GNUC_PREREQ(4,1)
|
||||
# pragma GCC visibility pop
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -29,11 +29,11 @@ int FAST_FUNC cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
|
||||
if (errno != ENOENT) {
|
||||
#if ENABLE_FEATURE_VERBOSE_CP_MESSAGE
|
||||
if (errno == ENOTDIR) {
|
||||
bb_error_msg("can't stat '%s': Path has non-directory component", fn);
|
||||
bb_error_msg("cannot stat '%s': Path has non-directory component", fn);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
bb_perror_msg("can't stat '%s'", fn);
|
||||
bb_perror_msg("cannot stat '%s'", fn);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -31,7 +31,7 @@ mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
|
||||
security_context_t scontext;
|
||||
#endif
|
||||
int opt;
|
||||
opt = getopt32(argv, "m:" IF_SELINUX("Z:"), &smode IF_SELINUX(,&scontext));
|
||||
opt = getopt32(argv, "m:" USE_SELINUX("Z:"), &smode USE_SELINUX(,&scontext));
|
||||
if (opt & 1) {
|
||||
if (bb_parse_mode(smode, &mode))
|
||||
umask(0);
|
||||
|
||||
Loaded 100 of 979 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user