Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c71db663de | ||
|
|
8b7f6928c6 | ||
|
|
a2af67a8c5 | ||
|
|
d0119d15f9 | ||
|
|
8d42f86b14 |
No files matched your search
@@ -101,7 +101,8 @@ config FEATURE_INSTALLER
|
||||
help
|
||||
Enable 'busybox --install [-s]' support. This will allow you to use
|
||||
busybox at runtime to create hard links or symlinks for all the
|
||||
applets that are compiled into busybox.
|
||||
applets that are compiled into busybox. This feature requires the
|
||||
/proc filesystem.
|
||||
|
||||
config LOCALE_SUPPORT
|
||||
bool "Enable locale support (system needs locale for this to work)"
|
||||
@@ -140,13 +141,6 @@ config FEATURE_CLEAN_UP
|
||||
Don't enable this unless you have a really good reason to clean
|
||||
things up manually.
|
||||
|
||||
config FEATURE_PIDFILE
|
||||
bool "Support writing pidfiles"
|
||||
default n
|
||||
help
|
||||
This option makes some applets (e.g. crond, syslogd, inetd) write
|
||||
a pidfile in /var/run. Some applications rely on them.
|
||||
|
||||
config FEATURE_SUID
|
||||
bool "Support for SUID/SGID handling"
|
||||
default n
|
||||
@@ -162,6 +156,13 @@ config FEATURE_SUID
|
||||
are login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs,
|
||||
and vlock.
|
||||
|
||||
config FEATURE_SYSLOG
|
||||
bool "Support for 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.
|
||||
|
||||
config FEATURE_SUID_CONFIG
|
||||
bool "Runtime SUID/SGID configuration via /etc/busybox.conf"
|
||||
default n if FEATURE_SUID
|
||||
@@ -202,6 +203,14 @@ config FEATURE_SUID_CONFIG_QUIET
|
||||
/etc/busybox.conf should be readable by the user needing the SUID, check
|
||||
this option to avoid users to be notified about missing permissions.
|
||||
|
||||
config FEATURE_HAVE_RPC
|
||||
bool "RPC support"
|
||||
default y
|
||||
help
|
||||
Select this if you have rpc support.
|
||||
This automatically turns off all configuration options that rely
|
||||
on RPC.
|
||||
|
||||
config SELINUX
|
||||
bool "Support NSA Security Enhanced Linux"
|
||||
default n
|
||||
@@ -222,20 +231,6 @@ config SELINUX
|
||||
|
||||
Most people will leave this set to 'N'.
|
||||
|
||||
config FEATURE_PREFER_APPLETS
|
||||
bool "exec prefers applets"
|
||||
default n
|
||||
help
|
||||
This is an experimental option which directs applets about to
|
||||
call 'exec' to try and find an applicable busybox applet before
|
||||
searching the PATH. This is typically done by exec'ing
|
||||
/proc/self/exe.
|
||||
This may affect shell, find -exec, xargs and similar applets.
|
||||
They will use applets even if /bin/<applet> -> busybox link
|
||||
is missing (or is not a link to busybox). However, this causes
|
||||
problems in chroot jails without mounted /proc and with ps/top
|
||||
(command name can be shown as 'exe' for applets started this way).
|
||||
|
||||
config BUSYBOX_EXEC_PATH
|
||||
string "Path to BusyBox executable"
|
||||
default "/proc/self/exe"
|
||||
@@ -246,22 +241,6 @@ config BUSYBOX_EXEC_PATH
|
||||
executable. If you haven't got /proc, set this to wherever you
|
||||
want to run BusyBox from.
|
||||
|
||||
# These are auto-selected by other options
|
||||
|
||||
config FEATURE_SYSLOG
|
||||
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.
|
||||
|
||||
config FEATURE_HAVE_RPC
|
||||
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.
|
||||
|
||||
endmenu
|
||||
|
||||
menu 'Build Options'
|
||||
@@ -365,29 +344,21 @@ config DEBUG
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
config WERROR
|
||||
bool "Abort compilation on any warning"
|
||||
config DEBUG_PESSIMIZE
|
||||
bool "Disable compiler optimizations."
|
||||
default n
|
||||
depends on DEBUG
|
||||
help
|
||||
Selecting this will add -Werror to gcc command line.
|
||||
|
||||
Most people should answer N.
|
||||
|
||||
# Seems to be unused
|
||||
#config DEBUG_PESSIMIZE
|
||||
# bool "Disable compiler optimizations."
|
||||
# default n
|
||||
# depends on DEBUG
|
||||
# help
|
||||
# The compiler's optimization of source code can eliminate and reorder
|
||||
# code, resulting in an executable that's hard to understand when
|
||||
# stepping through it with a debugger. This switches it off, resulting
|
||||
# in a much bigger executable that more closely matches the source
|
||||
# code.
|
||||
The compiler's optimization of source code can eliminate and reorder
|
||||
code, resulting in an executable that's hard to understand when
|
||||
stepping through it with a debugger. This switches it off, resulting
|
||||
in a much bigger executable that more closely matches the source
|
||||
code.
|
||||
|
||||
choice
|
||||
prompt "Additional debugging library"
|
||||
default NO_DEBUG_LIB
|
||||
depends on DEBUG
|
||||
help
|
||||
Using an additional debugging library will make BusyBox become
|
||||
considerable larger and will cause it to run more slowly. You
|
||||
@@ -426,14 +397,14 @@ config EFENCE
|
||||
|
||||
endchoice
|
||||
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3?"
|
||||
config DEBUG_YANK_SUSv2
|
||||
bool "Disable obsolete features removed before SUSv3?"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
This option will disable 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.)
|
||||
will not be supported in head, tail, and fold. (Note: should
|
||||
yank from renice too.)
|
||||
|
||||
endmenu
|
||||
|
||||
@@ -447,30 +418,31 @@ config INSTALL_NO_USR
|
||||
that you really want this behaviour.
|
||||
|
||||
choice
|
||||
prompt "Applets links"
|
||||
default INSTALL_APPLET_SYMLINKS
|
||||
help
|
||||
Choose how you install applets links.
|
||||
prompt "Applets links"
|
||||
default INSTALL_APPLET_SYMLINKS
|
||||
help
|
||||
Choose how you install applets links.
|
||||
|
||||
config INSTALL_APPLET_SYMLINKS
|
||||
bool "as soft-links"
|
||||
help
|
||||
Install applets as soft-links to the busybox binary. This needs some
|
||||
free inodes on the filesystem, but might help with filesystem
|
||||
generators that can't cope with hard-links.
|
||||
bool "as soft-links"
|
||||
help
|
||||
Install applets as soft-links to the busybox binary. This needs some
|
||||
free inodes on the filesystem, but might help with filesystem
|
||||
generators that can't cope with hard-links.
|
||||
|
||||
config INSTALL_APPLET_HARDLINKS
|
||||
bool "as hard-links"
|
||||
help
|
||||
Install applets as hard-links to the busybox binary. This might count
|
||||
on a filesystem with few inodes.
|
||||
bool "as hard-links"
|
||||
help
|
||||
Install applets as hard-links to the busybox binary. This might count
|
||||
on a filesystem with few inodes.
|
||||
|
||||
config INSTALL_APPLET_DONT
|
||||
bool "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE || FEATURE_PREFER_APPLETS
|
||||
help
|
||||
Do not install applet links. Useful when using the -install feature
|
||||
or a standalone shell for rescue purposes.
|
||||
bool
|
||||
prompt "not installed"
|
||||
depends on FEATURE_INSTALLER || FEATURE_SH_STANDALONE_SHELL
|
||||
help
|
||||
Do not install applets links. Usefull when using the -install feature
|
||||
or a standalone shell for rescue pruposes.
|
||||
|
||||
endchoice
|
||||
|
||||
@@ -505,5 +477,3 @@ source procps/Config.in
|
||||
source shell/Config.in
|
||||
source sysklogd/Config.in
|
||||
source runit/Config.in
|
||||
source selinux/Config.in
|
||||
source ipsvd/Config.in
|
||||
@@ -5,7 +5,7 @@ The BusyBox build process is similar to the Linux kernel build:
|
||||
|
||||
make menuconfig # This creates a file called ".config"
|
||||
make # This creates the "busybox" executable
|
||||
make install # or make CONFIG_PREFIX=/path/from/root install
|
||||
make install # or make PREFIX=/path/from/root install
|
||||
|
||||
The full list of configuration and install options is available by typing:
|
||||
|
||||
@@ -114,7 +114,7 @@ configuration step, as in:
|
||||
make O=/some/empty/directory allyesconfig
|
||||
cd /some/empty/directory
|
||||
make
|
||||
make CONFIG_PREFIX=. install
|
||||
make PREFIX=. install
|
||||
|
||||
More Information:
|
||||
=================
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 7
|
||||
SUBLEVEL = 5
|
||||
PATCHLEVEL = 3
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -71,7 +71,7 @@ endif
|
||||
# In both cases the working directory must be the root of the kernel src.
|
||||
# 1) O=
|
||||
# Use "make O=dir/to/store/output/files/"
|
||||
#
|
||||
#
|
||||
# 2) Set KBUILD_OUTPUT
|
||||
# Set the environment variable KBUILD_OUTPUT to point to the directory
|
||||
# where the output files shall be placed.
|
||||
@@ -145,7 +145,7 @@ export srctree objtree VPATH TOPDIR
|
||||
# SUBARCH tells the usermode build what the underlying arch is. That is set
|
||||
# first, and if a usermode build is happening, the "ARCH=um" on the command
|
||||
# line overrides the setting of ARCH below. If a native build is happening,
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# then ARCH is assigned, getting whatever value it gets normally, and
|
||||
# SUBARCH is subsequently ignored.
|
||||
|
||||
SUBARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
|
||||
@@ -183,6 +183,11 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
|
||||
else if [ -x /bin/bash ]; then echo /bin/bash; \
|
||||
else echo sh; fi ; fi)
|
||||
|
||||
HOSTCC = gcc
|
||||
HOSTCXX = g++
|
||||
HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
|
||||
HOSTCXXFLAGS = -O2
|
||||
|
||||
# Decide whether to build built-in, modular, or both.
|
||||
# Normally, just do built-in.
|
||||
|
||||
@@ -224,7 +229,7 @@ export KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
|
||||
# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
|
||||
#
|
||||
# If $(quiet) is empty, the whole command will be printed.
|
||||
# If it is set to "quiet_", only the short version will be printed.
|
||||
# If it is set to "quiet_", only the short version will be printed.
|
||||
# If it is set to "silent_", nothing wil be printed at all, since
|
||||
# the variable $(silent_cmd_cc_o_c) doesn't exist.
|
||||
#
|
||||
@@ -257,16 +262,9 @@ export quiet Q KBUILD_VERBOSE
|
||||
# Look for make include files relative to root of kernel src
|
||||
MAKEFLAGS += --include-dir=$(srctree)
|
||||
|
||||
HOSTCC = gcc
|
||||
HOSTCXX = g++
|
||||
HOSTCFLAGS :=
|
||||
HOSTCXXFLAGS :=
|
||||
# We need some generic definitions
|
||||
include $(srctree)/scripts/Kbuild.include
|
||||
|
||||
HOSTCFLAGS += $(call hostcc-option,-Wall -Wstrict-prototypes -O2 -fomit-frame-pointer,)
|
||||
HOSTCXXFLAGS += -O2
|
||||
|
||||
# For maximum performance (+ possibly random breakage, uncomment
|
||||
# the following)
|
||||
|
||||
@@ -275,8 +273,8 @@ MAKEFLAGS += -rR
|
||||
# Make variables (CC, etc...)
|
||||
|
||||
AS = $(CROSS_COMPILE)as
|
||||
LD = $(CROSS_COMPILE)ld
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
LD = $(CC) -nostdlib
|
||||
CPP = $(CC) -E
|
||||
AR = $(CROSS_COMPILE)ar
|
||||
NM = $(CROSS_COMPILE)nm
|
||||
@@ -301,11 +299,9 @@ AFLAGS_KERNEL =
|
||||
|
||||
# Use LINUXINCLUDE when you must reference the include/ directory.
|
||||
# Needed to be compatible with the O= option
|
||||
CFLAGS := $(CFLAGS)
|
||||
CPPFLAGS := $(CPPFLAGS)
|
||||
AFLAGS := $(AFLAGS)
|
||||
LDFLAGS := $(LDFLAGS)
|
||||
LDLIBS :=
|
||||
CFLAGS :=
|
||||
CPPFLAGS :=
|
||||
AFLAGS :=
|
||||
|
||||
# Read KERNELRELEASE from .kernelrelease (if it exists)
|
||||
KERNELRELEASE = $(shell cat .kernelrelease 2> /dev/null)
|
||||
@@ -317,9 +313,8 @@ export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION \
|
||||
HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
|
||||
|
||||
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
|
||||
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
|
||||
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
|
||||
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
|
||||
export FLTFLAGS
|
||||
|
||||
# When compiling out-of-tree modules, put MODVERDIR in the module
|
||||
# tree rather than in the kernel tree. The kernel tree might
|
||||
@@ -356,7 +351,7 @@ endif
|
||||
# catch them early, and hand them over to scripts/kconfig/Makefile
|
||||
# It is allowed to specify more targets when calling make, including
|
||||
# mixing *config targets and build targets.
|
||||
# For example 'make oldconfig all'.
|
||||
# For example 'make oldconfig all'.
|
||||
# Detect when mixed targets is specified, and make a second invocation
|
||||
# of make so .config is not included in this case either (for *config).
|
||||
|
||||
@@ -434,10 +429,13 @@ libs-y := \
|
||||
coreutils/libcoreutils/ \
|
||||
debianutils/ \
|
||||
e2fsprogs/ \
|
||||
e2fsprogs/blkid/ \
|
||||
e2fsprogs/e2p/ \
|
||||
e2fsprogs/ext2fs/ \
|
||||
e2fsprogs/uuid/ \
|
||||
editors/ \
|
||||
findutils/ \
|
||||
init/ \
|
||||
ipsvd/ \
|
||||
libbb/ \
|
||||
libpwdgrp/ \
|
||||
loginutils/ \
|
||||
@@ -448,7 +446,6 @@ libs-y := \
|
||||
networking/udhcp/ \
|
||||
procps/ \
|
||||
runit/ \
|
||||
selinux/ \
|
||||
shell/ \
|
||||
sysklogd/ \
|
||||
util-linux/ \
|
||||
@@ -487,7 +484,7 @@ endif
|
||||
# The all: target is the default when no target is given on the
|
||||
# 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
|
||||
# Defaults busybox but it is usually overriden in the arch makefile
|
||||
all: busybox
|
||||
|
||||
-include $(srctree)/arch/$(ARCH)/Makefile
|
||||
@@ -536,6 +533,7 @@ libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
|
||||
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
|
||||
libs-y := $(libs-y1) $(libs-y2)
|
||||
|
||||
|
||||
# Build busybox
|
||||
# ---------------------------------------------------------------------------
|
||||
# busybox is build from the objects selected by $(busybox-init) and
|
||||
@@ -568,14 +566,20 @@ busybox-all := $(core-y) $(libs-y)
|
||||
# Rule to link busybox - also used during CONFIG_KALLSYMS
|
||||
# May be overridden by arch/$(ARCH)/Makefile
|
||||
quiet_cmd_busybox__ ?= LINK $@
|
||||
ifdef CONFIG_STATIC
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) $(LDFLAGS) \
|
||||
-o $@ -Wl,-Map -Wl,$@.map \
|
||||
-static \
|
||||
-o $@ \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group \
|
||||
$(LDLIBS)
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group
|
||||
else
|
||||
cmd_busybox__ ?= $(srctree)/scripts/trylink $(CC) -o $@ $(LDFLAGS) \
|
||||
-Wl,--warn-common -Wl,--sort-common -Wl,--gc-sections \
|
||||
-Wl,--start-group $(busybox-all) -Wl,--end-group
|
||||
endif
|
||||
|
||||
# Generate System.map
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
quiet_cmd_sysmap = SYSMAP
|
||||
cmd_sysmap = $(CONFIG_SHELL) $(srctree)/scripts/mksysmap
|
||||
|
||||
# Link of busybox
|
||||
@@ -631,7 +635,7 @@ endef
|
||||
# First command is ':' to allow us to use + in front of this rule
|
||||
cmd_ksym_ld = $(cmd_busybox__)
|
||||
define rule_ksym_ld
|
||||
:
|
||||
:
|
||||
+$(call cmd,busybox_version)
|
||||
$(call cmd,busybox__)
|
||||
$(Q)echo 'cmd_$@ := $(cmd_busybox__)' > $(@D)/.$(@F).cmd
|
||||
@@ -679,14 +683,10 @@ busybox_unstripped: $(busybox-all) FORCE
|
||||
$(Q)rm -f .old_version
|
||||
|
||||
busybox: busybox_unstripped
|
||||
ifeq ($(SKIP_STRIP),y)
|
||||
$(Q)cp $< $@
|
||||
else
|
||||
$(Q)$(STRIP) -s --remove-section=.note --remove-section=.comment \
|
||||
busybox_unstripped -o $@
|
||||
endif
|
||||
|
||||
# The actual objects are generated when descending,
|
||||
# The actual objects are generated when descending,
|
||||
# make sure no implicit rule kicks in
|
||||
$(sort $(busybox-all)): $(busybox-dirs) ;
|
||||
|
||||
@@ -719,7 +719,7 @@ _localver = $(foreach f, $(__localver), $(if $(findstring ~, $(f)),,$(f)))
|
||||
localver = $(subst $(space),, \
|
||||
$(shell cat /dev/null $(_localver)) \
|
||||
$(patsubst "%",%,$(CONFIG_LOCALVERSION)))
|
||||
|
||||
|
||||
# If CONFIG_LOCALVERSION_AUTO is set scripts/setlocalversion is called
|
||||
# and if the SCM is know a tag from the SCM is appended.
|
||||
# The appended tag is determinded by the SCM used.
|
||||
@@ -760,7 +760,7 @@ PHONY += prepare-all
|
||||
# 2) Create the include2 directory, used for the second asm symlink
|
||||
prepare3: .kernelrelease
|
||||
ifneq ($(KBUILD_SRC),)
|
||||
@echo ' Using $(srctree) as source for busybox'
|
||||
@echo ' Using $(srctree) as source for kernel'
|
||||
$(Q)if [ -f $(srctree)/.config ]; then \
|
||||
echo " $(srctree) is not clean, please run 'make mrproper'";\
|
||||
echo " in the '$(srctree)' directory.";\
|
||||
@@ -802,14 +802,12 @@ export CPPFLAGS_busybox.lds += -P -C -U$(ARCH)
|
||||
#bbox# @ln -fsn asm-$(ARCH) $@
|
||||
|
||||
# Split autoconf.h into include/linux/config/*
|
||||
quiet_cmd_gen_bbconfigopts = GEN include/bbconfigopts.h
|
||||
cmd_gen_bbconfigopts = $(srctree)/scripts/mkconfigs > include/bbconfigopts.h
|
||||
quiet_cmd_split_autoconf = SPLIT include/autoconf.h -> include/config/*
|
||||
cmd_split_autoconf = scripts/basic/split-include include/autoconf.h include/config
|
||||
#bbox# piggybacked generation of few .h files
|
||||
include/config/MARKER: scripts/basic/split-include include/autoconf.h
|
||||
$(call cmd,split_autoconf)
|
||||
$(call cmd,gen_bbconfigopts)
|
||||
@echo ' SPLIT include/autoconf.h -> include/config/*'
|
||||
@scripts/basic/split-include include/autoconf.h include/config
|
||||
@echo ' GEN include/bbconfigopts.h'
|
||||
@$(srctree)/scripts/mkconfigs >include/bbconfigopts.h
|
||||
@touch $@
|
||||
|
||||
# Generate some files
|
||||
@@ -917,7 +915,7 @@ endif # CONFIG_MODULES
|
||||
|
||||
# Directories & files removed with 'make clean'
|
||||
CLEAN_DIRS += $(MODVERDIR)
|
||||
CLEAN_FILES += busybox* System.map .kernelrelease \
|
||||
CLEAN_FILES += busybox* System.map \
|
||||
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
|
||||
|
||||
# Directories & files removed with 'make mrproper'
|
||||
@@ -1247,7 +1245,7 @@ endif
|
||||
$(build)=$(build-dir) $(@:.ko=.o)
|
||||
$(Q)$(MAKE) -rR -f $(srctree)/scripts/Makefile.modpost
|
||||
|
||||
# FIXME Should go into a make.lib or something
|
||||
# FIXME Should go into a make.lib or something
|
||||
# ===========================================================================
|
||||
|
||||
quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
|
||||
|
||||
+6
-10
@@ -2,6 +2,9 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
%.bflt: %_unstripped
|
||||
$(CROSS_COMPILE)elf2flt $(ELF2FLTFLAGS) $< -o $@
|
||||
|
||||
busybox.links: $(srctree)/applets/busybox.mkll $(objtree)/include/autoconf.h $(srctree)/include/applets.h
|
||||
$(Q)-$(SHELL) $^ >$@
|
||||
|
||||
@@ -35,9 +38,9 @@ ifneq ($(strip $(DO_INSTALL_LIBS)),n)
|
||||
done
|
||||
endif
|
||||
|
||||
check test: busybox busybox.links
|
||||
check test: busybox
|
||||
bindir=$(objtree) srcdir=$(srctree)/testsuite SED="$(SED)" \
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:0=),-v)
|
||||
$(SHELL) $(srctree)/testsuite/runtest $(if $(KBUILD_VERBOSE:1=),-v)
|
||||
|
||||
.PHONY: release
|
||||
release: distclean
|
||||
@@ -67,7 +70,6 @@ sizes: busybox_unstripped
|
||||
.PHONY: bloatcheck
|
||||
bloatcheck: busybox_old busybox_unstripped
|
||||
@$(srctree)/scripts/bloat-o-meter busybox_old busybox_unstripped
|
||||
@$(CROSS_COMPILE)size busybox_old busybox_unstripped
|
||||
|
||||
.PHONY: baseline
|
||||
baseline: busybox_unstripped
|
||||
@@ -77,13 +79,9 @@ baseline: busybox_unstripped
|
||||
objsizes: busybox_unstripped
|
||||
$(srctree)/scripts/objsizes
|
||||
|
||||
.PHONY: stksizes
|
||||
stksizes: busybox_unstripped
|
||||
$(CROSS_COMPILE)objdump -d busybox_unstripped | $(srctree)/scripts/checkstack.pl $(ARCH)
|
||||
|
||||
.PHONY: bigdata
|
||||
bigdata: busybox_unstripped
|
||||
$(CROSS_COMPILE)nm --size-sort busybox_unstripped | grep -vi ' [tr] '
|
||||
nm --size-sort busybox_unstripped | grep -vi ' [tr] ' | tail -20
|
||||
|
||||
# Documentation Targets
|
||||
.PHONY: doc
|
||||
@@ -145,5 +143,3 @@ SYN_CPPFLAGS := $(subst $(brace_close),\$(brace_close),$(SYN_CPPFLAGS))
|
||||
.PHONY: html
|
||||
html: $(syn)
|
||||
synopsis -f HTML -Wf,title="'BusyBox Documentation'" -o $@ $^
|
||||
|
||||
-include $(srctree)/Makefile.local
|
||||
+8
-73
@@ -3,12 +3,11 @@
|
||||
# ==========================================================================
|
||||
|
||||
BB_VER = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
|
||||
SKIP_STRIP = n
|
||||
|
||||
# -std=gnu99 needed for [U]LLONG_MAX on some systems
|
||||
CPPFLAGS += $(call cc-option,-std=gnu99,)
|
||||
|
||||
CPPFLAGS += \
|
||||
-std=gnu99 \
|
||||
-Iinclude -Ilibbb \
|
||||
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) -I$(srctree)/libbb \
|
||||
-include include/autoconf.h \
|
||||
@@ -16,78 +15,14 @@ CPPFLAGS += \
|
||||
$(if $(CONFIG_LFS),-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64) \
|
||||
-D"BB_VER=KBUILD_STR($(BB_VER))" -DBB_BT=AUTOCONF_TIMESTAMP
|
||||
|
||||
# flag checks are grouped together to speed the checks up a bit..
|
||||
CFLAGS += $(call cc-option,-Wall -Wshadow -Wwrite-strings,)
|
||||
CFLAGS += $(call cc-option,-Wundef -Wstrict-prototypes,)
|
||||
# If you want to add "-Wmissing-prototypes -Wmissing-declarations" above
|
||||
# (or anything else for that matter) make sure that it is still possible
|
||||
# to build bbox without warnings. Current offender: find.c:alloc_action().
|
||||
# Looks more like gcc bug: gcc will warn on it with or without prototype.
|
||||
# But still, warning-free compile is a must, or else we will drown
|
||||
# in warnings pretty soon.
|
||||
|
||||
ifeq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Werror,)
|
||||
else
|
||||
# for development, warn a little bit about unused results..
|
||||
CPPFLAGS += -D_FORTIFY_SOURCE=2
|
||||
endif
|
||||
# gcc 3.x emits bogus "old style proto" warning on find.c:alloc_action()
|
||||
CFLAGS += $(call cc-ifversion, -ge, 0400, -Wold-style-definition)
|
||||
|
||||
# gcc emits bogus "no prev proto" warning on find.c:alloc_action()
|
||||
ifneq ($(CONFIG_WERROR),y)
|
||||
CFLAGS += $(call cc-option,-Wmissing-prototypes -Wmissing-declarations,)
|
||||
endif
|
||||
|
||||
CFLAGS += $(call cc-option,-Os -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections,)
|
||||
# -fno-guess-branch-probability: prohibit pseudo-random guessing
|
||||
# of branch probabilities (hopefully makes bloatcheck more stable):
|
||||
CFLAGS += $(call cc-option,-fno-guess-branch-probability,)
|
||||
CFLAGS += $(call cc-option,-funsigned-char -static-libgcc,)
|
||||
CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1,)
|
||||
|
||||
# FIXME: These warnings are at least partially to be concerned about and should
|
||||
# be fixed..
|
||||
#CFLAGS+=$(call cc-option,-Wconversion,)
|
||||
CFLAGS += \
|
||||
-Wall -Wstrict-prototypes -Wshadow -Werror -Wundef \
|
||||
-funsigned-char -fno-builtin-strlen -finline-limit=0 -static-libgcc \
|
||||
-Os -falign-functions=1 -falign-jumps=1 -falign-loops=1 \
|
||||
-fomit-frame-pointer -ffunction-sections -fdata-sections
|
||||
|
||||
ifeq ($(CONFIG_DEBUG),y)
|
||||
CFLAGS += $(call cc-option,-g)
|
||||
CFLAGS += -g
|
||||
LDFLAGS += -g
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_STATIC),y)
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
|
||||
BBOX_LIB_LIST = m crypt
|
||||
|
||||
ifeq ($(CONFIG_PAM),y)
|
||||
BBOX_LIB_LIST += pam pam_misc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
BBOX_LIB_LIST += selinux sepol
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EFENCE),y)
|
||||
BBOX_LIB_LIST += efence
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_DMALLOC),y)
|
||||
BBOX_LIB_LIST += dmalloc
|
||||
endif
|
||||
|
||||
# For scripts/trylink
|
||||
export BBOX_LIB_LIST
|
||||
|
||||
#LDFLAGS += -nostdlib
|
||||
|
||||
LDFLAGS_ELF2FLT = -Wl,-elf2flt
|
||||
ifneq (,$(findstring $(LDFLAGS_ELF2FLT),$(LDFLAGS)))
|
||||
SKIP_STRIP = y
|
||||
endif
|
||||
|
||||
# Busybox is a stack-fatty so make sure we increase default size
|
||||
# TODO: use "make stksizes" to find & fix big stack users
|
||||
# (we stole scripts/checkstack.pl from the kernel... thanks guys!)
|
||||
FLTFLAGS += -s 20000
|
||||
+1
-3
@@ -27,7 +27,7 @@ help:
|
||||
@echo ' make SED="$(objtree)/sed"'
|
||||
@echo
|
||||
@echo 'Installation:'
|
||||
@echo ' install - install busybox into $(CONFIG_PREFIX)'
|
||||
@echo ' install - install busybox into $(PREFIX)'
|
||||
@echo ' uninstall'
|
||||
@echo
|
||||
@echo 'Development:'
|
||||
@@ -39,6 +39,4 @@ help:
|
||||
@echo ' release - create a distribution tarball'
|
||||
@echo ' sizes - show size of all enabled busybox symbols'
|
||||
@echo ' objsizes - show size of each .o object built'
|
||||
@echo ' bigdata - show data objects, biggest first'
|
||||
@echo ' stksizes - show stack users, biggest first'
|
||||
@echo
|
||||
@@ -50,10 +50,10 @@ Using busybox:
|
||||
|
||||
The build automatically generates a file "busybox.links", which is used by
|
||||
'make install' to create symlinks to the BusyBox binary for all compiled in
|
||||
commands. This uses the CONFIG_PREFIX environment variable to specify
|
||||
where to install, and installs hardlinks or symlinks depending
|
||||
on the configuration preferences. (You can also manually run
|
||||
the install script at "applets/install.sh").
|
||||
commands. This uses the PREFIX environment variable to specify where to
|
||||
install, and installs hardlinks or symlinks depending on the configuration
|
||||
preferences. (You can also manually run the install script at
|
||||
"applets/install.sh").
|
||||
|
||||
----------------
|
||||
|
||||
|
||||
@@ -36,7 +36,12 @@ Rob Landley <rob@landley.net>:
|
||||
modutils. The orig depmod is rather pointless to have to add to a firmware image
|
||||
in when we already have a insmod/rmmod and friends.
|
||||
Unify base64 handling.
|
||||
[done]
|
||||
There's base64 encoding and decoding going on in:
|
||||
networking/wget.c:base64enc()
|
||||
coreutils/uudecode.c:read_base64()
|
||||
coreutils/uuencode.c:tbl_base64[]
|
||||
networking/httpd.c:decodeBase64()
|
||||
And probably elsewhere. That needs to be unified into libbb functions.
|
||||
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
|
||||
@@ -125,6 +130,7 @@ Bernhard Fischer <busybox@busybox.net> suggests to look at these:
|
||||
make bb_common_bufsiz1 configurable, size wise.
|
||||
make pipesize configurable, size wise.
|
||||
Use bb_common_bufsiz1 throughout applets!
|
||||
Add chrt applet. Please CC Bernhard if you suggest a patch.
|
||||
|
||||
As yet unclaimed:
|
||||
|
||||
@@ -148,10 +154,6 @@ 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
|
||||
---
|
||||
ps / top
|
||||
Add support for both RSS and VSIZE rather than just one or the other.
|
||||
Or make it a build option.
|
||||
---
|
||||
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
|
||||
@@ -163,19 +165,6 @@ man
|
||||
ar
|
||||
Write support?
|
||||
---
|
||||
stty / catv
|
||||
stty's visible() function and catv's guts are identical. Merge them into
|
||||
an appropriate libbb function.
|
||||
---
|
||||
struct suffix_mult
|
||||
Several duplicate users of: grep -r "1024\*1024" * -B2 -A1
|
||||
Merge to a single size_suffixes[] in libbb.
|
||||
Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd
|
||||
---
|
||||
tail
|
||||
./busybox tail -f foo.c~ TODO
|
||||
should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
|
||||
fmt+ if another (not the current) file did change
|
||||
|
||||
Architectural issues:
|
||||
|
||||
|
||||
@@ -1,710 +0,0 @@
|
||||
# This .config compiles for NOMMU.
|
||||
# TODO:
|
||||
# Pick disabled applet, enable & try to make it compile & work on NOMMU
|
||||
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.6.0.svn
|
||||
# Wed Apr 11 01:29:04 2007
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
#
|
||||
# Busybox Settings
|
||||
#
|
||||
|
||||
#
|
||||
# General Configuration
|
||||
#
|
||||
# CONFIG_NITPICK is not set
|
||||
# CONFIG_DESKTOP is not set
|
||||
# CONFIG_FEATURE_BUFFERS_USE_MALLOC is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
CONFIG_SHOW_USAGE=y
|
||||
CONFIG_FEATURE_VERBOSE_USAGE=y
|
||||
CONFIG_FEATURE_COMPRESS_USAGE=y
|
||||
CONFIG_FEATURE_INSTALLER=y
|
||||
# CONFIG_LOCALE_SUPPORT is not set
|
||||
CONFIG_GETOPT_LONG=y
|
||||
CONFIG_FEATURE_DEVPTS=y
|
||||
# CONFIG_FEATURE_CLEAN_UP is not set
|
||||
CONFIG_FEATURE_PIDFILE=y
|
||||
CONFIG_FEATURE_SUID=y
|
||||
CONFIG_FEATURE_SYSLOG=y
|
||||
# CONFIG_FEATURE_SUID_CONFIG is not set
|
||||
# CONFIG_FEATURE_SUID_CONFIG_QUIET is not set
|
||||
# CONFIG_FEATURE_HAVE_RPC is not set
|
||||
# CONFIG_SELINUX is not set
|
||||
CONFIG_FEATURE_PREFER_APPLETS=y
|
||||
CONFIG_BUSYBOX_EXEC_PATH="/proc/self/exe"
|
||||
|
||||
#
|
||||
# Build Options
|
||||
#
|
||||
# CONFIG_STATIC is not set
|
||||
# CONFIG_BUILD_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_FULL_LIBBUSYBOX is not set
|
||||
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
|
||||
CONFIG_LFS=y
|
||||
# CONFIG_BUILD_AT_ONCE is not set
|
||||
|
||||
#
|
||||
# Debugging Options
|
||||
#
|
||||
# CONFIG_DEBUG is not set
|
||||
CONFIG_WERROR=y
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
# CONFIG_EFENCE is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
|
||||
#
|
||||
# Installation Options
|
||||
#
|
||||
# CONFIG_INSTALL_NO_USR is not set
|
||||
CONFIG_INSTALL_APPLET_SYMLINKS=y
|
||||
# CONFIG_INSTALL_APPLET_HARDLINKS is not set
|
||||
# CONFIG_INSTALL_APPLET_DONT is not set
|
||||
CONFIG_PREFIX="./_install"
|
||||
|
||||
#
|
||||
# Busybox Library Tuning
|
||||
#
|
||||
CONFIG_PASSWORD_MINLEN=6
|
||||
CONFIG_MD5_SIZE_VS_SPEED=2
|
||||
CONFIG_FEATURE_EDITING=y
|
||||
# CONFIG_FEATURE_EDITING_FANCY_KEYS is not set
|
||||
# CONFIG_FEATURE_EDITING_VI is not set
|
||||
CONFIG_FEATURE_EDITING_HISTORY=15
|
||||
# CONFIG_FEATURE_EDITING_SAVEHISTORY is not set
|
||||
# CONFIG_FEATURE_TAB_COMPLETION is not set
|
||||
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
|
||||
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
|
||||
|
||||
#
|
||||
# Applets
|
||||
#
|
||||
|
||||
#
|
||||
# Archival Utilities
|
||||
#
|
||||
CONFIG_AR=y
|
||||
CONFIG_FEATURE_AR_LONG_FILENAMES=y
|
||||
CONFIG_BUNZIP2=y
|
||||
CONFIG_CPIO=y
|
||||
# CONFIG_DPKG is not set
|
||||
# CONFIG_DPKG_DEB is not set
|
||||
# CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY is not set
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
# CONFIG_RPM is not set
|
||||
CONFIG_TAR=y
|
||||
CONFIG_FEATURE_TAR_CREATE=y
|
||||
# CONFIG_FEATURE_TAR_BZIP2 is not set
|
||||
# CONFIG_FEATURE_TAR_LZMA is not set
|
||||
CONFIG_FEATURE_TAR_FROM=y
|
||||
# CONFIG_FEATURE_TAR_GZIP is not set
|
||||
# CONFIG_FEATURE_TAR_COMPRESS is not set
|
||||
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
CONFIG_UNZIP=y
|
||||
|
||||
#
|
||||
# Common options for cpio and tar
|
||||
#
|
||||
CONFIG_FEATURE_UNARCHIVE_TAPE=y
|
||||
# CONFIG_FEATURE_DEB_TAR_GZ is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_BZ2 is not set
|
||||
# CONFIG_FEATURE_DEB_TAR_LZMA is not set
|
||||
|
||||
#
|
||||
# Coreutils
|
||||
#
|
||||
CONFIG_BASENAME=y
|
||||
CONFIG_CAL=y
|
||||
CONFIG_CAT=y
|
||||
CONFIG_CATV=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_FEATURE_DATE_ISOFMT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_DIRNAME=y
|
||||
CONFIG_DOS2UNIX=y
|
||||
CONFIG_UNIX2DOS=y
|
||||
CONFIG_DU=y
|
||||
CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K=y
|
||||
CONFIG_ECHO=y
|
||||
CONFIG_FEATURE_FANCY_ECHO=y
|
||||
CONFIG_ENV=y
|
||||
CONFIG_FEATURE_ENV_LONG_OPTIONS=y
|
||||
CONFIG_EXPR=y
|
||||
CONFIG_EXPR_MATH_SUPPORT_64=y
|
||||
CONFIG_FALSE=y
|
||||
CONFIG_FOLD=y
|
||||
CONFIG_HEAD=y
|
||||
CONFIG_FEATURE_FANCY_HEAD=y
|
||||
CONFIG_HOSTID=y
|
||||
CONFIG_ID=y
|
||||
CONFIG_INSTALL=y
|
||||
CONFIG_FEATURE_INSTALL_LONG_OPTIONS=y
|
||||
CONFIG_LENGTH=y
|
||||
CONFIG_LN=y
|
||||
CONFIG_LOGNAME=y
|
||||
CONFIG_LS=y
|
||||
CONFIG_FEATURE_LS_FILETYPES=y
|
||||
CONFIG_FEATURE_LS_FOLLOWLINKS=y
|
||||
CONFIG_FEATURE_LS_RECURSIVE=y
|
||||
CONFIG_FEATURE_LS_SORTFILES=y
|
||||
CONFIG_FEATURE_LS_TIMESTAMPS=y
|
||||
CONFIG_FEATURE_LS_USERNAME=y
|
||||
CONFIG_FEATURE_LS_COLOR=y
|
||||
CONFIG_FEATURE_LS_COLOR_IS_DEFAULT=y
|
||||
CONFIG_MD5SUM=y
|
||||
CONFIG_MKDIR=y
|
||||
CONFIG_FEATURE_MKDIR_LONG_OPTIONS=y
|
||||
CONFIG_MKFIFO=y
|
||||
CONFIG_MKNOD=y
|
||||
CONFIG_MV=y
|
||||
CONFIG_FEATURE_MV_LONG_OPTIONS=y
|
||||
CONFIG_NICE=y
|
||||
CONFIG_NOHUP=y
|
||||
CONFIG_OD=y
|
||||
CONFIG_PRINTENV=y
|
||||
CONFIG_PRINTF=y
|
||||
CONFIG_PWD=y
|
||||
CONFIG_REALPATH=y
|
||||
CONFIG_RM=y
|
||||
CONFIG_RMDIR=y
|
||||
CONFIG_SEQ=y
|
||||
CONFIG_SHA1SUM=y
|
||||
CONFIG_SLEEP=y
|
||||
CONFIG_FEATURE_FANCY_SLEEP=y
|
||||
CONFIG_SORT=y
|
||||
CONFIG_FEATURE_SORT_BIG=y
|
||||
CONFIG_SPLIT=y
|
||||
CONFIG_FEATURE_SPLIT_FANCY=y
|
||||
CONFIG_STAT=y
|
||||
CONFIG_FEATURE_STAT_FORMAT=y
|
||||
CONFIG_STTY=y
|
||||
CONFIG_SUM=y
|
||||
CONFIG_SYNC=y
|
||||
CONFIG_TAIL=y
|
||||
CONFIG_FEATURE_FANCY_TAIL=y
|
||||
CONFIG_TEE=y
|
||||
CONFIG_FEATURE_TEE_USE_BLOCK_IO=y
|
||||
CONFIG_TEST=y
|
||||
CONFIG_FEATURE_TEST_64=y
|
||||
CONFIG_TOUCH=y
|
||||
CONFIG_TR=y
|
||||
CONFIG_FEATURE_TR_CLASSES=y
|
||||
CONFIG_FEATURE_TR_EQUIV=y
|
||||
CONFIG_TRUE=y
|
||||
CONFIG_TTY=y
|
||||
CONFIG_UNAME=y
|
||||
CONFIG_UNIQ=y
|
||||
CONFIG_USLEEP=y
|
||||
CONFIG_UUDECODE=y
|
||||
CONFIG_UUENCODE=y
|
||||
CONFIG_WATCH=y
|
||||
CONFIG_WC=y
|
||||
CONFIG_FEATURE_WC_LARGE=y
|
||||
CONFIG_WHO=y
|
||||
CONFIG_WHOAMI=y
|
||||
CONFIG_YES=y
|
||||
|
||||
#
|
||||
# Common options for cp and mv
|
||||
#
|
||||
CONFIG_FEATURE_PRESERVE_HARDLINKS=y
|
||||
|
||||
#
|
||||
# Common options for ls, more and telnet
|
||||
#
|
||||
CONFIG_FEATURE_AUTOWIDTH=y
|
||||
|
||||
#
|
||||
# Common options for df, du, ls
|
||||
#
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
#
|
||||
# Console Utilities
|
||||
#
|
||||
CONFIG_CHVT=y
|
||||
CONFIG_CLEAR=y
|
||||
CONFIG_DEALLOCVT=y
|
||||
CONFIG_DUMPKMAP=y
|
||||
CONFIG_LOADFONT=y
|
||||
CONFIG_LOADKMAP=y
|
||||
CONFIG_OPENVT=y
|
||||
CONFIG_RESET=y
|
||||
CONFIG_RESIZE=y
|
||||
CONFIG_FEATURE_RESIZE_PRINT=y
|
||||
CONFIG_SETCONSOLE=y
|
||||
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
|
||||
CONFIG_SETKEYCODES=y
|
||||
CONFIG_SETLOGCONS=y
|
||||
|
||||
#
|
||||
# Debian Utilities
|
||||
#
|
||||
CONFIG_MKTEMP=y
|
||||
CONFIG_PIPE_PROGRESS=y
|
||||
CONFIG_READLINK=y
|
||||
CONFIG_FEATURE_READLINK_FOLLOW=y
|
||||
CONFIG_RUN_PARTS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_RUN_PARTS_FANCY=y
|
||||
# CONFIG_START_STOP_DAEMON is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_FANCY is not set
|
||||
# CONFIG_FEATURE_START_STOP_DAEMON_LONG_OPTIONS is not set
|
||||
CONFIG_WHICH=y
|
||||
|
||||
#
|
||||
# Editors
|
||||
#
|
||||
CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_MATH=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
CONFIG_VI=y
|
||||
CONFIG_FEATURE_VI_COLON=y
|
||||
CONFIG_FEATURE_VI_YANKMARK=y
|
||||
CONFIG_FEATURE_VI_SEARCH=y
|
||||
CONFIG_FEATURE_VI_USE_SIGNALS=y
|
||||
CONFIG_FEATURE_VI_DOT_CMD=y
|
||||
CONFIG_FEATURE_VI_READONLY=y
|
||||
CONFIG_FEATURE_VI_SETOPTS=y
|
||||
CONFIG_FEATURE_VI_SET=y
|
||||
CONFIG_FEATURE_VI_WIN_RESIZE=y
|
||||
CONFIG_FEATURE_VI_OPTIMIZE_CURSOR=y
|
||||
CONFIG_FEATURE_ALLOW_EXEC=y
|
||||
|
||||
#
|
||||
# Finding Utilities
|
||||
#
|
||||
CONFIG_FIND=y
|
||||
CONFIG_FEATURE_FIND_PRINT0=y
|
||||
CONFIG_FEATURE_FIND_MTIME=y
|
||||
CONFIG_FEATURE_FIND_MMIN=y
|
||||
CONFIG_FEATURE_FIND_PERM=y
|
||||
CONFIG_FEATURE_FIND_TYPE=y
|
||||
CONFIG_FEATURE_FIND_XDEV=y
|
||||
CONFIG_FEATURE_FIND_NEWER=y
|
||||
CONFIG_FEATURE_FIND_INUM=y
|
||||
CONFIG_FEATURE_FIND_EXEC=y
|
||||
CONFIG_FEATURE_FIND_USER=y
|
||||
CONFIG_FEATURE_FIND_GROUP=y
|
||||
CONFIG_FEATURE_FIND_NOT=y
|
||||
CONFIG_FEATURE_FIND_DEPTH=y
|
||||
CONFIG_FEATURE_FIND_PAREN=y
|
||||
CONFIG_FEATURE_FIND_SIZE=y
|
||||
CONFIG_FEATURE_FIND_PRUNE=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_CONTEXT=y
|
||||
CONFIG_XARGS=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_QUOTES=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT=y
|
||||
CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM=y
|
||||
|
||||
#
|
||||
# Init Utilities
|
||||
#
|
||||
# CONFIG_INIT is not set
|
||||
# CONFIG_DEBUG_INIT is not set
|
||||
# CONFIG_FEATURE_USE_INITTAB is not set
|
||||
# CONFIG_FEATURE_INIT_SCTTY is not set
|
||||
# CONFIG_FEATURE_INIT_SYSLOG is not set
|
||||
# CONFIG_FEATURE_EXTRA_QUIET is not set
|
||||
# CONFIG_FEATURE_INIT_COREDUMPS is not set
|
||||
# CONFIG_FEATURE_INITRD is not set
|
||||
CONFIG_HALT=y
|
||||
CONFIG_MESG=y
|
||||
|
||||
#
|
||||
# Login/Password Management Utilities
|
||||
#
|
||||
CONFIG_FEATURE_SHADOWPASSWDS=y
|
||||
CONFIG_USE_BB_SHADOW=y
|
||||
CONFIG_USE_BB_PWD_GRP=y
|
||||
CONFIG_ADDGROUP=y
|
||||
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
|
||||
CONFIG_DELGROUP=y
|
||||
CONFIG_ADDUSER=y
|
||||
CONFIG_DELUSER=y
|
||||
CONFIG_GETTY=y
|
||||
CONFIG_FEATURE_UTMP=y
|
||||
CONFIG_FEATURE_WTMP=y
|
||||
CONFIG_LOGIN=y
|
||||
CONFIG_LOGIN_SCRIPTS=y
|
||||
CONFIG_FEATURE_SECURETTY=y
|
||||
CONFIG_PASSWD=y
|
||||
CONFIG_FEATURE_PASSWD_WEAK_CHECK=y
|
||||
CONFIG_SU=y
|
||||
CONFIG_FEATURE_SU_SYSLOG=y
|
||||
CONFIG_FEATURE_SU_CHECKS_SHELLS=y
|
||||
CONFIG_SULOGIN=y
|
||||
CONFIG_VLOCK=y
|
||||
|
||||
#
|
||||
# Linux Ext2 FS Progs
|
||||
#
|
||||
CONFIG_CHATTR=y
|
||||
CONFIG_FSCK=y
|
||||
CONFIG_LSATTR=y
|
||||
|
||||
#
|
||||
# Linux Module Utilities
|
||||
#
|
||||
CONFIG_INSMOD=y
|
||||
CONFIG_FEATURE_INSMOD_VERSION_CHECKING=y
|
||||
CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS=y
|
||||
CONFIG_FEATURE_INSMOD_LOADINKMEM=y
|
||||
CONFIG_FEATURE_INSMOD_LOAD_MAP=y
|
||||
CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL=y
|
||||
CONFIG_RMMOD=y
|
||||
CONFIG_LSMOD=y
|
||||
CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT=y
|
||||
CONFIG_MODPROBE=y
|
||||
CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS=y
|
||||
CONFIG_FEATURE_MODPROBE_FANCY_ALIAS=y
|
||||
|
||||
#
|
||||
# Options common to multiple modutils
|
||||
#
|
||||
CONFIG_FEATURE_CHECK_TAINTED_MODULE=y
|
||||
CONFIG_FEATURE_2_4_MODULES=y
|
||||
CONFIG_FEATURE_2_6_MODULES=y
|
||||
# CONFIG_FEATURE_QUERY_MODULE_INTERFACE is not set
|
||||
|
||||
#
|
||||
# Linux System Utilities
|
||||
#
|
||||
CONFIG_DMESG=y
|
||||
CONFIG_FEATURE_DMESG_PRETTY=y
|
||||
CONFIG_FBSET=y
|
||||
CONFIG_FEATURE_FBSET_FANCY=y
|
||||
CONFIG_FEATURE_FBSET_READMODE=y
|
||||
CONFIG_FDFLUSH=y
|
||||
CONFIG_FDFORMAT=y
|
||||
CONFIG_FDISK=y
|
||||
CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
|
||||
CONFIG_FEATURE_FDISK_WRITABLE=y
|
||||
CONFIG_FEATURE_AIX_LABEL=y
|
||||
CONFIG_FEATURE_SGI_LABEL=y
|
||||
CONFIG_FEATURE_SUN_LABEL=y
|
||||
CONFIG_FEATURE_OSF_LABEL=y
|
||||
CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
|
||||
#
|
||||
# Minix filesystem support
|
||||
#
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_HEXDUMP=y
|
||||
CONFIG_HWCLOCK=y
|
||||
CONFIG_FEATURE_HWCLOCK_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
CONFIG_IPCRM=y
|
||||
CONFIG_IPCS=y
|
||||
CONFIG_LOSETUP=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_EXEC=y
|
||||
CONFIG_MKSWAP=y
|
||||
CONFIG_FEATURE_MKSWAP_V0=y
|
||||
CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_MOUNT=y
|
||||
# CONFIG_FEATURE_MOUNT_NFS is not set
|
||||
CONFIG_FEATURE_MOUNT_CIFS=y
|
||||
CONFIG_FEATURE_MOUNT_FLAGS=y
|
||||
CONFIG_FEATURE_MOUNT_FSTAB=y
|
||||
CONFIG_PIVOT_ROOT=y
|
||||
CONFIG_RDATE=y
|
||||
CONFIG_READPROFILE=y
|
||||
CONFIG_SETARCH=y
|
||||
CONFIG_SWAPONOFF=y
|
||||
CONFIG_SWITCH_ROOT=y
|
||||
CONFIG_UMOUNT=y
|
||||
CONFIG_FEATURE_UMOUNT_ALL=y
|
||||
|
||||
#
|
||||
# Common options for mount/umount
|
||||
#
|
||||
CONFIG_FEATURE_MOUNT_LOOP=y
|
||||
# CONFIG_FEATURE_MTAB_SUPPORT is not set
|
||||
|
||||
#
|
||||
# Miscellaneous Utilities
|
||||
#
|
||||
CONFIG_ADJTIMEX=y
|
||||
# CONFIG_BBCONFIG is not set
|
||||
CONFIG_CHRT=y
|
||||
# CONFIG_CROND is not set
|
||||
# CONFIG_DEBUG_CROND_OPTION is not set
|
||||
# CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set
|
||||
# CONFIG_CRONTAB is not set
|
||||
CONFIG_DC=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_EJECT=y
|
||||
CONFIG_LAST=y
|
||||
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_HDPARM=y
|
||||
CONFIG_FEATURE_HDPARM_GET_IDENTITY=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF=y
|
||||
CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA=y
|
||||
CONFIG_MAKEDEVS=y
|
||||
# CONFIG_FEATURE_MAKEDEVS_LEAF is not set
|
||||
CONFIG_FEATURE_MAKEDEVS_TABLE=y
|
||||
CONFIG_MOUNTPOINT=y
|
||||
CONFIG_MT=y
|
||||
CONFIG_NMETER=y
|
||||
CONFIG_RAIDAUTORUN=y
|
||||
CONFIG_READAHEAD=y
|
||||
CONFIG_RUNLEVEL=y
|
||||
CONFIG_RX=y
|
||||
CONFIG_STRINGS=y
|
||||
CONFIG_SETSID=y
|
||||
# CONFIG_TASKSET is not set
|
||||
# CONFIG_FEATURE_TASKSET_FANCY is not set
|
||||
CONFIG_TIME=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
# Networking Utilities
|
||||
#
|
||||
CONFIG_FEATURE_IPV6=y
|
||||
# CONFIG_VERBOSE_RESOLUTION_ERRORS is not set
|
||||
CONFIG_ARP=y
|
||||
CONFIG_ARPING=y
|
||||
CONFIG_DNSD=y
|
||||
CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
CONFIG_HOSTNAME=y
|
||||
# CONFIG_HTTPD is not set
|
||||
# CONFIG_FEATURE_HTTPD_RELOAD_CONFIG_SIGHUP is not set
|
||||
# CONFIG_FEATURE_HTTPD_SETUID is not set
|
||||
# CONFIG_FEATURE_HTTPD_BASIC_AUTH is not set
|
||||
# CONFIG_FEATURE_HTTPD_AUTH_MD5 is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES is not set
|
||||
# CONFIG_FEATURE_HTTPD_CGI is not set
|
||||
# CONFIG_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR is not set
|
||||
# CONFIG_FEATURE_HTTPD_SET_REMOTE_PORT_TO_ENV is not set
|
||||
# CONFIG_FEATURE_HTTPD_ENCODE_URL_STR is not set
|
||||
CONFIG_IFCONFIG=y
|
||||
CONFIG_FEATURE_IFCONFIG_STATUS=y
|
||||
CONFIG_FEATURE_IFCONFIG_SLIP=y
|
||||
CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ=y
|
||||
CONFIG_FEATURE_IFCONFIG_HW=y
|
||||
CONFIG_FEATURE_IFCONFIG_BROADCAST_PLUS=y
|
||||
# CONFIG_IFUPDOWN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IP_BUILTIN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IFCONFIG_BUILTIN is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV4 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPV6 is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_IPX is not set
|
||||
# CONFIG_FEATURE_IFUPDOWN_MAPPING is not set
|
||||
# CONFIG_INETD is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_ECHO is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DISCARD is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_TIME is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_DAYTIME is not set
|
||||
# CONFIG_FEATURE_INETD_SUPPORT_BUILTIN_CHARGEN is not set
|
||||
# CONFIG_FEATURE_INETD_RPC is not set
|
||||
CONFIG_IP=y
|
||||
CONFIG_FEATURE_IP_ADDRESS=y
|
||||
CONFIG_FEATURE_IP_LINK=y
|
||||
CONFIG_FEATURE_IP_ROUTE=y
|
||||
CONFIG_FEATURE_IP_TUNNEL=y
|
||||
CONFIG_FEATURE_IP_RULE=y
|
||||
CONFIG_FEATURE_IP_SHORT_FORMS=y
|
||||
CONFIG_IPADDR=y
|
||||
CONFIG_IPLINK=y
|
||||
CONFIG_IPROUTE=y
|
||||
CONFIG_IPTUNNEL=y
|
||||
CONFIG_IPRULE=y
|
||||
CONFIG_IPCALC=y
|
||||
CONFIG_FEATURE_IPCALC_FANCY=y
|
||||
CONFIG_FEATURE_IPCALC_LONG_OPTIONS=y
|
||||
CONFIG_NAMEIF=y
|
||||
CONFIG_NC=y
|
||||
CONFIG_NC_SERVER=y
|
||||
CONFIG_NC_EXTRA=y
|
||||
CONFIG_NETSTAT=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
CONFIG_ROUTE=y
|
||||
CONFIG_TELNET=y
|
||||
CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
# CONFIG_TELNETD is not set
|
||||
# CONFIG_FEATURE_TELNETD_STANDALONE is not set
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
# CONFIG_DEBUG_TFTP is not set
|
||||
CONFIG_TRACEROUTE=y
|
||||
# CONFIG_FEATURE_TRACEROUTE_VERBOSE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE is not set
|
||||
# CONFIG_FEATURE_TRACEROUTE_USE_ICMP is not set
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
# CONFIG_APP_UDHCPC is not set
|
||||
# CONFIG_FEATURE_UDHCP_DEBUG is not set
|
||||
CONFIG_FEATURE_RFC3397=y
|
||||
CONFIG_VCONFIG=y
|
||||
CONFIG_WGET=y
|
||||
CONFIG_FEATURE_WGET_STATUSBAR=y
|
||||
CONFIG_FEATURE_WGET_AUTHENTICATION=y
|
||||
CONFIG_FEATURE_WGET_LONG_OPTIONS=y
|
||||
CONFIG_ZCIP=y
|
||||
|
||||
#
|
||||
# Process Utilities
|
||||
#
|
||||
CONFIG_FREE=y
|
||||
CONFIG_FUSER=y
|
||||
CONFIG_KILL=y
|
||||
CONFIG_KILLALL=y
|
||||
CONFIG_KILLALL5=y
|
||||
CONFIG_PIDOF=y
|
||||
CONFIG_FEATURE_PIDOF_SINGLE=y
|
||||
CONFIG_FEATURE_PIDOF_OMIT=y
|
||||
CONFIG_PS=y
|
||||
CONFIG_FEATURE_PS_WIDE=y
|
||||
CONFIG_RENICE=y
|
||||
CONFIG_BB_SYSCTL=y
|
||||
CONFIG_TOP=y
|
||||
CONFIG_FEATURE_TOP_CPU_USAGE_PERCENTAGE=y
|
||||
CONFIG_UPTIME=y
|
||||
|
||||
#
|
||||
# Shells
|
||||
#
|
||||
# CONFIG_FEATURE_SH_IS_ASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_HUSH is not set
|
||||
# CONFIG_FEATURE_SH_IS_LASH is not set
|
||||
# CONFIG_FEATURE_SH_IS_MSH is not set
|
||||
CONFIG_FEATURE_SH_IS_NONE=y
|
||||
# CONFIG_ASH 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_TEST is not set
|
||||
# CONFIG_ASH_CMDCMD is not set
|
||||
# CONFIG_ASH_MAIL is not set
|
||||
# CONFIG_ASH_OPTIMIZE_FOR_SIZE is not set
|
||||
# CONFIG_ASH_RANDOM_SUPPORT is not set
|
||||
# CONFIG_ASH_EXPAND_PRMT is not set
|
||||
# CONFIG_HUSH is not set
|
||||
# CONFIG_LASH is not set
|
||||
CONFIG_MSH=y
|
||||
|
||||
#
|
||||
# Bourne Shell Options
|
||||
#
|
||||
CONFIG_FEATURE_SH_EXTRA_QUIET=y
|
||||
CONFIG_FEATURE_SH_STANDALONE=y
|
||||
|
||||
#
|
||||
# System Logging Utilities
|
||||
#
|
||||
CONFIG_SYSLOGD=y
|
||||
CONFIG_FEATURE_ROTATE_LOGFILE=y
|
||||
CONFIG_FEATURE_REMOTE_LOG=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG=y
|
||||
CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE=16
|
||||
CONFIG_LOGREAD=y
|
||||
CONFIG_FEATURE_LOGREAD_REDUCED_LOCKING=y
|
||||
CONFIG_KLOGD=y
|
||||
CONFIG_LOGGER=y
|
||||
|
||||
#
|
||||
# Runit Utilities
|
||||
#
|
||||
# CONFIG_RUNSV is not set
|
||||
# CONFIG_RUNSVDIR is not set
|
||||
CONFIG_SV=y
|
||||
# CONFIG_SVLOGD is not set
|
||||
CONFIG_CHPST=y
|
||||
CONFIG_SETUIDGID=y
|
||||
CONFIG_ENVUIDGID=y
|
||||
CONFIG_ENVDIR=y
|
||||
CONFIG_SOFTLIMIT=y
|
||||
# CONFIG_CHCON is not set
|
||||
# CONFIG_FEATURE_CHCON_LONG_OPTIONS is not set
|
||||
# CONFIG_GETENFORCE is not set
|
||||
# CONFIG_GETSEBOOL is not set
|
||||
# CONFIG_LOAD_POLICY is not set
|
||||
# CONFIG_MATCHPATHCON is not set
|
||||
# CONFIG_RUNCON is not set
|
||||
# CONFIG_FEATURE_RUNCON_LONG_OPTIONS is not set
|
||||
# CONFIG_SELINUXENABLED is not set
|
||||
# CONFIG_SETENFORCE is not set
|
||||
|
||||
#
|
||||
# ipsvd utilities
|
||||
#
|
||||
# CONFIG_TCPSVD is not set
|
||||
# CONFIG_UDPSVD is not set
|
||||
+10
-14
@@ -5,21 +5,17 @@
|
||||
# Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||
|
||||
obj-y:=
|
||||
obj-y += applets.o
|
||||
obj-y += applets.o
|
||||
obj-y += busybox.o
|
||||
|
||||
# Generated file needs additional love
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
# Generated files need additional love
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
always := $(hostprogs-y)
|
||||
HOSTCFLAGS_usage.o = -I$(srctree)/include
|
||||
|
||||
applets/applets.o: include/usage_compressed.h
|
||||
applets/usage: .config $(srctree)/applets/usage_compressed
|
||||
include/usage_compressed.h: applets/usage $(srctree)/applets/usage_compressed
|
||||
$(call cmd,gen_usage_compressed)
|
||||
include/usage_compressed.h: $(srctree)/include/usage.h applets/usage
|
||||
@echo ' GEN include/usage_compressed.h'
|
||||
@$(srctree)/applets/usage_compressed include/usage_compressed.h applets
|
||||
+179
-364
@@ -12,29 +12,21 @@
|
||||
* Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
|
||||
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
|
||||
#warning Static linking against glibc produces buggy executables
|
||||
#warning (glibc does not cope well with ld --gc-sections).
|
||||
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
|
||||
#warning Note that glibc is unsuitable for static linking anyway.
|
||||
#warning If you still want to do it, remove -Wl,--gc-sections
|
||||
#warning from top-level Makefile and remove this warning.
|
||||
#error Aborting compilation.
|
||||
#warning Note that glibc is utterly unsuitable for static linking anyway.
|
||||
#endif
|
||||
|
||||
|
||||
/* Declare <applet>_main() */
|
||||
#define PROTOTYPES
|
||||
#include "applets.h"
|
||||
#undef PROTOTYPES
|
||||
|
||||
#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
|
||||
/* Define usage_messages[] */
|
||||
static const char usage_messages[] ALIGN1 = ""
|
||||
static const char usage_messages[] =
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
@@ -42,35 +34,38 @@ static const char usage_messages[] ALIGN1 = ""
|
||||
#undef MAKE_USAGE
|
||||
#else
|
||||
#define usage_messages 0
|
||||
#endif /* SHOW_USAGE */
|
||||
#endif /* ENABLE_SHOW_USAGE */
|
||||
|
||||
/* Define struct bb_applet applets[] */
|
||||
#undef APPLET
|
||||
#undef APPLET_NOUSAGE
|
||||
#undef PROTOTYPES
|
||||
#include "applets.h"
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry. */
|
||||
|
||||
#if ENABLE_FEATURE_SH_STANDALONE
|
||||
const unsigned short NUM_APPLETS = ARRAY_SIZE(applets);
|
||||
#endif
|
||||
const struct bb_applet *current_applet;
|
||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||
#if !BB_MMU
|
||||
bool re_execed;
|
||||
#endif
|
||||
static struct BB_applet *applet_using;
|
||||
|
||||
USE_FEATURE_SUID(static uid_t ruid;) /* real uid */
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
|
||||
#if ENABLE_FEATURE_SUID_CONFIG
|
||||
|
||||
/* applets[] is const, so we have to define this "override" structure */
|
||||
static struct BB_suid_config {
|
||||
const struct bb_applet *m_applet;
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#define CONFIG_FILE "/etc/busybox.conf"
|
||||
|
||||
/* applets [] is const, so we have to define this "override" structure */
|
||||
static struct BB_suid_config
|
||||
{
|
||||
struct BB_applet *m_applet;
|
||||
|
||||
uid_t m_uid;
|
||||
gid_t m_gid;
|
||||
mode_t m_mode;
|
||||
|
||||
struct BB_suid_config *m_next;
|
||||
} *suid_config;
|
||||
|
||||
static bool suid_cfg_readable;
|
||||
static int suid_cfg_readable;
|
||||
|
||||
/* check if u is member of group g */
|
||||
static int ingroup(uid_t u, gid_t g)
|
||||
@@ -103,55 +98,53 @@ static char *get_trimmed_slice(char *s, char *e)
|
||||
break;
|
||||
}
|
||||
}
|
||||
e[1] = '\0';
|
||||
e[1] = 0;
|
||||
|
||||
/* Next, advance past all leading space and return a ptr to the
|
||||
* first non-space char; possibly the terminating nul. */
|
||||
return skip_whitespace(s);
|
||||
}
|
||||
|
||||
|
||||
#define parse_error(x) { err=x; goto pe_label; }
|
||||
|
||||
/* Don't depend on the tools to combine strings. */
|
||||
static const char config_file[] ALIGN1 = "/etc/busybox.conf";
|
||||
static const char config_file[] = CONFIG_FILE;
|
||||
|
||||
/* There are 4 chars + 1 nul for each of user/group/other. */
|
||||
static const char mode_chars[] = "Ssx-\0Ssx-\0Ttx-";
|
||||
|
||||
/* We don't supply a value for the nul, so an index adjustment is
|
||||
* necessary below. Also, we use unsigned short here to save some
|
||||
* space even though these are really mode_t values. */
|
||||
static const unsigned short mode_mask[] ALIGN2 = {
|
||||
/* SST sst xxx --- */
|
||||
static const unsigned short mode_mask[] = {
|
||||
/* SST sst xxx --- */
|
||||
S_ISUID, S_ISUID|S_IXUSR, S_IXUSR, 0, /* user */
|
||||
S_ISGID, S_ISGID|S_IXGRP, S_IXGRP, 0, /* group */
|
||||
0, S_IXOTH, S_IXOTH, 0 /* other */
|
||||
};
|
||||
|
||||
#define parse_error(x) do { errmsg = x; goto pe_label; } while (0)
|
||||
|
||||
static void parse_config_file(void)
|
||||
{
|
||||
struct BB_suid_config *sct_head;
|
||||
struct BB_suid_config *sct;
|
||||
const struct bb_applet *applet;
|
||||
struct BB_applet *applet;
|
||||
FILE *f;
|
||||
const char *errmsg;
|
||||
char *err;
|
||||
char *s;
|
||||
char *e;
|
||||
int i;
|
||||
unsigned lc;
|
||||
smallint section;
|
||||
int i, lc, section;
|
||||
char buffer[256];
|
||||
struct stat st;
|
||||
|
||||
assert(!suid_config); /* Should be set to NULL by bss init. */
|
||||
assert(!suid_config); /* Should be set to NULL by bss init. */
|
||||
|
||||
ruid = getuid();
|
||||
if (ruid == 0) /* run by root - don't need to even read config file */
|
||||
return;
|
||||
|
||||
if ((stat(config_file, &st) != 0) /* No config file? */
|
||||
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|
||||
|| (st.st_uid != 0) /* Not owned by root? */
|
||||
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|
||||
|| !(f = fopen(config_file, "r")) /* Cannot open? */
|
||||
) {
|
||||
if ((stat(config_file, &st) != 0) /* No config file? */
|
||||
|| !S_ISREG(st.st_mode) /* Not a regular file? */
|
||||
|| (st.st_uid != 0) /* Not owned by root? */
|
||||
|| (st.st_mode & (S_IWGRP | S_IWOTH)) /* Writable by non-root? */
|
||||
|| !(f = fopen(config_file, "r")) /* Cannot open? */
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,7 +152,7 @@ static void parse_config_file(void)
|
||||
sct_head = NULL;
|
||||
section = lc = 0;
|
||||
|
||||
while (1) {
|
||||
do {
|
||||
s = buffer;
|
||||
|
||||
if (!fgets(s, sizeof(buffer), f)) { /* Are we done? */
|
||||
@@ -187,8 +180,7 @@ static void parse_config_file(void)
|
||||
|
||||
/* Trim leading and trailing whitespace, ignoring comments, and
|
||||
* check if the resulting string is empty. */
|
||||
s = get_trimmed_slice(s, strchrnul(s, '#'));
|
||||
if (!*s) {
|
||||
if (!*(s = get_trimmed_slice(s, strchrnul(s, '#')))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -198,11 +190,10 @@ static void parse_config_file(void)
|
||||
/* Unlike the old code, we ignore leading and trailing
|
||||
* whitespace for the section name. We also require that
|
||||
* there are no stray characters after the closing bracket. */
|
||||
e = strchr(s, ']');
|
||||
if (!e /* Missing right bracket? */
|
||||
|| e[1] /* Trailing characters? */
|
||||
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
|
||||
) {
|
||||
if (!(e = strchr(s, ']')) /* Missing right bracket? */
|
||||
|| e[1] /* Trailing characters? */
|
||||
|| !*(s = get_trimmed_slice(s+1, e)) /* Missing name? */
|
||||
) {
|
||||
parse_error("section header");
|
||||
}
|
||||
/* Right now we only have one section so just check it.
|
||||
@@ -228,8 +219,7 @@ static void parse_config_file(void)
|
||||
* where both key and value could contain inner whitespace. */
|
||||
|
||||
/* First get the key (an applet name in our case). */
|
||||
e = strchr(s, '=');
|
||||
if (e) {
|
||||
if (!!(e = strchr(s, '='))) {
|
||||
s = get_trimmed_slice(s, e);
|
||||
}
|
||||
if (!e || !*s) { /* Missing '=' or empty key. */
|
||||
@@ -238,10 +228,9 @@ static void parse_config_file(void)
|
||||
|
||||
/* Ok, we have an applet name. Process the rhs if this
|
||||
* applet is currently built in and ignore it otherwise.
|
||||
* Note: this can hide config file bugs which only pop
|
||||
* Note: This can hide config file bugs which only pop
|
||||
* up when the busybox configuration is changed. */
|
||||
applet = find_applet_by_name(s);
|
||||
if (applet) {
|
||||
if ((applet = find_applet_by_name(s))) {
|
||||
/* Note: We currently don't check for duplicates!
|
||||
* The last config line for each applet will be the
|
||||
* one used since we insert at the head of the list.
|
||||
@@ -256,13 +245,9 @@ static void parse_config_file(void)
|
||||
|
||||
e = skip_whitespace(e+1);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
/* There are 4 chars + 1 nul for each of user/group/other. */
|
||||
static const char mode_chars[] ALIGN1 = "Ssx-\0" "Ssx-\0" "Ttx-";
|
||||
|
||||
for (i=0 ; i < 3 ; i++) {
|
||||
const char *q;
|
||||
q = strchrnul(mode_chars + 5*i, *e++);
|
||||
if (!*q) {
|
||||
if (!*(q = strchrnul(mode_chars + 5*i, *e++))) {
|
||||
parse_error("mode");
|
||||
}
|
||||
/* Adjust by -i to account for nul. */
|
||||
@@ -273,32 +258,35 @@ static void parse_config_file(void)
|
||||
|
||||
s = skip_whitespace(e);
|
||||
|
||||
/* Note: we require whitespace between the mode and the
|
||||
/* Note: We require whitespace between the mode and the
|
||||
* user/group info. */
|
||||
if ((s == e) || !(e = strchr(s, '.'))) {
|
||||
parse_error("<uid>.<gid>");
|
||||
}
|
||||
*e++ = '\0';
|
||||
*e++ = 0;
|
||||
|
||||
/* We can't use get_ug_id here since it would exit()
|
||||
* if a uid or gid was not found. Oh well... */
|
||||
sct->m_uid = bb_strtoul(s, NULL, 10);
|
||||
if (errno) {
|
||||
struct passwd *pwd = getpwnam(s);
|
||||
if (!pwd) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
}
|
||||
{
|
||||
char *e2;
|
||||
|
||||
sct->m_gid = bb_strtoul(e, NULL, 10);
|
||||
if (errno) {
|
||||
struct group *grp;
|
||||
grp = getgrnam(e);
|
||||
if (!grp) {
|
||||
parse_error("group");
|
||||
sct->m_uid = strtoul(s, &e2, 10);
|
||||
if (*e2 || (s == e2)) {
|
||||
struct passwd *pwd = getpwnam(s);
|
||||
if (!pwd) {
|
||||
parse_error("user");
|
||||
}
|
||||
sct->m_uid = pwd->pw_uid;
|
||||
}
|
||||
|
||||
sct->m_gid = strtoul(e, &e2, 10);
|
||||
if (*e2 || (e == e2)) {
|
||||
struct group *grp;
|
||||
if (!(grp = getgrnam(e))) {
|
||||
parse_error("group");
|
||||
}
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
sct->m_gid = grp->gr_gid;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
@@ -315,11 +303,11 @@ static void parse_config_file(void)
|
||||
parse_error("keyword outside section");
|
||||
}
|
||||
|
||||
} /* while (1) */
|
||||
} while (1);
|
||||
|
||||
pe_label:
|
||||
fprintf(stderr, "Parse error in %s, line %d: %s\n",
|
||||
config_file, lc, errmsg);
|
||||
config_file, lc, err);
|
||||
|
||||
fclose(f);
|
||||
/* Release any allocated memory before returning. */
|
||||
@@ -328,341 +316,168 @@ static void parse_config_file(void)
|
||||
free(sct_head);
|
||||
sct_head = sct;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
static inline void parse_config_file(void)
|
||||
#define parse_config_file()
|
||||
#endif /* CONFIG_FEATURE_SUID_CONFIG */
|
||||
|
||||
#ifdef CONFIG_FEATURE_SUID
|
||||
static void check_suid(struct BB_applet *applet)
|
||||
{
|
||||
USE_FEATURE_SUID(ruid = getuid();)
|
||||
}
|
||||
#endif /* FEATURE_SUID_CONFIG */
|
||||
uid_t ruid = getuid(); /* real [ug]id */
|
||||
uid_t rgid = getgid();
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_SUID
|
||||
static void check_suid(const struct bb_applet *applet)
|
||||
{
|
||||
gid_t rgid; /* real gid */
|
||||
|
||||
if (ruid == 0) /* set by parse_config_file() */
|
||||
return; /* run by root - no need to check more */
|
||||
rgid = getgid();
|
||||
|
||||
#if ENABLE_FEATURE_SUID_CONFIG
|
||||
#ifdef CONFIG_FEATURE_SUID_CONFIG
|
||||
if (suid_cfg_readable) {
|
||||
uid_t uid;
|
||||
struct BB_suid_config *sct;
|
||||
mode_t m;
|
||||
|
||||
for (sct = suid_config; sct; sct = sct->m_next) {
|
||||
if (sct->m_applet == applet)
|
||||
goto found;
|
||||
break;
|
||||
}
|
||||
if (sct) {
|
||||
mode_t m = sct->m_mode;
|
||||
|
||||
if (sct->m_uid == ruid) /* same uid */
|
||||
m >>= 6;
|
||||
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid)) /* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!(m & S_IXOTH)) /* is x bit not set ? */
|
||||
bb_error_msg_and_die("you have no permission to run this applet!");
|
||||
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) { /* *both* have to be set for sgid */
|
||||
xsetgid(sct->m_gid);
|
||||
} else xsetgid(rgid); /* no sgid -> drop */
|
||||
|
||||
if (sct->m_mode & S_ISUID) xsetuid(sct->m_uid);
|
||||
else xsetuid(ruid); /* no suid -> drop */
|
||||
} else {
|
||||
/* default: drop all privileges */
|
||||
xsetgid(rgid);
|
||||
xsetuid(ruid);
|
||||
}
|
||||
/* default: drop all privileges */
|
||||
xsetgid(rgid);
|
||||
xsetuid(ruid);
|
||||
return;
|
||||
found:
|
||||
m = sct->m_mode;
|
||||
if (sct->m_uid == ruid)
|
||||
/* same uid */
|
||||
m >>= 6;
|
||||
else if ((sct->m_gid == rgid) || ingroup(ruid, sct->m_gid))
|
||||
/* same group / in group */
|
||||
m >>= 3;
|
||||
|
||||
if (!(m & S_IXOTH)) /* is x bit not set ? */
|
||||
bb_error_msg_and_die("you have no permission to run this applet!");
|
||||
|
||||
/* _both_ sgid and group_exec have to be set for setegid */
|
||||
if ((sct->m_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
|
||||
rgid = sct->m_gid;
|
||||
/* else (no setegid) we will set egid = rgid */
|
||||
|
||||
/* We set effective AND saved ids. If saved-id is not set
|
||||
* like we do below, seteiud(0) can still later succeed! */
|
||||
if (setresgid(-1, rgid, rgid))
|
||||
bb_perror_msg_and_die("setresgid");
|
||||
|
||||
/* do we have to set effective uid? */
|
||||
uid = ruid;
|
||||
if (sct->m_mode & S_ISUID)
|
||||
uid = sct->m_uid;
|
||||
/* else (no seteuid) we will set euid = ruid */
|
||||
|
||||
if (setresuid(-1, uid, uid))
|
||||
bb_perror_msg_and_die("setresuid");
|
||||
return;
|
||||
}
|
||||
#if !ENABLE_FEATURE_SUID_CONFIG_QUIET
|
||||
{
|
||||
static bool onetime = 0;
|
||||
} else {
|
||||
#ifndef CONFIG_FEATURE_SUID_CONFIG_QUIET
|
||||
static int onetime = 0;
|
||||
|
||||
if (!onetime) {
|
||||
onetime = 1;
|
||||
fprintf(stderr, "Using fallback suid method\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
if (applet->need_suid == _BB_SUID_ALWAYS) {
|
||||
/* Real uid is not 0. If euid isn't 0 too, suid bit
|
||||
* is most probably not set on our executable */
|
||||
if (geteuid())
|
||||
bb_error_msg_and_die("applet requires root privileges!");
|
||||
if (geteuid()) bb_error_msg_and_die("applet requires root privileges!");
|
||||
} else if (applet->need_suid == _BB_SUID_NEVER) {
|
||||
xsetgid(rgid); /* drop all privileges */
|
||||
xsetgid(rgid); /* drop all privileges */
|
||||
xsetuid(ruid);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define check_suid(x) ((void)0)
|
||||
#endif /* FEATURE_SUID */
|
||||
#define check_suid(x)
|
||||
#endif /* CONFIG_FEATURE_SUID */
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_COMPRESS_USAGE
|
||||
|
||||
#ifdef CONFIG_FEATURE_COMPRESS_USAGE
|
||||
|
||||
#include "usage_compressed.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static const char *unpack_usage_messages(void)
|
||||
{
|
||||
char *outbuf = NULL;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
int input[2], output[2], pid;
|
||||
char *buf;
|
||||
|
||||
i = start_bunzip(&bd,
|
||||
/* src_fd: */ -1,
|
||||
/* inbuf: */ packed_usage,
|
||||
/* len: */ sizeof(packed_usage));
|
||||
/* read_bunzip can longjmp to start_bunzip, and ultimately
|
||||
* end up here with i != 0 on read data errors! Not trivial */
|
||||
if (!i) {
|
||||
/* Cannot use xmalloc: will leak bd in NOFORK case! */
|
||||
outbuf = malloc_or_warn(SIZEOF_usage_messages);
|
||||
if (outbuf)
|
||||
read_bunzip(bd, outbuf, SIZEOF_usage_messages);
|
||||
if(pipe(input) < 0 || pipe(output) < 0)
|
||||
exit(1);
|
||||
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case -1: /* error */
|
||||
exit(1);
|
||||
case 0: /* child */
|
||||
close(input[1]);
|
||||
close(output[0]);
|
||||
uncompressStream(input[0], output[1]);
|
||||
exit(0);
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
return outbuf;
|
||||
/* parent */
|
||||
|
||||
close(input[0]);
|
||||
close(output[1]);
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case -1: /* error */
|
||||
exit(1);
|
||||
case 0: /* child */
|
||||
full_write(input[1], packed_usage, sizeof(packed_usage));
|
||||
exit(0);
|
||||
}
|
||||
/* parent */
|
||||
close(input[1]);
|
||||
|
||||
buf = xmalloc(SIZEOF_usage_messages);
|
||||
full_read(output[0], buf, SIZEOF_usage_messages);
|
||||
return buf;
|
||||
}
|
||||
#define dealloc_usage_messages(s) free(s)
|
||||
|
||||
#else
|
||||
|
||||
#define unpack_usage_messages() usage_messages
|
||||
#define dealloc_usage_messages(s) ((void)(s))
|
||||
|
||||
#endif /* FEATURE_COMPRESS_USAGE */
|
||||
|
||||
#endif /* ENABLE_FEATURE_COMPRESS_USAGE */
|
||||
|
||||
void bb_show_usage(void)
|
||||
{
|
||||
if (ENABLE_SHOW_USAGE) {
|
||||
const char *format_string;
|
||||
const char *p;
|
||||
const char *usage_string = p = unpack_usage_messages();
|
||||
const char *usage_string = unpack_usage_messages();
|
||||
int i;
|
||||
|
||||
i = current_applet - applets;
|
||||
while (i) {
|
||||
while (*p++) continue;
|
||||
i--;
|
||||
}
|
||||
for (i = applet_using - applets; i > 0;)
|
||||
if (!*usage_string++) --i;
|
||||
|
||||
fprintf(stderr, "%s multi-call binary\n", bb_banner);
|
||||
format_string = "\nUsage: %s %s\n\n";
|
||||
if (*p == '\b')
|
||||
format_string = "\nNo help available.\n\n";
|
||||
fprintf(stderr, format_string, applet_name, p);
|
||||
dealloc_usage_messages((char*)usage_string);
|
||||
format_string = "%s\n\nUsage: %s %s\n\n";
|
||||
if (*usage_string == '\b')
|
||||
format_string = "%s\n\nNo help available.\n\n";
|
||||
fprintf(stderr, format_string, bb_msg_full_version,
|
||||
applet_using->name, usage_string);
|
||||
}
|
||||
xfunc_die();
|
||||
}
|
||||
|
||||
exit(xfunc_error_retval);
|
||||
}
|
||||
|
||||
static int applet_name_compare(const void *name, const void *vapplet)
|
||||
{
|
||||
const struct bb_applet *applet = vapplet;
|
||||
const struct BB_applet *applet = vapplet;
|
||||
|
||||
return strcmp(name, applet->name);
|
||||
}
|
||||
|
||||
const struct bb_applet *find_applet_by_name(const char *name)
|
||||
extern const size_t NUM_APPLETS;
|
||||
|
||||
struct BB_applet *find_applet_by_name(const char *name)
|
||||
{
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
|
||||
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
|
||||
applet_name_compare);
|
||||
}
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
{
|
||||
/* directory table
|
||||
* this should be consistent w/ the enum,
|
||||
* busybox.h::bb_install_loc_t, or else... */
|
||||
static const char usr_bin [] ALIGN1 = "/usr/bin";
|
||||
static const char usr_sbin[] ALIGN1 = "/usr/sbin";
|
||||
static const char *const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
if (ENABLE_FEATURE_SUID_CONFIG) parse_config_file();
|
||||
|
||||
int (*lf)(const char *, const char *) = link;
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
lf = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].install_loc],
|
||||
applets[i].name);
|
||||
rc = lf(busybox, fpc);
|
||||
if (rc != 0 && errno != EEXIST) {
|
||||
bb_perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
if (!strncmp(name, "busybox", 7)) busybox_main(argc, argv);
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
applet_using = find_applet_by_name(name);
|
||||
if (applet_using) {
|
||||
applet_name = applet_using->name;
|
||||
if(argc==2 && !strcmp(argv[1], "--help")) bb_show_usage();
|
||||
if(ENABLE_FEATURE_SUID) check_suid(applet_using);
|
||||
exit((*(applet_using->main))(argc, argv));
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define install_links(x,y) ((void)0)
|
||||
#endif /* FEATURE_INSTALLER */
|
||||
|
||||
|
||||
/* If we were called as "busybox..." */
|
||||
static int busybox_main(char **argv)
|
||||
{
|
||||
if (!argv[1]) {
|
||||
/* Called without arguments */
|
||||
const struct bb_applet *a;
|
||||
int col, output_width;
|
||||
help:
|
||||
output_width = 80;
|
||||
if (ENABLE_FEATURE_AUTOWIDTH) {
|
||||
/* Obtain the terminal width */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
}
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
|
||||
printf("%s multi-call binary\n", bb_banner); /* reuse const string... */
|
||||
printf("Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
"Licensed under GPLv2. See source distribution for full notice.\n"
|
||||
"\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n"
|
||||
"\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n");
|
||||
col = 0;
|
||||
a = applets;
|
||||
while (a->name) {
|
||||
if (col > output_width) {
|
||||
puts(",");
|
||||
col = 0;
|
||||
}
|
||||
col += printf("%s%s", (col ? ", " : "\t"), a->name);
|
||||
a++;
|
||||
}
|
||||
puts("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
|
||||
const char *busybox;
|
||||
busybox = xmalloc_readlink(bb_busybox_exec_path);
|
||||
if (!busybox)
|
||||
busybox = bb_busybox_exec_path;
|
||||
/* -s makes symlinks */
|
||||
install_links(busybox, argv[2] && strcmp(argv[2], "-s") == 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
/* "busybox --help [<applet>]" */
|
||||
if (!argv[2])
|
||||
goto help;
|
||||
/* convert to "<applet> --help" */
|
||||
argv[0] = argv[2];
|
||||
argv[2] = NULL;
|
||||
} else {
|
||||
/* "busybox <applet> arg1 arg2 ..." */
|
||||
argv++;
|
||||
}
|
||||
/* we want "<argv[0]>: applet not found", not "busybox: ..." */
|
||||
applet_name = argv[0];
|
||||
run_applet_and_exit(argv[0], argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
void run_current_applet_and_exit(char **argv)
|
||||
{
|
||||
int argc = 1;
|
||||
|
||||
while (argv[argc])
|
||||
argc++;
|
||||
|
||||
/* Reinit some shared global data */
|
||||
optind = 1;
|
||||
xfunc_error_retval = EXIT_FAILURE;
|
||||
|
||||
applet_name = current_applet->name;
|
||||
if (argc == 2 && !strcmp(argv[1], "--help"))
|
||||
bb_show_usage();
|
||||
if (ENABLE_FEATURE_SUID)
|
||||
check_suid(current_applet);
|
||||
exit(current_applet->main(argc, argv));
|
||||
}
|
||||
|
||||
void run_applet_and_exit(const char *name, char **argv)
|
||||
{
|
||||
current_applet = find_applet_by_name(name);
|
||||
if (current_applet)
|
||||
run_current_applet_and_exit(argv);
|
||||
if (!strncmp(name, "busybox", 7))
|
||||
exit(busybox_main(argv));
|
||||
}
|
||||
|
||||
|
||||
#ifdef __GLIBC__
|
||||
/* Make it reside in R/W memory: */
|
||||
int *const bb_errno __attribute__ ((section (".data")));
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
#ifdef __GLIBC__
|
||||
(*(int **)&bb_errno) = __errno_location();
|
||||
#endif
|
||||
|
||||
#if !BB_MMU
|
||||
/* NOMMU re-exec trick sets high-order bit in first byte of name */
|
||||
if (argv[0][0] & 0x80) {
|
||||
re_execed = 1;
|
||||
argv[0][0] &= 0x7f;
|
||||
}
|
||||
#endif
|
||||
applet_name = argv[0];
|
||||
if (applet_name[0] == '-')
|
||||
applet_name++;
|
||||
applet_name = bb_basename(applet_name);
|
||||
|
||||
parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
|
||||
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
run_applet_and_exit(applet_name, argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* BusyBox' main applet dispatcher.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "busybox.h"
|
||||
|
||||
const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE;
|
||||
|
||||
#ifdef CONFIG_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static const char usr_bin [] ="/usr/bin";
|
||||
static const char usr_sbin[] ="/usr/sbin";
|
||||
|
||||
static const char* const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].location], applets[i].name);
|
||||
rc = Link(busybox, fpc);
|
||||
if (rc!=0 && errno!=EEXIST) {
|
||||
bb_perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#define install_links(x,y)
|
||||
#endif /* CONFIG_FEATURE_INSTALLER */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
applet_name=argv[0];
|
||||
if (*applet_name == '-') applet_name++;
|
||||
for (s = applet_name; *s ;)
|
||||
if (*(s++) == '/') applet_name = s;
|
||||
|
||||
/* Set locale for everybody except 'init' */
|
||||
if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
run_applet_by_name(applet_name, argc, argv);
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (ENABLE_FEATURE_INSTALLER && argc > 1 && !strcmp(argv[1], "--install")) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
// XXX: FIXME: this is broken. Why not just use argv[0] ?
|
||||
busybox = xreadlink("/proc/self/exe");
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Deal with --help. (Also print help when called with no arguments) */
|
||||
|
||||
if (argc==1 || !strcmp(argv[1],"--help") ) {
|
||||
if (argc>2) {
|
||||
applet_name = argv[2];
|
||||
run_applet_by_name(applet_name, 2, argv);
|
||||
} else {
|
||||
const struct BB_applet *a;
|
||||
int col, output_width;
|
||||
|
||||
if (ENABLE_FEATURE_AUTOWIDTH) {
|
||||
/* Obtain the terminal width. */
|
||||
get_terminal_width_height(0, &output_width, NULL);
|
||||
/* leading tab and room to wrap */
|
||||
output_width -= sizeof("start-stop-daemon, ") + 8;
|
||||
} else output_width = 80 - sizeof("start-stop-daemon, ") - 8;
|
||||
|
||||
printf("%s\n"
|
||||
"Copyright (C) 1998-2006 Erik Andersen, Rob Landley, and others.\n"
|
||||
"Licensed under GPLv2. See source distribution for full notice.\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as!\n"
|
||||
"\nCurrently defined functions:\n", bb_msg_full_version);
|
||||
|
||||
col=0;
|
||||
for(a = applets; a->name;) {
|
||||
col += printf("%s%s", (col ? ", " : "\t"), (a++)->name);
|
||||
if (col > output_width && a->name) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
printf("\n\n");
|
||||
exit(0);
|
||||
}
|
||||
} else run_applet_by_name(argv[1], argc-1, argv+1);
|
||||
|
||||
bb_error_msg_and_die("applet not found");
|
||||
}
|
||||
@@ -9,11 +9,12 @@ const char *applet_name;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
//Ok to remove? #include "bb_config.h"
|
||||
#include "usage.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
applet_name = argv[0];
|
||||
applet_name=argv[0];
|
||||
|
||||
return APPLET_main(argc,argv);
|
||||
}
|
||||
|
||||
+2
-2
@@ -43,7 +43,7 @@ if [ "$cleanup" = "1" ] && [ -e "$prefix/bin/busybox" ]; then
|
||||
inode=`ls -i "$prefix/bin/busybox" | awk '{print $1}'`
|
||||
sub_shell_it=`
|
||||
cd "$prefix"
|
||||
for d in usr/sbin usr/bin sbin bin; do
|
||||
for d in usr/sbin usr/bin sbin bin ; do
|
||||
pd=$PWD
|
||||
if [ -d "$d" ]; then
|
||||
cd $d
|
||||
@@ -58,7 +58,7 @@ rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
|
||||
for i in $h; do
|
||||
for i in $h ; do
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
|
||||
+2
-3
@@ -1,11 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <unistd.h>
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "../include/autoconf.h"
|
||||
#include "../include/busybox.h"
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
static const char usage_messages[] =
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
|
||||
@@ -12,8 +12,8 @@ sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
exec >"$target"
|
||||
|
||||
echo 'static const char packed_usage[] ALIGN1 = '
|
||||
echo 'static const char packed_usage[] = '
|
||||
"$loc/usage" | bzip2 -1 | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' -e 's/ *\(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
|
||||
| $SED -e 's/^[^ ]*//' -e 's/ \(..\)/\\x\1/g' -e 's/^\(.*\)$/"\1"/'
|
||||
echo ';'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
+1
-3
@@ -2,6 +2,4 @@
|
||||
# Build system
|
||||
# ==========================================================================
|
||||
|
||||
# -mpreferred-stack-boundary=2 is essential in preventing gcc 4.2.x
|
||||
# from aligning stack to 16 bytes. (Which is gcc's way of supporting SSE).
|
||||
CFLAGS += $(call cc-option,-march=i386 -mpreferred-stack-boundary=2,)
|
||||
CFLAGS += -march=i386 -mpreferred-stack-boundary=2
|
||||
+1
-17
@@ -131,14 +131,7 @@ config RPM
|
||||
bool "rpm"
|
||||
default n
|
||||
help
|
||||
Mini RPM applet - queries and extracts RPM packages.
|
||||
|
||||
config FEATURE_RPM_BZ2
|
||||
bool "Enable handling of rpms with bzip2-compressed data inside"
|
||||
default n
|
||||
depends on RPM
|
||||
help
|
||||
Enable handling of rpms with bzip2-compressed data inside.
|
||||
Mini RPM applet - queries and extracts
|
||||
|
||||
config TAR
|
||||
bool "tar"
|
||||
@@ -205,15 +198,6 @@ config FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
the old GNU format; help to kill this old format by
|
||||
repacking your ancient archives with the new format.
|
||||
|
||||
config FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
bool "Enable untarring of tarballs with checksums produced by buggy Sun tar"
|
||||
default N
|
||||
depends on TAR
|
||||
help
|
||||
This option is required to unpack archives created by some old
|
||||
version of Sun's tar (it was calculating checksum using signed arithmetic).
|
||||
It is said to be fixed in newer Sun tar, but "old" tarballs still exist.
|
||||
|
||||
config FEATURE_TAR_GNU_EXTENSIONS
|
||||
bool "Enable support for some GNU tar extensions"
|
||||
default y
|
||||
|
||||
+5
-5
@@ -8,15 +8,15 @@ libs-y += libunarchive/
|
||||
|
||||
lib-y:=
|
||||
lib-$(CONFIG_AR) += ar.o
|
||||
lib-$(CONFIG_BUNZIP2) += bbunzip.o
|
||||
lib-$(CONFIG_UNLZMA) += bbunzip.o
|
||||
lib-$(CONFIG_BUNZIP2) += bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += unlzma.o
|
||||
lib-$(CONFIG_CPIO) += cpio.o
|
||||
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_GUNZIP) += gunzip.o
|
||||
lib-$(CONFIG_GZIP) += gzip.o
|
||||
lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o
|
||||
lib-$(CONFIG_RPM) += rpm.o
|
||||
lib-$(CONFIG_TAR) += tar.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += bbunzip.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += unzip.o
|
||||
+6
-9
@@ -14,7 +14,7 @@
|
||||
* http://www.unix-systems.org/single_unix_specification_v2/xcu/ar.html
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
@@ -38,21 +38,19 @@ static void header_verbose_list_ar(const file_header_t *file_header)
|
||||
#define AR_OPT_CREATE 0x20
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv);
|
||||
int ar_main(int argc, char **argv)
|
||||
{
|
||||
static const char msg_unsupported_err[] ALIGN1 =
|
||||
"archive %s is not supported";
|
||||
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned opt;
|
||||
static const char msg_unsupported_err[] =
|
||||
"Archive %s not supported. Install binutils 'ar'.";
|
||||
char magic[8];
|
||||
|
||||
archive_handle = init_handle();
|
||||
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argv, "ptxovcr");
|
||||
opt_complementary = "--:p:t:x:-1:?:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argc, argv, "ptxovcr");
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
@@ -89,8 +87,7 @@ int ar_main(int argc, char **argv)
|
||||
}
|
||||
archive_handle->offset += 7;
|
||||
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
while (get_header_ar(archive_handle) == EXIT_SUCCESS);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,349 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Common code for gunzip-like applets
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
enum {
|
||||
OPT_STDOUT = 0x1,
|
||||
OPT_FORCE = 0x2,
|
||||
/* gunzip only: */
|
||||
OPT_VERBOSE = 0x4,
|
||||
OPT_DECOMPRESS = 0x8,
|
||||
OPT_TEST = 0x10,
|
||||
};
|
||||
|
||||
static
|
||||
int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
|
||||
{
|
||||
int fd = open3_or_warn(filename, flags, mode);
|
||||
if (fd < 0) {
|
||||
return 1;
|
||||
}
|
||||
xmove_fd(fd, to_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bbunpack(char **argv,
|
||||
char* (*make_new_name)(char *filename),
|
||||
USE_DESKTOP(long long) int (*unpacker)(void)
|
||||
)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename, *new_name;
|
||||
smallint exitcode = 0;
|
||||
|
||||
do {
|
||||
/* NB: new_name is *maybe* malloc'ed! */
|
||||
new_name = NULL;
|
||||
filename = *argv; /* can be NULL - 'streaming' bunzip2 */
|
||||
|
||||
if (filename && LONE_DASH(filename))
|
||||
filename = NULL;
|
||||
|
||||
/* Open src */
|
||||
if (filename) {
|
||||
if (stat(filename, &stat_buf) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
err:
|
||||
exitcode = 1;
|
||||
goto free_name;
|
||||
}
|
||||
if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Special cases: test, stdout */
|
||||
if (option_mask32 & (OPT_STDOUT|OPT_TEST)) {
|
||||
if (option_mask32 & OPT_TEST)
|
||||
if (open_to_or_warn(STDOUT_FILENO, bb_dev_null, O_WRONLY, 0))
|
||||
goto err;
|
||||
filename = NULL;
|
||||
}
|
||||
|
||||
/* Open dst if we are going to unpack to file */
|
||||
if (filename) {
|
||||
new_name = make_new_name(filename);
|
||||
if (!new_name) {
|
||||
bb_error_msg("%s: unknown suffix - ignored", filename);
|
||||
goto err;
|
||||
}
|
||||
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
|
||||
/* GNU gunzip goes not bail out, but goes to next file */
|
||||
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
stat_buf.st_mode))
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Check that the input is sane */
|
||||
if (isatty(STDIN_FILENO) && (option_mask32 & OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
status = unpacker();
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
if (status >= 0) {
|
||||
/* TODO: restore user/group/times here? */
|
||||
/* Delete _compressed_ file */
|
||||
del = filename;
|
||||
/* restore extension (unless tgz -> tar case) */
|
||||
if (new_name == filename)
|
||||
filename[strlen(filename)] = '.';
|
||||
}
|
||||
xunlink(del);
|
||||
|
||||
#if 0 /* Currently buggy - wrong name: "a.gz: 261% - replaced with a.gz" */
|
||||
/* Extreme bloat for gunzip compat */
|
||||
if (ENABLE_DESKTOP && (option_mask32 & OPT_VERBOSE) && status >= 0) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
filename, (unsigned)(stat_buf.st_size*100 / (status+1)), new_name);
|
||||
}
|
||||
#endif
|
||||
|
||||
free_name:
|
||||
if (new_name != filename)
|
||||
free(new_name);
|
||||
}
|
||||
} while (*argv && *++argv);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
|
||||
#if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_generic(char *filename, const char *expected_ext)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension + 1, expected_ext) != 0) {
|
||||
/* Mimic GNU gunzip - "real" bunzip2 tries to */
|
||||
/* unpack file anyway, to file.out */
|
||||
return NULL;
|
||||
}
|
||||
*extension = '\0';
|
||||
return filename;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_BUNZIP2
|
||||
|
||||
static
|
||||
char* make_new_name_bunzip2(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "bz2");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_bunzip2(void)
|
||||
{
|
||||
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int bunzip2_main(int argc, char **argv);
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
if (applet_name[2] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
#if ENABLE_GUNZIP
|
||||
|
||||
static
|
||||
char* make_new_name_gunzip(char *filename)
|
||||
{
|
||||
char *extension = strrchr(filename, '.');
|
||||
|
||||
if (!extension)
|
||||
return NULL;
|
||||
|
||||
extension++;
|
||||
if (strcmp(extension, "tgz" + 1) == 0
|
||||
#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
|
||||
|| strcmp(extension, "Z") == 0
|
||||
#endif
|
||||
) {
|
||||
extension[-1] = '\0';
|
||||
} else if (strcmp(extension, "tgz") == 0) {
|
||||
filename = xstrdup(filename);
|
||||
extension = strrchr(filename, '.');
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_gunzip(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(STDIN_FILENO) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(STDIN_FILENO);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else if (magic2 == 0x8b) {
|
||||
check_header_gzip_or_die(STDIN_FILENO);
|
||||
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
} else {
|
||||
goto bad_magic;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
} else {
|
||||
bad_magic:
|
||||
bb_error_msg("invalid magic");
|
||||
/* status is still == -1 */
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int gunzip_main(int argc, char **argv);
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cfvdt");
|
||||
argv += optind;
|
||||
/* if called as zcat */
|
||||
if (applet_name[1] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_gunzip, unpack_gunzip);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNLZMA
|
||||
|
||||
static
|
||||
char* make_new_name_unlzma(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "lzma");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_unlzma(void)
|
||||
{
|
||||
return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int unlzma_main(int argc, char **argv);
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
/* lzmacat? */
|
||||
if (applet_name[4] == 'c')
|
||||
option_mask32 |= OPT_STDOUT;
|
||||
|
||||
return bbunpack(argv, make_new_name_unlzma, unpack_unlzma);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#if ENABLE_UNCOMPRESS
|
||||
|
||||
static
|
||||
char* make_new_name_uncompress(char *filename)
|
||||
{
|
||||
return make_new_name_generic(filename, "Z");
|
||||
}
|
||||
|
||||
static
|
||||
USE_DESKTOP(long long) int unpack_uncompress(void)
|
||||
{
|
||||
USE_DESKTOP(long long) int status = -1;
|
||||
|
||||
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
|
||||
bb_error_msg("invalid magic");
|
||||
} else {
|
||||
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int uncompress_main(int argc, char **argv);
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "cf");
|
||||
argv += optind;
|
||||
|
||||
return bbunpack(argv, make_new_name_uncompress, unpack_uncompress);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Modified for busybox by Glenn McGrath <bug1@iinet.net.au>
|
||||
* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define BUNZIP2_OPT_STDOUT 1
|
||||
#define BUNZIP2_OPT_FORCE 2
|
||||
|
||||
int bunzip2_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, dst_fd;
|
||||
|
||||
opt = getopt32(argc, argv, "cf");
|
||||
|
||||
/* Set input filename and number */
|
||||
filename = argv[optind];
|
||||
if ((filename) && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as bzcat force the stdout flag */
|
||||
if ((opt & BUNZIP2_OPT_STDOUT) || applet_name[2] == 'c')
|
||||
filename = 0;
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && (opt & BUNZIP2_OPT_FORCE) == 0) {
|
||||
bb_error_msg_and_die("compressed data not read from terminal, "
|
||||
"use -f to force it");
|
||||
}
|
||||
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* extension = filename+strlen(filename)-4 is buggy:
|
||||
* strlen may be less than 4 */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".bz2") != 0) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else dst_fd = STDOUT_FILENO;
|
||||
status = uncompressStream(src_fd, dst_fd);
|
||||
if (filename) {
|
||||
if (status >= 0) filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
+13
-10
@@ -11,18 +11,21 @@
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "unarchive.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define CPIO_OPT_EXTRACT 0x01
|
||||
#define CPIO_OPT_TEST 0x02
|
||||
#define CPIO_OPT_UNCONDITIONAL 0x04
|
||||
#define CPIO_OPT_VERBOSE 0x08
|
||||
#define CPIO_OPT_FILE 0x10
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
#define CPIO_OPT_EXTRACT 0x01
|
||||
#define CPIO_OPT_TEST 0x02
|
||||
#define CPIO_OPT_UNCONDITIONAL 0x04
|
||||
#define CPIO_OPT_VERBOSE 0x08
|
||||
#define CPIO_OPT_FILE 0x10
|
||||
#define CPIO_OPT_CREATE_LEADING_DIR 0x20
|
||||
#define CPIO_OPT_PRESERVE_MTIME 0x40
|
||||
|
||||
int cpio_main(int argc, char **argv);
|
||||
int cpio_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *archive_handle;
|
||||
@@ -35,7 +38,7 @@ int cpio_main(int argc, char **argv)
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
|
||||
|
||||
opt = getopt32(argv, "ituvF:dm", &cpio_filename);
|
||||
opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
|
||||
+326
-263
File diff suppressed because it is too large.
Load diff
+10
-11
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define DPKG_DEB_OPT_CONTENTS 1
|
||||
@@ -13,14 +13,13 @@
|
||||
#define DPKG_DEB_OPT_EXTRACT 8
|
||||
#define DPKG_DEB_OPT_EXTRACT_VERBOSE 16
|
||||
|
||||
int dpkg_deb_main(int argc, char **argv);
|
||||
int dpkg_deb_main(int argc, char **argv)
|
||||
{
|
||||
archive_handle_t *ar_archive;
|
||||
archive_handle_t *tar_archive;
|
||||
llist_t *control_tar_llist = NULL;
|
||||
unsigned opt;
|
||||
const char *extract_dir = NULL;
|
||||
char *extract_dir = NULL;
|
||||
short argcount = 1;
|
||||
|
||||
/* Setup the tar archive handle */
|
||||
@@ -31,18 +30,18 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
ar_archive->sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#if ENABLE_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.gz");
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.gz");
|
||||
llist_add_to(&control_tar_llist, "control.tar.gz");
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_archive->accept), (char*)"data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
llist_add_to(&(ar_archive->accept), "data.tar.bz2");
|
||||
llist_add_to(&control_tar_llist, "control.tar.bz2");
|
||||
#endif
|
||||
|
||||
opt_complementary = "?c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
|
||||
opt = getopt32(argv, "cefXx");
|
||||
opt = getopt32(argc, argv, "cefXx");
|
||||
|
||||
if (opt & DPKG_DEB_OPT_CONTENTS) {
|
||||
tar_archive->action_header = header_verbose_list;
|
||||
@@ -61,7 +60,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
* it should accept a second argument which specifies a
|
||||
* specific field to print */
|
||||
ar_archive->accept = control_tar_llist;
|
||||
llist_add_to(&(tar_archive->accept), (char*)"./control");
|
||||
llist_add_to(&(tar_archive->accept), "./control");
|
||||
tar_archive->filter = filter_accept_list;
|
||||
tar_archive->action_data = data_extract_to_stdout;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip v1.2.4 Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@codepoet.org> to support files as
|
||||
* well as stdin/stdout, and to generally behave itself wrt command line
|
||||
* handling.
|
||||
*
|
||||
* General cleanup to better adhere to the style guide and make use of standard
|
||||
* busybox functions by Glenn McGrath <bug1@iinet.net.au>
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*
|
||||
* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
* The unzip code was written and put in the public domain by Mark Adler.
|
||||
* Portions of the lzw code are derived from the public domain 'compress'
|
||||
* written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies,
|
||||
* Ken Turkowski, Dave Mack and Peter Jannesen.
|
||||
*
|
||||
* See the license_msg below and the file COPYING for the software license.
|
||||
* See the file algorithm.doc for the compression algorithms and file formats.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_OPT_STDOUT 1
|
||||
#define GUNZIP_OPT_FORCE 2
|
||||
#define GUNZIP_OPT_TEST 4
|
||||
#define GUNZIP_OPT_DECOMPRESS 8
|
||||
#define GUNZIP_OPT_VERBOSE 0x10
|
||||
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
int exitcode = 0;
|
||||
unsigned opt;
|
||||
|
||||
opt = getopt32(argc, argv, "cftdv");
|
||||
/* if called as zcat */
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
}
|
||||
|
||||
do {
|
||||
struct stat stat_buf;
|
||||
char *old_path = argv[optind];
|
||||
char *delete_path = NULL;
|
||||
char *new_path = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
optind++;
|
||||
|
||||
if (old_path == NULL || strcmp(old_path, "-") == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
opt |= GUNZIP_OPT_STDOUT;
|
||||
USE_DESKTOP(opt &= ~GUNZIP_OPT_VERBOSE;)
|
||||
optind = argc; /* we don't handle "gunzip - a.gz b.gz" */
|
||||
} else {
|
||||
src_fd = xopen(old_path, O_RDONLY);
|
||||
/* Get the time stamp on the input file. */
|
||||
fstat(src_fd, &stat_buf);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && !(opt & GUNZIP_OPT_FORCE)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal, use -f to force it");
|
||||
}
|
||||
|
||||
/* Set output filename and number */
|
||||
if (opt & GUNZIP_OPT_TEST) {
|
||||
dst_fd = xopen(bb_dev_null, O_WRONLY); /* why does test use filenum 2 ? */
|
||||
} else if (opt & GUNZIP_OPT_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
char *extension;
|
||||
|
||||
new_path = xstrdup(old_path);
|
||||
|
||||
extension = strrchr(new_path, '.');
|
||||
#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
|
||||
if (extension && (strcmp(extension, ".Z") == 0)) {
|
||||
*extension = '\0';
|
||||
} else
|
||||
#endif
|
||||
if (extension && (strcmp(extension, ".gz") == 0)) {
|
||||
*extension = '\0';
|
||||
} else if (extension && (strcmp(extension, ".tgz") == 0)) {
|
||||
extension[2] = 'a';
|
||||
extension[3] = 'r';
|
||||
} else {
|
||||
// FIXME: should we die or just skip to next?
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
|
||||
/* Open output file (with correct permissions) */
|
||||
dst_fd = xopen3(new_path, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = old_path;
|
||||
}
|
||||
|
||||
status = -1;
|
||||
/* do the decompression, and cleanup */
|
||||
if (xread_char(src_fd) == 0x1f) {
|
||||
unsigned char magic2;
|
||||
|
||||
magic2 = xread_char(src_fd);
|
||||
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
} else if (magic2 == 0x8b) {
|
||||
check_header_gzip(src_fd); // FIXME: xfunc? _or_die?
|
||||
status = inflate_gunzip(src_fd, dst_fd);
|
||||
} else {
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
if (status < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
exitcode = 1;
|
||||
}
|
||||
else if (ENABLE_DESKTOP && (opt & GUNZIP_OPT_VERBOSE)) {
|
||||
fprintf(stderr, "%s: %u%% - replaced with %s\n",
|
||||
old_path, (unsigned)(stat_buf.st_size*100 / (status+1)), new_path);
|
||||
}
|
||||
} else {
|
||||
bb_error_msg("invalid magic");
|
||||
exitcode = 1;
|
||||
}
|
||||
if (status < 0 && new_path) {
|
||||
/* Unzip failed, remove new path instead of old path */
|
||||
delete_path = new_path;
|
||||
}
|
||||
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
bb_error_msg("cannot remove %s", delete_path);
|
||||
exitcode = 1;
|
||||
}
|
||||
|
||||
free(new_path);
|
||||
|
||||
} while (optind < argc);
|
||||
|
||||
return exitcode;
|
||||
}
|
||||
+1533
-1143
File diff suppressed because it is too large.
Load diff
@@ -26,6 +26,7 @@ lib-y:= \
|
||||
\
|
||||
data_align.o \
|
||||
find_list_entry.o \
|
||||
open_transformer.o \
|
||||
init_handle.o
|
||||
|
||||
GUNZIP_FILES:= check_header_gzip.o decompress_unzip.o
|
||||
@@ -35,34 +36,24 @@ DPKG_FILES:= \
|
||||
get_header_tar.o \
|
||||
filter_accept_list_reassign.o
|
||||
|
||||
lib-$(CONFIG_RPM) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
|
||||
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
|
||||
lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
|
||||
lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
|
||||
lib-$(CONFIG_CPIO) += get_header_cpio.o
|
||||
lib-$(CONFIG_DPKG) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
|
||||
lib-$(CONFIG_TAR) += get_header_tar.o
|
||||
lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
|
||||
lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
|
||||
lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
|
||||
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
|
||||
lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
|
||||
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
|
||||
@@ -3,8 +3,8 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
|
||||
unsigned char *buf, size_t count)
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip_or_die */
|
||||
#include "unarchive.h" /* for external decl of check_header_gzip */
|
||||
|
||||
void check_header_gzip_or_die(int src_fd)
|
||||
void check_header_gzip(int src_fd)
|
||||
{
|
||||
union {
|
||||
unsigned char raw[8];
|
||||
@@ -29,7 +30,7 @@ void check_header_gzip_or_die(int src_fd)
|
||||
|
||||
if (header.formatted.flags & 0x04) {
|
||||
/* bit 2 set: extra field present */
|
||||
unsigned extra_short;
|
||||
unsigned char extra_short;
|
||||
|
||||
extra_short = xread_char(src_fd) + (xread_char(src_fd) << 8);
|
||||
while (extra_short > 0) {
|
||||
@@ -42,13 +43,13 @@ void check_header_gzip_or_die(int src_fd)
|
||||
/* Discard original name if any */
|
||||
if (header.formatted.flags & 0x08) {
|
||||
/* bit 3 set: original file name present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Discard file comment if any */
|
||||
if (header.formatted.flags & 0x10) {
|
||||
/* bit 4 set: file comment present */
|
||||
while (xread_char(src_fd) != 0);
|
||||
while(xread_char(src_fd) != 0);
|
||||
}
|
||||
|
||||
/* Read the header checksum */
|
||||
@@ -56,4 +57,6 @@ void check_header_gzip_or_die(int src_fd)
|
||||
xread_char(src_fd);
|
||||
xread_char(src_fd);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -3,7 +3,10 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
//#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
@@ -14,4 +17,6 @@ void data_align(archive_handle_t *archive_handle, const unsigned short boundary)
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -25,8 +25,7 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
file_header->name);
|
||||
bb_perror_msg_and_die("cannot remove old file");
|
||||
}
|
||||
}
|
||||
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
@@ -53,16 +52,13 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
|
||||
/* 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)
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_name)
|
||||
&& (file_header->size == 0)
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
res = link(file_header->link_name, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "hard",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
bb_perror_msg("cannot create hard link");
|
||||
}
|
||||
} else {
|
||||
/* Create the filesystem entry */
|
||||
@@ -71,28 +67,28 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
/* Regular file */
|
||||
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);
|
||||
bb_copyfd_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)
|
||||
if ((errno != EISDIR) && (res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot make dir %s", file_header->name);
|
||||
bb_perror_msg("extract_archive: %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
/* Symlink */
|
||||
res = symlink(file_header->link_target, file_header->name);
|
||||
res = symlink(file_header->link_name, file_header->name);
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
"from %s to %s", "sym",
|
||||
bb_perror_msg("cannot create symlink "
|
||||
"from %s to '%s'",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
file_header->link_name);
|
||||
}
|
||||
break;
|
||||
case S_IFSOCK:
|
||||
@@ -114,18 +110,10 @@ void data_extract_all(archive_handle_t *archive_handle)
|
||||
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
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->flags & ARCHIVE_NOPRESERVE_PERM)) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
|
||||
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,9 @@
|
||||
|
||||
void data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned int size = archive_handle->file_header->size;
|
||||
const unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xzalloc(size + 1);
|
||||
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -3,12 +3,10 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
#include <unistd.h>
|
||||
|
||||
void data_extract_to_stdout(archive_handle_t *archive_handle)
|
||||
{
|
||||
bb_copyfd_exact_size(archive_handle->src_fd,
|
||||
STDOUT_FILENO,
|
||||
archive_handle->file_header->size);
|
||||
bb_copyfd_size(archive_handle->src_fd, STDOUT_FILENO, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -3,8 +3,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
void data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
|
||||
@@ -32,103 +32,104 @@
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Constants for Huffman coding */
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define SYMBOL_RUNA 0
|
||||
#define SYMBOL_RUNB 1
|
||||
#define MAX_GROUPS 6
|
||||
#define GROUP_SIZE 50 /* 64 would have been more efficient */
|
||||
#define MAX_HUFCODE_BITS 20 /* Longest Huffman code allowed */
|
||||
#define MAX_SYMBOLS 258 /* 256 literals + RUNA + RUNB */
|
||||
#define SYMBOL_RUNA 0
|
||||
#define SYMBOL_RUNB 1
|
||||
|
||||
/* Status return values */
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
#define RETVAL_OK 0
|
||||
#define RETVAL_LAST_BLOCK (-1)
|
||||
#define RETVAL_NOT_BZIP_DATA (-2)
|
||||
#define RETVAL_UNEXPECTED_INPUT_EOF (-3)
|
||||
#define RETVAL_UNEXPECTED_OUTPUT_EOF (-4)
|
||||
#define RETVAL_DATA_ERROR (-5)
|
||||
#define RETVAL_OUT_OF_MEMORY (-6)
|
||||
#define RETVAL_OBSOLETE_INPUT (-7)
|
||||
|
||||
/* Other housekeeping constants */
|
||||
#define IOBUF_SIZE 4096
|
||||
#define IOBUF_SIZE 4096
|
||||
|
||||
/* This is what we know about each Huffman coding group */
|
||||
struct group_data {
|
||||
/* We have an extra slot at the end of limit[] for a sentinal value. */
|
||||
int limit[MAX_HUFCODE_BITS+1], base[MAX_HUFCODE_BITS], permute[MAX_SYMBOLS];
|
||||
int limit[MAX_HUFCODE_BITS+1],base[MAX_HUFCODE_BITS],permute[MAX_SYMBOLS];
|
||||
int minLen, maxLen;
|
||||
};
|
||||
|
||||
/* Structure holding all the housekeeping data, including IO buffers and
|
||||
memory that persists between calls to bunzip */
|
||||
|
||||
struct bunzip_data {
|
||||
typedef struct {
|
||||
/* State for interrupting output loop */
|
||||
int writeCopies, writePos, writeRunCountdown, writeCount, writeCurrent;
|
||||
|
||||
int writeCopies,writePos,writeRunCountdown,writeCount,writeCurrent;
|
||||
|
||||
/* I/O tracking data (file handles, buffers, positions, etc.) */
|
||||
int in_fd, out_fd, inbufCount, inbufPos /*, outbufPos*/;
|
||||
|
||||
int in_fd,out_fd,inbufCount,inbufPos /*,outbufPos*/;
|
||||
unsigned char *inbuf /*,*outbuf*/;
|
||||
unsigned inbufBitCount, inbufBits;
|
||||
unsigned int inbufBitCount, inbufBits;
|
||||
|
||||
/* The CRC values stored in the block header and calculated from the data */
|
||||
|
||||
uint32_t headerCRC, totalCRC, writeCRC;
|
||||
|
||||
uint32_t *crc32Table;
|
||||
/* Intermediate buffer and its size (in bytes) */
|
||||
unsigned *dbuf, dbufSize;
|
||||
|
||||
/* For I/O error handling */
|
||||
jmp_buf jmpbuf;
|
||||
unsigned int *dbuf, dbufSize;
|
||||
|
||||
/* These things are a bit too big to go on the stack */
|
||||
|
||||
/* Big things go last (register-relative addressing can be larger for big offsets */
|
||||
uint32_t crc32Table[256];
|
||||
unsigned char selectors[32768]; /* nSelectors=15 bits */
|
||||
struct group_data groups[MAX_GROUPS]; /* Huffman coding tables */
|
||||
};
|
||||
/* typedef struct bunzip_data bunzip_data; -- done in .h file */
|
||||
|
||||
/* For I/O error handling */
|
||||
|
||||
jmp_buf jmpbuf;
|
||||
} bunzip_data;
|
||||
|
||||
/* Return the next nnn bits of input. All reads from the compressed input
|
||||
are done through this function. All reads are big endian */
|
||||
|
||||
static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
static unsigned int get_bits(bunzip_data *bd, char bits_wanted)
|
||||
{
|
||||
unsigned bits = 0;
|
||||
unsigned int bits=0;
|
||||
|
||||
/* If we need to get more data from the byte buffer, do so. (Loop getting
|
||||
one byte at a time to enforce endianness and avoid unaligned access.) */
|
||||
|
||||
while (bd->inbufBitCount < bits_wanted) {
|
||||
while (bd->inbufBitCount<bits_wanted) {
|
||||
|
||||
/* If we need to read more data from file into byte buffer, do so */
|
||||
|
||||
if (bd->inbufPos == bd->inbufCount) {
|
||||
/* if "no input fd" case: in_fd == -1, read fails, we jump */
|
||||
bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE);
|
||||
if (bd->inbufCount <= 0)
|
||||
longjmp(bd->jmpbuf, RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
bd->inbufPos = 0;
|
||||
if(bd->inbufPos==bd->inbufCount) {
|
||||
if((bd->inbufCount = read(bd->in_fd, bd->inbuf, IOBUF_SIZE)) <= 0)
|
||||
longjmp(bd->jmpbuf,RETVAL_UNEXPECTED_INPUT_EOF);
|
||||
bd->inbufPos=0;
|
||||
}
|
||||
|
||||
/* Avoid 32-bit overflow (dump bit buffer to top of output) */
|
||||
|
||||
if (bd->inbufBitCount >= 24) {
|
||||
bits = bd->inbufBits & ((1 << bd->inbufBitCount) - 1);
|
||||
bits_wanted -= bd->inbufBitCount;
|
||||
bits <<= bits_wanted;
|
||||
bd->inbufBitCount = 0;
|
||||
if(bd->inbufBitCount>=24) {
|
||||
bits=bd->inbufBits&((1<<bd->inbufBitCount)-1);
|
||||
bits_wanted-=bd->inbufBitCount;
|
||||
bits<<=bits_wanted;
|
||||
bd->inbufBitCount=0;
|
||||
}
|
||||
|
||||
/* Grab next 8 bits of input from buffer. */
|
||||
|
||||
bd->inbufBits = (bd->inbufBits<<8) | bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount += 8;
|
||||
bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount+=8;
|
||||
}
|
||||
|
||||
/* Calculate result */
|
||||
|
||||
bd->inbufBitCount -= bits_wanted;
|
||||
bits |= (bd->inbufBits >> bd->inbufBitCount) & ((1 << bits_wanted) - 1);
|
||||
bd->inbufBitCount-=bits_wanted;
|
||||
bits|=(bd->inbufBits>>bd->inbufBitCount)&((1<<bits_wanted)-1);
|
||||
|
||||
return bits;
|
||||
}
|
||||
@@ -138,26 +139,26 @@ static unsigned get_bits(bunzip_data *bd, char bits_wanted)
|
||||
static int get_next_block(bunzip_data *bd)
|
||||
{
|
||||
struct group_data *hufGroup;
|
||||
int dbufCount, nextSym, dbufSize, groupCount, *base, *limit, selector,
|
||||
i, j, k, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
|
||||
int dbufCount,nextSym,dbufSize,groupCount,*base,*limit,selector,
|
||||
i,j,k,t,runPos,symCount,symTotal,nSelectors,byteCount[256];
|
||||
unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
|
||||
unsigned *dbuf, origPtr;
|
||||
unsigned int *dbuf,origPtr;
|
||||
|
||||
dbuf = bd->dbuf;
|
||||
dbufSize = bd->dbufSize;
|
||||
selectors = bd->selectors;
|
||||
dbuf=bd->dbuf;
|
||||
dbufSize=bd->dbufSize;
|
||||
selectors=bd->selectors;
|
||||
|
||||
/* Reset longjmp I/O error handling */
|
||||
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
i=setjmp(bd->jmpbuf);
|
||||
if(i) return i;
|
||||
|
||||
/* Read in header signature and CRC, then validate signature.
|
||||
(last block signature means CRC is for whole file, return now) */
|
||||
|
||||
i = get_bits(bd, 24);
|
||||
j = get_bits(bd, 24);
|
||||
bd->headerCRC = get_bits(bd, 32);
|
||||
i = get_bits(bd,24);
|
||||
j = get_bits(bd,24);
|
||||
bd->headerCRC=get_bits(bd,32);
|
||||
if ((i == 0x177245) && (j == 0x385090)) return RETVAL_LAST_BLOCK;
|
||||
if ((i != 0x314159) || (j != 0x265359)) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
@@ -165,9 +166,8 @@ static int get_next_block(bunzip_data *bd)
|
||||
some code for this in busybox 1.0.0-pre3, but nobody ever noticed that
|
||||
it didn't actually work. */
|
||||
|
||||
if (get_bits(bd, 1)) return RETVAL_OBSOLETE_INPUT;
|
||||
origPtr = get_bits(bd, 24);
|
||||
if (origPtr > dbufSize) return RETVAL_DATA_ERROR;
|
||||
if(get_bits(bd,1)) return RETVAL_OBSOLETE_INPUT;
|
||||
if((origPtr=get_bits(bd,24)) > dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* mapping table: if some byte values are never used (encoding things
|
||||
like ascii text), the compression code removes the gaps to have fewer
|
||||
@@ -175,52 +175,48 @@ static int get_next_block(bunzip_data *bd)
|
||||
values were present. We make a translation table to convert the symbols
|
||||
back to the corresponding bytes. */
|
||||
|
||||
t = get_bits(bd, 16);
|
||||
symTotal = 0;
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (t & (1 << (15-i))) {
|
||||
k = get_bits(bd, 16);
|
||||
for (j = 0; j < 16; j++)
|
||||
if (k & (1 << (15-j)))
|
||||
symToByte[symTotal++] = (16*i) + j;
|
||||
t=get_bits(bd, 16);
|
||||
symTotal=0;
|
||||
for (i=0;i<16;i++) {
|
||||
if(t&(1<<(15-i))) {
|
||||
k=get_bits(bd,16);
|
||||
for(j=0;j<16;j++)
|
||||
if(k&(1<<(15-j))) symToByte[symTotal++]=(16*i)+j;
|
||||
}
|
||||
}
|
||||
|
||||
/* How many different Huffman coding groups does this block use? */
|
||||
|
||||
groupCount = get_bits(bd, 3);
|
||||
if (groupCount < 2 || groupCount > MAX_GROUPS)
|
||||
return RETVAL_DATA_ERROR;
|
||||
groupCount=get_bits(bd,3);
|
||||
if (groupCount<2 || groupCount>MAX_GROUPS) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* nSelectors: Every GROUP_SIZE many symbols we select a new Huffman coding
|
||||
group. Read in the group selector list, which is stored as MTF encoded
|
||||
bit runs. (MTF=Move To Front, as each value is used it's moved to the
|
||||
start of the list.) */
|
||||
|
||||
nSelectors = get_bits(bd, 15);
|
||||
if (!nSelectors) return RETVAL_DATA_ERROR;
|
||||
for (i = 0; i < groupCount; i++) mtfSymbol[i] = i;
|
||||
for (i = 0; i < nSelectors; i++) {
|
||||
if(!(nSelectors=get_bits(bd, 15))) return RETVAL_DATA_ERROR;
|
||||
for(i=0; i<groupCount; i++) mtfSymbol[i] = i;
|
||||
for(i=0; i<nSelectors; i++) {
|
||||
|
||||
/* Get next value */
|
||||
|
||||
for (j = 0; get_bits(bd, 1); j++)
|
||||
if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
for(j=0;get_bits(bd,1);j++) if (j>=groupCount) return RETVAL_DATA_ERROR;
|
||||
|
||||
/* Decode MTF to get the next selector */
|
||||
|
||||
uc = mtfSymbol[j];
|
||||
for (;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
mtfSymbol[0] = selectors[i] = uc;
|
||||
for(;j;j--) mtfSymbol[j] = mtfSymbol[j-1];
|
||||
mtfSymbol[0]=selectors[i]=uc;
|
||||
}
|
||||
|
||||
/* Read the Huffman coding tables for each group, which code for symTotal
|
||||
literal symbols, plus two run symbols (RUNA, RUNB) */
|
||||
|
||||
symCount = symTotal + 2;
|
||||
for (j = 0; j < groupCount; j++) {
|
||||
unsigned char length[MAX_SYMBOLS], temp[MAX_HUFCODE_BITS+1];
|
||||
int minLen, maxLen, pp;
|
||||
symCount=symTotal+2;
|
||||
for (j=0; j<groupCount; j++) {
|
||||
unsigned char length[MAX_SYMBOLS],temp[MAX_HUFCODE_BITS+1];
|
||||
int minLen, maxLen, pp;
|
||||
|
||||
/* Read Huffman code lengths for each symbol. They're stored in
|
||||
a way similar to mtf; record a starting value for the first symbol,
|
||||
@@ -229,17 +225,17 @@ static int get_next_block(bunzip_data *bd)
|
||||
an optimization that makes the test inside the loop simpler: symbol
|
||||
length 0 becomes negative, so an unsigned inequality catches it.) */
|
||||
|
||||
t = get_bits(bd, 5) - 1;
|
||||
t=get_bits(bd, 5)-1;
|
||||
for (i = 0; i < symCount; i++) {
|
||||
for (;;) {
|
||||
if ((unsigned)t > (MAX_HUFCODE_BITS-1))
|
||||
for(;;) {
|
||||
if (((unsigned)t) > (MAX_HUFCODE_BITS-1))
|
||||
return RETVAL_DATA_ERROR;
|
||||
|
||||
/* If first bit is 0, stop. Else second bit indicates whether
|
||||
to increment or decrement the value. Optimization: grab 2
|
||||
bits and unget the second if the first was 0. */
|
||||
|
||||
k = get_bits(bd, 2);
|
||||
k = get_bits(bd,2);
|
||||
if (k < 2) {
|
||||
bd->inbufBitCount++;
|
||||
break;
|
||||
@@ -247,20 +243,20 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
/* Add one if second bit 1, else subtract 1. Avoids if/else */
|
||||
|
||||
t += (((k+1) & 2) - 1);
|
||||
t+=(((k+1)&2)-1);
|
||||
}
|
||||
|
||||
/* Correct for the initial -1, to get the final symbol length */
|
||||
|
||||
length[i] = t + 1;
|
||||
length[i]=t+1;
|
||||
}
|
||||
|
||||
/* Find largest and smallest lengths in this group */
|
||||
|
||||
minLen = maxLen = length[0];
|
||||
for (i = 1; i < symCount; i++) {
|
||||
if (length[i] > maxLen) maxLen = length[i];
|
||||
else if (length[i] < minLen) minLen = length[i];
|
||||
minLen=maxLen=length[0];
|
||||
for(i = 1; i < symCount; i++) {
|
||||
if(length[i] > maxLen) maxLen = length[i];
|
||||
else if(length[i] < minLen) minLen = length[i];
|
||||
}
|
||||
|
||||
/* Calculate permute[], base[], and limit[] tables from length[].
|
||||
@@ -274,7 +270,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
* length: each code with a value>limit[length] needs another bit.
|
||||
*/
|
||||
|
||||
hufGroup = bd->groups + j;
|
||||
hufGroup=bd->groups+j;
|
||||
hufGroup->minLen = minLen;
|
||||
hufGroup->maxLen = maxLen;
|
||||
|
||||
@@ -282,31 +278,30 @@ static int get_next_block(bunzip_data *bd)
|
||||
and limit array pointers so we're not always wasting the first
|
||||
entry. We do this again when using them (during symbol decoding).*/
|
||||
|
||||
base = hufGroup->base - 1;
|
||||
limit = hufGroup->limit - 1;
|
||||
base=hufGroup->base-1;
|
||||
limit=hufGroup->limit-1;
|
||||
|
||||
/* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
|
||||
|
||||
pp = 0;
|
||||
for (i = minLen; i <= maxLen; i++) {
|
||||
temp[i] = limit[i] = 0;
|
||||
for (t = 0; t < symCount; t++)
|
||||
if (length[t] == i)
|
||||
hufGroup->permute[pp++] = t;
|
||||
pp=0;
|
||||
for(i=minLen;i<=maxLen;i++) {
|
||||
temp[i]=limit[i]=0;
|
||||
for(t=0;t<symCount;t++)
|
||||
if(length[t]==i) hufGroup->permute[pp++] = t;
|
||||
}
|
||||
|
||||
/* Count symbols coded for at each bit length */
|
||||
|
||||
for (i = 0; i < symCount; i++) temp[length[i]]++;
|
||||
for (i=0;i<symCount;i++) temp[length[i]]++;
|
||||
|
||||
/* Calculate limit[] (the largest symbol-coding value at each bit
|
||||
* length, which is (previous limit<<1)+symbols at this level), and
|
||||
* base[] (number of symbols to ignore at each bit length, which is
|
||||
* limit minus the cumulative count of symbols coded for already). */
|
||||
|
||||
pp = t = 0;
|
||||
for (i = minLen; i < maxLen; i++) {
|
||||
pp += temp[i];
|
||||
pp=t=0;
|
||||
for (i=minLen; i<maxLen; i++) {
|
||||
pp+=temp[i];
|
||||
|
||||
/* We read the largest possible symbol size and then unget bits
|
||||
after determining how many we need, and those extra bits could
|
||||
@@ -315,14 +310,13 @@ static int get_next_block(bunzip_data *bd)
|
||||
so here we set all the trailing to-be-ignored bits to 1 so they
|
||||
don't affect the value>limit[length] comparison. */
|
||||
|
||||
limit[i] = (pp << (maxLen - i)) - 1;
|
||||
pp <<= 1;
|
||||
t += temp[i];
|
||||
base[i+1] = pp - t;
|
||||
limit[i]= (pp << (maxLen - i)) - 1;
|
||||
pp<<=1;
|
||||
base[i+1]=pp-(t+=temp[i]);
|
||||
}
|
||||
limit[maxLen+1] = INT_MAX; /* Sentinal value for reading next sym. */
|
||||
limit[maxLen] = pp + temp[maxLen] - 1;
|
||||
base[minLen] = 0;
|
||||
limit[maxLen]=pp+temp[maxLen]-1;
|
||||
base[minLen]=0;
|
||||
}
|
||||
|
||||
/* We've finished reading and digesting the block header. Now read this
|
||||
@@ -331,24 +325,24 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
/* Initialize symbol occurrence counters and symbol Move To Front table */
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
for(i=0;i<256;i++) {
|
||||
byteCount[i] = 0;
|
||||
mtfSymbol[i] = (unsigned char)i;
|
||||
mtfSymbol[i]=(unsigned char)i;
|
||||
}
|
||||
|
||||
/* Loop through compressed symbols. */
|
||||
|
||||
runPos = dbufCount = selector = 0;
|
||||
for (;;) {
|
||||
runPos=dbufCount=selector=0;
|
||||
for(;;) {
|
||||
|
||||
/* fetch next Huffman coding group from list. */
|
||||
|
||||
symCount = GROUP_SIZE - 1;
|
||||
if (selector >= nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup = bd->groups + selectors[selector++];
|
||||
base = hufGroup->base - 1;
|
||||
limit = hufGroup->limit - 1;
|
||||
continue_this_group:
|
||||
symCount=GROUP_SIZE-1;
|
||||
if(selector>=nSelectors) return RETVAL_DATA_ERROR;
|
||||
hufGroup=bd->groups+selectors[selector++];
|
||||
base=hufGroup->base-1;
|
||||
limit=hufGroup->limit-1;
|
||||
continue_this_group:
|
||||
|
||||
/* Read next Huffman-coded symbol. */
|
||||
|
||||
@@ -359,34 +353,33 @@ static int get_next_block(bunzip_data *bd)
|
||||
valid compressed file. As a further optimization, we do the read
|
||||
inline (falling back to a call to get_bits if the buffer runs
|
||||
dry). The following (up to got_huff_bits:) is equivalent to
|
||||
j = get_bits(bd, hufGroup->maxLen);
|
||||
j=get_bits(bd,hufGroup->maxLen);
|
||||
*/
|
||||
|
||||
while (bd->inbufBitCount < hufGroup->maxLen) {
|
||||
if (bd->inbufPos == bd->inbufCount) {
|
||||
j = get_bits(bd, hufGroup->maxLen);
|
||||
while (bd->inbufBitCount<hufGroup->maxLen) {
|
||||
if(bd->inbufPos==bd->inbufCount) {
|
||||
j = get_bits(bd,hufGroup->maxLen);
|
||||
goto got_huff_bits;
|
||||
}
|
||||
bd->inbufBits = (bd->inbufBits << 8) | bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount += 8;
|
||||
bd->inbufBits=(bd->inbufBits<<8)|bd->inbuf[bd->inbufPos++];
|
||||
bd->inbufBitCount+=8;
|
||||
};
|
||||
bd->inbufBitCount -= hufGroup->maxLen;
|
||||
j = (bd->inbufBits >> bd->inbufBitCount) & ((1 << hufGroup->maxLen) - 1);
|
||||
bd->inbufBitCount-=hufGroup->maxLen;
|
||||
j = (bd->inbufBits>>bd->inbufBitCount)&((1<<hufGroup->maxLen)-1);
|
||||
|
||||
got_huff_bits:
|
||||
got_huff_bits:
|
||||
|
||||
/* Figure how how many bits are in next symbol and unget extras */
|
||||
|
||||
i = hufGroup->minLen;
|
||||
while (j > limit[i]) ++i;
|
||||
i=hufGroup->minLen;
|
||||
while(j>limit[i]) ++i;
|
||||
bd->inbufBitCount += (hufGroup->maxLen - i);
|
||||
|
||||
/* Huffman decode value to get nextSym (with bounds checking) */
|
||||
|
||||
if (i > hufGroup->maxLen)
|
||||
return RETVAL_DATA_ERROR;
|
||||
j = (j >> (hufGroup->maxLen - i)) - base[i];
|
||||
if ((unsigned)j >= MAX_SYMBOLS)
|
||||
if ((i > hufGroup->maxLen)
|
||||
|| (((unsigned)(j=(j>>(hufGroup->maxLen-i))-base[i]))
|
||||
>= MAX_SYMBOLS))
|
||||
return RETVAL_DATA_ERROR;
|
||||
nextSym = hufGroup->permute[j];
|
||||
|
||||
@@ -395,11 +388,11 @@ static int get_next_block(bunzip_data *bd)
|
||||
check if nextSym indicates a repeated run, and if so loop collecting
|
||||
how many times to repeat the last literal. */
|
||||
|
||||
if ((unsigned)nextSym <= SYMBOL_RUNB) { /* RUNA or RUNB */
|
||||
if (((unsigned)nextSym) <= SYMBOL_RUNB) { /* RUNA or RUNB */
|
||||
|
||||
/* If this is the start of a new run, zero out counter */
|
||||
|
||||
if (!runPos) {
|
||||
if(!runPos) {
|
||||
runPos = 1;
|
||||
t = 0;
|
||||
}
|
||||
@@ -413,7 +406,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
context). Thus space is saved. */
|
||||
|
||||
t += (runPos << nextSym); /* +runPos if RUNA; +2*runPos if RUNB */
|
||||
if (runPos < dbufSize) runPos <<= 1;
|
||||
if(runPos < dbufSize) runPos <<= 1;
|
||||
goto end_of_huffman_loop;
|
||||
}
|
||||
|
||||
@@ -422,18 +415,18 @@ static int get_next_block(bunzip_data *bd)
|
||||
copies to our buffer of decoded symbols (dbuf) now. (The last
|
||||
literal used is the one at the head of the mtfSymbol array.) */
|
||||
|
||||
if (runPos) {
|
||||
runPos = 0;
|
||||
if (dbufCount + t >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
if(runPos) {
|
||||
runPos=0;
|
||||
if(dbufCount+t>=dbufSize) return RETVAL_DATA_ERROR;
|
||||
|
||||
uc = symToByte[mtfSymbol[0]];
|
||||
byteCount[uc] += t;
|
||||
while (t--) dbuf[dbufCount++] = uc;
|
||||
while(t--) dbuf[dbufCount++]=uc;
|
||||
}
|
||||
|
||||
/* Is this the terminating symbol? */
|
||||
|
||||
if (nextSym > symTotal) break;
|
||||
if(nextSym>symTotal) break;
|
||||
|
||||
/* At this point, nextSym indicates a new literal character. Subtract
|
||||
one to get the position in the MTF array at which this literal is
|
||||
@@ -443,7 +436,7 @@ static int get_next_block(bunzip_data *bd)
|
||||
as part of a run above. Therefore 1 unused mtf position minus
|
||||
2 non-literal nextSym values equals -1.) */
|
||||
|
||||
if (dbufCount >= dbufSize) return RETVAL_DATA_ERROR;
|
||||
if(dbufCount>=dbufSize) return RETVAL_DATA_ERROR;
|
||||
i = nextSym - 1;
|
||||
uc = mtfSymbol[i];
|
||||
|
||||
@@ -456,22 +449,22 @@ static int get_next_block(bunzip_data *bd)
|
||||
mtfSymbol[i] = mtfSymbol[i-1];
|
||||
} while (--i);
|
||||
mtfSymbol[0] = uc;
|
||||
uc = symToByte[uc];
|
||||
uc=symToByte[uc];
|
||||
|
||||
/* We have our literal byte. Save it into dbuf. */
|
||||
|
||||
byteCount[uc]++;
|
||||
dbuf[dbufCount++] = (unsigned)uc;
|
||||
dbuf[dbufCount++] = (unsigned int)uc;
|
||||
|
||||
/* Skip group initialization if we're not done with this group. Done
|
||||
* this way to avoid compiler warning. */
|
||||
|
||||
end_of_huffman_loop:
|
||||
if (symCount--) goto continue_this_group;
|
||||
end_of_huffman_loop:
|
||||
if(symCount--) goto continue_this_group;
|
||||
}
|
||||
|
||||
/* At this point, we've read all the Huffman-coded symbols (and repeated
|
||||
runs) for this block from the input stream, and decoded them into the
|
||||
runs) for this block from the input stream, and decoded them into the
|
||||
intermediate buffer. There are dbufCount many decoded bytes in dbuf[].
|
||||
Now undo the Burrows-Wheeler transform on dbuf.
|
||||
See http://dogma.net/markn/articles/bwt/bwt.htm
|
||||
@@ -479,17 +472,17 @@ static int get_next_block(bunzip_data *bd)
|
||||
|
||||
/* Turn byteCount into cumulative occurrence counts of 0 to n-1. */
|
||||
|
||||
j = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
k = j + byteCount[i];
|
||||
j=0;
|
||||
for(i=0;i<256;i++) {
|
||||
k=j+byteCount[i];
|
||||
byteCount[i] = j;
|
||||
j = k;
|
||||
j=k;
|
||||
}
|
||||
|
||||
/* Figure out what order dbuf would be in if we sorted it. */
|
||||
|
||||
for (i = 0; i < dbufCount; i++) {
|
||||
uc = (unsigned char)(dbuf[i] & 0xff);
|
||||
for (i=0;i<dbufCount;i++) {
|
||||
uc=(unsigned char)(dbuf[i] & 0xff);
|
||||
dbuf[byteCount[uc]] |= (i << 8);
|
||||
byteCount[uc]++;
|
||||
}
|
||||
@@ -498,14 +491,14 @@ static int get_next_block(bunzip_data *bd)
|
||||
doesn't get output, and if the first three characters are identical
|
||||
it doesn't qualify as a run (hence writeRunCountdown=5). */
|
||||
|
||||
if (dbufCount) {
|
||||
if (origPtr >= dbufCount) return RETVAL_DATA_ERROR;
|
||||
bd->writePos = dbuf[origPtr];
|
||||
bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
|
||||
bd->writePos >>= 8;
|
||||
bd->writeRunCountdown = 5;
|
||||
if(dbufCount) {
|
||||
if(origPtr>=dbufCount) return RETVAL_DATA_ERROR;
|
||||
bd->writePos=dbuf[origPtr];
|
||||
bd->writeCurrent=(unsigned char)(bd->writePos&0xff);
|
||||
bd->writePos>>=8;
|
||||
bd->writeRunCountdown=5;
|
||||
}
|
||||
bd->writeCount = dbufCount;
|
||||
bd->writeCount=dbufCount;
|
||||
|
||||
return RETVAL_OK;
|
||||
}
|
||||
@@ -517,18 +510,18 @@ static int get_next_block(bunzip_data *bd)
|
||||
are ignored, data is written to out_fd and return is RETVAL_OK or error.
|
||||
*/
|
||||
|
||||
int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
static int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
{
|
||||
const unsigned *dbuf;
|
||||
int pos, current, previous, gotcount;
|
||||
const unsigned int *dbuf;
|
||||
int pos,current,previous,gotcount;
|
||||
|
||||
/* If last read was short due to end of file, return last block now */
|
||||
if (bd->writeCount < 0) return bd->writeCount;
|
||||
if(bd->writeCount<0) return bd->writeCount;
|
||||
|
||||
gotcount = 0;
|
||||
dbuf = bd->dbuf;
|
||||
pos = bd->writePos;
|
||||
current = bd->writeCurrent;
|
||||
dbuf=bd->dbuf;
|
||||
pos=bd->writePos;
|
||||
current=bd->writeCurrent;
|
||||
|
||||
/* We will always have pending decoded data to write into the output
|
||||
buffer unless this is the very first call (in which case we haven't
|
||||
@@ -542,13 +535,13 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
|
||||
/* Loop outputting bytes */
|
||||
|
||||
for (;;) {
|
||||
for(;;) {
|
||||
|
||||
/* If the output buffer is full, snapshot state and return */
|
||||
|
||||
if (gotcount >= len) {
|
||||
bd->writePos =pos;
|
||||
bd->writeCurrent = current;
|
||||
if(gotcount >= len) {
|
||||
bd->writePos=pos;
|
||||
bd->writeCurrent=current;
|
||||
bd->writeCopies++;
|
||||
return len;
|
||||
}
|
||||
@@ -556,8 +549,8 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Write next byte into output buffer, updating CRC */
|
||||
|
||||
outbuf[gotcount++] = current;
|
||||
bd->writeCRC = (bd->writeCRC << 8)
|
||||
^ bd->crc32Table[(bd->writeCRC >> 24) ^ current];
|
||||
bd->writeCRC=(((bd->writeCRC)<<8)
|
||||
^bd->crc32Table[((bd->writeCRC)>>24)^current]);
|
||||
|
||||
/* Loop now if we're outputting multiple copies of this byte */
|
||||
|
||||
@@ -565,32 +558,31 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
--bd->writeCopies;
|
||||
continue;
|
||||
}
|
||||
decode_next_byte:
|
||||
decode_next_byte:
|
||||
if (!bd->writeCount--) break;
|
||||
/* Follow sequence vector to undo Burrows-Wheeler transform */
|
||||
previous = current;
|
||||
pos = dbuf[pos];
|
||||
current = pos & 0xff;
|
||||
pos >>= 8;
|
||||
previous=current;
|
||||
pos=dbuf[pos];
|
||||
current=pos&0xff;
|
||||
pos>>=8;
|
||||
|
||||
/* After 3 consecutive copies of the same byte, the 4th is a repeat
|
||||
count. We count down from 4 instead
|
||||
* of counting up because testing for non-zero is faster */
|
||||
|
||||
if (--bd->writeRunCountdown) {
|
||||
if (current != previous)
|
||||
bd->writeRunCountdown = 4;
|
||||
if(--bd->writeRunCountdown) {
|
||||
if(current!=previous) bd->writeRunCountdown=4;
|
||||
} else {
|
||||
|
||||
/* We have a repeated run, this byte indicates the count */
|
||||
|
||||
bd->writeCopies = current;
|
||||
current = previous;
|
||||
bd->writeRunCountdown = 5;
|
||||
bd->writeCopies=current;
|
||||
current=previous;
|
||||
bd->writeRunCountdown=5;
|
||||
|
||||
/* Sometimes there are just 3 bytes (run length 0) */
|
||||
|
||||
if (!bd->writeCopies) goto decode_next_byte;
|
||||
if(!bd->writeCopies) goto decode_next_byte;
|
||||
|
||||
/* Subtract the 1 copy we'd output anyway to get extras */
|
||||
|
||||
@@ -600,13 +592,13 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
|
||||
/* Decompression of this block completed successfully */
|
||||
|
||||
bd->writeCRC = ~bd->writeCRC;
|
||||
bd->totalCRC = ((bd->totalCRC << 1) | (bd->totalCRC >> 31)) ^ bd->writeCRC;
|
||||
bd->writeCRC=~bd->writeCRC;
|
||||
bd->totalCRC=((bd->totalCRC<<1) | (bd->totalCRC>>31)) ^ bd->writeCRC;
|
||||
|
||||
/* If this block had a CRC error, force file level CRC error. */
|
||||
|
||||
if (bd->writeCRC != bd->headerCRC) {
|
||||
bd->totalCRC = bd->headerCRC+1;
|
||||
if(bd->writeCRC!=bd->headerCRC) {
|
||||
bd->totalCRC=bd->headerCRC+1;
|
||||
return RETVAL_LAST_BLOCK;
|
||||
}
|
||||
}
|
||||
@@ -614,107 +606,86 @@ int read_bunzip(bunzip_data *bd, char *outbuf, int len)
|
||||
/* Refill the intermediate buffer by Huffman-decoding next block of input */
|
||||
/* (previous is just a convenient unused temp variable here) */
|
||||
|
||||
previous = get_next_block(bd);
|
||||
if (previous) {
|
||||
bd->writeCount = previous;
|
||||
return (previous != RETVAL_LAST_BLOCK) ? previous : gotcount;
|
||||
previous=get_next_block(bd);
|
||||
if(previous) {
|
||||
bd->writeCount=previous;
|
||||
return (previous!=RETVAL_LAST_BLOCK) ? previous : gotcount;
|
||||
}
|
||||
bd->writeCRC = ~0;
|
||||
pos = bd->writePos;
|
||||
current = bd->writeCurrent;
|
||||
bd->writeCRC=~0;
|
||||
pos=bd->writePos;
|
||||
current=bd->writeCurrent;
|
||||
goto decode_next_byte;
|
||||
}
|
||||
|
||||
|
||||
/* Allocate the structure, read file header. If in_fd==-1, inbuf must contain
|
||||
a complete bunzip file (len bytes long). If in_fd!=-1, inbuf and len are
|
||||
ignored, and data is read from file handle into temporary buffer. */
|
||||
|
||||
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
|
||||
should work for NOFORK applets too, we must be extremely careful to not leak
|
||||
any allocations! */
|
||||
|
||||
int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
|
||||
static int start_bunzip(bunzip_data **bdp, int in_fd, unsigned char *inbuf,
|
||||
int len)
|
||||
{
|
||||
bunzip_data *bd;
|
||||
unsigned i;
|
||||
enum {
|
||||
BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0'
|
||||
};
|
||||
unsigned int i;
|
||||
const unsigned int BZh0=(((unsigned int)'B')<<24)+(((unsigned int)'Z')<<16)
|
||||
+(((unsigned int)'h')<<8)+(unsigned int)'0';
|
||||
|
||||
/* Figure out how much data to allocate */
|
||||
|
||||
i = sizeof(bunzip_data);
|
||||
if (in_fd != -1) i += IOBUF_SIZE;
|
||||
i=sizeof(bunzip_data);
|
||||
if(in_fd!=-1) i+=IOBUF_SIZE;
|
||||
|
||||
/* Allocate bunzip_data. Most fields initialize to zero. */
|
||||
|
||||
bd = *bdp = xzalloc(i);
|
||||
bd=*bdp=xzalloc(i);
|
||||
|
||||
/* Setup input buffer */
|
||||
|
||||
bd->in_fd = in_fd;
|
||||
if (-1 == in_fd) {
|
||||
/* in this case, bd->inbuf is read-only */
|
||||
bd->inbuf = (void*)inbuf; /* cast away const-ness */
|
||||
bd->inbufCount = len;
|
||||
} else
|
||||
bd->inbuf = (unsigned char *)(bd + 1);
|
||||
if(-1==(bd->in_fd=in_fd)) {
|
||||
bd->inbuf=inbuf;
|
||||
bd->inbufCount=len;
|
||||
} else bd->inbuf=(unsigned char *)(bd+1);
|
||||
|
||||
/* Init the CRC32 table (big endian) */
|
||||
|
||||
crc32_filltable(bd->crc32Table, 1);
|
||||
bd->crc32Table = crc32_filltable(1);
|
||||
|
||||
/* Setup for I/O error handling via longjmp */
|
||||
|
||||
i = setjmp(bd->jmpbuf);
|
||||
if (i) return i;
|
||||
i=setjmp(bd->jmpbuf);
|
||||
if(i) return i;
|
||||
|
||||
/* Ensure that file starts with "BZh['1'-'9']." */
|
||||
|
||||
i = get_bits(bd, 32);
|
||||
if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
|
||||
i = get_bits(bd,32);
|
||||
if (((unsigned int)(i-BZh0-1)) >= 9) return RETVAL_NOT_BZIP_DATA;
|
||||
|
||||
/* Fourth byte (ascii '1'-'9'), indicates block size in units of 100k of
|
||||
uncompressed data. Allocate intermediate buffer for block. */
|
||||
|
||||
bd->dbufSize = 100000 * (i - BZh0);
|
||||
bd->dbufSize=100000*(i-BZh0);
|
||||
|
||||
/* Cannot use xmalloc - may leak bd in NOFORK case! */
|
||||
bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(int));
|
||||
if (!bd->dbuf) {
|
||||
free(bd);
|
||||
xfunc_die();
|
||||
}
|
||||
bd->dbuf=xmalloc(bd->dbufSize * sizeof(int));
|
||||
return RETVAL_OK;
|
||||
}
|
||||
|
||||
void dealloc_bunzip(bunzip_data *bd)
|
||||
{
|
||||
free(bd->dbuf);
|
||||
free(bd);
|
||||
}
|
||||
|
||||
|
||||
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
|
||||
/* Example usage: decompress src_fd to dst_fd. (Stops at end of bzip data,
|
||||
not end of file.) */
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
uncompressStream(int src_fd, int dst_fd)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
char *outbuf;
|
||||
bunzip_data *bd;
|
||||
int i;
|
||||
|
||||
outbuf = xmalloc(IOBUF_SIZE);
|
||||
i = start_bunzip(&bd, src_fd, NULL, 0);
|
||||
if (!i) {
|
||||
for (;;) {
|
||||
i = read_bunzip(bd, outbuf, IOBUF_SIZE);
|
||||
if (i <= 0) break;
|
||||
if (i != safe_write(dst_fd, outbuf, i)) {
|
||||
i = RETVAL_UNEXPECTED_OUTPUT_EOF;
|
||||
outbuf=xmalloc(IOBUF_SIZE);
|
||||
i=start_bunzip(&bd,src_fd,0,0);
|
||||
if(!i) {
|
||||
for(;;) {
|
||||
if((i=read_bunzip(bd,outbuf,IOBUF_SIZE)) <= 0) break;
|
||||
if(i!=write(dst_fd,outbuf,i)) {
|
||||
i=RETVAL_UNEXPECTED_OUTPUT_EOF;
|
||||
break;
|
||||
}
|
||||
USE_DESKTOP(total_written += i;)
|
||||
@@ -723,18 +694,19 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
|
||||
/* Check CRC and release memory */
|
||||
|
||||
if (i == RETVAL_LAST_BLOCK) {
|
||||
if (bd->headerCRC != bd->totalCRC) {
|
||||
if(i==RETVAL_LAST_BLOCK) {
|
||||
if (bd->headerCRC!=bd->totalCRC) {
|
||||
bb_error_msg("data integrity error when decompressing");
|
||||
} else {
|
||||
i = RETVAL_OK;
|
||||
i=RETVAL_OK;
|
||||
}
|
||||
} else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
||||
} else if (i==RETVAL_UNEXPECTED_OUTPUT_EOF) {
|
||||
bb_error_msg("compressed file ends unexpectedly");
|
||||
} else {
|
||||
bb_error_msg("decompression failed");
|
||||
}
|
||||
dealloc_bunzip(bd);
|
||||
free(bd->dbuf);
|
||||
free(bd);
|
||||
free(outbuf);
|
||||
|
||||
return i ? i : USE_DESKTOP(total_written) + 0;
|
||||
@@ -742,22 +714,18 @@ unpack_bz2_stream(int src_fd, int dst_fd)
|
||||
|
||||
#ifdef TESTING
|
||||
|
||||
static char *const bunzip_errors[] = {
|
||||
NULL, "Bad file checksum", "Not bzip data",
|
||||
"Unexpected input EOF", "Unexpected output EOF", "Data error",
|
||||
"Out of memory", "Obsolete (pre 0.9.5) bzip format not supported"
|
||||
};
|
||||
static char * const bunzip_errors[]={NULL,"Bad file checksum","Not bzip data",
|
||||
"Unexpected input EOF","Unexpected output EOF","Data error",
|
||||
"Out of memory","Obsolete (pre 0.9.5) bzip format not supported."};
|
||||
|
||||
/* Dumb little test thing, decompress stdin to stdout */
|
||||
int main(int argc, char **argv)
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int i = unpack_bz2_stream(0, 1);
|
||||
int i=uncompressStream(0,1);
|
||||
char c;
|
||||
|
||||
if (i < 0)
|
||||
fprintf(stderr,"%s\n", bunzip_errors[-i]);
|
||||
else if (read(0, &c, 1))
|
||||
fprintf(stderr,"Trailing garbage ignored\n");
|
||||
if(i<0) fprintf(stderr,"%s\n", bunzip_errors[-i]);
|
||||
else if(read(0,&c,1)) fprintf(stderr,"Trailing garbage ignored\n");
|
||||
return -i;
|
||||
}
|
||||
#endif
|
||||
@@ -7,6 +7,7 @@
|
||||
* (see disclaimer below)
|
||||
*/
|
||||
|
||||
|
||||
/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
|
||||
*
|
||||
* Authors:
|
||||
@@ -25,6 +26,9 @@
|
||||
* [... History snipped ...]
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Default input buffer size */
|
||||
#define IBUFSIZ 2048
|
||||
@@ -33,101 +37,97 @@
|
||||
#define OBUFSIZ 2048
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compression if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
#define MAGIC_1 (char_type)'\037' /* First byte of compressed file */
|
||||
#define MAGIC_2 (char_type)'\235' /* Second byte of compressed file */
|
||||
#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
|
||||
/* Masks 0x20 and 0x40 are free. */
|
||||
/* I think 0x20 should mean that there is */
|
||||
/* a fourth header byte (for expansion). */
|
||||
#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */
|
||||
/* compression rate is dropping flush tables */
|
||||
/* the next two codes should not be changed lightly, as they must not */
|
||||
/* lie within the contiguous general code space. */
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1) /* unused */
|
||||
#define HPRIME 9941 /* unused */
|
||||
#define BITS 16
|
||||
#define BITS_STR "16"
|
||||
#undef MAXSEG_64K /* unused */
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
#define FAST
|
||||
|
||||
#define HBITS 17 /* 50% occupancy */
|
||||
#define HSIZE (1<<HBITS)
|
||||
#define HMASK (HSIZE-1)
|
||||
#define HPRIME 9941
|
||||
#define BITS 16
|
||||
#undef MAXSEG_64K
|
||||
#define MAXCODE(n) (1L << (n))
|
||||
|
||||
/* Block compress mode -C compatible with 2.0 */
|
||||
static int block_mode = BLOCK_MODE;
|
||||
|
||||
/* user settable max # bits/code */
|
||||
static int maxbits = BITS;
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
||||
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
||||
#define clear_htab() memset(htab, -1, HSIZE)
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256);
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((unsigned char *)(htab))[i]
|
||||
#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
|
||||
#define clear_tab_prefixof() memset(codetab, 0, 256)
|
||||
|
||||
/*
|
||||
* Decompress stdin to stdout. This routine adapts to the codes in the
|
||||
* file building the "string" table on-the-fly; requiring no table to
|
||||
* be stored in the compressed file.
|
||||
* be stored in the compressed file. The tables used herein are shared
|
||||
* with those of the compress() routine. See the definitions above.
|
||||
*/
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
USE_DESKTOP(long long) int retval = -1;
|
||||
unsigned char *stackp;
|
||||
long code;
|
||||
long int code;
|
||||
int finchar;
|
||||
long oldcode;
|
||||
long incode;
|
||||
long int oldcode;
|
||||
long int incode;
|
||||
int inbits;
|
||||
int posbits;
|
||||
int outpos;
|
||||
int insize;
|
||||
int bitmask;
|
||||
long free_ent;
|
||||
long maxcode;
|
||||
long maxmaxcode;
|
||||
long int free_ent;
|
||||
long int maxcode;
|
||||
long int maxmaxcode;
|
||||
int n_bits;
|
||||
int rsize = 0;
|
||||
unsigned char *inbuf; /* were eating insane amounts of stack - */
|
||||
unsigned char *outbuf; /* bad for some embedded targets */
|
||||
unsigned char *htab;
|
||||
unsigned short *codetab;
|
||||
|
||||
/* Hmm, these were statics - why?! */
|
||||
/* user settable max # bits/code */
|
||||
int maxbits; /* = BITS; */
|
||||
/* block compress mode -C compatible with 2.0 */
|
||||
int block_mode; /* = BLOCK_MODE; */
|
||||
|
||||
inbuf = xzalloc(IBUFSIZ + 64);
|
||||
outbuf = xzalloc(OBUFSIZ + 2048);
|
||||
htab = xzalloc(HSIZE); /* wsn't zeroed out before, maybe can xmalloc? */
|
||||
codetab = xzalloc(HSIZE * sizeof(codetab[0]));
|
||||
RESERVE_CONFIG_UBUFFER(inbuf, IBUFSIZ + 64);
|
||||
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
|
||||
unsigned char htab[HSIZE];
|
||||
unsigned short codetab[HSIZE];
|
||||
memset(inbuf, 0, IBUFSIZ + 64);
|
||||
memset(outbuf, 0, OBUFSIZ + 2048);
|
||||
|
||||
insize = 0;
|
||||
|
||||
/* xread isn't good here, we have to return - caller may want
|
||||
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||
if (full_read(fd_in, inbuf, 1) != 1) {
|
||||
bb_error_msg("short read");
|
||||
goto err;
|
||||
}
|
||||
inbuf[0] = xread_char(fd_in);
|
||||
|
||||
maxbits = inbuf[0] & BIT_MASK;
|
||||
block_mode = inbuf[0] & BLOCK_MODE;
|
||||
maxmaxcode = MAXCODE(maxbits);
|
||||
|
||||
if (maxbits > BITS) {
|
||||
bb_error_msg("compressed with %d bits, can only handle "
|
||||
BITS_STR" bits", maxbits);
|
||||
goto err;
|
||||
bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits,
|
||||
BITS);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
oldcode = -1;
|
||||
finchar = 0;
|
||||
outpos = 0;
|
||||
@@ -136,21 +136,20 @@ uncompress(int fd_in, int fd_out)
|
||||
free_ent = ((block_mode) ? FIRST : 256);
|
||||
|
||||
/* As above, initialize the first 256 entries in the table. */
|
||||
/*clear_tab_prefixof(); - done by xzalloc */
|
||||
clear_tab_prefixof();
|
||||
|
||||
for (code = 255; code >= 0; --code) {
|
||||
tab_suffixof(code) = (unsigned char) code;
|
||||
}
|
||||
|
||||
do {
|
||||
resetbuf:
|
||||
resetbuf:;
|
||||
{
|
||||
int i;
|
||||
int e;
|
||||
int o;
|
||||
|
||||
o = posbits >> 3;
|
||||
e = insize - o;
|
||||
e = insize - (o = (posbits >> 3));
|
||||
|
||||
for (i = 0; i < e; ++i)
|
||||
inbuf[i] = inbuf[i + o];
|
||||
@@ -161,7 +160,6 @@ uncompress(int fd_in, int fd_out)
|
||||
|
||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||
//error check??
|
||||
insize += rsize;
|
||||
}
|
||||
|
||||
@@ -186,8 +184,8 @@ uncompress(int fd_in, int fd_out)
|
||||
{
|
||||
unsigned char *p = &inbuf[posbits >> 3];
|
||||
|
||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||
}
|
||||
posbits += n_bits;
|
||||
|
||||
@@ -206,9 +204,8 @@ uncompress(int fd_in, int fd_out)
|
||||
((posbits - 1) +
|
||||
((n_bits << 3) -
|
||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||
n_bits = INIT_BITS;
|
||||
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||
bitmask = (1 << INIT_BITS) - 1;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
||||
bitmask = (1 << n_bits) - 1;
|
||||
goto resetbuf;
|
||||
}
|
||||
|
||||
@@ -228,7 +225,7 @@ uncompress(int fd_in, int fd_out)
|
||||
insize, posbits, p[-1], p[0], p[1], p[2], p[3],
|
||||
(posbits & 07));
|
||||
bb_error_msg("uncompress: corrupt input");
|
||||
goto err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*--stackp = (unsigned char) finchar;
|
||||
@@ -236,20 +233,18 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
/* Generate output characters in reverse order */
|
||||
while ((long) code >= (long) 256) {
|
||||
while ((long int) code >= (long int) 256) {
|
||||
*--stackp = tab_suffixof(code);
|
||||
code = tab_prefixof(code);
|
||||
}
|
||||
|
||||
finchar = tab_suffixof(code);
|
||||
*--stackp = (unsigned char) finchar;
|
||||
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
|
||||
|
||||
/* And put them out in forward order */
|
||||
{
|
||||
int i;
|
||||
|
||||
i = de_stack - stackp;
|
||||
if (outpos + i >= OBUFSIZ) {
|
||||
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
|
||||
do {
|
||||
if (i > OBUFSIZ - outpos) {
|
||||
i = OBUFSIZ - outpos;
|
||||
@@ -261,14 +256,12 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
if (outpos >= OBUFSIZ) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
outpos = 0;
|
||||
}
|
||||
stackp += i;
|
||||
i = de_stack - stackp;
|
||||
} while (i > 0);
|
||||
} while ((i = (de_stack - stackp)) > 0);
|
||||
} else {
|
||||
memcpy(outbuf + outpos, stackp, i);
|
||||
outpos += i;
|
||||
@@ -276,8 +269,7 @@ uncompress(int fd_in, int fd_out)
|
||||
}
|
||||
|
||||
/* Generate the new entry. */
|
||||
code = free_ent;
|
||||
if (code < maxmaxcode) {
|
||||
if ((code = free_ent) < maxmaxcode) {
|
||||
tab_prefixof(code) = (unsigned short) oldcode;
|
||||
tab_suffixof(code) = (unsigned char) finchar;
|
||||
free_ent = code + 1;
|
||||
@@ -290,16 +282,11 @@ uncompress(int fd_in, int fd_out)
|
||||
} while (rsize > 0);
|
||||
|
||||
if (outpos > 0) {
|
||||
full_write(fd_out, outbuf, outpos);
|
||||
//error check??
|
||||
write(fd_out, outbuf, outpos);
|
||||
USE_DESKTOP(total_written += outpos;)
|
||||
}
|
||||
|
||||
retval = USE_DESKTOP(total_written) + 0;
|
||||
err:
|
||||
free(inbuf);
|
||||
free(outbuf);
|
||||
free(htab);
|
||||
free(codetab);
|
||||
return retval;
|
||||
RELEASE_CONFIG_BUFFER(inbuf);
|
||||
RELEASE_CONFIG_BUFFER(outbuf);
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
@@ -12,8 +12,8 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
# define speed_inline ALWAYS_INLINE
|
||||
#ifdef CONFIG_FEATURE_LZMA_FAST
|
||||
# define speed_inline ATTRIBUTE_ALWAYS_INLINE
|
||||
#else
|
||||
# define speed_inline
|
||||
#endif
|
||||
@@ -22,23 +22,15 @@
|
||||
typedef struct {
|
||||
int fd;
|
||||
uint8_t *ptr;
|
||||
|
||||
/* Was keeping rc on stack in unlzma and separately allocating buffer,
|
||||
* but with "buffer 'attached to' allocated rc" code is smaller: */
|
||||
/* uint8_t *buffer; */
|
||||
#define RC_BUFFER ((uint8_t*)(rc+1))
|
||||
|
||||
uint8_t *buffer;
|
||||
uint8_t *buffer_end;
|
||||
|
||||
/* Had provisions for variable buffer, but we don't need it here */
|
||||
/* int buffer_size; */
|
||||
#define RC_BUFFER_SIZE 0x10000
|
||||
|
||||
int buffer_size;
|
||||
uint32_t code;
|
||||
uint32_t range;
|
||||
uint32_t bound;
|
||||
} rc_t;
|
||||
|
||||
|
||||
#define RC_TOP_BITS 24
|
||||
#define RC_MOVE_BITS 5
|
||||
#define RC_MODEL_TOTAL_BITS 11
|
||||
@@ -47,24 +39,22 @@ typedef struct {
|
||||
/* 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);
|
||||
if (buffer_size <= 0)
|
||||
rc->buffer_size = read(rc->fd, rc->buffer, rc->buffer_size);
|
||||
if (rc->buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
rc->buffer_end = RC_BUFFER + buffer_size;
|
||||
rc->ptr = rc->buffer;
|
||||
rc->buffer_end = rc->buffer + rc->buffer_size;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
static void rc_init(rc_t * rc, int fd, int buffer_size)
|
||||
{
|
||||
int i;
|
||||
rc_t* rc;
|
||||
|
||||
rc = xmalloc(sizeof(rc_t) + RC_BUFFER_SIZE);
|
||||
|
||||
rc->fd = fd;
|
||||
/* rc->buffer_size = buffer_size; */
|
||||
rc->buffer_end = RC_BUFFER + RC_BUFFER_SIZE;
|
||||
rc->buffer = xmalloc(buffer_size);
|
||||
rc->buffer_size = buffer_size;
|
||||
rc->buffer_end = rc->buffer + rc->buffer_size;
|
||||
rc->ptr = rc->buffer_end;
|
||||
|
||||
rc->code = 0;
|
||||
@@ -74,14 +64,13 @@ static rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
rc_read(rc);
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static ALWAYS_INLINE void rc_free(rc_t * rc)
|
||||
/* Called once. TODO: bb_maybe_free() */
|
||||
static ATTRIBUTE_ALWAYS_INLINE void rc_free(rc_t * rc)
|
||||
{
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(rc);
|
||||
free(rc->buffer);
|
||||
}
|
||||
|
||||
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
|
||||
@@ -92,18 +81,16 @@ static void rc_do_normalize(rc_t * rc)
|
||||
rc->range <<= 8;
|
||||
rc->code = (rc->code << 8) | *rc->ptr++;
|
||||
}
|
||||
static ALWAYS_INLINE void rc_normalize(rc_t * rc)
|
||||
static ATTRIBUTE_ALWAYS_INLINE void rc_normalize(rc_t * rc)
|
||||
{
|
||||
if (rc->range < (1 << RC_TOP_BITS)) {
|
||||
rc_do_normalize(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/* rc_is_bit_0 is called 9 times */
|
||||
/* 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.
|
||||
* Because we want to always expose (rc->code < rc->bound) to optimizer
|
||||
*/
|
||||
static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p)
|
||||
{
|
||||
@@ -111,7 +98,7 @@ static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p)
|
||||
rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
|
||||
return rc->bound;
|
||||
}
|
||||
static ALWAYS_INLINE int rc_is_bit_0(rc_t * rc, uint16_t * p)
|
||||
static ATTRIBUTE_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;
|
||||
@@ -145,7 +132,7 @@ static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol)
|
||||
}
|
||||
|
||||
/* Called once */
|
||||
static ALWAYS_INLINE int rc_direct_bit(rc_t * rc)
|
||||
static ATTRIBUTE_ALWAYS_INLINE int rc_direct_bit(rc_t * rc)
|
||||
{
|
||||
rc_normalize(rc);
|
||||
rc->range >>= 1;
|
||||
@@ -176,61 +163,56 @@ typedef struct {
|
||||
} __attribute__ ((packed)) lzma_header_t;
|
||||
|
||||
|
||||
/* #defines will force compiler to compute/optimize each one with each usage.
|
||||
* Have heart and use enum instead. */
|
||||
enum {
|
||||
LZMA_BASE_SIZE = 1846,
|
||||
LZMA_LIT_SIZE = 768,
|
||||
#define LZMA_BASE_SIZE 1846
|
||||
#define LZMA_LIT_SIZE 768
|
||||
|
||||
LZMA_NUM_POS_BITS_MAX = 4,
|
||||
#define LZMA_NUM_POS_BITS_MAX 4
|
||||
|
||||
LZMA_LEN_NUM_LOW_BITS = 3,
|
||||
LZMA_LEN_NUM_MID_BITS = 3,
|
||||
LZMA_LEN_NUM_HIGH_BITS = 8,
|
||||
#define LZMA_LEN_NUM_LOW_BITS 3
|
||||
#define LZMA_LEN_NUM_MID_BITS 3
|
||||
#define LZMA_LEN_NUM_HIGH_BITS 8
|
||||
|
||||
LZMA_LEN_CHOICE = 0,
|
||||
LZMA_LEN_CHOICE_2 = (LZMA_LEN_CHOICE + 1),
|
||||
LZMA_LEN_LOW = (LZMA_LEN_CHOICE_2 + 1),
|
||||
LZMA_LEN_MID = (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS))),
|
||||
LZMA_LEN_HIGH = (LZMA_LEN_MID \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS))),
|
||||
LZMA_NUM_LEN_PROBS = (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS)),
|
||||
#define LZMA_LEN_CHOICE 0
|
||||
#define LZMA_LEN_CHOICE_2 (LZMA_LEN_CHOICE + 1)
|
||||
#define LZMA_LEN_LOW (LZMA_LEN_CHOICE_2 + 1)
|
||||
#define LZMA_LEN_MID (LZMA_LEN_LOW \
|
||||
+ (1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_LOW_BITS)))
|
||||
#define LZMA_LEN_HIGH (LZMA_LEN_MID \
|
||||
+(1 << (LZMA_NUM_POS_BITS_MAX + LZMA_LEN_NUM_MID_BITS)))
|
||||
#define LZMA_NUM_LEN_PROBS (LZMA_LEN_HIGH + (1 << LZMA_LEN_NUM_HIGH_BITS))
|
||||
|
||||
LZMA_NUM_STATES = 12,
|
||||
LZMA_NUM_LIT_STATES = 7,
|
||||
#define LZMA_NUM_STATES 12
|
||||
#define LZMA_NUM_LIT_STATES 7
|
||||
|
||||
LZMA_START_POS_MODEL_INDEX = 4,
|
||||
LZMA_END_POS_MODEL_INDEX = 14,
|
||||
LZMA_NUM_FULL_DISTANCES = (1 << (LZMA_END_POS_MODEL_INDEX >> 1)),
|
||||
#define LZMA_START_POS_MODEL_INDEX 4
|
||||
#define LZMA_END_POS_MODEL_INDEX 14
|
||||
#define LZMA_NUM_FULL_DISTANCES (1 << (LZMA_END_POS_MODEL_INDEX >> 1))
|
||||
|
||||
LZMA_NUM_POS_SLOT_BITS = 6,
|
||||
LZMA_NUM_LEN_TO_POS_STATES = 4,
|
||||
#define LZMA_NUM_POS_SLOT_BITS 6
|
||||
#define LZMA_NUM_LEN_TO_POS_STATES 4
|
||||
|
||||
LZMA_NUM_ALIGN_BITS = 4,
|
||||
#define LZMA_NUM_ALIGN_BITS 4
|
||||
|
||||
LZMA_MATCH_MIN_LEN = 2,
|
||||
|
||||
LZMA_IS_MATCH = 0,
|
||||
LZMA_IS_REP = (LZMA_IS_MATCH + (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_IS_REP_G0 = (LZMA_IS_REP + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G1 = (LZMA_IS_REP_G0 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_G2 = (LZMA_IS_REP_G1 + LZMA_NUM_STATES),
|
||||
LZMA_IS_REP_0_LONG = (LZMA_IS_REP_G2 + LZMA_NUM_STATES),
|
||||
LZMA_POS_SLOT = (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX)),
|
||||
LZMA_SPEC_POS = (LZMA_POS_SLOT \
|
||||
+ (LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS)),
|
||||
LZMA_ALIGN = (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX),
|
||||
LZMA_LEN_CODER = (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS)),
|
||||
LZMA_REP_LEN_CODER = (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
LZMA_LITERAL = (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS),
|
||||
};
|
||||
#define LZMA_MATCH_MIN_LEN 2
|
||||
|
||||
#define LZMA_IS_MATCH 0
|
||||
#define LZMA_IS_REP (LZMA_IS_MATCH + (LZMA_NUM_STATES <<LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_IS_REP_G0 (LZMA_IS_REP + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G1 (LZMA_IS_REP_G0 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_G2 (LZMA_IS_REP_G1 + LZMA_NUM_STATES)
|
||||
#define LZMA_IS_REP_0_LONG (LZMA_IS_REP_G2 + LZMA_NUM_STATES)
|
||||
#define LZMA_POS_SLOT (LZMA_IS_REP_0_LONG \
|
||||
+ (LZMA_NUM_STATES << LZMA_NUM_POS_BITS_MAX))
|
||||
#define LZMA_SPEC_POS (LZMA_POS_SLOT \
|
||||
+(LZMA_NUM_LEN_TO_POS_STATES << LZMA_NUM_POS_SLOT_BITS))
|
||||
#define LZMA_ALIGN (LZMA_SPEC_POS \
|
||||
+ LZMA_NUM_FULL_DISTANCES - LZMA_END_POS_MODEL_INDEX)
|
||||
#define LZMA_LEN_CODER (LZMA_ALIGN + (1 << LZMA_NUM_ALIGN_BITS))
|
||||
#define LZMA_REP_LEN_CODER (LZMA_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
#define LZMA_LITERAL (LZMA_REP_LEN_CODER + LZMA_NUM_LEN_PROBS)
|
||||
|
||||
USE_DESKTOP(long long) int
|
||||
unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
unlzma(int src_fd, int dst_fd)
|
||||
{
|
||||
USE_DESKTOP(long long total_written = 0;)
|
||||
lzma_header_t header;
|
||||
@@ -243,7 +225,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
uint16_t *prob_lit;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
rc_t rc;
|
||||
int i, mi;
|
||||
uint8_t *buffer;
|
||||
uint8_t previous_byte = 0;
|
||||
@@ -252,7 +234,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
xread(src_fd, &header, sizeof(header));
|
||||
if (read(src_fd, &header, sizeof(header)) != sizeof(header))
|
||||
bb_error_msg_and_die("can't read header");
|
||||
|
||||
if (header.pos >= (9 * 5 * 5))
|
||||
bb_error_msg_and_die("bad header");
|
||||
@@ -277,16 +260,16 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
for (i = 0; i < num_probs; i++)
|
||||
p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
||||
|
||||
rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
|
||||
rc_init(&rc, src_fd, 0x10000);
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
|
||||
prob =
|
||||
p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
if (rc_is_bit_0(rc, prob)) {
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
mi = 1;
|
||||
rc_update_bit_0(rc, prob);
|
||||
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)))));
|
||||
@@ -304,7 +287,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
prob_lit = prob + 0x100 + bit + mi;
|
||||
if (rc_get_bit(rc, prob_lit, &mi)) {
|
||||
if (rc_get_bit(&rc, prob_lit, &mi)) {
|
||||
if (!bit)
|
||||
break;
|
||||
} else {
|
||||
@@ -315,7 +298,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
while (mi < 0x100) {
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
rc_get_bit(&rc, prob_lit, &mi);
|
||||
}
|
||||
previous_byte = (uint8_t) mi;
|
||||
|
||||
@@ -323,8 +306,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
if (state < 4)
|
||||
@@ -337,24 +320,24 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int offset;
|
||||
uint16_t *prob_len;
|
||||
|
||||
rc_update_bit_1(rc, prob);
|
||||
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);
|
||||
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;
|
||||
prob = p + LZMA_LEN_CODER;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
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);
|
||||
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_0(rc, prob)) {
|
||||
rc_update_bit_0(rc, prob);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
pos = buffer_pos - rep0;
|
||||
@@ -365,30 +348,30 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
}
|
||||
} else {
|
||||
uint32_t distance;
|
||||
|
||||
rc_update_bit_1(rc, prob);
|
||||
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);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
distance = rep1;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
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);
|
||||
if (rc_is_bit_0(&rc, prob)) {
|
||||
rc_update_bit_0(&rc, prob);
|
||||
distance = rep2;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob);
|
||||
rc_update_bit_1(&rc, prob);
|
||||
distance = rep3;
|
||||
rep3 = rep2;
|
||||
}
|
||||
@@ -402,30 +385,30 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
|
||||
prob_len = prob + LZMA_LEN_CHOICE;
|
||||
if (rc_is_bit_0(rc, prob_len)) {
|
||||
rc_update_bit_0(rc, prob_len);
|
||||
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 {
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
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);
|
||||
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;
|
||||
} else {
|
||||
rc_update_bit_1(rc, prob_len);
|
||||
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;
|
||||
}
|
||||
}
|
||||
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
|
||||
rc_bit_tree_decode(&rc, prob_len, num_bits, &len);
|
||||
len += offset;
|
||||
|
||||
if (state < 4) {
|
||||
@@ -438,7 +421,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
rc_bit_tree_decode(&rc, prob, LZMA_NUM_POS_SLOT_BITS,
|
||||
&pos_slot);
|
||||
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
||||
num_bits = (pos_slot >> 1) - 1;
|
||||
@@ -449,7 +432,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
} else {
|
||||
num_bits -= LZMA_NUM_ALIGN_BITS;
|
||||
while (num_bits--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(&rc);
|
||||
prob = p + LZMA_ALIGN;
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
num_bits = LZMA_NUM_ALIGN_BITS;
|
||||
@@ -457,7 +440,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
i = 1;
|
||||
mi = 1;
|
||||
while (num_bits--) {
|
||||
if (rc_get_bit(rc, prob + mi, &mi))
|
||||
if (rc_get_bit(&rc, prob + mi, &mi))
|
||||
rep0 |= i;
|
||||
i <<= 1;
|
||||
}
|
||||
@@ -478,8 +461,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
if (buffer_pos == header.dict_size) {
|
||||
buffer_pos = 0;
|
||||
global_pos += header.dict_size;
|
||||
if (full_write(dst_fd, buffer, header.dict_size) != header.dict_size)
|
||||
goto bad;
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, header.dict_size);
|
||||
USE_DESKTOP(total_written += header.dict_size;)
|
||||
}
|
||||
len--;
|
||||
@@ -487,13 +470,9 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (full_write(dst_fd, buffer, buffer_pos) != buffer_pos) {
|
||||
bad:
|
||||
rc_free(rc);
|
||||
return -1;
|
||||
}
|
||||
rc_free(rc);
|
||||
// FIXME: error check
|
||||
write(dst_fd, buffer, buffer_pos);
|
||||
USE_DESKTOP(total_written += buffer_pos;)
|
||||
rc_free(&rc);
|
||||
return USE_DESKTOP(total_written) + 0;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,7 +5,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Accept any non-null name, its not really a filter at all */
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -5,13 +5,17 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
* Reassign the subarchive metadata parser based on the filename extension
|
||||
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
* Reassign the subarchive metadata parser based on the filename extension
|
||||
* e.g. if its a .tar.gz modify archive_handle->sub_archive to process a .tar.gz
|
||||
* or if its a .tar.bz2 make archive_handle->sub_archive handle that
|
||||
*/
|
||||
char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
{
|
||||
@@ -23,13 +27,13 @@ char filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
name_ptr = strrchr(archive_handle->file_header->name, '.');
|
||||
|
||||
/* Modify the subarchive handler based on the extension */
|
||||
#if ENABLE_FEATURE_DEB_TAR_GZ
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_GZ
|
||||
if (strcmp(name_ptr, ".gz") == 0) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DEB_TAR_BZ2
|
||||
#ifdef CONFIG_FEATURE_DEB_TAR_BZ2
|
||||
if (strcmp(name_ptr, ".bz2") == 0) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_bz2;
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/*
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
/* Find a string in a shell pattern list */
|
||||
|
||||
@@ -23,9 +23,9 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
char magic[2];
|
||||
} formatted;
|
||||
} ar;
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
static char *ar_long_names;
|
||||
static unsigned ar_long_name_size;
|
||||
static unsigned int ar_long_name_size;
|
||||
#endif
|
||||
|
||||
/* dont use xread as we want to handle the error ourself */
|
||||
@@ -66,9 +66,7 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
unsigned long_offset;
|
||||
|
||||
#ifdef CONFIG_FEATURE_AR_LONG_FILENAMES
|
||||
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
|
||||
@@ -80,22 +78,20 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
} else 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 */
|
||||
} else {
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
(saved in variable long_name) that conatains the real filename */
|
||||
const unsigned int 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);
|
||||
}
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (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
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
@@ -109,8 +105,7 @@ char get_header_ar(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
if (archive_handle->sub_archive) {
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
|
||||
/* repeat */;
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS);
|
||||
} else {
|
||||
archive_handle->action_data(archive_handle);
|
||||
}
|
||||
|
||||
@@ -16,9 +16,8 @@ typedef struct hardlinks_s {
|
||||
char get_header_cpio(archive_handle_t *archive_handle)
|
||||
{
|
||||
static hardlinks_t *saved_hardlinks = NULL;
|
||||
static unsigned pending_hardlinks = 0;
|
||||
static unsigned short pending_hardlinks = 0;
|
||||
static int inode;
|
||||
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
char cpio_header[110];
|
||||
int namesize;
|
||||
@@ -31,7 +30,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
tmp = saved_hardlinks;
|
||||
oldtmp = NULL;
|
||||
|
||||
file_header->link_target = file_header->name;
|
||||
file_header->link_name = file_header->name;
|
||||
file_header->size = 0;
|
||||
|
||||
while (tmp) {
|
||||
@@ -57,7 +56,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
saved_hardlinks = tmp;
|
||||
}
|
||||
|
||||
file_header->name = file_header->link_target;
|
||||
file_header->name = file_header->link_name;
|
||||
|
||||
if (pending_hardlinks > 1) {
|
||||
bb_error_msg("error resolving hardlink: archive made by GNU cpio 2.0-2.2?");
|
||||
@@ -104,7 +103,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
/* Always round up */
|
||||
printf("%d blocks\n", (int) (archive_handle->offset % 512 ?
|
||||
archive_handle->offset / 512 + 1 :
|
||||
archive_handle->offset / 512
|
||||
archive_handle->offset / 512
|
||||
));
|
||||
if (saved_hardlinks) { /* Bummer - we still have unresolved hardlinks */
|
||||
hardlinks_t *tmp = saved_hardlinks;
|
||||
@@ -123,12 +122,12 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
}
|
||||
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
file_header->link_target = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, file_header->link_target, file_header->size);
|
||||
file_header->link_name = xzalloc(file_header->size + 1);
|
||||
xread(archive_handle->src_fd, file_header->link_name, file_header->size);
|
||||
archive_handle->offset += file_header->size;
|
||||
file_header->size = 0; /* Stop possible seeks in future */
|
||||
} else {
|
||||
file_header->link_target = NULL;
|
||||
file_header->link_name = NULL;
|
||||
}
|
||||
if (nlink > 1 && !S_ISDIR(file_header->mode)) {
|
||||
if (file_header->size == 0) { /* Put file on a linked list for later */
|
||||
@@ -155,7 +154,7 @@ char get_header_cpio(archive_handle_t *archive_handle)
|
||||
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
free(file_header->link_name);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ static unsigned long long getOctal(char *str, int len)
|
||||
*/
|
||||
str[len] = '\0';
|
||||
v = strtoull(str, &str, 8);
|
||||
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
|
||||
if (*str)
|
||||
bb_error_msg_and_die("corrupted octal value in tar header");
|
||||
return v;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ static unsigned long long getOctal(char *str, int len)
|
||||
void BUG_tar_header_size(void);
|
||||
char get_header_tar(archive_handle_t *archive_handle)
|
||||
{
|
||||
static smallint end;
|
||||
static int end;
|
||||
|
||||
file_header_t *file_header = archive_handle->file_header;
|
||||
struct {
|
||||
@@ -69,10 +69,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
char padding[12]; /* 500-512 */
|
||||
} tar;
|
||||
char *cp;
|
||||
int i, sum_u, sum;
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
int sum_s;
|
||||
#endif
|
||||
int sum, i;
|
||||
int parse_names;
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
@@ -113,41 +110,18 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
#endif
|
||||
bb_error_msg_and_die("invalid tar magic");
|
||||
}
|
||||
|
||||
/* Do checksum on headers.
|
||||
* POSIX says that checksum is done on unsigned bytes, but
|
||||
* Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source. */
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s = ' ' * sizeof(tar.chksum);
|
||||
#endif
|
||||
sum_u = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
/* Do checksum on headers */
|
||||
sum = ' ' * sizeof(tar.chksum);
|
||||
for (i = 0; i < 148 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
for (i = 156; i < 512; i++) {
|
||||
sum_u += ((unsigned char*)&tar)[i];
|
||||
#if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
for (i = 156; i < 512 ; i++) {
|
||||
sum += ((char*)&tar)[i];
|
||||
}
|
||||
#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)) {
|
||||
if (sum != xstrtoul(tar.chksum, 8)) {
|
||||
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';
|
||||
@@ -160,13 +134,13 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
unsigned major = GET_OCTAL(tar.devmajor);
|
||||
file_header->device = makedev(major, minor);
|
||||
}
|
||||
file_header->link_target = NULL;
|
||||
file_header->link_name = NULL;
|
||||
if (!linkname && parse_names && tar.linkname[0]) {
|
||||
/* we trash magic[0] here, it's ok */
|
||||
tar.linkname[sizeof(tar.linkname)] = '\0';
|
||||
file_header->link_target = xstrdup(tar.linkname);
|
||||
/* FIXME: what if we have non-link object with link_target? */
|
||||
/* Will link_target be free()ed? */
|
||||
file_header->link_name = xstrdup(tar.linkname);
|
||||
/* FIXME: what if we have non-link object with link_name? */
|
||||
/* Will link_name be free()ed? */
|
||||
}
|
||||
file_header->mtime = GET_OCTAL(tar.mtime);
|
||||
file_header->size = GET_OCTAL(tar.size);
|
||||
@@ -267,7 +241,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
longname = NULL;
|
||||
}
|
||||
if (linkname) {
|
||||
file_header->link_target = linkname;
|
||||
file_header->link_name = linkname;
|
||||
linkname = NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -279,7 +253,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
}
|
||||
|
||||
/* Strip trailing '/' in directories */
|
||||
/* Must be done after mode is set as '/' is used to check if it's a directory */
|
||||
/* Must be done after mode is set as '/' is used to check if its a directory */
|
||||
cp = last_char_is(file_header->name, '/');
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
@@ -296,7 +270,7 @@ char get_header_tar(archive_handle_t *archive_handle)
|
||||
}
|
||||
archive_handle->offset += file_header->size;
|
||||
|
||||
free(file_header->link_target);
|
||||
free(file_header->link_name);
|
||||
/* Do not free(file_header->name)! */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
@@ -11,7 +18,7 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
|
||||
@@ -3,31 +3,26 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
char get_header_tar_gz(archive_handle_t *archive_handle)
|
||||
{
|
||||
#if BB_MMU
|
||||
unsigned char magic[2];
|
||||
#endif
|
||||
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
/* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
|
||||
* Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
|
||||
* need the header. */
|
||||
#if BB_MMU
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
#endif
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
@@ -14,7 +13,7 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
|
||||
/* Can't lseek over pipes */
|
||||
archive_handle->seek = seek_by_read;
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
void header_list(const file_header_t *file_header)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include "unarchive.h"
|
||||
|
||||
void header_skip(const file_header_t *file_header ATTRIBUTE_UNUSED)
|
||||
|
||||
@@ -23,8 +23,8 @@ void header_verbose_list(const file_header_t *file_header)
|
||||
mtime->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
if (file_header->link_target) {
|
||||
printf(" -> %s", file_header->link_target);
|
||||
if (file_header->link_name) {
|
||||
printf(" -> %s", file_header->link_name);
|
||||
}
|
||||
/* putchar isnt used anywhere else i dont think */
|
||||
puts("");
|
||||
|
||||
@@ -3,52 +3,37 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#include "unarchive.h"
|
||||
|
||||
/* transformer(), more than meets the eye */
|
||||
/*
|
||||
* On MMU machine, the transform_prog and ... are stripped
|
||||
* by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
|
||||
*/
|
||||
int open_transformer(int src_fd,
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
|
||||
const char *transform_prog, ...)
|
||||
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
|
||||
{
|
||||
int fd_pipe[2];
|
||||
int pid;
|
||||
|
||||
xpipe(fd_pipe);
|
||||
if (pipe(fd_pipe) != 0) {
|
||||
bb_perror_msg_and_die("can't create pipe");
|
||||
}
|
||||
|
||||
#if BB_MMU
|
||||
pid = fork();
|
||||
#else
|
||||
pid = vfork();
|
||||
#endif
|
||||
if (pid == -1)
|
||||
if (pid == -1) {
|
||||
bb_perror_msg_and_die("fork failed");
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
#if !BB_MMU
|
||||
va_list ap;
|
||||
#endif
|
||||
/* child process */
|
||||
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
||||
// FIXME: error check?
|
||||
#if BB_MMU
|
||||
transformer(src_fd, fd_pipe[1]);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
}
|
||||
close(fd_pipe[1]); /* Send EOF */
|
||||
close(src_fd);
|
||||
exit(0);
|
||||
#else
|
||||
xmove_fd(src_fd, 0);
|
||||
xmove_fd(fd_pipe[1], 1);
|
||||
va_start(ap, transform_prog);
|
||||
BB_EXECVP(transform_prog, ap);
|
||||
bb_perror_and_die("exec failed");
|
||||
#endif
|
||||
/* notreached */
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,18 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amount)
|
||||
{
|
||||
if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
|
||||
#if ENABLE_FEATURE_UNARCHIVE_TAPE
|
||||
#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
|
||||
if (errno == ESPIPE) {
|
||||
seek_by_read(archive_handle, amount);
|
||||
} else
|
||||
|
||||
@@ -3,14 +3,17 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
/* 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 seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
|
||||
{
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
if (jump_size) {
|
||||
bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,11 @@
|
||||
/*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "unarchive.h"
|
||||
#include "libbb.h"
|
||||
|
||||
void unpack_ar_archive(archive_handle_t *ar_archive)
|
||||
{
|
||||
|
||||
+127
-207
@@ -7,47 +7,47 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_CHAR_TYPE 1
|
||||
#define RPM_INT8_TYPE 2
|
||||
#define RPM_INT16_TYPE 3
|
||||
#define RPM_INT32_TYPE 4
|
||||
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
|
||||
#define RPM_STRING_TYPE 6
|
||||
#define RPM_BIN_TYPE 7
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_CHAR_TYPE 1
|
||||
#define RPM_INT8_TYPE 2
|
||||
#define RPM_INT16_TYPE 3
|
||||
#define RPM_INT32_TYPE 4
|
||||
/* #define RPM_INT64_TYPE 5 ---- These aren't supported (yet) */
|
||||
#define RPM_STRING_TYPE 6
|
||||
#define RPM_BIN_TYPE 7
|
||||
#define RPM_STRING_ARRAY_TYPE 8
|
||||
#define RPM_I18NSTRING_TYPE 9
|
||||
|
||||
#define TAG_NAME 1000
|
||||
#define TAG_VERSION 1001
|
||||
#define TAG_RELEASE 1002
|
||||
#define TAG_SUMMARY 1004
|
||||
#define TAG_DESCRIPTION 1005
|
||||
#define TAG_BUILDTIME 1006
|
||||
#define TAG_BUILDHOST 1007
|
||||
#define TAG_SIZE 1009
|
||||
#define TAG_VENDOR 1011
|
||||
#define TAG_LICENSE 1014
|
||||
#define TAG_PACKAGER 1015
|
||||
#define TAG_GROUP 1016
|
||||
#define TAG_URL 1020
|
||||
#define TAG_PREIN 1023
|
||||
#define TAG_POSTIN 1024
|
||||
#define TAG_FILEFLAGS 1037
|
||||
#define TAG_FILEUSERNAME 1039
|
||||
#define TAG_FILEGROUPNAME 1040
|
||||
#define TAG_SOURCERPM 1044
|
||||
#define TAG_PREINPROG 1085
|
||||
#define TAG_POSTINPROG 1086
|
||||
#define TAG_PREFIXS 1098
|
||||
#define TAG_DIRINDEXES 1116
|
||||
#define TAG_BASENAMES 1117
|
||||
#define TAG_DIRNAMES 1118
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
#define RPMTAG_NAME 1000
|
||||
#define RPMTAG_VERSION 1001
|
||||
#define RPMTAG_RELEASE 1002
|
||||
#define RPMTAG_SUMMARY 1004
|
||||
#define RPMTAG_DESCRIPTION 1005
|
||||
#define RPMTAG_BUILDTIME 1006
|
||||
#define RPMTAG_BUILDHOST 1007
|
||||
#define RPMTAG_SIZE 1009
|
||||
#define RPMTAG_VENDOR 1011
|
||||
#define RPMTAG_LICENSE 1014
|
||||
#define RPMTAG_PACKAGER 1015
|
||||
#define RPMTAG_GROUP 1016
|
||||
#define RPMTAG_URL 1020
|
||||
#define RPMTAG_PREIN 1023
|
||||
#define RPMTAG_POSTIN 1024
|
||||
#define RPMTAG_FILEFLAGS 1037
|
||||
#define RPMTAG_FILEUSERNAME 1039
|
||||
#define RPMTAG_FILEGROUPNAME 1040
|
||||
#define RPMTAG_SOURCERPM 1044
|
||||
#define RPMTAG_PREINPROG 1085
|
||||
#define RPMTAG_POSTINPROG 1086
|
||||
#define RPMTAG_PREFIXS 1098
|
||||
#define RPMTAG_DIRINDEXES 1116
|
||||
#define RPMTAG_BASENAMES 1117
|
||||
#define RPMTAG_DIRNAMES 1118
|
||||
#define RPMFILE_CONFIG (1 << 0)
|
||||
#define RPMFILE_DOC (1 << 1)
|
||||
|
||||
enum rpm_functions_e {
|
||||
rpm_query = 1,
|
||||
@@ -73,40 +73,38 @@ static int tagcount;
|
||||
static void extract_cpio_gz(int fd);
|
||||
static rpm_index **rpm_gettags(int fd, int *num_tags);
|
||||
static int bsearch_rpmtag(const void *key, const void *item);
|
||||
static char *rpm_getstr(int tag, int itemindex);
|
||||
static char *rpm_getstring(int tag, int itemindex);
|
||||
static int rpm_getint(int tag, int itemindex);
|
||||
static int rpm_getcount(int tag);
|
||||
static void fileaction_dobackup(char *filename, int fileref);
|
||||
static void fileaction_setowngrp(char *filename, int fileref);
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref));
|
||||
|
||||
int rpm_main(int argc, char **argv);
|
||||
int rpm_main(int argc, char **argv)
|
||||
{
|
||||
int opt = 0, func = 0, rpm_fd, offset;
|
||||
const int pagesize = getpagesize();
|
||||
|
||||
while ((opt = getopt(argc, argv, "iqpldc")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': /* First arg: Install mode, with q: Information */
|
||||
if (!func) func = rpm_install;
|
||||
case 'i': // First arg: Install mode, with q: Information
|
||||
if (!func) func |= rpm_install;
|
||||
else func |= rpm_query_info;
|
||||
break;
|
||||
case 'q': /* First arg: Query mode */
|
||||
if (func) bb_show_usage();
|
||||
func = rpm_query;
|
||||
case 'q': // First arg: Query mode
|
||||
if (!func) func |= rpm_query;
|
||||
else bb_show_usage();
|
||||
break;
|
||||
case 'p': /* Query a package */
|
||||
case 'p': // Query a package
|
||||
func |= rpm_query_package;
|
||||
break;
|
||||
case 'l': /* List files in a package */
|
||||
case 'l': // List files in a package
|
||||
func |= rpm_query_list;
|
||||
break;
|
||||
case 'd': /* List doc files in a package (implies list) */
|
||||
case 'd': // List doc files in a package (implies list)
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_doc;
|
||||
break;
|
||||
case 'c': /* List config files in a package (implies list) */
|
||||
case 'c': // List config files in a package (implies list)
|
||||
func |= rpm_query_list;
|
||||
func |= rpm_query_list_config;
|
||||
break;
|
||||
@@ -114,90 +112,66 @@ int rpm_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
if (!argc) bb_show_usage();
|
||||
|
||||
while (*argv) {
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, &tagcount);
|
||||
if (!mytags)
|
||||
bb_error_msg_and_die("error reading rpm header");
|
||||
offset = xlseek(rpm_fd, 0, SEEK_CUR);
|
||||
/* Mimimum is one page */
|
||||
map = mmap(0, offset > pagesize ? (offset + offset % pagesize) : pagesize, PROT_READ, MAP_PRIVATE, rpm_fd, 0);
|
||||
|
||||
if (optind == argc) bb_show_usage();
|
||||
while (optind < argc) {
|
||||
rpm_fd = xopen(argv[optind], O_RDONLY);
|
||||
mytags = rpm_gettags(rpm_fd, (int *) &tagcount);
|
||||
offset = lseek(rpm_fd, 0, SEEK_CUR);
|
||||
if (!mytags) { printf("Error reading rpm header\n"); exit(-1); }
|
||||
map = mmap(0, offset > getpagesize() ? (offset + offset % getpagesize()) : getpagesize(), PROT_READ, MAP_PRIVATE, rpm_fd, 0); // Mimimum is one page
|
||||
if (func & rpm_install) {
|
||||
/* Backup any config files */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_dobackup);
|
||||
/* Extact the archive */
|
||||
extract_cpio_gz(rpm_fd);
|
||||
/* Set the correct file uid/gid's */
|
||||
loop_through_files(TAG_BASENAMES, fileaction_setowngrp);
|
||||
}
|
||||
else if ((func & (rpm_query|rpm_query_package)) == (rpm_query|rpm_query_package)) {
|
||||
if (!(func & (rpm_query_info|rpm_query_list))) {
|
||||
/* If just a straight query, just give package name */
|
||||
printf("%s-%s-%s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_RELEASE, 0));
|
||||
loop_through_files(RPMTAG_BASENAMES, fileaction_dobackup); /* Backup any config files */
|
||||
extract_cpio_gz(rpm_fd); // Extact the archive
|
||||
loop_through_files(RPMTAG_BASENAMES, fileaction_setowngrp); /* Set the correct file uid/gid's */
|
||||
} else if (func & rpm_query && func & rpm_query_package) {
|
||||
if (!((func & rpm_query_info) || (func & rpm_query_list))) { // If just a straight query, just give package name
|
||||
printf("%s-%s-%s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_RELEASE, 0));
|
||||
}
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
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);
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstring(RPMTAG_NAME, 0), rpm_getstring(RPMTAG_PREFIXS, 0) ? rpm_getstring(RPMTAG_PREFIXS, 0) : "(not relocateable)");
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstring(RPMTAG_VERSION, 0), rpm_getstring(RPMTAG_VENDOR, 0) ? rpm_getstring(RPMTAG_VENDOR, 0) : "(none)");
|
||||
bdate_time = rpm_getint(RPMTAG_BUILDTIME, 0);
|
||||
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));
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(TAG_SIZE, 0), rpm_getstr(TAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstr(TAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstr(TAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstr(TAG_DESCRIPTION, 0));
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstring(RPMTAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstring(RPMTAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstring(RPMTAG_GROUP, 0), rpm_getstring(RPMTAG_SOURCERPM, 0));
|
||||
printf("Size : %-33dLicense: %s\n", rpm_getint(RPMTAG_SIZE, 0), rpm_getstring(RPMTAG_LICENSE, 0));
|
||||
printf("URL : %s\n", rpm_getstring(RPMTAG_URL, 0));
|
||||
printf("Summary : %s\n", rpm_getstring(RPMTAG_SUMMARY, 0));
|
||||
printf("Description :\n%s\n", rpm_getstring(RPMTAG_DESCRIPTION, 0));
|
||||
}
|
||||
if (func & rpm_query_list) {
|
||||
int count, it, flags;
|
||||
count = rpm_getcount(TAG_BASENAMES);
|
||||
count = rpm_getcount(RPMTAG_BASENAMES);
|
||||
for (it = 0; it < count; it++) {
|
||||
flags = rpm_getint(TAG_FILEFLAGS, it);
|
||||
switch (func & (rpm_query_list_doc|rpm_query_list_config)) {
|
||||
case rpm_query_list_doc:
|
||||
if (!(flags & RPMFILE_DOC)) continue;
|
||||
break;
|
||||
case rpm_query_list_config:
|
||||
if (!(flags & RPMFILE_CONFIG)) continue;
|
||||
break;
|
||||
case rpm_query_list_doc|rpm_query_list_config:
|
||||
if (!(flags & (RPMFILE_CONFIG|RPMFILE_DOC))) continue;
|
||||
break;
|
||||
flags = rpm_getint(RPMTAG_FILEFLAGS, it);
|
||||
switch ((func & rpm_query_list_doc) + (func & rpm_query_list_config))
|
||||
{
|
||||
case rpm_query_list_doc: if (!(flags & RPMFILE_DOC)) continue; break;
|
||||
case rpm_query_list_config: if (!(flags & RPMFILE_CONFIG)) continue; break;
|
||||
case rpm_query_list_doc + rpm_query_list_config: if (!((flags & RPMFILE_CONFIG) || (flags & RPMFILE_DOC))) continue; break;
|
||||
}
|
||||
printf("%s%s\n",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, it)),
|
||||
rpm_getstr(TAG_BASENAMES, it));
|
||||
printf("%s%s\n", rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES, it)), rpm_getstring(RPMTAG_BASENAMES, it));
|
||||
}
|
||||
}
|
||||
}
|
||||
free(mytags);
|
||||
optind++;
|
||||
free (mytags);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extract_cpio_gz(int fd)
|
||||
{
|
||||
static void extract_cpio_gz(int fd) {
|
||||
archive_handle_t *archive_handle;
|
||||
unsigned char magic[2];
|
||||
#if BB_MMU
|
||||
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
|
||||
enum { xformer_prog = 0 };
|
||||
#else
|
||||
enum { xformer = 0 };
|
||||
const char *xformer_prog;
|
||||
#endif
|
||||
|
||||
/* Initialize */
|
||||
/* Initialise */
|
||||
archive_handle = init_handle();
|
||||
archive_handle->seek = seek_by_read;
|
||||
//archive_handle->action_header = header_list;
|
||||
@@ -208,53 +182,25 @@ static void extract_cpio_gz(int fd)
|
||||
archive_handle->offset = 0;
|
||||
|
||||
xread(archive_handle->src_fd, &magic, 2);
|
||||
#if BB_MMU
|
||||
xformer = unpack_gz_stream;
|
||||
#else
|
||||
xformer_prog = "gunzip";
|
||||
#endif
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
if (ENABLE_FEATURE_RPM_BZ2
|
||||
&& (magic[0] == 0x42) && (magic[1] == 0x5a)) {
|
||||
#if BB_MMU
|
||||
xformer = unpack_bz2_stream;
|
||||
#else
|
||||
xformer_prog = "bunzip2";
|
||||
#endif
|
||||
/* We can do better, need modifying unpack_bz2_stream to not require
|
||||
* first 2 bytes. Not very hard to do... I mean, TODO :) */
|
||||
xlseek(archive_handle->src_fd, -2, SEEK_CUR);
|
||||
} else
|
||||
bb_error_msg_and_die("no gzip"
|
||||
USE_FEATURE_RPM_BZ2("/bzip")
|
||||
" magic");
|
||||
} else {
|
||||
check_header_gzip_or_die(archive_handle->src_fd);
|
||||
#if !BB_MMU
|
||||
/* NOMMU version of open_transformer execs an external unzipper that should
|
||||
* have the file position at the start of the file */
|
||||
xlseek(archive_handle->src_fd, 0, SEEK_SET);
|
||||
#endif
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
check_header_gzip(archive_handle->src_fd);
|
||||
xchdir("/"); // Install RPM's to root
|
||||
|
||||
xchdir("/"); /* Install RPM's to root */
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
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(struct rpmtag *));
|
||||
rpm_index **tags = xzalloc(200 * sizeof(struct rpmtag *)); /* We should never need mode than 200, and realloc later */
|
||||
int pass, tagindex = 0;
|
||||
lseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
xlseek(fd, 96, SEEK_CUR); /* Seek past the unused lead */
|
||||
|
||||
/* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
for (pass = 0; pass < 2; pass++) {
|
||||
for (pass = 0; pass < 2; pass++) { /* 1st pass is the signature headers, 2nd is the main stuff */
|
||||
struct {
|
||||
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
@@ -265,31 +211,24 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
|
||||
rpm_index *tmpindex;
|
||||
int storepos;
|
||||
|
||||
xread(fd, &header, sizeof(header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0)
|
||||
return NULL; /* Invalid magic */
|
||||
if (header.version != 1)
|
||||
return NULL; /* This program only supports v1 headers */
|
||||
read(fd, &header, sizeof(header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) return NULL; /* Invalid magic */
|
||||
if (header.version != 1) return NULL; /* This program only supports v1 headers */
|
||||
header.size = ntohl(header.size);
|
||||
header.entries = ntohl(header.entries);
|
||||
storepos = xlseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
storepos = lseek(fd,0,SEEK_CUR) + header.entries * 16;
|
||||
|
||||
while (header.entries--) {
|
||||
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);
|
||||
read(fd, tmpindex, sizeof(rpm_index));
|
||||
tmpindex->tag = ntohl(tmpindex->tag); tmpindex->type = ntohl(tmpindex->type); tmpindex->count = ntohl(tmpindex->count);
|
||||
tmpindex->offset = storepos + ntohl(tmpindex->offset);
|
||||
if (pass==0)
|
||||
tmpindex->tag -= 743;
|
||||
if (pass==0) tmpindex->tag -= 743;
|
||||
}
|
||||
xlseek(fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
/* Skip padding to 8 byte boundary after reading signature headers */
|
||||
if (pass==0)
|
||||
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
lseek(fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
if (pass==0) lseek(fd, (8 - (lseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR); /* Skip padding to 8 byte boundary after reading signature headers */
|
||||
}
|
||||
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
|
||||
tags = realloc(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 */
|
||||
}
|
||||
@@ -305,59 +244,42 @@ static int rpm_getcount(int tag)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found)
|
||||
return 0;
|
||||
return found[0]->count;
|
||||
if (!found) return 0;
|
||||
else return found[0]->count;
|
||||
}
|
||||
|
||||
static char *rpm_getstr(int tag, int itemindex)
|
||||
static char *rpm_getstring(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return NULL;
|
||||
if (!found || itemindex >= found[0]->count) 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);
|
||||
for (n=0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
for (n=0; n < itemindex; n++) tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
}
|
||||
return NULL;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
static int rpm_getint(int tag, int itemindex)
|
||||
{
|
||||
rpm_index **found;
|
||||
int *tmpint; /* NB: using int8_t* would be easier to code */
|
||||
|
||||
int n, *tmpint;
|
||||
/* gcc throws warnings here when sizeof(void*)!=sizeof(int) ...
|
||||
* it's ok to ignore it because tag won't be used as a pointer */
|
||||
found = bsearch(&tag, mytags, tagcount, sizeof(struct rpmtag *), bsearch_rpmtag);
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
if (!found || itemindex >= found[0]->count) return -1;
|
||||
tmpint = (int *) (map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
/*return ntohl(*tmpint);*/
|
||||
/* int can be != int32_t */
|
||||
return ntohl(*(int32_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT16_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*2);
|
||||
/* ??? read int, and THEN ntohs() it?? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return ntohs(*(int16_t*)tmpint);
|
||||
}
|
||||
if (found[0]->type == RPM_INT8_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex);
|
||||
/* ??? why we don't read byte here??? */
|
||||
/*return ntohs(*tmpint);*/
|
||||
return *(int8_t*)tmpint;
|
||||
}
|
||||
return -1;
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 4);
|
||||
return ntohl(*tmpint);
|
||||
} else if (found[0]->type == RPM_INT16_TYPE) {
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 2);
|
||||
return ntohs(*tmpint);
|
||||
} else if (found[0]->type == RPM_INT8_TYPE) {
|
||||
for (n=0; n<itemindex; n++) tmpint = (int *) ((void *) tmpint + 1);
|
||||
return ntohs(*tmpint);
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
static void fileaction_dobackup(char *filename, int fileref)
|
||||
@@ -365,11 +287,9 @@ static void fileaction_dobackup(char *filename, int fileref)
|
||||
struct stat oldfile;
|
||||
int stat_res;
|
||||
char *newname;
|
||||
if (rpm_getint(TAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) {
|
||||
/* Only need to backup config files */
|
||||
stat_res = lstat(filename, &oldfile);
|
||||
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) {
|
||||
/* File already exists - really should check MD5's etc to see if different */
|
||||
if (rpm_getint(RPMTAG_FILEFLAGS, fileref) & RPMFILE_CONFIG) { /* Only need to backup config files */
|
||||
stat_res = lstat (filename, &oldfile);
|
||||
if (stat_res == 0 && S_ISREG(oldfile.st_mode)) { /* File already exists - really should check MD5's etc to see if different */
|
||||
newname = xasprintf("%s.rpmorig", filename);
|
||||
copy_file(filename, newname, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS);
|
||||
remove_file(filename, FILEUTILS_RECUR | FILEUTILS_FORCE);
|
||||
@@ -381,18 +301,18 @@ static void fileaction_dobackup(char *filename, int fileref)
|
||||
static void fileaction_setowngrp(char *filename, int fileref)
|
||||
{
|
||||
int uid, gid;
|
||||
uid = xuname2uid(rpm_getstr(TAG_FILEUSERNAME, fileref));
|
||||
gid = xgroup2gid(rpm_getstr(TAG_FILEGROUPNAME, fileref));
|
||||
uid = bb_xgetpwnam(rpm_getstring(RPMTAG_FILEUSERNAME, fileref));
|
||||
gid = bb_xgetgrnam(rpm_getstring(RPMTAG_FILEGROUPNAME, fileref));
|
||||
chown(filename, uid, gid);
|
||||
}
|
||||
|
||||
static void loop_through_files(int filetag, void (*fileaction)(char *filename, int fileref))
|
||||
{
|
||||
int count = 0;
|
||||
while (rpm_getstr(filetag, count)) {
|
||||
char* filename = xasprintf("%s%s",
|
||||
rpm_getstr(TAG_DIRNAMES, rpm_getint(TAG_DIRINDEXES, count)),
|
||||
rpm_getstr(TAG_BASENAMES, count));
|
||||
while (rpm_getstring(filetag, count)) {
|
||||
char * filename = xasprintf("%s%s",
|
||||
rpm_getstring(RPMTAG_DIRNAMES, rpm_getint(RPMTAG_DIRINDEXES,
|
||||
count)), rpm_getstring(RPMTAG_BASENAMES, count));
|
||||
fileaction(filename, count++);
|
||||
free(filename);
|
||||
}
|
||||
|
||||
+3
-4
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_MAGIC "\355\253\356\333"
|
||||
@@ -49,7 +49,6 @@ static void skip_header(int rpm_fd)
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv);
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
@@ -79,8 +78,8 @@ int rpm2cpio_main(int argc, char **argv)
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
}
|
||||
|
||||
check_header_gzip_or_die(rpm_fd);
|
||||
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
check_header_gzip(rpm_fd);
|
||||
if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
}
|
||||
|
||||
|
||||
+100
-143
@@ -23,12 +23,10 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
#include <fnmatch.h>
|
||||
#include <getopt.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
|
||||
@@ -39,7 +37,6 @@
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
#define NAME_SIZE 100
|
||||
#define NAME_SIZE_STR "100"
|
||||
typedef struct TarHeader TarHeader;
|
||||
struct TarHeader { /* byte offset */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
@@ -59,6 +56,7 @@ struct TarHeader { /* byte offset */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly the TAR_BLOCK_SIZE) */
|
||||
};
|
||||
typedef struct TarHeader TarHeader;
|
||||
|
||||
/*
|
||||
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
|
||||
@@ -75,7 +73,6 @@ struct HardLinkInfo {
|
||||
};
|
||||
|
||||
/* Some info to be carried along when creating a new tarball */
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
for the tarball */
|
||||
@@ -88,6 +85,7 @@ struct TarBallInfo {
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
};
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
|
||||
/* A nice enum with all the possible tar file content types */
|
||||
enum TarFileType {
|
||||
@@ -136,6 +134,7 @@ static void freeHardLinkInfo(HardLinkInfo ** hlInfoHeadPtr)
|
||||
}
|
||||
*hlInfoHeadPtr = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
@@ -174,9 +173,6 @@ static void putOctal(char *cp, int len, off_t value)
|
||||
|
||||
static void chksum_and_xwrite(int fd, struct TarHeader* hp)
|
||||
{
|
||||
/* POSIX says that checksum is done on unsigned bytes
|
||||
* (Sun and HP-UX gets it wrong... more details in
|
||||
* GNU tar source) */
|
||||
const unsigned char *cp;
|
||||
int chksum, size;
|
||||
|
||||
@@ -277,8 +273,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
tbInfo->hlInfo->name, 0);
|
||||
#endif
|
||||
} else if (S_ISLNK(statbuf->st_mode)) {
|
||||
char *lpath = xmalloc_readlink_or_warn(fileName);
|
||||
if (!lpath)
|
||||
char *lpath = xreadlink(fileName);
|
||||
if (!lpath) /* Already printed err msg inside xreadlink() */
|
||||
return FALSE;
|
||||
header.typeflag = SYMTYPE;
|
||||
strncpy(header.linkname, lpath, sizeof(header.linkname));
|
||||
@@ -352,7 +348,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
{
|
||||
while (excluded_files) {
|
||||
@@ -375,12 +371,12 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
# else
|
||||
#define exclude_file(excluded_files, file) 0
|
||||
#endif
|
||||
# endif
|
||||
|
||||
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
void *userData, int depth ATTRIBUTE_UNUSED)
|
||||
void *userData, int depth)
|
||||
{
|
||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
|
||||
const char *header_name;
|
||||
@@ -417,11 +413,11 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
|
||||
header_name = fileName;
|
||||
while (header_name[0] == '/') {
|
||||
static smallint warned;
|
||||
static int alreadyWarned = FALSE;
|
||||
|
||||
if (!warned) {
|
||||
if (alreadyWarned == FALSE) {
|
||||
bb_error_msg("removing leading '/' from member names");
|
||||
warned = 1;
|
||||
alreadyWarned = TRUE;
|
||||
}
|
||||
header_name++;
|
||||
}
|
||||
@@ -442,8 +438,9 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
/* Is this a regular file? */
|
||||
if (tbInfo->hlInfo == NULL && S_ISREG(statbuf->st_mode)) {
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
inputFileFd = open_or_warn(fileName, O_RDONLY);
|
||||
inputFileFd = open(fileName, O_RDONLY);
|
||||
if (inputFileFd < 0) {
|
||||
bb_perror_msg("%s: cannot open", fileName);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -455,30 +452,28 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
|
||||
/* If it was a regular file, write out the body */
|
||||
if (inputFileFd >= 0) {
|
||||
size_t readSize;
|
||||
/* Write the file to the archive. */
|
||||
/* We record size into header first, */
|
||||
/* and then write out file. If file shrinks in between, */
|
||||
/* tar will be corrupted. So we don't allow for that. */
|
||||
/* NB: GNU tar 1.16 warns and pads with zeroes */
|
||||
/* or even seeks back and updates header */
|
||||
bb_copyfd_exact_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////off_t readSize;
|
||||
////readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
////if (readSize != statbuf->st_size && readSize >= 0) {
|
||||
//// bb_error_msg_and_die("short read from %s, aborting", fileName);
|
||||
////}
|
||||
off_t readSize = 0;
|
||||
|
||||
/* write the file to the archive */
|
||||
readSize = bb_copyfd_size(inputFileFd, tbInfo->tarFd, statbuf->st_size);
|
||||
/* readSize < 0 means that error was already reported */
|
||||
if (readSize != statbuf->st_size && readSize >= 0) {
|
||||
/* Deadly. We record size into header first, */
|
||||
/* and then write out file. If file shrinks in between, */
|
||||
/* tar will be corrupted. So bail out. */
|
||||
/* NB: GNU tar 1.16 warns and pads with zeroes */
|
||||
/* or even seeks back and updates header */
|
||||
bb_error_msg_and_die("short read from %s, aborting", fileName);
|
||||
}
|
||||
/* Check that file did not grow in between? */
|
||||
/* if (safe_read(inputFileFd, 1) == 1) warn but continue? */
|
||||
|
||||
/* if (safe_read(inputFileFd,1) == 1) warn but continue? */
|
||||
close(inputFileFd);
|
||||
|
||||
/* Pad the file up to the tar block size */
|
||||
/* (a few tricks here in the name of code size) */
|
||||
readSize = (-(int)statbuf->st_size) & (TAR_BLOCK_SIZE-1);
|
||||
memset(block_buf, 0, readSize);
|
||||
xwrite(tbInfo->tarFd, block_buf, readSize);
|
||||
readSize = (-(int)readSize) & (TAR_BLOCK_SIZE-1);
|
||||
memset(bb_common_bufsiz1, 0, readSize);
|
||||
xwrite(tbInfo->tarFd, bb_common_bufsiz1, readSize);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
@@ -507,19 +502,20 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
int gzipDataPipe[2] = { -1, -1 };
|
||||
int gzipStatusPipe[2] = { -1, -1 };
|
||||
volatile int vfork_exec_errno = 0;
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
|
||||
xpipe(gzipDataPipe);
|
||||
xpipe(gzipStatusPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0)
|
||||
bb_perror_msg_and_die("pipe");
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
# if __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &include;
|
||||
(void) &errorFlag;
|
||||
(void) &zip_exec;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
gzipPid = vfork();
|
||||
|
||||
@@ -532,7 +528,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
close(gzipStatusPipe[0]);
|
||||
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
|
||||
|
||||
BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
|
||||
execlp(zip_exec, zip_exec, "-f", NULL);
|
||||
vfork_exec_errno = errno;
|
||||
|
||||
close(gzipStatusPipe[1]);
|
||||
@@ -563,17 +559,16 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, ACTION_RECURSE |
|
||||
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0))
|
||||
if (!recursive_action(include->data, TRUE, dereferenceFlag,
|
||||
FALSE, writeFileToTarball, writeFileToTarball, &tbInfo, 0))
|
||||
{
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
include = include->link;
|
||||
}
|
||||
/* Write two empty blocks to the end of the archive */
|
||||
memset(block_buf, 0, 2*TAR_BLOCK_SIZE);
|
||||
xwrite(tbInfo.tarFd, block_buf, 2*TAR_BLOCK_SIZE);
|
||||
memset(bb_common_bufsiz1, 0, 2*TAR_BLOCK_SIZE);
|
||||
xwrite(tbInfo.tarFd, bb_common_bufsiz1, 2*TAR_BLOCK_SIZE);
|
||||
|
||||
/* To be pedantically correct, we would check if the tarball
|
||||
* is smaller than 20 tar blocks, and pad it if it was smaller,
|
||||
@@ -590,21 +585,16 @@ static int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
|
||||
if (gzipPid) {
|
||||
int status;
|
||||
if (waitpid(gzipPid, &status, 0) == -1)
|
||||
bb_perror_msg("waitpid");
|
||||
else if (!WIFEXITED(status) || WEXITSTATUS(status))
|
||||
/* gzip was killed or has exited with nonzero! */
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
return errorFlag;
|
||||
if (gzipPid && waitpid(gzipPid, NULL, 0) == -1)
|
||||
bb_error_msg("waitpid failed");
|
||||
|
||||
return !errorFlag;
|
||||
}
|
||||
#else
|
||||
int writeTarFile(const int tar_fd, const int verboseFlag,
|
||||
const unsigned long dereferenceFlag, const llist_t *include,
|
||||
const llist_t *exclude, const int gzip);
|
||||
#endif /* FEATURE_TAR_CREATE */
|
||||
#endif /* tar_create */
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
@@ -632,7 +622,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_TAR_COMPRESS
|
||||
@@ -648,7 +638,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL);
|
||||
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
|
||||
archive_handle->offset = 0;
|
||||
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
|
||||
/* nothing */;
|
||||
@@ -657,30 +647,7 @@ static char get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
#define get_header_tar_Z NULL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* Looks like it isn't needed - tar detects malformed (truncated)
|
||||
* archive if e.g. bunzip2 fails */
|
||||
static int child_error;
|
||||
|
||||
static void handle_SIGCHLD(int status)
|
||||
{
|
||||
/* Actually, 'status' is a signo. We reuse it for other needs */
|
||||
|
||||
/* Wait for any child without blocking */
|
||||
if (waitpid(-1, &status, WNOHANG) < 0)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
||||
/* child exited with 0 */
|
||||
return;
|
||||
/* Cannot happen?
|
||||
if (!WIFSIGNALED(status) && !WIFEXITED(status)) return; */
|
||||
child_error = 1;
|
||||
}
|
||||
#define get_header_tar_Z 0
|
||||
#endif
|
||||
|
||||
enum {
|
||||
@@ -715,47 +682,47 @@ enum {
|
||||
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
|
||||
};
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
static const char tar_longopts[] ALIGN1 =
|
||||
"list\0" No_argument "t"
|
||||
"extract\0" No_argument "x"
|
||||
"directory\0" Required_argument "C"
|
||||
"file\0" Required_argument "f"
|
||||
"to-stdout\0" No_argument "O"
|
||||
"same-permissions\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
"keep-old\0" No_argument "k"
|
||||
static const struct option tar_long_options[] = {
|
||||
{ "list", 0, NULL, 't' },
|
||||
{ "extract", 0, NULL, 'x' },
|
||||
{ "directory", 1, NULL, 'C' },
|
||||
{ "file", 1, NULL, 'f' },
|
||||
{ "to-stdout", 0, NULL, 'O' },
|
||||
{ "same-permissions", 0, NULL, 'p' },
|
||||
{ "verbose", 0, NULL, 'v' },
|
||||
{ "keep-old", 0, NULL, 'k' },
|
||||
# if ENABLE_FEATURE_TAR_CREATE
|
||||
"create\0" No_argument "c"
|
||||
"dereference\0" No_argument "h"
|
||||
{ "create", 0, NULL, 'c' },
|
||||
{ "dereference", 0, NULL, 'h' },
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_BZIP2
|
||||
"bzip2\0" No_argument "j"
|
||||
{ "bzip2", 0, NULL, 'j' },
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_LZMA
|
||||
"lzma\0" No_argument "a"
|
||||
{ "lzma", 0, NULL, 'a' },
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
"files-from\0" Required_argument "T"
|
||||
"exclude-from\0" Required_argument "X"
|
||||
{ "files-from", 1, NULL, 'T' },
|
||||
{ "exclude-from", 1, NULL, 'X' },
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_GZIP
|
||||
"gzip\0" No_argument "z"
|
||||
{ "gzip", 0, NULL, 'z' },
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_COMPRESS
|
||||
"compress\0" No_argument "Z"
|
||||
{ "compress", 0, NULL, 'Z' },
|
||||
# endif
|
||||
"no-same-owner\0" No_argument "\xfd"
|
||||
"no-same-permissions\0" No_argument "\xfe"
|
||||
{ "no-same-owner", 0, NULL, 0xfd },
|
||||
{ "no-same-permissions",0, NULL, 0xfe },
|
||||
/* --exclude takes next bit position in option mask, */
|
||||
/* 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"
|
||||
{ "exclude", 1, NULL, 0xff },
|
||||
# endif
|
||||
;
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
int tar_main(int argc, char **argv);
|
||||
int tar_main(int argc, char **argv)
|
||||
{
|
||||
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
|
||||
@@ -764,9 +731,7 @@ int tar_main(int argc, char **argv)
|
||||
const char *tar_filename = "-";
|
||||
unsigned opt;
|
||||
int verboseFlag = 0;
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
llist_t *excludes = NULL;
|
||||
#endif
|
||||
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
@@ -779,16 +744,14 @@ int tar_main(int argc, char **argv)
|
||||
"tt:vv:" // count -t,-v
|
||||
"?:" // bail out with usage instead of error return
|
||||
"X::T::" // cumulative lists
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
|
||||
"\xff::" // cumulative lists for --exclude
|
||||
#endif
|
||||
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;
|
||||
applet_long_options = tar_long_options;
|
||||
#endif
|
||||
opt = getopt32(argv,
|
||||
opt = getopt32(argc, argv,
|
||||
"txC:f:Opvk"
|
||||
USE_FEATURE_TAR_CREATE( "ch" )
|
||||
USE_FEATURE_TAR_BZIP2( "j" )
|
||||
@@ -796,15 +759,14 @@ int tar_main(int argc, char **argv)
|
||||
USE_FEATURE_TAR_FROM( "T:X:")
|
||||
USE_FEATURE_TAR_GZIP( "z" )
|
||||
USE_FEATURE_TAR_COMPRESS("Z" )
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
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
|
||||
,
|
||||
&base_dir, // -C dir
|
||||
&tar_filename, // -f filename
|
||||
USE_FEATURE_TAR_FROM(&(tar_handle->accept),) // T
|
||||
USE_FEATURE_TAR_FROM(&(tar_handle->reject),) // X
|
||||
USE_FEATURE_TAR_FROM(&excludes ,) // --exclude
|
||||
&verboseFlag, // combined count for -t and -v
|
||||
&verboseFlag // combined count for -t and -v
|
||||
);
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
@@ -837,19 +799,17 @@ int tar_main(int argc, char **argv)
|
||||
if (opt & OPT_COMPRESS)
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
if (ENABLE_FEATURE_TAR_FROM) {
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *temp = excludes->link;
|
||||
excludes->link = tar_handle->reject;
|
||||
tar_handle->reject = excludes;
|
||||
excludes = temp;
|
||||
}
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
}
|
||||
#endif
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
#endif
|
||||
|
||||
/* Check if we are reading from stdin */
|
||||
if (argv[optind] && *argv[optind] == '-') {
|
||||
@@ -864,9 +824,10 @@ int tar_main(int argc, char **argv)
|
||||
char *cp = last_char_is(argv[optind], '/');
|
||||
if (cp > argv[optind])
|
||||
*cp = '\0';
|
||||
llist_add_to_end(&tar_handle->accept, argv[optind]);
|
||||
llist_add_to(&tar_handle->accept, argv[optind]);
|
||||
optind++;
|
||||
}
|
||||
tar_handle->accept = rev_llist(tar_handle->accept);
|
||||
|
||||
if (tar_handle->accept || tar_handle->reject)
|
||||
tar_handle->filter = filter_accept_reject_list;
|
||||
@@ -890,7 +851,7 @@ int tar_main(int argc, char **argv)
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
|
||||
if (LONE_DASH(tar_filename)) {
|
||||
if (tar_filename[0] == '-' && !tar_filename[1]) {
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
@@ -901,11 +862,6 @@ int tar_main(int argc, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
/* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
signal(SIGCHLD, handle_SIGCHLD);
|
||||
#endif
|
||||
|
||||
/* create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
int zipMode = 0;
|
||||
@@ -913,10 +869,11 @@ int tar_main(int argc, char **argv)
|
||||
zipMode = 1;
|
||||
if (ENABLE_FEATURE_TAR_BZIP2 && get_header_ptr == get_header_tar_bz2)
|
||||
zipMode = 2;
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
writeTarFile(tar_handle->src_fd, verboseFlag, opt & OPT_DEREFERENCE,
|
||||
tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
while (get_header_ptr(tar_handle) == EXIT_SUCCESS)
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Uncompress applet for busybox (c) 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define GUNZIP_TO_STDOUT 1
|
||||
#define GUNZIP_FORCE 2
|
||||
|
||||
int uncompress_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
unsigned long flags;
|
||||
|
||||
flags = getopt32(argc, argv, "cf");
|
||||
|
||||
while (optind < argc) {
|
||||
char *compressed_file = argv[optind++];
|
||||
char *delete_path = NULL;
|
||||
char *uncompressed_file = NULL;
|
||||
int src_fd;
|
||||
int dst_fd;
|
||||
|
||||
if (strcmp(compressed_file, "-") == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
flags |= GUNZIP_TO_STDOUT;
|
||||
} else {
|
||||
src_fd = xopen(compressed_file, O_RDONLY);
|
||||
}
|
||||
|
||||
/* Check that the input is sane. */
|
||||
if (isatty(src_fd) && ((flags & GUNZIP_FORCE) == 0)) {
|
||||
bb_error_msg_and_die
|
||||
("compressed data not read from terminal. Use -f to force it.");
|
||||
}
|
||||
|
||||
/* Set output filename and number */
|
||||
if (flags & GUNZIP_TO_STDOUT) {
|
||||
dst_fd = STDOUT_FILENO;
|
||||
} else {
|
||||
struct stat stat_buf;
|
||||
char *extension;
|
||||
|
||||
uncompressed_file = xstrdup(compressed_file);
|
||||
|
||||
extension = strrchr(uncompressed_file, '.');
|
||||
if (!extension || (strcmp(extension, ".Z") != 0)) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
*extension = '\0';
|
||||
|
||||
/* Open output file */
|
||||
xstat(compressed_file, &stat_buf);
|
||||
dst_fd = xopen3(uncompressed_file,
|
||||
O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
|
||||
/* If unzip succeeds remove the old file */
|
||||
delete_path = compressed_file;
|
||||
}
|
||||
|
||||
/* do the decompression, and cleanup */
|
||||
if ((xread_char(src_fd) != 0x1f) || (xread_char(src_fd) != 0x9d)) {
|
||||
bb_error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
status = uncompress(src_fd, dst_fd);
|
||||
|
||||
if ((status != EXIT_SUCCESS) && (uncompressed_file)) {
|
||||
/* Unzip failed, remove the uncomressed file instead of compressed file */
|
||||
delete_path = uncompressed_file;
|
||||
}
|
||||
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
close(dst_fd);
|
||||
}
|
||||
if (src_fd != STDIN_FILENO) {
|
||||
close(src_fd);
|
||||
}
|
||||
|
||||
/* delete_path will be NULL if in test mode or from stdin */
|
||||
if (delete_path && (unlink(delete_path) == -1)) {
|
||||
bb_error_msg_and_die("cannot remove %s", delete_path);
|
||||
}
|
||||
|
||||
free(uncompressed_file);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Small lzma deflate implementation.
|
||||
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
|
||||
*
|
||||
* Based on bunzip.c from busybox
|
||||
*
|
||||
* Licensed under GPL v2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* Why our g[un]zip/bunzip2 are so ugly compared to this beauty? */
|
||||
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define UNLZMA_OPT_STDOUT 1
|
||||
|
||||
int unlzma_main(int argc, char **argv)
|
||||
{
|
||||
USE_DESKTOP(long long) int status;
|
||||
char *filename;
|
||||
unsigned opt;
|
||||
int src_fd, dst_fd;
|
||||
|
||||
opt = getopt32(argc, argv, "c");
|
||||
|
||||
/* Set input filename and number */
|
||||
filename = argv[optind];
|
||||
if (filename && (filename[0] != '-') && (filename[1] != '\0')) {
|
||||
/* Open input file */
|
||||
src_fd = xopen(filename, O_RDONLY);
|
||||
} else {
|
||||
src_fd = STDIN_FILENO;
|
||||
filename = 0;
|
||||
}
|
||||
|
||||
/* if called as lzmacat force the stdout flag */
|
||||
if ((opt & UNLZMA_OPT_STDOUT) || applet_name[4] == 'c')
|
||||
filename = 0;
|
||||
|
||||
if (filename) {
|
||||
struct stat stat_buf;
|
||||
/* bug: char *extension = filename + strlen(filename) - 5; */
|
||||
char *extension = strrchr(filename, '.');
|
||||
if (!extension || strcmp(extension, ".lzma") != 0) {
|
||||
bb_error_msg_and_die("invalid extension");
|
||||
}
|
||||
xstat(filename, &stat_buf);
|
||||
*extension = '\0';
|
||||
dst_fd = xopen3(filename, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
stat_buf.st_mode);
|
||||
} else
|
||||
dst_fd = STDOUT_FILENO;
|
||||
status = unlzma(src_fd, dst_fd);
|
||||
if (filename) {
|
||||
if (status >= 0) /* if success delete src, else delete dst */
|
||||
filename[strlen(filename)] = '.';
|
||||
if (unlink(filename) < 0) {
|
||||
bb_error_msg_and_die("cannot remove %s", filename);
|
||||
}
|
||||
}
|
||||
|
||||
return (status < 0);
|
||||
}
|
||||
+30
-21
@@ -24,7 +24,7 @@
|
||||
* - central directory
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50)
|
||||
@@ -32,6 +32,9 @@
|
||||
#define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50)
|
||||
#define ZIP_DD_MAGIC SWAP_LE32(0x08074b50)
|
||||
|
||||
extern unsigned int gunzip_crc;
|
||||
extern unsigned int gunzip_bytes_out;
|
||||
|
||||
typedef union {
|
||||
unsigned char raw[26];
|
||||
struct {
|
||||
@@ -51,9 +54,9 @@ typedef union {
|
||||
static void unzip_skip(int fd, off_t skip)
|
||||
{
|
||||
if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
|
||||
if (errno != ESPIPE)
|
||||
if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
|
||||
bb_error_msg_and_die("seek failure");
|
||||
bb_copyfd_exact_size(fd, -1, skip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,20 +75,22 @@ static int 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(src_fd, dst_fd, size);
|
||||
if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
|
||||
bb_error_msg_and_die("cannot complete extraction");
|
||||
}
|
||||
|
||||
} else {
|
||||
/* Method 8 - inflate */
|
||||
inflate_unzip_result res;
|
||||
/* err = */ inflate_unzip(&res, zip_header->formatted.cmpsize, src_fd, dst_fd);
|
||||
// we should check for -1 error return
|
||||
inflate_init(zip_header->formatted.cmpsize);
|
||||
inflate_unzip(src_fd, dst_fd);
|
||||
inflate_cleanup();
|
||||
/* Validate decompression - crc */
|
||||
if (zip_header->formatted.crc32 != (res.crc ^ 0xffffffffL)) {
|
||||
if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
|
||||
bb_error_msg("invalid compressed data--%s error", "crc");
|
||||
return 1;
|
||||
}
|
||||
/* Validate decompression - size */
|
||||
if (zip_header->formatted.ucmpsize != res.bytes_out) {
|
||||
if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
|
||||
bb_error_msg("invalid compressed data--%s error", "length");
|
||||
return 1;
|
||||
}
|
||||
@@ -93,7 +98,6 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unzip_main(int argc, char **argv);
|
||||
int unzip_main(int argc, char **argv)
|
||||
{
|
||||
zip_header_t zip_header;
|
||||
@@ -110,7 +114,7 @@ int unzip_main(int argc, char **argv)
|
||||
char key_buf[512];
|
||||
struct stat stat_buf;
|
||||
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
while((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
@@ -134,8 +138,7 @@ int unzip_main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 1 : /* The zip file */
|
||||
src_fn = xmalloc(strlen(optarg)+4);
|
||||
strcpy(src_fn, optarg);
|
||||
src_fn = xstrndup(optarg, strlen(optarg)+4);
|
||||
opt_range++;
|
||||
break;
|
||||
|
||||
@@ -184,19 +187,20 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Open input file */
|
||||
if (LONE_DASH(src_fn)) {
|
||||
if (strcmp("-", src_fn) == 0) {
|
||||
src_fd = STDIN_FILENO;
|
||||
/* Cannot use prompt mode since zip data is arriving on STDIN */
|
||||
overwrite = (overwrite == o_prompt) ? o_never : overwrite;
|
||||
|
||||
} else {
|
||||
static const char *const extn[] = {"", ".zip", ".ZIP"};
|
||||
int orig_src_fn_len = strlen(src_fn);
|
||||
for (i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
for(i = 0; (i < 3) && (src_fd == -1); i++) {
|
||||
strcpy(src_fn + orig_src_fn_len, extn[i]);
|
||||
src_fd = open(src_fn, O_RDONLY);
|
||||
}
|
||||
if (src_fd == -1) {
|
||||
src_fn[orig_src_fn_len] = '\0';
|
||||
src_fn[orig_src_fn_len] = 0;
|
||||
bb_error_msg_and_die("cannot open %s, %s.zip, %s.ZIP", src_fn, src_fn, src_fn);
|
||||
}
|
||||
}
|
||||
@@ -246,8 +250,8 @@ int unzip_main(int argc, char **argv)
|
||||
unzip_skip(src_fd, zip_header.formatted.extra_len);
|
||||
|
||||
if ((verbosity == v_list) && !list_header_done){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
printf(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----\n");
|
||||
list_header_done = 1;
|
||||
}
|
||||
|
||||
@@ -271,8 +275,10 @@ int unzip_main(int argc, char **argv)
|
||||
dst_fn);
|
||||
total_entries++;
|
||||
i = 'n';
|
||||
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
i = -1;
|
||||
|
||||
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
|
||||
if (stat(dst_fn, &stat_buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
@@ -293,15 +299,17 @@ int unzip_main(int argc, char **argv)
|
||||
i = 'n';
|
||||
|
||||
} else { /* Extract file */
|
||||
_check_file:
|
||||
_check_file:
|
||||
if (stat(dst_fn, &stat_buf) == -1) { /* File does not exist */
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
|
||||
}
|
||||
i = 'y';
|
||||
|
||||
} else { /* File already exists */
|
||||
if (overwrite == o_never) {
|
||||
i = 'n';
|
||||
|
||||
} else if (S_ISREG(stat_buf.st_mode)) { /* File is regular file */
|
||||
if (overwrite == o_always) {
|
||||
i = 'y';
|
||||
@@ -312,6 +320,7 @@ int unzip_main(int argc, char **argv)
|
||||
}
|
||||
i = key_buf[0];
|
||||
}
|
||||
|
||||
} else { /* File is not regular file */
|
||||
bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
|
||||
}
|
||||
@@ -330,7 +339,7 @@ int unzip_main(int argc, char **argv)
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
if (unzip_extract(&zip_header, src_fd, dst_fd)) {
|
||||
failed = 1;
|
||||
failed = 1;
|
||||
}
|
||||
if (dst_fd != STDOUT_FILENO) {
|
||||
/* closing STDOUT is potentially bad for future business */
|
||||
|
||||
@@ -85,7 +85,7 @@ config SETCONSOLE
|
||||
config FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on SETCONSOLE && GETOPT_LONG
|
||||
depends on SET_CONSOLE && GETOPT_LONG
|
||||
help
|
||||
Support long options for the setconsole applet.
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
enum {
|
||||
@@ -15,7 +15,6 @@ enum {
|
||||
VT_WAITACTIVE = 0x5607 /* wait for vt active */
|
||||
};
|
||||
|
||||
int chvt_main(int argc, char **argv);
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
@@ -25,9 +24,10 @@ int chvt_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
fd = get_console_fd();
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
/* double cast suppresses "cast to ptr from int of different size */
|
||||
xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num);
|
||||
xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num);
|
||||
num = xatoul_range(argv[1], 1, 63);
|
||||
if ((-1 == ioctl(fd, VT_ACTIVATE, num))
|
||||
|| (-1 == ioctl(fd, VT_WAITACTIVE, num))) {
|
||||
bb_perror_msg_and_die("ioctl");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -10,9 +10,11 @@
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
int clear_main(int argc, char **argv);
|
||||
int clear_main(int argc, char **argv)
|
||||
{
|
||||
return printf("\033[H\033[J") != 6;
|
||||
|
||||
@@ -10,20 +10,19 @@
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
|
||||
|
||||
int deallocvt_main(int argc, char **argv);
|
||||
int deallocvt_main(int argc, char **argv)
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
/* num = 0 deallocate all unused consoles */
|
||||
int num = 0;
|
||||
|
||||
switch (argc) {
|
||||
case 2:
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
num = xatoul_range(argv[1], 1, 63);
|
||||
/* Fallthrough */
|
||||
case 1:
|
||||
break;
|
||||
@@ -31,7 +30,8 @@ int deallocvt_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* double cast suppresses "cast to ptr from int of different size */
|
||||
xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
|
||||
if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) {
|
||||
bb_perror_msg_and_die("VT_DISALLOCATE");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
@@ -22,19 +22,18 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int dumpkmap_main(int argc, char **argv);
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc >= 2 && argv[1][0] == '-')
|
||||
if (argc >= 2 && *argv[1] == '-')
|
||||
bb_show_usage();
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
|
||||
write(1, "bkeymap", 7);
|
||||
write(1, magic, 7);
|
||||
|
||||
/* Here we want to set everything to 0 except for indexes:
|
||||
* [0-2] [4-6] [8-10] [12] */
|
||||
@@ -50,12 +49,12 @@ int dumpkmap_main(int argc, char **argv)
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (!ioctl_or_perror(fd, KDGKBENT, &ke,
|
||||
"ioctl failed with %s, %s, %p",
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
bb_perror_msg("ioctl failed with %s, %s, %p",
|
||||
(char *)&ke.kb_index,
|
||||
(char *)&ke.kb_table,
|
||||
&ke.kb_value)
|
||||
) {
|
||||
&ke.kb_value);
|
||||
} else {
|
||||
write(1, (void*)&ke.kb_value, 2);
|
||||
}
|
||||
}
|
||||
|
||||
+56
-44
@@ -7,7 +7,7 @@
|
||||
* Loads the console font, and possibly the corresponding screen map(s).
|
||||
* (Adapted for busybox by Matej Vela.)
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include <sys/kd.h>
|
||||
|
||||
enum {
|
||||
@@ -21,27 +21,42 @@ enum {
|
||||
};
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
unsigned char charsize; /* Character size */
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
unsigned char charsize; /* Character size */
|
||||
};
|
||||
|
||||
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
loadnewfont(fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
|
||||
{
|
||||
char *buf;
|
||||
char buf[16384];
|
||||
int i;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (unit < 1 || unit > 32)
|
||||
bb_error_msg_and_die("bad character size %d", unit);
|
||||
|
||||
buf = xzalloc(16 * 1024);
|
||||
/*memset(buf, 0, 16 * 1024);*/
|
||||
for (i = 0; i < fontsize; i++)
|
||||
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
|
||||
|
||||
#if defined(PIO_FONTX) && !defined(__sparc__)
|
||||
#if defined( PIO_FONTX ) && !defined( __sparc__ )
|
||||
{
|
||||
struct consolefontdesc cfd;
|
||||
|
||||
@@ -49,13 +64,13 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
|
||||
cfd.charheight = unit;
|
||||
cfd.chardata = buf;
|
||||
|
||||
if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
|
||||
goto ret; /* success */
|
||||
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
|
||||
return; /* success */
|
||||
bb_perror_msg("PIO_FONTX ioctl error (trying PIO_FONT)");
|
||||
}
|
||||
#endif
|
||||
xioctl(fd, PIO_FONT, buf);
|
||||
ret:
|
||||
free(buf);
|
||||
if (ioctl(fd, PIO_FONT, buf))
|
||||
bb_perror_msg_and_die("PIO_FONT ioctl error");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -66,14 +81,14 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
struct unipair *up;
|
||||
int ct = 0, maxct;
|
||||
int glyph;
|
||||
uint16_t unicode;
|
||||
u_short unicode;
|
||||
|
||||
maxct = tailsz; /* more than enough */
|
||||
up = xmalloc(maxct * sizeof(struct unipair));
|
||||
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
|
||||
|
||||
for (glyph = 0; glyph < fontsize; glyph++) {
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((uint16_t) inbuf[1]) << 8) + inbuf[0];
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
tailsz -= 2;
|
||||
inbuf += 2;
|
||||
if (unicode == PSF_SEPARATOR)
|
||||
@@ -90,38 +105,49 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
advice.advised_hashsize = 0;
|
||||
advice.advised_hashstep = 0;
|
||||
advice.advised_hashlevel = 0;
|
||||
xioctl(fd, PIO_UNIMAPCLR, &advice);
|
||||
if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
#ifdef ENOIOCTLCMD
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
bb_error_msg("it seems this kernel is older than 1.1.92");
|
||||
bb_error_msg_and_die("no Unicode mapping table loaded");
|
||||
} else
|
||||
#endif
|
||||
bb_perror_msg_and_die("PIO_UNIMAPCLR");
|
||||
}
|
||||
ud.entry_ct = ct;
|
||||
ud.entries = up;
|
||||
xioctl(fd, PIO_UNIMAP, &ud);
|
||||
if (ioctl(fd, PIO_UNIMAP, &ud)) {
|
||||
bb_perror_msg_and_die("PIO_UNIMAP");
|
||||
}
|
||||
}
|
||||
|
||||
static void loadnewfont(int fd)
|
||||
{
|
||||
enum { INBUF_SIZE = 32*1024 + 1 };
|
||||
|
||||
int unit;
|
||||
unsigned inputlth, offset;
|
||||
/* Was on stack, but 32k is a bit too much: */
|
||||
unsigned char *inbuf = xmalloc(INBUF_SIZE);
|
||||
unsigned char inbuf[32768]; /* primitive */
|
||||
unsigned int inputlth, offset;
|
||||
|
||||
/*
|
||||
* We used to look at the length of the input file
|
||||
* with stat(); now that we accept compressed files,
|
||||
* just read the entire file.
|
||||
*/
|
||||
inputlth = full_read(STDIN_FILENO, inbuf, INBUF_SIZE);
|
||||
if (inputlth < 0)
|
||||
inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
|
||||
if (ferror(stdin))
|
||||
bb_perror_msg_and_die("error reading input font");
|
||||
if (inputlth >= INBUF_SIZE)
|
||||
bb_error_msg_and_die("font too large");
|
||||
/* use malloc/realloc in case of giant files;
|
||||
maybe these do not occur: 16kB for the font,
|
||||
and 16kB for the map leaves 32 unicode values
|
||||
for each font position */
|
||||
if (!feof(stdin))
|
||||
bb_perror_msg_and_die("font too large");
|
||||
|
||||
/* test for psf first */
|
||||
{
|
||||
struct psf_header psfhdr;
|
||||
int fontsize;
|
||||
int hastable;
|
||||
unsigned head0, head;
|
||||
unsigned int head0, head;
|
||||
|
||||
if (inputlth < sizeof(struct psf_header))
|
||||
goto no_psf;
|
||||
@@ -134,7 +160,7 @@ static void loadnewfont(int fd)
|
||||
if (psfhdr.mode > PSF_MAXMODE)
|
||||
bb_error_msg_and_die("unsupported psf file mode");
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
#if !defined(PIO_FONTX) || defined(__sparc__)
|
||||
#if !defined( PIO_FONTX ) || defined( __sparc__ )
|
||||
if (fontsize != 256)
|
||||
bb_error_msg_and_die("only fontsize 256 supported");
|
||||
#endif
|
||||
@@ -150,8 +176,8 @@ static void loadnewfont(int fd)
|
||||
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
|
||||
return;
|
||||
}
|
||||
no_psf:
|
||||
|
||||
no_psf:
|
||||
/* file with three code pages? */
|
||||
if (inputlth == 9780) {
|
||||
offset = 40;
|
||||
@@ -165,17 +191,3 @@ static void loadnewfont(int fd)
|
||||
}
|
||||
do_loadfont(fd, inbuf + offset, unit, 256);
|
||||
}
|
||||
|
||||
int loadfont_main(int argc, char **argv);
|
||||
int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc != 1)
|
||||
bb_show_usage();
|
||||
|
||||
fd = xopen(CURRENT_VC, O_RDWR);
|
||||
loadnewfont(fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define BINARY_KEYMAP_MAGIC "bkeymap"
|
||||
|
||||
@@ -25,12 +25,11 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
int loadkmap_main(int argc, char **argv);
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
uint16_t ibuff[NR_KEYS];
|
||||
u_short ibuff[NR_KEYS];
|
||||
char flags[MAX_NR_KEYMAPS];
|
||||
char buff[7];
|
||||
|
||||
@@ -47,7 +46,7 @@ int loadkmap_main(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
xread(0, ibuff, NR_KEYS * sizeof(uint16_t));
|
||||
xread(0, ibuff, NR_KEYS * sizeof(u_short));
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
|
||||
+23
-13
@@ -10,26 +10,36 @@
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
int openvt_main(int argc, char **argv);
|
||||
int openvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
char vtname[sizeof(VC_FORMAT) + 2];
|
||||
|
||||
if (argc < 3)
|
||||
|
||||
if (argc < 3) {
|
||||
bb_show_usage();
|
||||
|
||||
}
|
||||
/* check for illegal vt number: < 1 or > 63 */
|
||||
sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
|
||||
sprintf(vtname, VC_FORMAT, (int)xatoul_range(argv[1], 1, 63));
|
||||
|
||||
bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
|
||||
/* grab new one */
|
||||
close(0);
|
||||
xopen(vtname, O_RDWR);
|
||||
dup2(0, STDOUT_FILENO);
|
||||
dup2(0, STDERR_FILENO);
|
||||
if (fork() == 0) {
|
||||
/* leave current vt */
|
||||
if (setsid() < 0) {
|
||||
bb_perror_msg_and_die("setsid");
|
||||
}
|
||||
close(0); /* so that new vt becomes stdin */
|
||||
|
||||
BB_EXECVP(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
/* and grab new one */
|
||||
fd = xopen(vtname, O_RDWR);
|
||||
|
||||
/* Reassign stdout and sterr */
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
dup2(fd, STDERR_FILENO);
|
||||
|
||||
execvp(argv[2], &argv[2]);
|
||||
_exit(1);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -10,9 +10,11 @@
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int reset_main(int argc, char **argv);
|
||||
int reset_main(int argc, char **argv)
|
||||
{
|
||||
if (isatty(1)) {
|
||||
|
||||
+11
-42
@@ -7,63 +7,32 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
/* no options, no getopt */
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define ESC "\033"
|
||||
|
||||
#define old_termios (*(struct termios*)&bb_common_bufsiz1)
|
||||
|
||||
static void
|
||||
onintr(int sig ATTRIBUTE_UNUSED)
|
||||
{
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int resize_main(int argc, char **argv);
|
||||
int resize_main(int argc, char **argv)
|
||||
{
|
||||
struct termios new;
|
||||
struct winsize w = { 0,0,0,0 };
|
||||
struct termios old, new;
|
||||
struct winsize w = {0,0,0,0};
|
||||
int ret;
|
||||
|
||||
/* We use _stderr_ in order to make resize usable
|
||||
* in shell backticks (those redirect stdout away from tty).
|
||||
* NB: other versions of resize open "/dev/tty"
|
||||
* and operate on it - should we do the same?
|
||||
*/
|
||||
|
||||
tcgetattr(STDERR_FILENO, &old_termios); /* fiddle echo */
|
||||
new = old_termios;
|
||||
tcgetattr(STDOUT_FILENO, &old); /* fiddle echo */
|
||||
new = old;
|
||||
new.c_cflag |= (CLOCAL | CREAD);
|
||||
new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
|
||||
signal(SIGINT, onintr);
|
||||
signal(SIGQUIT, onintr);
|
||||
signal(SIGTERM, onintr);
|
||||
signal(SIGALRM, onintr);
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &new);
|
||||
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &new);
|
||||
/* save_cursor_pos 7
|
||||
* scroll_whole_screen [r
|
||||
* put_cursor_waaaay_off [$x;$yH
|
||||
* get_cursor_pos [6n
|
||||
* restore_cursor_pos 8
|
||||
*/
|
||||
fprintf(stderr, ESC"7" ESC"[r" ESC"[999;999H" ESC"[6n");
|
||||
alarm(3); /* Just in case terminal won't answer */
|
||||
scanf(ESC"[%hu;%huR", &w.ws_row, &w.ws_col);
|
||||
fprintf(stderr, ESC"8");
|
||||
|
||||
/* BTW, other versions of resize recalculate w.ws_xpixel, ws.ws_ypixel
|
||||
* by calculating character cell HxW from old values
|
||||
* (gotten via TIOCGWINSZ) and recomputing *pixel values */
|
||||
ret = ioctl(STDERR_FILENO, TIOCSWINSZ, &w);
|
||||
|
||||
tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
|
||||
|
||||
printf("\0337\033[r\033[999;999H\033[6n");
|
||||
scanf("\033[%hu;%huR", &w.ws_row, &w.ws_col);
|
||||
ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);
|
||||
printf("\0338");
|
||||
tcsetattr(STDOUT_FILENO, TCSANOW, &old);
|
||||
if (ENABLE_FEATURE_RESIZE_PRINT)
|
||||
printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
|
||||
w.ws_col, w.ws_row);
|
||||
|
||||
return ret;
|
||||
}
|
||||
+11
-10
@@ -7,27 +7,26 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <getopt.h>
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
static const char setconsole_longopts[] ALIGN1 =
|
||||
"reset\0" No_argument "r"
|
||||
;
|
||||
static const struct option setconsole_long_options[] = {
|
||||
{ "reset", 0, NULL, 'r' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
#define OPT_SETCONS_RESET 1
|
||||
|
||||
int setconsole_main(int argc, char **argv);
|
||||
int setconsole_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
const char *device = CURRENT_TTY;
|
||||
|
||||
#if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS
|
||||
applet_long_options = setconsole_longopts;
|
||||
applet_long_options = setconsole_long_options;
|
||||
#endif
|
||||
flags = getopt32(argv, "r");
|
||||
flags = getopt32(argc, argv, "r");
|
||||
|
||||
if (argc - optind > 1)
|
||||
bb_show_usage();
|
||||
@@ -38,9 +37,11 @@ int setconsole_main(int argc, char **argv)
|
||||
device = argv[optind];
|
||||
} else {
|
||||
if (flags & OPT_SETCONS_RESET)
|
||||
device = DEV_CONSOLE;
|
||||
device = CONSOLE_DEV;
|
||||
}
|
||||
|
||||
xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
|
||||
if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) {
|
||||
bb_perror_msg_and_die("TIOCCONS");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -9,8 +9,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
//#include <sys/ioctl.h>
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbkeycode {
|
||||
@@ -20,8 +24,8 @@ enum {
|
||||
KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */
|
||||
};
|
||||
|
||||
int setkeycodes_main(int argc, char** argv);
|
||||
int setkeycodes_main(int argc, char** argv)
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
@@ -39,9 +43,9 @@ int setkeycodes_main(int argc, char** argv)
|
||||
a.scancode -= 0xe000;
|
||||
a.scancode += 128;
|
||||
}
|
||||
ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
|
||||
"failed to set SCANCODE %x to KEYCODE %d",
|
||||
sc, a.keycode);
|
||||
if (ioctl(fd, KDSETKEYCODE, &a)) {
|
||||
bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
|
||||
@@ -9,10 +9,9 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
int setlogcons_main(int argc, char **argv);
|
||||
int setlogcons_main(int argc, char **argv)
|
||||
extern int setlogcons_main(int argc, char **argv)
|
||||
{
|
||||
struct {
|
||||
char fn;
|
||||
@@ -25,7 +24,8 @@ int setlogcons_main(int argc, char **argv)
|
||||
if (argc == 2)
|
||||
arg.subarg = xatoul_range(argv[1], 0, 63);
|
||||
|
||||
xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
|
||||
if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg))
|
||||
bb_perror_msg_and_die("TIOCLINUX");
|
||||
|
||||
return 0;
|
||||
}
|
||||
+47
-55
@@ -65,6 +65,13 @@ config CKSUM
|
||||
help
|
||||
cksum is used to calculate the CRC32 checksum of a file.
|
||||
|
||||
config CMP
|
||||
bool "cmp"
|
||||
default n
|
||||
help
|
||||
cmp is used to compare two files and returns the result
|
||||
to standard output.
|
||||
|
||||
config COMM
|
||||
bool "comm"
|
||||
default n
|
||||
@@ -135,6 +142,38 @@ config DF
|
||||
df reports the amount of disk space used and available
|
||||
on filesystems.
|
||||
|
||||
config DIFF
|
||||
bool "diff"
|
||||
default n
|
||||
help
|
||||
diff compares two files or directories and outputs the
|
||||
differences between them in a form that can be given to
|
||||
the patch command.
|
||||
|
||||
config FEATURE_DIFF_BINARY
|
||||
bool "Enable checks for binary files"
|
||||
default y
|
||||
depends on DIFF
|
||||
help
|
||||
This option enables support for checking for binary files
|
||||
before a comparison is carried out.
|
||||
|
||||
config FEATURE_DIFF_DIR
|
||||
bool "Enable directory support"
|
||||
default y
|
||||
depends on DIFF
|
||||
help
|
||||
This option enables support for directory and subdirectory
|
||||
comparison.
|
||||
|
||||
config FEATURE_DIFF_MINIMAL
|
||||
bool "Enable -d option to find smaller sets of changes"
|
||||
default n
|
||||
depends on DIFF
|
||||
help
|
||||
Enabling this option allows the use of -d to make diff
|
||||
try hard to find the smallest possible set of changes.
|
||||
|
||||
config DIRNAME
|
||||
bool "dirname"
|
||||
default n
|
||||
@@ -200,19 +239,6 @@ config FEATURE_ENV_LONG_OPTIONS
|
||||
help
|
||||
Support long options for the env applet.
|
||||
|
||||
config EXPAND
|
||||
bool "expand"
|
||||
default n
|
||||
help
|
||||
By default, convert all tabs to spaces.
|
||||
|
||||
config FEATURE_EXPAND_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on EXPAND && GETOPT_LONG
|
||||
help
|
||||
Support long options for the expand applet.
|
||||
|
||||
config EXPR
|
||||
bool "expr"
|
||||
default n
|
||||
@@ -448,20 +474,6 @@ config PWD
|
||||
help
|
||||
pwd is used to print the current directory.
|
||||
|
||||
config READLINK
|
||||
bool "readlink"
|
||||
default n
|
||||
help
|
||||
This program reads a symbolic link and returns the name
|
||||
of the file it points to
|
||||
|
||||
config FEATURE_READLINK_FOLLOW
|
||||
bool "Enable canonicalization by following all symlinks (-f)"
|
||||
default n
|
||||
depends on READLINK
|
||||
help
|
||||
Enable the readlink option (-f).
|
||||
|
||||
config REALPATH
|
||||
bool "realpath"
|
||||
default n
|
||||
@@ -524,21 +536,6 @@ config FEATURE_SORT_BIG
|
||||
The SuSv3 sort standard is available at:
|
||||
http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
|
||||
|
||||
config SPLIT
|
||||
bool "split"
|
||||
default n
|
||||
help
|
||||
split a file into pieces.
|
||||
|
||||
config FEATURE_SPLIT_FANCY
|
||||
bool "fancy extensions"
|
||||
default n
|
||||
depends on SPLIT
|
||||
help
|
||||
Add support for features not required by SUSv3.
|
||||
Supports additional suffixes 'b' for 512 bytes,
|
||||
'g' for 1GiB for the -b option.
|
||||
|
||||
config STAT
|
||||
bool "stat"
|
||||
default n
|
||||
@@ -668,19 +665,6 @@ config UNAME
|
||||
help
|
||||
uname is used to print system information.
|
||||
|
||||
config UNEXPAND
|
||||
bool "unexpand"
|
||||
default n
|
||||
help
|
||||
By default, convert only leading sequences of blanks to tabs.
|
||||
|
||||
config FEATURE_UNEXPAND_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on UNEXPAND && GETOPT_LONG
|
||||
help
|
||||
Support long options for the unexpand applet.
|
||||
|
||||
config UNIQ
|
||||
bool "uniq"
|
||||
default n
|
||||
@@ -705,6 +689,14 @@ config UUENCODE
|
||||
help
|
||||
uuencode is used to uuencode a file.
|
||||
|
||||
config WATCH
|
||||
bool "watch"
|
||||
default n
|
||||
select DATE
|
||||
help
|
||||
watch is used to execute a program periodically, showing
|
||||
output to the screen.
|
||||
|
||||
config WC
|
||||
bool "wc"
|
||||
default n
|
||||
|
||||
+3
-8
@@ -10,28 +10,26 @@ lib-y:=
|
||||
lib-$(CONFIG_BASENAME) += basename.o
|
||||
lib-$(CONFIG_CAL) += cal.o
|
||||
lib-$(CONFIG_CAT) += cat.o
|
||||
lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
||||
lib-$(CONFIG_LESS) += cat.o # less too
|
||||
lib-$(CONFIG_CATV) += catv.o
|
||||
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
|
||||
lib-$(CONFIG_CHMOD) += chmod.o
|
||||
lib-$(CONFIG_CHOWN) += chown.o
|
||||
lib-$(CONFIG_CHROOT) += chroot.o
|
||||
lib-$(CONFIG_CKSUM) += cksum.o
|
||||
lib-$(CONFIG_CMP) += cmp.o
|
||||
lib-$(CONFIG_COMM) += comm.o
|
||||
lib-$(CONFIG_CP) += cp.o
|
||||
lib-$(CONFIG_CUT) += cut.o
|
||||
lib-$(CONFIG_DATE) += date.o
|
||||
lib-$(CONFIG_DD) += dd.o
|
||||
lib-$(CONFIG_DF) += df.o
|
||||
lib-$(CONFIG_DIFF) += diff.o
|
||||
lib-$(CONFIG_DIRNAME) += dirname.o
|
||||
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
|
||||
lib-$(CONFIG_DU) += du.o
|
||||
lib-$(CONFIG_ECHO) += echo.o
|
||||
lib-$(CONFIG_ASH) += echo.o # used by ash
|
||||
lib-$(CONFIG_ENV) += env.o
|
||||
lib-$(CONFIG_EXPR) += expr.o
|
||||
lib-$(CONFIG_EXPAND) += expand.o
|
||||
lib-$(CONFIG_FALSE) += false.o
|
||||
lib-$(CONFIG_FOLD) += fold.o
|
||||
lib-$(CONFIG_HEAD) += head.o
|
||||
@@ -53,14 +51,12 @@ lib-$(CONFIG_OD) += od.o
|
||||
lib-$(CONFIG_PRINTENV) += printenv.o
|
||||
lib-$(CONFIG_PRINTF) += printf.o
|
||||
lib-$(CONFIG_PWD) += pwd.o
|
||||
lib-$(CONFIG_READLINK) += readlink.o
|
||||
lib-$(CONFIG_REALPATH) += realpath.o
|
||||
lib-$(CONFIG_RM) += rm.o
|
||||
lib-$(CONFIG_RMDIR) += rmdir.o
|
||||
lib-$(CONFIG_SEQ) += seq.o
|
||||
lib-$(CONFIG_SHA1SUM) += md5_sha1_sum.o
|
||||
lib-$(CONFIG_SLEEP) += sleep.o
|
||||
lib-$(CONFIG_SPLIT) += split.o
|
||||
lib-$(CONFIG_SORT) += sort.o
|
||||
lib-$(CONFIG_STAT) += stat.o
|
||||
lib-$(CONFIG_STTY) += stty.o
|
||||
@@ -69,17 +65,16 @@ lib-$(CONFIG_SYNC) += sync.o
|
||||
lib-$(CONFIG_TAIL) += tail.o
|
||||
lib-$(CONFIG_TEE) += tee.o
|
||||
lib-$(CONFIG_TEST) += test.o
|
||||
lib-$(CONFIG_ASH) += test.o # used by ash
|
||||
lib-$(CONFIG_TOUCH) += touch.o
|
||||
lib-$(CONFIG_TR) += tr.o
|
||||
lib-$(CONFIG_TRUE) += true.o
|
||||
lib-$(CONFIG_TTY) += tty.o
|
||||
lib-$(CONFIG_UNAME) += uname.o
|
||||
lib-$(CONFIG_UNEXPAND) += expand.o
|
||||
lib-$(CONFIG_UNIQ) += uniq.o
|
||||
lib-$(CONFIG_USLEEP) += usleep.o
|
||||
lib-$(CONFIG_UUDECODE) += uudecode.o
|
||||
lib-$(CONFIG_UUENCODE) += uuencode.o
|
||||
lib-$(CONFIG_WATCH) += watch.o
|
||||
lib-$(CONFIG_WC) += wc.o
|
||||
lib-$(CONFIG_WHO) += who.o
|
||||
lib-$(CONFIG_WHOAMI) += whoami.o
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
* 3) Save some space by using strcmp(). Calling strncmp() here was silly.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int basename_main(int argc, char **argv);
|
||||
int basename_main(int argc, char **argv)
|
||||
{
|
||||
size_t m, n;
|
||||
@@ -46,5 +46,5 @@ int basename_main(int argc, char **argv)
|
||||
|
||||
puts(s);
|
||||
|
||||
return fflush(stdout);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+64
-55
@@ -17,9 +17,7 @@
|
||||
* Major size reduction... over 50% (>1.5k) on i386.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
|
||||
#include "busybox.h"
|
||||
|
||||
#define THURSDAY 4 /* for reformation */
|
||||
#define SATURDAY 6 /* 1 Jan 1 was a Saturday */
|
||||
@@ -30,25 +28,29 @@
|
||||
#define MAXDAYS 42 /* max slots in a month array */
|
||||
#define SPACE -1 /* used in day array */
|
||||
|
||||
static const unsigned char days_in_month[] ALIGN1 = {
|
||||
static const char days_in_month[] = {
|
||||
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
|
||||
};
|
||||
|
||||
static const unsigned char sep1752[] ALIGN1 = {
|
||||
static const char sep1752[] = {
|
||||
1, 2, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30
|
||||
};
|
||||
|
||||
static unsigned julian;
|
||||
static int julian;
|
||||
|
||||
/* leap year -- account for Gregorian reformation in 1752 */
|
||||
static int leap_year(unsigned yr)
|
||||
#define leap_year(yr) \
|
||||
((yr) <= 1752 ? !((yr) % 4) : \
|
||||
(!((yr) % 4) && ((yr) % 100)) || !((yr) % 400))
|
||||
|
||||
static int is_leap_year(int year)
|
||||
{
|
||||
if (yr <= 1752)
|
||||
return !(yr % 4);
|
||||
return (!(yr % 4) && (yr % 100)) || !(yr % 400);
|
||||
return leap_year(year);
|
||||
}
|
||||
#undef leap_year
|
||||
#define leap_year(yr) is_leap_year(yr)
|
||||
|
||||
/* number of centuries since 1700, not inclusive */
|
||||
#define centuries_since_1700(yr) \
|
||||
@@ -62,12 +64,12 @@ static int leap_year(unsigned yr)
|
||||
#define leap_years_since_year_1(yr) \
|
||||
((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
|
||||
|
||||
static void center(char *, unsigned, unsigned);
|
||||
static void day_array(unsigned, unsigned, unsigned *);
|
||||
static void trim_trailing_spaces_and_print(char *);
|
||||
static void center (char *, int, int);
|
||||
static void day_array (int, int, int *);
|
||||
static void trim_trailing_spaces_and_print (char *);
|
||||
|
||||
static void blank_string(char *buf, size_t buflen);
|
||||
static char *build_row(char *p, unsigned *dp);
|
||||
static char *build_row(char *p, int *dp);
|
||||
|
||||
#define DAY_LEN 3 /* 3 spaces per day */
|
||||
#define J_DAY_LEN (DAY_LEN + 1)
|
||||
@@ -75,24 +77,30 @@ static char *build_row(char *p, unsigned *dp);
|
||||
#define J_WEEK_LEN (WEEK_LEN + 7)
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
|
||||
int cal_main(int argc, 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;
|
||||
int month, year, flags, i;
|
||||
char *month_names[12];
|
||||
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
|
||||
char buf[40];
|
||||
|
||||
flags = getopt32(argv, "jy");
|
||||
julian = flags & 1;
|
||||
month = 0;
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
// Done in busybox.c, ok to remove?
|
||||
//#ifdef CONFIG_LOCALE_SUPPORT
|
||||
// setlocale(LC_TIME, "");
|
||||
//#endif
|
||||
|
||||
if (argc > 2) {
|
||||
flags = getopt32(argc, argv, "jy");
|
||||
|
||||
julian = flags & 1;
|
||||
|
||||
argv += optind;
|
||||
|
||||
month = 0;
|
||||
|
||||
if ((argc -= optind) > 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
@@ -105,12 +113,12 @@ int cal_main(int argc, char **argv)
|
||||
}
|
||||
} else {
|
||||
if (argc == 2) {
|
||||
month = xatou_range(*argv++, 1, 12);
|
||||
month = xatoul_range(*argv++, 1, 12);
|
||||
}
|
||||
year = xatou_range(*argv, 1, 9999);
|
||||
year = xatoul_range(*argv, 1, 9999);
|
||||
}
|
||||
|
||||
blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian);
|
||||
blank_string(day_headings, sizeof(day_headings) - 7 + 7*julian);
|
||||
|
||||
i = 0;
|
||||
do {
|
||||
@@ -126,8 +134,8 @@ int cal_main(int argc, char **argv)
|
||||
} while (++i < 12);
|
||||
|
||||
if (month) {
|
||||
unsigned row, len, days[MAXDAYS];
|
||||
unsigned *dp = days;
|
||||
int row, len, days[MAXDAYS];
|
||||
int *dp = days;
|
||||
char lineout[30];
|
||||
|
||||
day_array(month, year, dp);
|
||||
@@ -141,8 +149,8 @@ int cal_main(int argc, char **argv)
|
||||
trim_trailing_spaces_and_print(lineout);
|
||||
}
|
||||
} else {
|
||||
unsigned row, which_cal, week_len, days[12][MAXDAYS];
|
||||
unsigned *dp;
|
||||
int row, which_cal, week_len, days[12][MAXDAYS];
|
||||
int *dp;
|
||||
char lineout[80];
|
||||
|
||||
sprintf(lineout, "%d", year);
|
||||
@@ -189,21 +197,19 @@ int cal_main(int argc, char **argv)
|
||||
* out end to end. You would have 42 numbers or spaces. This routine
|
||||
* builds that array for any month from Jan. 1 through Dec. 9999.
|
||||
*/
|
||||
static void day_array(unsigned month, unsigned year, unsigned *days)
|
||||
static void day_array(int month, int year, int *days)
|
||||
{
|
||||
unsigned long temp;
|
||||
unsigned i;
|
||||
unsigned day, dw, dm;
|
||||
long temp;
|
||||
int i;
|
||||
int j_offset;
|
||||
int day, dw, dm;
|
||||
|
||||
memset(days, SPACE, MAXDAYS * sizeof(int));
|
||||
|
||||
if ((month == 9) && (year == 1752)) {
|
||||
/* Assumes the Gregorian reformation eliminates
|
||||
* 3 Sep. 1752 through 13 Sep. 1752.
|
||||
*/
|
||||
unsigned j_offset = julian * 244;
|
||||
size_t oday = 0;
|
||||
|
||||
j_offset = julian * 244;
|
||||
do {
|
||||
days[oday+2] = sep1752[oday] + j_offset;
|
||||
} while (++oday < sizeof(sep1752));
|
||||
@@ -212,7 +218,7 @@ static void day_array(unsigned month, unsigned year, unsigned *days)
|
||||
}
|
||||
|
||||
/* day_in_year
|
||||
* return the 1 based day number within the year
|
||||
* return the 1 based day number within the year
|
||||
*/
|
||||
day = 1;
|
||||
if ((month > 2) && leap_year(year)) {
|
||||
@@ -225,15 +231,17 @@ static void day_array(unsigned month, unsigned year, unsigned *days)
|
||||
}
|
||||
|
||||
/* day_in_week
|
||||
* return the 0 based day number for any date from 1 Jan. 1 to
|
||||
* 31 Dec. 9999. Assumes the Gregorian reformation eliminates
|
||||
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
|
||||
* missing days.
|
||||
* return the 0 based day number for any date from 1 Jan. 1 to
|
||||
* 31 Dec. 9999. Assumes the Gregorian reformation eliminates
|
||||
* 3 Sep. 1752 through 13 Sep. 1752. Returns Thursday for all
|
||||
* missing days.
|
||||
*/
|
||||
temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1) + day;
|
||||
dw = THURSDAY;
|
||||
temp = (long)(year - 1) * 365 + leap_years_since_year_1(year - 1)
|
||||
+ day;
|
||||
if (temp < FIRST_MISSING_DAY) {
|
||||
dw = ((temp - 1 + SATURDAY) % 7);
|
||||
} else {
|
||||
} else if (temp >= (FIRST_MISSING_DAY + NUMBER_MISSING_DAYS)) {
|
||||
dw = (((temp - 1 + SATURDAY) - NUMBER_MISSING_DAYS) % 7);
|
||||
}
|
||||
|
||||
@@ -246,9 +254,10 @@ static void day_array(unsigned month, unsigned year, unsigned *days)
|
||||
++dm;
|
||||
}
|
||||
|
||||
do {
|
||||
while (dm) {
|
||||
days[dw++] = day++;
|
||||
} while (--dm);
|
||||
--dm;
|
||||
}
|
||||
}
|
||||
|
||||
static void trim_trailing_spaces_and_print(char *s)
|
||||
@@ -258,7 +267,7 @@ static void trim_trailing_spaces_and_print(char *s)
|
||||
while (*p) {
|
||||
++p;
|
||||
}
|
||||
while (p != s) {
|
||||
while (p > s) {
|
||||
--p;
|
||||
if (!(isspace)(*p)) { /* We want the function... not the inline. */
|
||||
p[1] = '\0';
|
||||
@@ -269,9 +278,9 @@ static void trim_trailing_spaces_and_print(char *s)
|
||||
puts(s);
|
||||
}
|
||||
|
||||
static void center(char *str, unsigned len, unsigned separate)
|
||||
static void center(char *str, int len, int separate)
|
||||
{
|
||||
unsigned n = strlen(str);
|
||||
int n = strlen(str);
|
||||
len -= n;
|
||||
printf("%*s%*s", (len/2) + n, str, (len/2) + (len % 2) + separate, "");
|
||||
}
|
||||
@@ -282,16 +291,15 @@ static void blank_string(char *buf, size_t buflen)
|
||||
buf[buflen-1] = '\0';
|
||||
}
|
||||
|
||||
static char *build_row(char *p, unsigned *dp)
|
||||
static char *build_row(char *p, int *dp)
|
||||
{
|
||||
unsigned col, val, day;
|
||||
int col, val, day;
|
||||
|
||||
memset(p, ' ', (julian + DAY_LEN) * 7);
|
||||
|
||||
col = 0;
|
||||
do {
|
||||
day = *dp++;
|
||||
if (day != SPACE) {
|
||||
if ((day = *dp++) != SPACE) {
|
||||
if (julian) {
|
||||
++p;
|
||||
if (day >= 100) {
|
||||
@@ -300,8 +308,7 @@ static char *build_row(char *p, unsigned *dp)
|
||||
day %= 100;
|
||||
}
|
||||
}
|
||||
val = day / 10;
|
||||
if (val > 0) {
|
||||
if ((val = day / 10) > 0) {
|
||||
*p = val + '0';
|
||||
}
|
||||
*++p = day % 10 + '0';
|
||||
@@ -345,3 +352,5 @@ static char *build_row(char *p, unsigned *dp)
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
+16
-27
@@ -10,43 +10,32 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
|
||||
int bb_cat(char **argv)
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
static const char *const argv_dash[] = { "-", NULL };
|
||||
|
||||
int fd;
|
||||
FILE *f;
|
||||
int retval = EXIT_SUCCESS;
|
||||
|
||||
if (!*argv)
|
||||
argv = (char**) &argv_dash;
|
||||
getopt32(argc, argv, "u");
|
||||
|
||||
argv += optind;
|
||||
if (!*argv) {
|
||||
*--argv = "-";
|
||||
}
|
||||
|
||||
do {
|
||||
fd = STDIN_FILENO;
|
||||
if (!LONE_DASH(*argv))
|
||||
fd = open_or_warn(*argv, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
/* This is not an xfunc - never exits */
|
||||
off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
|
||||
if (fd != STDIN_FILENO)
|
||||
close(fd);
|
||||
if (r >= 0)
|
||||
f = fopen_or_warn_stdin(*argv);
|
||||
if (f) {
|
||||
off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
|
||||
fclose_if_not_stdin(f);
|
||||
if (r >= 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
retval = EXIT_FAILURE;
|
||||
} while (*++argv);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
int cat_main(int argc, char **argv);
|
||||
int cat_main(int argc, char **argv)
|
||||
{
|
||||
getopt32(argv, "u");
|
||||
argv += optind;
|
||||
return bb_cat(argv);
|
||||
}
|
||||
+13
-23
@@ -10,54 +10,44 @@
|
||||
/* See "Cat -v considered harmful" at
|
||||
* http://cm.bell-labs.com/cm/cs/doc/84/kp.ps.gz */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
int catv_main(int argc, char **argv);
|
||||
int catv_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int fd;
|
||||
int retval = EXIT_SUCCESS, fd;
|
||||
unsigned flags;
|
||||
|
||||
flags = getopt32(argv, "etv");
|
||||
flags = getopt32(argc, argv, "etv");
|
||||
#define CATV_OPT_e (1<<0)
|
||||
#define CATV_OPT_t (1<<1)
|
||||
#define CATV_OPT_v (1<<2)
|
||||
flags ^= CATV_OPT_v;
|
||||
argv += optind;
|
||||
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
fd = 0;
|
||||
if (!argv[0]) {
|
||||
argv--;
|
||||
goto jump_in;
|
||||
}
|
||||
argv += optind;
|
||||
do {
|
||||
fd = open_or_warn(*argv, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
/* Read from stdin if there's nothing else to do. */
|
||||
fd = 0;
|
||||
if (*argv && 0 > (fd = xopen(*argv, O_RDONLY)))
|
||||
retval = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
jump_in:
|
||||
for (;;) {
|
||||
else for (;;) {
|
||||
int i, res;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
res = read(fd, read_buf, COMMON_BUFSIZE);
|
||||
res = read(fd, bb_common_bufsiz1, sizeof(bb_common_bufsiz1));
|
||||
if (res < 0)
|
||||
retval = EXIT_FAILURE;
|
||||
if (res < 1)
|
||||
break;
|
||||
for (i = 0; i < res; i++) {
|
||||
unsigned char c = read_buf[i];
|
||||
char c = bb_common_bufsiz1[i];
|
||||
|
||||
if (c > 126 && (flags & CATV_OPT_v)) {
|
||||
if (c == 127) {
|
||||
printf("^?");
|
||||
continue;
|
||||
} else {
|
||||
printf("M-");
|
||||
c -= 128;
|
||||
}
|
||||
printf("M-");
|
||||
c -= 128;
|
||||
}
|
||||
if (c < 32) {
|
||||
if (c == 10) {
|
||||
|
||||
+2
-6
@@ -7,16 +7,12 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chgrp.html */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int chgrp_main(int argc, char **argv);
|
||||
int chgrp_main(int argc, char **argv)
|
||||
{
|
||||
/* "chgrp [opts] abc file(s)" == "chown [opts] :abc file(s)" */
|
||||
|
||||
+13
-16
@@ -14,10 +14,7 @@
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chmod.html */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
#define OPT_RECURSE (option_mask32 & 1)
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 2) SKIP_DESKTOP(0))
|
||||
@@ -34,7 +31,7 @@
|
||||
* symbolic links encountered during recursive directory traversals.
|
||||
*/
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk, int depth)
|
||||
{
|
||||
mode_t newmode;
|
||||
|
||||
@@ -49,8 +46,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
|
||||
}
|
||||
newmode = statbuf->st_mode;
|
||||
|
||||
if (!bb_parse_mode((char *)param, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)param);
|
||||
if (!bb_parse_mode((char *)junk, &newmode))
|
||||
bb_error_msg_and_die("invalid mode: %s", (char *)junk);
|
||||
|
||||
if (chmod(fileName, newmode) == 0) {
|
||||
if (OPT_VERBOSE
|
||||
@@ -67,7 +64,6 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* param, i
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chmod_main(int argc, char **argv);
|
||||
int chmod_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
@@ -93,7 +89,7 @@ int chmod_main(int argc, char **argv)
|
||||
|
||||
/* Parse options */
|
||||
opt_complementary = "-2";
|
||||
getopt32(argv, ("-"OPT_STR) + 1); /* Reuse string */
|
||||
getopt32(argc, argv, ("-"OPT_STR) + 1); /* Reuse string */
|
||||
argv += optind;
|
||||
|
||||
/* Restore option-like mode if needed */
|
||||
@@ -104,6 +100,8 @@ int chmod_main(int argc, char **argv)
|
||||
do {
|
||||
if (!recursive_action(*argv,
|
||||
OPT_RECURSE, // recurse
|
||||
FALSE, // follow links: coreutils doesn't
|
||||
FALSE, // depth first
|
||||
fileAction, // file action
|
||||
fileAction, // dir action
|
||||
smode, // user data
|
||||
@@ -119,12 +117,10 @@ int chmod_main(int argc, char **argv)
|
||||
/*
|
||||
Security: chmod is too important and too subtle.
|
||||
This is a test script (busybox chmod versus coreutils).
|
||||
Run it in empty directory.
|
||||
Run it in empty dir. Probably requires bash.
|
||||
|
||||
#!/bin/sh
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
create() {
|
||||
function create() {
|
||||
rm -rf $1; mkdir $1
|
||||
(
|
||||
cd $1 || exit 1
|
||||
@@ -137,16 +133,17 @@ create() {
|
||||
ln -s ../up dir/up
|
||||
)
|
||||
}
|
||||
tst() {
|
||||
function tst() {
|
||||
(cd test1; $t1 $1)
|
||||
(cd test2; $t2 $1)
|
||||
(cd test1; ls -lR) >out1
|
||||
(cd test2; ls -lR) >out2
|
||||
echo "chmod $1" >out.diff
|
||||
if ! diff -u out1 out2 >>out.diff; then exit 1; fi
|
||||
rm out.diff
|
||||
mv out.diff out1.diff
|
||||
}
|
||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||
t1="/tmp/busybox chmod"
|
||||
t2="/usr/bin/chmod"
|
||||
create test1; create test2
|
||||
tst "a+w file"
|
||||
tst "a-w dir"
|
||||
|
||||
+44
-117
@@ -7,52 +7,43 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT SUSv3 defects - unsupported options -H, -L, and -P. */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
static uid_t uid = -1;
|
||||
static gid_t gid = -1;
|
||||
|
||||
static int (*chown_func)(const char *, uid_t, gid_t) = chown;
|
||||
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
|
||||
#define BIT_RECURSE 1
|
||||
#define OPT_RECURSE (option_mask32 & 1)
|
||||
#define OPT_NODEREF (option_mask32 & 2)
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 0x04) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 0x08) SKIP_DESKTOP(0))
|
||||
#define OPT_VERBOSE (USE_DESKTOP(option_mask32 & 4) SKIP_DESKTOP(0))
|
||||
#define OPT_CHANGED (USE_DESKTOP(option_mask32 & 8) SKIP_DESKTOP(0))
|
||||
#define OPT_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))
|
||||
/* POSIX options
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
#define OPT_STR ("Rh" USE_DESKTOP("vcf"))
|
||||
|
||||
/* TODO:
|
||||
* -H if a command line argument is a symbolic link to a directory, traverse it
|
||||
* -L traverse every symbolic link to a directory encountered
|
||||
* -P do not traverse any symbolic links (default)
|
||||
* We do not conform to the following:
|
||||
* "Specifying more than one of -H, -L, and -P is not an error.
|
||||
* The last option specified shall determine the behavior of the utility." */
|
||||
/* -L */
|
||||
#define BIT_TRAVERSE 0x20
|
||||
#define OPT_TRAVERSE (USE_DESKTOP(option_mask32 & BIT_TRAVERSE) SKIP_DESKTOP(0))
|
||||
/* -H or -L */
|
||||
#define BIT_TRAVERSE_TOP (0x20|0x40)
|
||||
#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
|
||||
|
||||
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
|
||||
|
||||
static struct bb_uidgid_t ugid = { -1, -1 };
|
||||
*/
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
void *cf, int depth)
|
||||
void ATTRIBUTE_UNUSED *junk, int depth)
|
||||
{
|
||||
uid_t u = (ugid.uid == (uid_t)-1) ? statbuf->st_uid : ugid.uid;
|
||||
gid_t g = (ugid.gid == (gid_t)-1) ? statbuf->st_gid : ugid.gid;
|
||||
// TODO: -H/-L/-P
|
||||
// if (depth ... && S_ISLNK(statbuf->st_mode)) ....
|
||||
|
||||
if (!((chown_fptr)cf)(fileName, u, g)) {
|
||||
if (!chown_func(fileName,
|
||||
(uid == (uid_t)-1) ? statbuf->st_uid : uid,
|
||||
(gid == (gid_t)-1) ? statbuf->st_gid : gid)) {
|
||||
if (OPT_VERBOSE
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
|
||||
|| (OPT_CHANGED && (statbuf->st_uid != uid || statbuf->st_gid != gid))
|
||||
) {
|
||||
printf("changed ownership of '%s' to %u:%u\n",
|
||||
fileName, (unsigned)u, (unsigned)g);
|
||||
printf("changed ownership of '%s' to %u:%u\n", fileName, uid, gid);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
@@ -61,45 +52,43 @@ static int fileAction(const char *fileName, struct stat *statbuf,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int chown_main(int argc, char **argv);
|
||||
int chown_main(int argc, char **argv)
|
||||
{
|
||||
int retval = EXIT_SUCCESS;
|
||||
int flags;
|
||||
chown_fptr chown_func;
|
||||
char *groupName;
|
||||
|
||||
opt_complementary = "-2";
|
||||
getopt32(argv, OPT_STR);
|
||||
getopt32(argc, argv, OPT_STR);
|
||||
|
||||
if (OPT_NODEREF) chown_func = lchown;
|
||||
|
||||
argv += optind;
|
||||
|
||||
/* This matches coreutils behavior (almost - see below) */
|
||||
chown_func = chown;
|
||||
if (OPT_NODEREF
|
||||
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
|
||||
USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
|
||||
) {
|
||||
chown_func = lchown;
|
||||
/* First, check if there is a group name here */
|
||||
groupName = strchr(*argv, '.');
|
||||
if (!groupName) {
|
||||
groupName = strchr(*argv, ':');
|
||||
}
|
||||
|
||||
flags = ACTION_DEPTHFIRST; /* match coreutils order */
|
||||
if (OPT_RECURSE)
|
||||
flags |= ACTION_RECURSE;
|
||||
if (OPT_TRAVERSE_TOP)
|
||||
flags |= ACTION_FOLLOWLINKS_L0; /* -H/-L: follow links on depth 0 */
|
||||
if (OPT_TRAVERSE)
|
||||
flags |= ACTION_FOLLOWLINKS; /* follow links if -L */
|
||||
|
||||
parse_chown_usergroup_or_die(&ugid, argv[0]);
|
||||
/* Check for the username and groupname */
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = get_ug_id(groupName, bb_xgetgrnam);
|
||||
}
|
||||
if (--groupName != *argv)
|
||||
uid = get_ug_id(*argv, bb_xgetpwnam);
|
||||
++argv;
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
argv++;
|
||||
do {
|
||||
if (!recursive_action(*argv,
|
||||
flags, /* flags */
|
||||
fileAction, /* file action */
|
||||
fileAction, /* dir action */
|
||||
chown_func, /* user data */
|
||||
0) /* depth */
|
||||
OPT_RECURSE, // recurse
|
||||
FALSE, // follow links: TODO: -H/-L/-P
|
||||
FALSE, // depth first
|
||||
fileAction, // file action
|
||||
fileAction, // dir action
|
||||
NULL, // user data
|
||||
0) // depth
|
||||
) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
@@ -107,65 +96,3 @@ int chown_main(int argc, char **argv)
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
Testcase. Run in empty directory.
|
||||
|
||||
#!/bin/sh
|
||||
t1="/tmp/busybox chown"
|
||||
t2="/usr/bin/chown"
|
||||
create() {
|
||||
rm -rf $1; mkdir $1
|
||||
(
|
||||
cd $1 || exit 1
|
||||
mkdir dir dir2
|
||||
>up
|
||||
>file
|
||||
>dir/file
|
||||
>dir2/file
|
||||
ln -s dir linkdir
|
||||
ln -s file linkfile
|
||||
ln -s ../up dir/linkup
|
||||
ln -s ../dir2 dir/linkupdir2
|
||||
)
|
||||
chown -R 0:0 $1
|
||||
}
|
||||
tst() {
|
||||
create test1
|
||||
create test2
|
||||
echo "[$1]" >>test1.out
|
||||
echo "[$1]" >>test2.out
|
||||
(cd test1; $t1 $1) >>test1.out 2>&1
|
||||
(cd test2; $t2 $1) >>test2.out 2>&1
|
||||
(cd test1; ls -lnR) >out1
|
||||
(cd test2; ls -lnR) >out2
|
||||
echo "chown $1" >out.diff
|
||||
if ! diff -u out1 out2 >>out.diff; then exit 1; fi
|
||||
rm out.diff
|
||||
}
|
||||
tst_for_each() {
|
||||
tst "$1 1:1 file"
|
||||
tst "$1 1:1 dir"
|
||||
tst "$1 1:1 linkdir"
|
||||
tst "$1 1:1 linkfile"
|
||||
}
|
||||
echo "If script produced 'out.diff' file, then at least one testcase failed"
|
||||
>test1.out
|
||||
>test2.out
|
||||
# These match coreutils 6.8:
|
||||
tst_for_each "-v"
|
||||
tst_for_each "-vR"
|
||||
tst_for_each "-vRP"
|
||||
tst_for_each "-vRL"
|
||||
tst_for_each "-vRH"
|
||||
tst_for_each "-vh"
|
||||
tst_for_each "-vhR"
|
||||
tst_for_each "-vhRP"
|
||||
tst_for_each "-vhRL"
|
||||
tst_for_each "-vhRH"
|
||||
# Fix `name' in coreutils output
|
||||
sed 's/`/'"'"'/g' -i test2.out
|
||||
# Compare us with coreutils output
|
||||
diff -u test1.out test2.out
|
||||
|
||||
*/
|
||||
+4
-6
@@ -9,9 +9,8 @@
|
||||
|
||||
/* BB_AUDIT SUSv3 N/A -- Matches GNU behavior. */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
int chroot_main(int argc, char **argv);
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
@@ -27,13 +26,12 @@ int chroot_main(int argc, char **argv)
|
||||
++argv;
|
||||
if (argc == 2) {
|
||||
argv -= 2;
|
||||
argv[0] = getenv("SHELL");
|
||||
if (!argv[0]) {
|
||||
argv[0] = (char *) DEFAULT_SHELL;
|
||||
if (!(*argv = getenv("SHELL"))) {
|
||||
*argv = (char *) DEFAULT_SHELL;
|
||||
}
|
||||
argv[1] = (char *) "-i";
|
||||
}
|
||||
|
||||
BB_EXECVP(*argv, argv);
|
||||
execvp(*argv, argv);
|
||||
bb_perror_msg_and_die("cannot execute %s", *argv);
|
||||
}
|
||||
+5
-6
@@ -6,12 +6,12 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
int cksum_main(int argc, char **argv);
|
||||
int cksum_main(int argc, char **argv)
|
||||
{
|
||||
uint32_t *crc32_table = crc32_filltable(NULL, 1);
|
||||
|
||||
uint32_t *crc32_table = crc32_filltable(1);
|
||||
|
||||
FILE *fp;
|
||||
uint32_t crc;
|
||||
@@ -27,9 +27,8 @@ int cksum_main(int argc, char **argv)
|
||||
crc = 0;
|
||||
length = 0;
|
||||
|
||||
#define read_buf bb_common_bufsiz1
|
||||
while ((bytes_read = fread(read_buf, 1, BUFSIZ, fp)) > 0) {
|
||||
cp = read_buf;
|
||||
while ((bytes_read = fread(bb_common_bufsiz1, 1, BUFSIZ, fp)) > 0) {
|
||||
cp = bb_common_bufsiz1;
|
||||
length += bytes_read;
|
||||
while (bytes_read--)
|
||||
crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ (*cp++)) & 0xffL];
|
||||
|
||||
@@ -21,66 +21,52 @@
|
||||
* in the '-l' case.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
static FILE *cmp_xfopen_input(const char *filename)
|
||||
static FILE *cmp_xfopen_input(const char * const filename)
|
||||
{
|
||||
FILE *fp;
|
||||
|
||||
fp = fopen_or_warn_stdin(filename);
|
||||
if (fp)
|
||||
return fp;
|
||||
xfunc_die(); /* We already output an error message. */
|
||||
exit(xfunc_error_retval); /* We already output an error message. */
|
||||
}
|
||||
|
||||
static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n";
|
||||
static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"d, line %d\n";
|
||||
// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"d %o %o\n"
|
||||
static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"d %3o %3o\n";
|
||||
static const char fmt_eof[] = "cmp: EOF on %s\n";
|
||||
static const char fmt_differ[] = "%s %s differ: char %d, line %d\n";
|
||||
// This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%d %o %o\n"
|
||||
static const char fmt_l_opt[] = "%.0s%.0s%d %3o %3o\n";
|
||||
|
||||
static const char opt_chars[] ALIGN1 = "sl";
|
||||
static const char opt_chars[] = "sl";
|
||||
#define CMP_OPT_s (1<<0)
|
||||
#define CMP_OPT_l (1<<1)
|
||||
|
||||
int cmp_main(int argc, char **argv);
|
||||
int cmp_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp1, *fp2, *outfile = stdout;
|
||||
const char *filename1, *filename2 = "-";
|
||||
USE_DESKTOP(off_t skip1 = 0, skip2 = 0;)
|
||||
off_t char_pos = 0;
|
||||
int line_pos = 1; /* Hopefully won't overflow... */
|
||||
const char *fmt;
|
||||
int c1, c2;
|
||||
int c1, c2, char_pos = 0, line_pos = 1;
|
||||
unsigned opt;
|
||||
int retval = 0;
|
||||
|
||||
xfunc_error_retval = 2; /* 1 is returned if files are different. */
|
||||
|
||||
opt_complementary = "-1"
|
||||
USE_DESKTOP(":?4")
|
||||
SKIP_DESKTOP(":?2")
|
||||
":l--s:s--l";
|
||||
opt = getopt32(argv, opt_chars);
|
||||
argv += optind;
|
||||
opt = getopt32(argc, argv, opt_chars);
|
||||
|
||||
filename1 = *argv;
|
||||
fp1 = cmp_xfopen_input(filename1);
|
||||
if (((opt & (CMP_OPT_s|CMP_OPT_l)) == (CMP_OPT_s|CMP_OPT_l))
|
||||
|| (((unsigned int)(--argc - optind)) > 1))
|
||||
bb_show_usage();
|
||||
|
||||
fp1 = cmp_xfopen_input(filename1 = *(argv += optind));
|
||||
|
||||
if (*++argv) {
|
||||
filename2 = *argv;
|
||||
#if ENABLE_DESKTOP
|
||||
if (*++argv) {
|
||||
skip1 = XATOOFF(*argv);
|
||||
if (*++argv) {
|
||||
skip2 = XATOOFF(*argv);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
fp2 = cmp_xfopen_input(filename2);
|
||||
if (fp1 == fp2) { /* Paranoia check... stdin == stdin? */
|
||||
|
||||
if (fp1 == fp2) { /* Paranioa check... stdin == stdin? */
|
||||
/* Note that we don't bother reading stdin. Neither does gnu wc.
|
||||
* But perhaps we should, so that other apps down the chain don't
|
||||
* get the input. Consider 'echo hello | (cmp - - && cat -)'.
|
||||
@@ -93,10 +79,6 @@ int cmp_main(int argc, char **argv)
|
||||
else
|
||||
fmt = fmt_differ;
|
||||
|
||||
#if ENABLE_DESKTOP
|
||||
while (skip1) { getc(fp1); skip1--; }
|
||||
while (skip2) { getc(fp2); skip2--; }
|
||||
#endif
|
||||
do {
|
||||
c1 = getc(fp1);
|
||||
c2 = getc(fp2);
|
||||
+44
-31
@@ -7,36 +7,43 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#define COMM_OPT_1 (1 << 0)
|
||||
#define COMM_OPT_2 (1 << 1)
|
||||
#define COMM_OPT_3 (1 << 2)
|
||||
#define COMM_OPT_1 0x01
|
||||
#define COMM_OPT_2 0x02
|
||||
#define COMM_OPT_3 0x04
|
||||
|
||||
/* These three variables control behaviour if non-zero */
|
||||
|
||||
static int only_file_1;
|
||||
static int only_file_2;
|
||||
static int both;
|
||||
|
||||
/* writeline outputs the input given, appropriately aligned according to class */
|
||||
static void writeline(char *line, int class, int flags)
|
||||
static void writeline(char *line, int class)
|
||||
{
|
||||
if (class == 0) {
|
||||
if (flags & COMM_OPT_1)
|
||||
if (!only_file_1)
|
||||
return;
|
||||
} else if (class == 1) {
|
||||
if (flags & COMM_OPT_2)
|
||||
if (!only_file_2)
|
||||
return;
|
||||
if (!(flags & COMM_OPT_1))
|
||||
if (only_file_1)
|
||||
putchar('\t');
|
||||
} else /*if (class == 2)*/ {
|
||||
if (flags & COMM_OPT_3)
|
||||
}
|
||||
else /*if (class == 2)*/ {
|
||||
if (!both)
|
||||
return;
|
||||
if (!(flags & COMM_OPT_1))
|
||||
if (only_file_1)
|
||||
putchar('\t');
|
||||
if (!(flags & COMM_OPT_2))
|
||||
if (only_file_2)
|
||||
putchar('\t');
|
||||
}
|
||||
fputs(line, stdout);
|
||||
}
|
||||
|
||||
int comm_main(int argc, char **argv);
|
||||
int comm_main(int argc, char **argv)
|
||||
/* This is the real core of the program - lines are compared here */
|
||||
static void cmp_files(char **infiles)
|
||||
{
|
||||
#define LINE_LEN 100
|
||||
#define BB_EOF_0 0x1
|
||||
@@ -44,19 +51,12 @@ int comm_main(int argc, char **argv)
|
||||
char thisline[2][LINE_LEN];
|
||||
FILE *streams[2];
|
||||
int i;
|
||||
unsigned flags;
|
||||
|
||||
opt_complementary = "=2";
|
||||
flags = getopt32(argv, "123");
|
||||
argv += optind;
|
||||
|
||||
for (i = 0; i < 2; ++i) {
|
||||
streams[i] = (argv[i][0] == '-' && !argv[i][1]) ? stdin : xfopen(argv[i], "r");
|
||||
streams[i] = ((infiles[i][0] == '=' && infiles[i][1]) ? stdin : xfopen(infiles[i], "r"));
|
||||
fgets(thisline[i], LINE_LEN, streams[i]);
|
||||
}
|
||||
|
||||
/* This is the real core of the program - lines are compared here */
|
||||
|
||||
while (*thisline[0] || *thisline[1]) {
|
||||
int order = 0;
|
||||
|
||||
@@ -78,11 +78,11 @@ int comm_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (order == 0 && !i)
|
||||
writeline(thisline[1], 2, flags);
|
||||
writeline(thisline[1], 2);
|
||||
else if (order > 0 && !(i & BB_EOF_1))
|
||||
writeline(thisline[1], 1, flags);
|
||||
writeline(thisline[1], 1);
|
||||
else if (order < 0 && !(i & BB_EOF_0))
|
||||
writeline(thisline[0], 0, flags);
|
||||
writeline(thisline[0], 0);
|
||||
|
||||
if (i & BB_EOF_0 & BB_EOF_1) {
|
||||
break;
|
||||
@@ -91,7 +91,7 @@ int comm_main(int argc, char **argv)
|
||||
i = (i & BB_EOF_0 ? 1 : 0);
|
||||
while (!feof(streams[i])) {
|
||||
if ((order < 0 && i) || (order > 0 && !i))
|
||||
writeline(thisline[i], i, flags);
|
||||
writeline(thisline[i], i);
|
||||
fgets(thisline[i], LINE_LEN, streams[i]);
|
||||
}
|
||||
break;
|
||||
@@ -104,10 +104,23 @@ int comm_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
fclose(streams[0]);
|
||||
fclose(streams[1]);
|
||||
}
|
||||
fclose(streams[0]);
|
||||
fclose(streams[1]);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
int comm_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
flags = getopt32(argc, argv, "123");
|
||||
|
||||
if (optind + 2 != argc)
|
||||
bb_show_usage();
|
||||
|
||||
only_file_1 = !(flags & COMM_OPT_1);
|
||||
only_file_2 = !(flags & COMM_OPT_2);
|
||||
both = !(flags & COMM_OPT_3);
|
||||
|
||||
cmp_files(argv + optind);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
+3
-14
@@ -3,7 +3,6 @@
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
* SELinux support by Yuichi Nakamura <ynakam@hitachisoft.jp>
|
||||
*
|
||||
* Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
@@ -15,13 +14,9 @@
|
||||
* Size reduction.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
#include "libcoreutils/coreutils.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int cp_main(int argc, char **argv);
|
||||
int cp_main(int argc, char **argv)
|
||||
{
|
||||
struct stat source_stat;
|
||||
@@ -44,8 +39,8 @@ int cp_main(int argc, char **argv)
|
||||
// -P and -d are the same (-P is POSIX, -d is GNU)
|
||||
// -r and -R are the same
|
||||
// -a = -pdR
|
||||
opt_complementary = "l--s:s--l:Pd:rR:apdR";
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHL");
|
||||
opt_complementary = "?:l--s:s--l:Pd:rR:apdR";
|
||||
flags = getopt32(argc, argv, FILEUTILS_CP_OPTSTR "arPHL");
|
||||
/* Default behavior of cp is to dereference, so we don't have to do
|
||||
* anything special when we are given -L.
|
||||
* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||
@@ -54,12 +49,6 @@ int cp_main(int argc, char **argv)
|
||||
if (flags & OPT_H) ... // deref command-line params only
|
||||
*/
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
|
||||
selinux_or_die();
|
||||
}
|
||||
#endif
|
||||
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* The sense of this flag was reversed. */
|
||||
|
||||
if (optind + 2 > argc) {
|
||||
|
||||
+12
-15
@@ -9,13 +9,10 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
/* option vars */
|
||||
static const char optstring[] ALIGN1 = "b:c:f:d:sn";
|
||||
static const char optstring[] = "b:c:f:d:sn";
|
||||
#define CUT_OPT_BYTE_FLGS (1<<0)
|
||||
#define CUT_OPT_CHAR_FLGS (1<<1)
|
||||
#define CUT_OPT_FIELDS_FLGS (1<<2)
|
||||
@@ -163,19 +160,18 @@ static void cut_file(FILE * file)
|
||||
}
|
||||
}
|
||||
|
||||
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
|
||||
static const char _op_on_field[] = " only when operating on fields";
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
char *sopt, *ltok;
|
||||
|
||||
opt_complementary = "b--bcf:c--bcf:f--bcf";
|
||||
getopt32(argv, optstring, &sopt, &sopt, &sopt, <ok);
|
||||
// argc -= optind;
|
||||
argv += optind;
|
||||
getopt32(argc, argv, optstring, &sopt, &sopt, &sopt, <ok);
|
||||
if (!(option_mask32 & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
|
||||
bb_error_msg_and_die("expected a list of bytes, characters, or fields");
|
||||
if (option_mask32 & BB_GETOPT_ERROR)
|
||||
bb_error_msg_and_die("only one type of list may be specified");
|
||||
|
||||
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
|
||||
if (strlen(ltok) > 1) {
|
||||
@@ -266,21 +262,22 @@ int cut_main(int argc, char **argv)
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
}
|
||||
|
||||
/* argv[0..argc-1] should be names of file to process. If no
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[0] == NULL || LONE_DASH(argv[0])) {
|
||||
if (argv[optind] == NULL
|
||||
|| (argv[optind][0] == '-' && argv[optind][1] == '\0')) {
|
||||
cut_file(stdin);
|
||||
} else {
|
||||
FILE *file;
|
||||
|
||||
do {
|
||||
file = fopen_or_warn(argv[0], "r");
|
||||
for (; optind < argc; optind++) {
|
||||
file = fopen_or_warn(argv[optind], "r");
|
||||
if (file) {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
} while (*++argv);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(cut_lists);
|
||||
|
||||
+24
-22
@@ -10,7 +10,7 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
all the GNU strftime stuff (its in libc, lets use it),
|
||||
@@ -32,13 +32,18 @@
|
||||
#define DATE_OPT_TIMESPEC 0x20
|
||||
#define DATE_OPT_HINT 0x40
|
||||
|
||||
static void xputenv(char *s)
|
||||
{
|
||||
if (putenv(s) != 0)
|
||||
bb_error_msg_and_die(bb_msg_memory_exhausted);
|
||||
}
|
||||
|
||||
static void maybe_set_utc(int opt)
|
||||
{
|
||||
if (opt & DATE_OPT_UTC)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
xputenv("TZ=UTC0");
|
||||
}
|
||||
|
||||
int date_main(int argc, char **argv);
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
time_t tm;
|
||||
@@ -51,9 +56,9 @@ int date_main(int argc, char **argv)
|
||||
char *isofmt_arg;
|
||||
char *hintfmt_arg;
|
||||
|
||||
opt_complementary = "d--s:s--d"
|
||||
opt_complementary = "?:d--s:s--d"
|
||||
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
opt = getopt32(argv, "Rs:ud:r:"
|
||||
opt = getopt32(argc, argv, "Rs:ud:r:"
|
||||
USE_FEATURE_DATE_ISOFMT("I::D:"),
|
||||
&date_str, &date_str, &filename
|
||||
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
|
||||
@@ -63,16 +68,15 @@ int date_main(int argc, char **argv)
|
||||
if (!isofmt_arg) {
|
||||
ifmt = 0; /* default is date */
|
||||
} else {
|
||||
static const char *const isoformats[] = {
|
||||
"date", "hours", "minutes", "seconds"
|
||||
};
|
||||
const char * const isoformats[] =
|
||||
{"date", "hours", "minutes", "seconds"};
|
||||
|
||||
for (ifmt = 0; ifmt < 4; ifmt++)
|
||||
if (!strcmp(isofmt_arg, isoformats[ifmt]))
|
||||
goto found;
|
||||
/* parse error */
|
||||
bb_show_usage();
|
||||
found: ;
|
||||
if (!strcmp(isofmt_arg, isoformats[ifmt])) {
|
||||
break;
|
||||
}
|
||||
if (ifmt == 4) /* parse error */
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,36 +206,34 @@ int date_main(int argc, char **argv)
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i++] = 'S';
|
||||
}
|
||||
format_utc:
|
||||
format_utc:
|
||||
date_fmt[i++] = '%';
|
||||
date_fmt[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
||||
}
|
||||
} else if (opt & DATE_OPT_RFC2822) {
|
||||
/* Undo busybox.c for date -R */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
setlocale(LC_TIME, "C");
|
||||
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = 22;
|
||||
goto format_utc;
|
||||
} else /* default case */
|
||||
date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
date_fmt = "%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
|
||||
#define date_buf bb_common_bufsiz1
|
||||
if (*date_fmt == '\0') {
|
||||
/* With no format string, just print a blank line */
|
||||
date_buf[0] = '\0';
|
||||
*bb_common_bufsiz1 = 0;
|
||||
} else {
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
strftime(date_buf, sizeof(date_buf), date_fmt, &tm_time);
|
||||
strftime(bb_common_bufsiz1, 200, date_fmt, &tm_time);
|
||||
}
|
||||
puts(date_buf);
|
||||
puts(bb_common_bufsiz1);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+102
-188
@@ -8,11 +8,8 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */
|
||||
#include "libbb.h"
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
@@ -20,33 +17,26 @@ static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "kD", 1000 },
|
||||
{ "k", 1024 },
|
||||
{ "K", 1024 }, /* compat with coreutils dd */
|
||||
{ "K", 1024 }, // compat with coreutils dd
|
||||
{ "MD", 1000000 },
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ }
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
/* We have to zero it out because of NOEXEC */
|
||||
#define INIT_G() memset(&G, 0, sizeof(G))
|
||||
|
||||
static off_t out_full, out_part, in_full, in_part;
|
||||
|
||||
static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal)
|
||||
{
|
||||
/* 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);
|
||||
fprintf(stderr, "%"OFF_FMT"d+%"OFF_FMT"d records in\n"
|
||||
"%"OFF_FMT"d+%"OFF_FMT"d records out\n",
|
||||
in_full, in_part,
|
||||
out_full, out_part);
|
||||
}
|
||||
|
||||
static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
|
||||
const char *const filename)
|
||||
const char* filename)
|
||||
{
|
||||
ssize_t n = full_write(fd, buf, len);
|
||||
if (n < 0)
|
||||
@@ -54,193 +44,103 @@ static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
|
||||
return n;
|
||||
}
|
||||
|
||||
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
|
||||
const char *filename)
|
||||
{
|
||||
ssize_t n = full_write_or_warn(fd, buf, len, filename);
|
||||
if (n < 0)
|
||||
return 1;
|
||||
if (n == obs)
|
||||
G.out_full++;
|
||||
else if (n) /* > 0 */
|
||||
G.out_part++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_LFS
|
||||
#define XATOU_SFX xatoull_sfx
|
||||
#else
|
||||
#define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv);
|
||||
int dd_main(int argc, char **argv)
|
||||
{
|
||||
enum {
|
||||
FLAG_SYNC = 1 << 0,
|
||||
FLAG_NOERROR = 1 << 1,
|
||||
FLAG_NOTRUNC = 1 << 2,
|
||||
FLAG_TWOBUFS = 1 << 3,
|
||||
FLAG_COUNT = 1 << 4,
|
||||
sync_flag = 1 << 0,
|
||||
noerror = 1 << 1,
|
||||
trunc_flag = 1 << 2,
|
||||
twobufs_flag = 1 << 3,
|
||||
};
|
||||
static const char keywords[] ALIGN1 =
|
||||
"bs=\0""count=\0""seek=\0""skip=\0""if=\0""of=\0"
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
"ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0"
|
||||
#endif
|
||||
;
|
||||
enum {
|
||||
OP_bs = 1,
|
||||
OP_count,
|
||||
OP_seek,
|
||||
OP_skip,
|
||||
OP_if,
|
||||
OP_of,
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
OP_ibs,
|
||||
OP_obs,
|
||||
OP_conv,
|
||||
OP_conv_notrunc,
|
||||
OP_conv_sync,
|
||||
OP_conv_noerror,
|
||||
#endif
|
||||
};
|
||||
size_t ibs = 512, obs = 512;
|
||||
int flags = trunc_flag;
|
||||
size_t oc = 0, ibs = 512, obs = 512;
|
||||
ssize_t n, w;
|
||||
off_t seek = 0, skip = 0, count = OFF_T_MAX;
|
||||
int oflag, ifd, ofd;
|
||||
const char *infile = NULL, *outfile = NULL;
|
||||
char *ibuf, *obuf;
|
||||
/* And these are all zeroed at once! */
|
||||
struct {
|
||||
int flags;
|
||||
int ifd, ofd;
|
||||
size_t oc;
|
||||
off_t count;
|
||||
off_t seek, skip;
|
||||
const char *infile, *outfile;
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
struct sigaction sigact;
|
||||
#endif
|
||||
} Z;
|
||||
#define flags (Z.flags )
|
||||
#define ifd (Z.ifd )
|
||||
#define ofd (Z.ofd )
|
||||
#define oc (Z.oc )
|
||||
#define count (Z.count )
|
||||
#define seek (Z.seek )
|
||||
#define skip (Z.skip )
|
||||
#define infile (Z.infile )
|
||||
#define outfile (Z.outfile)
|
||||
#define sigact (Z.sigact )
|
||||
|
||||
memset(&Z, 0, sizeof(Z));
|
||||
INIT_G();
|
||||
if (ENABLE_FEATURE_DD_SIGNAL_HANDLING) {
|
||||
struct sigaction sa;
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
sigact.sa_handler = dd_output_status;
|
||||
sigact.sa_flags = SA_RESTART;
|
||||
sigemptyset(&sigact.sa_mask);
|
||||
sigaction(SIGUSR1, &sigact, NULL);
|
||||
#endif
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_handler = dd_output_status;
|
||||
sa.sa_flags = SA_RESTART;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sigaction(SIGUSR1, &sa, 0);
|
||||
}
|
||||
|
||||
for (n = 1; n < argc; n++) {
|
||||
smalluint key_len;
|
||||
smalluint what;
|
||||
char *key;
|
||||
char *arg = argv[n];
|
||||
|
||||
//XXX:FIXME: we reject plain "dd --" This would cost ~20 bytes, so..
|
||||
//if (*arg == '-' && *++arg == '-' && !*++arg) continue;
|
||||
key = strstr(arg, "=");
|
||||
if (key == NULL)
|
||||
bb_show_usage();
|
||||
key_len = key - arg + 1;
|
||||
key = xstrndup(arg, key_len);
|
||||
what = index_in_strings(keywords, key) + 1;
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(key);
|
||||
if (what == 0)
|
||||
bb_show_usage();
|
||||
arg += key_len;
|
||||
/* Must fit into positive ssize_t */
|
||||
#if ENABLE_FEATURE_DD_IBS_OBS
|
||||
if (what == OP_ibs) {
|
||||
ibs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_obs) {
|
||||
obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_conv) {
|
||||
while (1) {
|
||||
/* find ',', replace them with nil so we can use arg for
|
||||
* index_in_strings() without copying.
|
||||
* We rely on arg being non-null, else strchr would fault.
|
||||
*/
|
||||
key = strchr(arg, ',');
|
||||
if (key)
|
||||
*key = '\0';
|
||||
what = index_in_strings(keywords, arg) + 1;
|
||||
if (what < OP_conv_notrunc)
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
|
||||
if (what == OP_conv_notrunc)
|
||||
flags |= FLAG_NOTRUNC;
|
||||
if (what == OP_conv_sync)
|
||||
flags |= FLAG_SYNC;
|
||||
if (what == OP_conv_noerror)
|
||||
flags |= FLAG_NOERROR;
|
||||
if (!key) /* no ',' left, so this was the last specifier */
|
||||
break;
|
||||
arg = key + 1; /* skip this keyword and ',' */
|
||||
}
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (what == OP_bs) {
|
||||
ibs = obs = xatoul_range_sfx(arg, 1, ((size_t)-1L)/2, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", arg, 4))
|
||||
ibs = xatoul_range_sfx(arg+4, 0, ((size_t)-1L)/2, dd_suffixes);
|
||||
else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", arg, 4))
|
||||
obs = xatoul_range_sfx(arg+4, 0, ((size_t)-1L)/2, dd_suffixes);
|
||||
else if (!strncmp("bs=", arg, 3))
|
||||
ibs = obs = xatoul_range_sfx(arg+3, 0, ((size_t)-1L)/2, dd_suffixes);
|
||||
/* These can be large: */
|
||||
if (what == OP_count) {
|
||||
flags |= FLAG_COUNT;
|
||||
count = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_seek) {
|
||||
seek = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_skip) {
|
||||
skip = XATOU_SFX(arg, dd_suffixes);
|
||||
continue;
|
||||
}
|
||||
if (what == OP_if) {
|
||||
infile = arg;
|
||||
continue;
|
||||
}
|
||||
if (what == OP_of)
|
||||
outfile = arg;
|
||||
else if (!strncmp("count=", arg, 6))
|
||||
count = XATOU_SFX(arg+6, dd_suffixes);
|
||||
else if (!strncmp("seek=", arg, 5))
|
||||
seek = XATOU_SFX(arg+5, dd_suffixes);
|
||||
else if (!strncmp("skip=", arg, 5))
|
||||
skip = XATOU_SFX(arg+5, dd_suffixes);
|
||||
|
||||
else if (!strncmp("if=", arg, 3))
|
||||
infile = arg+3;
|
||||
else if (!strncmp("of=", arg, 3))
|
||||
outfile = arg+3;
|
||||
else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("conv=", arg, 5)) {
|
||||
arg += 5;
|
||||
while (1) {
|
||||
if (!strncmp("notrunc", arg, 7)) {
|
||||
flags &= ~trunc_flag;
|
||||
arg += 7;
|
||||
} else if (!strncmp("sync", arg, 4)) {
|
||||
flags |= sync_flag;
|
||||
arg += 4;
|
||||
} else if (!strncmp("noerror", arg, 7)) {
|
||||
flags |= noerror;
|
||||
arg += 7;
|
||||
} else {
|
||||
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
|
||||
}
|
||||
if (arg[0] == '\0') break;
|
||||
if (*arg++ != ',') bb_show_usage();
|
||||
}
|
||||
} else
|
||||
bb_show_usage();
|
||||
}
|
||||
//XXX:FIXME for huge ibs or obs, malloc'ing them isn't the brightest idea ever
|
||||
|
||||
ibuf = obuf = xmalloc(ibs);
|
||||
if (ibs != obs) {
|
||||
flags |= FLAG_TWOBUFS;
|
||||
flags |= twobufs_flag;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
|
||||
if (infile != NULL)
|
||||
ifd = xopen(infile, O_RDONLY);
|
||||
else {
|
||||
/* ifd = STDIN_FILENO; - it's zero and it's already there */
|
||||
ifd = STDIN_FILENO;
|
||||
infile = bb_msg_standard_input;
|
||||
}
|
||||
if (outfile != NULL) {
|
||||
int oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && !(flags & FLAG_NOTRUNC))
|
||||
if (outfile != NULL) {
|
||||
oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && (flags & trunc_flag))
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
ofd = xopen(outfile, oflag);
|
||||
|
||||
if (seek && !(flags & FLAG_NOTRUNC)) {
|
||||
if (seek && (flags & trunc_flag)) {
|
||||
if (ftruncate(ofd, seek * obs) < 0) {
|
||||
struct stat st;
|
||||
|
||||
@@ -253,45 +153,50 @@ int dd_main(int argc, char **argv)
|
||||
ofd = STDOUT_FILENO;
|
||||
outfile = bb_msg_standard_output;
|
||||
}
|
||||
|
||||
if (skip) {
|
||||
if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) {
|
||||
while (skip-- > 0) {
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n < 0)
|
||||
goto die_infile;
|
||||
bb_perror_msg_and_die("%s", infile);
|
||||
if (n == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (seek) {
|
||||
if (lseek(ofd, seek * obs, SEEK_CUR) < 0)
|
||||
goto die_outfile;
|
||||
}
|
||||
|
||||
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);
|
||||
while (in_full + in_part != count) {
|
||||
if (flags & noerror) {
|
||||
/* Pre-zero the buffer when doing the noerror thing */
|
||||
memset(ibuf, '\0', ibs);
|
||||
}
|
||||
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
if (flags & FLAG_NOERROR) {
|
||||
if (flags & noerror) {
|
||||
n = ibs;
|
||||
bb_perror_msg("%s", infile);
|
||||
} else
|
||||
goto die_infile;
|
||||
bb_perror_msg_and_die("%s", infile);
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (flags & FLAG_SYNC) {
|
||||
in_part++;
|
||||
if (flags & sync_flag) {
|
||||
memset(ibuf + n, '\0', ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
if (flags & FLAG_TWOBUFS) {
|
||||
if (flags & twobufs_flag) {
|
||||
char *tmp = ibuf;
|
||||
while (n) {
|
||||
size_t d = obs - oc;
|
||||
@@ -303,23 +208,32 @@ int dd_main(int argc, char **argv)
|
||||
tmp += d;
|
||||
oc += d;
|
||||
if (oc == obs) {
|
||||
if (write_and_stats(ofd, obuf, obs, obs, outfile))
|
||||
goto out_status;
|
||||
w = full_write_or_warn(ofd, obuf, obs, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w == obs)
|
||||
out_full++;
|
||||
else if (w > 0)
|
||||
out_part++;
|
||||
oc = 0;
|
||||
}
|
||||
}
|
||||
} else if (write_and_stats(ofd, ibuf, n, obs, outfile))
|
||||
goto out_status;
|
||||
} else {
|
||||
w = full_write_or_warn(ofd, ibuf, n, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w == obs)
|
||||
out_full++;
|
||||
else if (w > 0)
|
||||
out_part++;
|
||||
}
|
||||
}
|
||||
|
||||
if (ENABLE_FEATURE_DD_IBS_OBS && oc) {
|
||||
w = full_write_or_warn(ofd, obuf, oc, outfile);
|
||||
if (w < 0) goto out_status;
|
||||
if (w > 0)
|
||||
G.out_part++;
|
||||
out_part++;
|
||||
}
|
||||
if (close(ifd) < 0) {
|
||||
die_infile:
|
||||
bb_perror_msg_and_die("%s", infile);
|
||||
}
|
||||
|
||||
|
||||
+35
-32
@@ -18,36 +18,39 @@
|
||||
* the command line. Properly round *-blocks, Used, and Available quantities.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#if !ENABLE_FEATURE_HUMAN_READABLE
|
||||
static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
#ifndef CONFIG_FEATURE_HUMAN_READABLE
|
||||
static long kscale(long b, long bs)
|
||||
{
|
||||
return (b * (unsigned long long) bs + 1024/2) / 1024;
|
||||
return ( b * (long long) bs + 1024/2 ) / 1024;
|
||||
}
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv);
|
||||
int df_main(int argc, char **argv)
|
||||
{
|
||||
unsigned long blocks_used;
|
||||
unsigned blocks_percent_used;
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
unsigned df_disp_hr = 1024;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
unsigned long 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";
|
||||
static const char hdr_1k[] = "1k-blocks"; /* default display is kilobytes */
|
||||
const char *disp_units_hdr = hdr_1k;
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk";
|
||||
opt = getopt32(argv, "hmk");
|
||||
opt = getopt32(argc, argv, "hmk");
|
||||
if (opt & 1) {
|
||||
df_disp_hr = 0;
|
||||
disp_units_hdr = " Size";
|
||||
@@ -57,7 +60,7 @@ int df_main(int argc, char **argv)
|
||||
disp_units_hdr = "1M-blocks";
|
||||
}
|
||||
#else
|
||||
opt = getopt32(argv, "k");
|
||||
opt = getopt32(argc, argv, "k");
|
||||
#endif
|
||||
|
||||
printf("Filesystem%11s%-15sUsed Available Use%% Mounted on\n",
|
||||
@@ -72,7 +75,7 @@ int df_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
do {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
|
||||
@@ -90,7 +93,7 @@ int df_main(int argc, char **argv)
|
||||
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;
|
||||
}
|
||||
@@ -108,7 +111,7 @@ int df_main(int argc, char **argv)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = 0;
|
||||
if (blocks_used + s.f_bavail) {
|
||||
blocks_percent_used = (blocks_used * 100ULL
|
||||
blocks_percent_used = (((long long) blocks_used) * 100
|
||||
+ (blocks_used + s.f_bavail)/2
|
||||
) / (blocks_used + s.f_bavail);
|
||||
}
|
||||
@@ -124,28 +127,28 @@ int df_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf(" %9s ",
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
printf("%-20s %9s ", device,
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
printf(" %9s " + 1,
|
||||
make_human_readable_str((s.f_blocks - s.f_bfree),
|
||||
printf("%9s ",
|
||||
make_human_readable_str( (s.f_blocks - s.f_bfree),
|
||||
s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s %3u%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
printf("%9s %3ld%% %s\n",
|
||||
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);
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
} while (1);
|
||||
|
||||
fflush_stdout_and_exit(status);
|
||||
}
|
||||
+306
-347
File diff suppressed because it is too large.
Load diff
+4
-5
@@ -10,11 +10,10 @@
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/dirname.html */
|
||||
|
||||
#include "libbb.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int dirname_main(int argc, char **argv);
|
||||
int dirname_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
@@ -23,5 +22,5 @@ int dirname_main(int argc, char **argv)
|
||||
|
||||
puts(dirname(argv[1]));
|
||||
|
||||
return fflush(stdout);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+38
-34
@@ -12,47 +12,51 @@
|
||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
enum {
|
||||
enum ConvType {
|
||||
CT_UNIX2DOS = 1,
|
||||
CT_DOS2UNIX
|
||||
};
|
||||
} ConvType;
|
||||
|
||||
/* if fn is NULL then input is stdin and output is stdout */
|
||||
static int convert(char *fn, int conv_type)
|
||||
static int convert(char *fn)
|
||||
{
|
||||
FILE *in, *out;
|
||||
int i;
|
||||
#define name_buf bb_common_bufsiz1
|
||||
|
||||
in = stdin;
|
||||
out = stdout;
|
||||
if (fn != NULL) {
|
||||
in = xfopen(fn, "rw");
|
||||
/*
|
||||
The file is then created with mode read/write and
|
||||
permissions 0666 for glibc 2.0.6 and earlier or
|
||||
0600 for glibc 2.0.7 and later.
|
||||
0600 for glibc 2.0.7 and later.
|
||||
*/
|
||||
snprintf(name_buf, sizeof(name_buf), "%sXXXXXX", fn);
|
||||
i = mkstemp(&name_buf[0]);
|
||||
if (i == -1 || chmod(name_buf, 0600) == -1) {
|
||||
snprintf(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), "%sXXXXXX", fn);
|
||||
/*
|
||||
sizeof bb_common_bufsiz1 is 4096, so it should be big enough to
|
||||
hold the full path. However if the output is truncated the
|
||||
subsequent call to mkstemp would fail.
|
||||
*/
|
||||
if ((i = mkstemp(&bb_common_bufsiz1[0])) == -1
|
||||
|| chmod(bb_common_bufsiz1, 0600) == -1) {
|
||||
bb_perror_nomsg_and_die();
|
||||
}
|
||||
out = fdopen(i, "w+");
|
||||
if (!out) {
|
||||
close(i);
|
||||
remove(name_buf);
|
||||
return -2;
|
||||
remove(bb_common_bufsiz1);
|
||||
}
|
||||
} else {
|
||||
in = stdin;
|
||||
out = stdout;
|
||||
}
|
||||
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
if (i == '\r')
|
||||
continue;
|
||||
if (i == '\n') {
|
||||
if (conv_type == CT_UNIX2DOS)
|
||||
if (ConvType == CT_UNIX2DOS)
|
||||
fputc('\r', out);
|
||||
fputc('\n', out);
|
||||
continue;
|
||||
@@ -63,14 +67,14 @@ static int convert(char *fn, int conv_type)
|
||||
if (fn != NULL) {
|
||||
if (fclose(in) < 0 || fclose(out) < 0) {
|
||||
bb_perror_nomsg();
|
||||
remove(name_buf);
|
||||
remove(bb_common_bufsiz1);
|
||||
return -2;
|
||||
}
|
||||
/* Assume they are both on the same filesystem (which
|
||||
* should be true since we put them into the same directory
|
||||
* so we _should_ be ok, but you never know... */
|
||||
if (rename(name_buf, fn) < 0) {
|
||||
bb_perror_msg("cannot rename '%s' as '%s'", name_buf, fn);
|
||||
if (rename(bb_common_bufsiz1, fn) < 0) {
|
||||
bb_perror_msg("cannot rename '%s' as '%s'", bb_common_bufsiz1, fn);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -78,34 +82,34 @@ static int convert(char *fn, int conv_type)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char **argv);
|
||||
int dos2unix_main(int argc, char **argv)
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
{
|
||||
int o, conv_type;
|
||||
int o;
|
||||
|
||||
/* See if we are supposed to be doing dos2unix or unix2dos */
|
||||
if (applet_name[0] == 'd') {
|
||||
conv_type = CT_DOS2UNIX; /* 2 */
|
||||
ConvType = CT_DOS2UNIX; /*2 */
|
||||
} else {
|
||||
conv_type = CT_UNIX2DOS; /* 1 */
|
||||
ConvType = CT_UNIX2DOS; /*1 */
|
||||
}
|
||||
|
||||
/* -u convert to unix, -d convert to dos */
|
||||
opt_complementary = "u--d:d--u"; /* mutually exclusive */
|
||||
o = getopt32(argv, "du");
|
||||
/* -u and -d are mutally exclusive */
|
||||
opt_complementary = "?:u--d:d--u";
|
||||
/* process parameters */
|
||||
/* -u convert to unix */
|
||||
/* -d convert to dos */
|
||||
o = getopt32(argc, argv, "du");
|
||||
|
||||
/* Do the conversion requested by an argument else do the default
|
||||
* conversion depending on our name. */
|
||||
if (o)
|
||||
conv_type = o;
|
||||
ConvType = o;
|
||||
|
||||
do {
|
||||
/* might be convert(NULL) if there is no filename given */
|
||||
o = convert(argv[optind], conv_type);
|
||||
if (o < 0)
|
||||
break;
|
||||
optind++;
|
||||
} while (optind < argc);
|
||||
if (optind < argc) {
|
||||
while (optind < argc)
|
||||
if ((o = convert(argv[optind++])) < 0)
|
||||
break;
|
||||
} else
|
||||
o = convert(NULL);
|
||||
|
||||
return o;
|
||||
}
|
||||
+45
-40
@@ -23,24 +23,28 @@
|
||||
* 4) Fixed busybox bug #1284 involving long overflow with human_readable.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
# if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
# ifdef CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned long disp_hr = 1024;
|
||||
# else
|
||||
static unsigned long disp_hr = 512;
|
||||
# endif
|
||||
#elif ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned disp_k = 1;
|
||||
#elif defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
static unsigned int disp_k = 1;
|
||||
#else
|
||||
static unsigned disp_k; /* bss inits to 0 */
|
||||
static unsigned int disp_k; /* bss inits to 0 */
|
||||
#endif
|
||||
|
||||
static int max_print_depth = INT_MAX;
|
||||
static nlink_t count_hardlinks = 1;
|
||||
|
||||
static int status;
|
||||
static int status
|
||||
#if EXIT_SUCCESS == 0
|
||||
= EXIT_SUCCESS
|
||||
#endif
|
||||
;
|
||||
static int print_files;
|
||||
static int slink_depth;
|
||||
static int du_depth;
|
||||
@@ -48,12 +52,12 @@ static int one_file_system;
|
||||
static dev_t dir_dev;
|
||||
|
||||
|
||||
static void print(long size, const char *const filename)
|
||||
static void print(long size, const char * const filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, disp_hr),
|
||||
filename);
|
||||
filename);
|
||||
#else
|
||||
if (disp_k) {
|
||||
size++;
|
||||
@@ -64,12 +68,12 @@ static void print(long size, const char *const filename)
|
||||
}
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(const char *const filename)
|
||||
static long du(const char * const filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
|
||||
if (lstat(filename, &statbuf) != 0) {
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
return 0;
|
||||
@@ -87,7 +91,7 @@ static long du(const char *const filename)
|
||||
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
if (slink_depth > du_depth) { /* -H or -L */
|
||||
if (stat(filename, &statbuf) != 0) {
|
||||
if ((stat(filename, &statbuf)) != 0) {
|
||||
bb_perror_msg("%s", filename);
|
||||
status = EXIT_FAILURE;
|
||||
return 0;
|
||||
@@ -101,7 +105,7 @@ static long du(const char *const filename)
|
||||
|
||||
if (statbuf.st_nlink > count_hardlinks) {
|
||||
/* Add files/directories with links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf)) {
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
return 0;
|
||||
}
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
@@ -126,7 +130,7 @@ static long du(const char *const filename)
|
||||
char *name = entry->d_name;
|
||||
|
||||
newfile = concat_subpath_file(filename, name);
|
||||
if (newfile == NULL)
|
||||
if(newfile == NULL)
|
||||
continue;
|
||||
++du_depth;
|
||||
sum += du(newfile);
|
||||
@@ -143,7 +147,6 @@ static long du(const char *const filename)
|
||||
return sum;
|
||||
}
|
||||
|
||||
int du_main(int argc, char **argv);
|
||||
int du_main(int argc, char **argv)
|
||||
{
|
||||
long total;
|
||||
@@ -152,9 +155,9 @@ int du_main(int argc, char **argv)
|
||||
char *smax_print_depth;
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
#ifdef CONFIG_FEATURE_DU_DEFUALT_BLOCKSIZE_1K
|
||||
if (getenv("POSIXLY_CORRECT")) { /* TODO - a new libbb function? */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
disp_hr = 512;
|
||||
#else
|
||||
disp_k = 0;
|
||||
@@ -168,62 +171,62 @@ int du_main(int argc, char **argv)
|
||||
* gnu du exits with an error code in this case. We choose to simply
|
||||
* ignore -a. This is consistent with -s being equivalent to -d 0.
|
||||
*/
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
#ifdef CONFIG_FEATURE_HUMAN_READABLE
|
||||
opt_complementary = "h-km:k-hm:m-hk:H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
|
||||
if (opt & (1 << 9)) {
|
||||
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc" "hm", &smax_print_depth);
|
||||
if((opt & (1 << 9))) {
|
||||
/* -h opt */
|
||||
disp_hr = 0;
|
||||
}
|
||||
if (opt & (1 << 10)) {
|
||||
if((opt & (1 << 10))) {
|
||||
/* -m opt */
|
||||
disp_hr = 1024*1024;
|
||||
}
|
||||
if (opt & (1 << 2)) {
|
||||
if((opt & (1 << 2))) {
|
||||
/* -k opt */
|
||||
disp_hr = 1024;
|
||||
}
|
||||
#else
|
||||
opt_complementary = "H-L:L-H:s-d:d-s";
|
||||
opt = getopt32(argv, "aHkLsx" "d:" "lc", &smax_print_depth);
|
||||
#if !ENABLE_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if (opt & (1 << 2)) {
|
||||
opt = getopt32(argc, argv, "aHkLsx" "d:" "lc", &smax_print_depth);
|
||||
#if !defined CONFIG_FEATURE_DU_DEFAULT_BLOCKSIZE_1K
|
||||
if((opt & (1 << 2))) {
|
||||
/* -k opt */
|
||||
disp_k = 1;
|
||||
disp_k = 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
if (opt & (1 << 0)) {
|
||||
if((opt & (1 << 0))) {
|
||||
/* -a opt */
|
||||
print_files = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 1)) {
|
||||
if((opt & (1 << 1))) {
|
||||
/* -H opt */
|
||||
slink_depth = 1;
|
||||
}
|
||||
if (opt & (1 << 3)) {
|
||||
if((opt & (1 << 3))) {
|
||||
/* -L opt */
|
||||
slink_depth = INT_MAX;
|
||||
slink_depth = INT_MAX;
|
||||
}
|
||||
if (opt & (1 << 4)) {
|
||||
if((opt & (1 << 4))) {
|
||||
/* -s opt */
|
||||
max_print_depth = 0;
|
||||
}
|
||||
max_print_depth = 0;
|
||||
}
|
||||
one_file_system = opt & (1 << 5); /* -x opt */
|
||||
if (opt & (1 << 6)) {
|
||||
if((opt & (1 << 6))) {
|
||||
/* -d opt */
|
||||
max_print_depth = xatoi_u(smax_print_depth);
|
||||
}
|
||||
if (opt & (1 << 7)) {
|
||||
if((opt & (1 << 7))) {
|
||||
/* -l opt */
|
||||
count_hardlinks = MAXINT(nlink_t);
|
||||
count_hardlinks = INT_MAX;
|
||||
}
|
||||
print_final_total = opt & (1 << 8); /* -c opt */
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
argv += optind;
|
||||
if (optind >= argc) {
|
||||
*--argv = (char*)".";
|
||||
*--argv = ".";
|
||||
if (slink_depth == 1) {
|
||||
slink_depth = 0;
|
||||
}
|
||||
@@ -235,8 +238,10 @@ int du_main(int argc, char **argv)
|
||||
total += du(*argv);
|
||||
slink_depth = slink_depth_save;
|
||||
} while (*++argv);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
reset_ino_dev_hashtable();
|
||||
#ifdef CONFIG_FEATURE_CLEAN_UP
|
||||
reset_ino_dev_hashtable();
|
||||
#endif
|
||||
|
||||
if (print_final_total) {
|
||||
print(total, "total");
|
||||
}
|
||||
|
||||
+45
-52
@@ -20,109 +20,102 @@
|
||||
* 1) In handling '\c' escape, the previous version only suppressed the
|
||||
* trailing newline. SUSv3 specifies _no_ output after '\c'.
|
||||
* 2) SUSv3 specifies that octal escapes are of the form \0{#{#{#}}}.
|
||||
* The previous version did not allow 4-digit octals.
|
||||
* The previous version version did not allow 4-digit octals.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int bb_echo(char **argv)
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv)
|
||||
{
|
||||
const char *arg;
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
enum {
|
||||
eflag = '\\',
|
||||
nflag = 1, /* 1 -- print '\n' */
|
||||
};
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
#ifndef CONFIG_FEATURE_FANCY_ECHO
|
||||
#define eflag '\\'
|
||||
++argv;
|
||||
#else
|
||||
const char *p;
|
||||
char nflag = 1;
|
||||
char eflag = 0;
|
||||
|
||||
while (1) {
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
goto newline_ret;
|
||||
if (*arg != '-')
|
||||
break;
|
||||
int nflag = 1;
|
||||
int eflag = 0;
|
||||
|
||||
while (*++argv && (**argv == '-')) {
|
||||
/* If it appears that we are handling options, then make sure
|
||||
* that all of the options specified are actually valid.
|
||||
* Otherwise, the string should just be echoed.
|
||||
*/
|
||||
p = arg + 1;
|
||||
if (!*p) /* A single '-', so echo it. */
|
||||
|
||||
if (!*(p = *argv + 1)) { /* A single '-', so echo it. */
|
||||
goto just_echo;
|
||||
}
|
||||
|
||||
do {
|
||||
if (!strrchr("neE", *p))
|
||||
if (strrchr("neE", *p) == 0) {
|
||||
goto just_echo;
|
||||
}
|
||||
} while (*++p);
|
||||
|
||||
/* All of the options in this arg are valid, so handle them. */
|
||||
p = arg + 1;
|
||||
p = *argv + 1;
|
||||
do {
|
||||
if (*p == 'n')
|
||||
if (*p == 'n') {
|
||||
nflag = 0;
|
||||
if (*p == 'e')
|
||||
} else if (*p == 'e') {
|
||||
eflag = '\\';
|
||||
} else {
|
||||
eflag = 0;
|
||||
}
|
||||
} while (*++p);
|
||||
}
|
||||
just_echo:
|
||||
|
||||
just_echo:
|
||||
#endif
|
||||
while (1) {
|
||||
/* arg is already == *argv and isn't NULL */
|
||||
while (*argv) {
|
||||
int c;
|
||||
|
||||
if (!eflag) {
|
||||
/* optimization for very common case */
|
||||
fputs(arg, stdout);
|
||||
} else while ((c = *arg++)) {
|
||||
while ((c = *(*argv)++)) {
|
||||
if (c == eflag) { /* Check for escape seq. */
|
||||
if (*arg == 'c') {
|
||||
if (**argv == 'c') {
|
||||
/* '\c' means cancel newline and
|
||||
* ignore all subsequent chars. */
|
||||
goto ret;
|
||||
return 0;
|
||||
}
|
||||
#if !ENABLE_FEATURE_FANCY_ECHO
|
||||
#ifndef CONFIG_FEATURE_FANCY_ECHO
|
||||
/* SUSv3 specifies that octal escapes must begin with '0'. */
|
||||
if ( (((unsigned char)*arg) - '1') >= 7)
|
||||
if (((unsigned int)(**argv - '1')) >= 7)
|
||||
#endif
|
||||
{
|
||||
/* Since SUSv3 mandates a first digit of 0, 4-digit octals
|
||||
* of the form \0### are accepted. */
|
||||
if (*arg == '0' && ((unsigned char)(arg[1]) - '0') < 8) {
|
||||
arg++;
|
||||
if ((**argv == '0') && (((unsigned int)(argv[0][1] - '0')) < 8)) {
|
||||
(*argv)++;
|
||||
}
|
||||
/* bb_process_escape_sequence can handle nul correctly */
|
||||
c = bb_process_escape_sequence(&arg);
|
||||
c = bb_process_escape_sequence((const char **) argv);
|
||||
}
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
arg = *++argv;
|
||||
if (!arg)
|
||||
break;
|
||||
putchar(' ');
|
||||
if (*++argv) {
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
|
||||
newline_ret:
|
||||
#ifdef CONFIG_FEATURE_FANCY_ECHO
|
||||
if (nflag) {
|
||||
putchar('\n');
|
||||
}
|
||||
ret:
|
||||
return fflush(stdout);
|
||||
#else
|
||||
putchar('\n');
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int echo_main(int argc, char** argv);
|
||||
int echo_main(int argc, char** argv)
|
||||
{
|
||||
return bb_echo(argv);
|
||||
(void)bb_echo(argc, argv);
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*-
|
||||
|
||||
+19
-17
@@ -29,41 +29,43 @@
|
||||
* - use xfunc_error_retval
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <errno.h>
|
||||
#include <getopt.h> /* struct option */
|
||||
extern char **environ;
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
static const char env_longopts[] ALIGN1 =
|
||||
"ignore-environment\0" No_argument "i"
|
||||
"unset\0" Required_argument "u"
|
||||
;
|
||||
static const struct option env_long_options[] = {
|
||||
{ "ignore-environment", 0, NULL, 'i' },
|
||||
{ "unset", 1, NULL, 'u' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
int env_main(int argc, char** argv);
|
||||
int env_main(int argc, char** argv)
|
||||
{
|
||||
/* cleanenv was static - why? */
|
||||
char *cleanenv[1];
|
||||
static char *cleanenv[1] = { NULL };
|
||||
|
||||
char **ep;
|
||||
unsigned opt;
|
||||
llist_t *unset_env = NULL;
|
||||
extern char **environ;
|
||||
|
||||
opt_complementary = "u::";
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
applet_long_options = env_longopts;
|
||||
applet_long_options = env_long_options;
|
||||
#endif
|
||||
opt = getopt32(argv, "+iu:", &unset_env);
|
||||
|
||||
opt = getopt32(argc, argv, "+iu:", &unset_env);
|
||||
|
||||
argv += optind;
|
||||
if (*argv && LONE_DASH(argv[0])) {
|
||||
if (*argv && (argv[0][0] == '-') && !argv[0][1]) {
|
||||
opt |= 1;
|
||||
++argv;
|
||||
}
|
||||
if (opt & 1) {
|
||||
cleanenv[0] = NULL;
|
||||
|
||||
if (opt & 1)
|
||||
environ = cleanenv;
|
||||
} else {
|
||||
else if (opt & 2) {
|
||||
while (unset_env) {
|
||||
unsetenv(unset_env->data);
|
||||
unset_env = unset_env->link;
|
||||
@@ -78,7 +80,7 @@ int env_main(int argc, char** argv)
|
||||
}
|
||||
|
||||
if (*argv) {
|
||||
BB_EXECVP(*argv, argv);
|
||||
execvp(*argv, argv);
|
||||
/* SUSv3-mandated exit codes. */
|
||||
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
|
||||
bb_perror_msg_and_die("%s", *argv);
|
||||
|
||||
Loaded 100 of 779 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user