Compare commits

..
12 Commits
Author SHA1 Message Date
Denis Vlasenko 4a81fe4173 apply post-1.11.2 fixes, bump version to 1.11.3 2008-09-28 16:40:02 +00:00
Bernhard Reutner-Fischer 3e7eca97b9 - sync with trunk 2008-09-05 15:30:24 +00:00
Bernhard Reutner-Fischer 9e6fe061d4 - fix typo 2008-09-05 15:23:53 +00:00
Bernhard Reutner-Fischer a959a858a3 - pull r22872 from trunk:
pidof/killall: allow find_pid_by_name to find running
 processes started as scripts_with_name_longer_than_15_bytes.sh
 closes bug 4054 (and is generally neat)
2008-09-05 12:05:47 +00:00
Denis Vlasenko 2957fc6992 apply post-1.11.1 patches, bump version to 1.11.2 2008-08-21 08:32:12 +00:00
Bernhard Reutner-Fischer 6857e4e2f3 - fix typo 2008-08-06 17:39:05 +00:00
Bernhard Reutner-Fischer 9a22b56d36 - remove erroneous & from &var. By Vladimir. (r23056 from trunk) 2008-08-06 08:21:27 +00:00
Bernhard Reutner-Fischer a4d0cd0a31 - don't free user-supplied string (via -e)
- fix helptext
(r23046 from trunk)
2008-08-05 14:33:37 +00:00
Denis Vlasenko f2b846e277 cpio: dont use UNUSED_PARAM, it exists only in 1.11.1 2008-07-11 21:50:45 +00:00
Denis Vlasenko fa1649e9ac cpio: backport the fix for
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=466771
2008-07-11 21:47:23 +00:00
Denis Vlasenko dee8587d92 Apply post-1.11.0 patches. Bump version to 1.11.1. 2008-07-11 12:19:14 +00:00
Denis Vlasenko f941306199 defconfig fix; "help output to fd 2" fix 2008-06-25 12:52:37 +00:00
542 changed files with 6629 additions and 11160 deletions

No files matched your search

+41 -57
View File
@@ -21,15 +21,6 @@ config DESKTOP
Select this only if you plan to use busybox on full-blown
desktop machine with common Linux distro, not on an embedded box.
config EXTRA_COMPAT
bool "Provide compatible behavior for rare corner cases (bigger code)"
default n
help
This option makes grep, sed etc handle rare corner cases
(embedded NUL bytes and such). This makes code bigger and uses
some GNU extensions in libc. You probably only need this option
if you plan to run busybox on desktop.
config FEATURE_ASSUME_UNICODE
bool "Assume that 1:1 char/glyph correspondence is not true"
default n
@@ -49,7 +40,7 @@ choice
There are 3 ways BusyBox can handle buffer allocations:
- Use malloc. This costs code size for the call to xmalloc.
- Put them on stack. For some very small machines with limited stack
space, this can be deadly. For most folks, this works just fine.
space, this can be deadly. For most folks, this works just fine.
- Put them in BSS. This works beautifully for computers with a real
MMU (and OS support), but wastes runtime RAM for uCLinux. This
behavior was the only one available for BusyBox versions 0.48 and
@@ -81,8 +72,8 @@ config FEATURE_VERBOSE_USAGE
select SHOW_USAGE
help
All BusyBox applets will show more verbose help messages when
busybox is invoked with --help. This will add a lot of text to the
busybox binary. In the default configuration, this will add about
busybox is invoked with --help. This will add a lot of text to the
busybox binary. In the default configuration, this will add about
13k, but it can add much more depending on your configuration.
config FEATURE_COMPRESS_USAGE
@@ -95,15 +86,15 @@ config FEATURE_COMPRESS_USAGE
If you have a really tiny busybox with few applets enabled (and
bunzip2 isn't one of them), the overhead of the decompressor might
be noticeable. Also, if you run executables directly from ROM
and have very little memory, this might not be a win. Otherwise,
be noticeable. Also, if you run executables directly from ROM
and have very little memory, this might not be a win. Otherwise,
you probably want this.
config FEATURE_INSTALLER
bool "Support --install [-s] to install applet links at runtime"
default n
help
Enable 'busybox --install [-s]' support. This will allow you to use
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.
@@ -127,7 +118,7 @@ config FEATURE_DEVPTS
help
Enable if you want BusyBox to use Unix98 PTY support. If enabled,
busybox will use /dev/ptmx for the master side of the pseudoterminal
and /dev/pts/<number> for the slave side. Otherwise, BSD style
and /dev/pts/<number> for the slave side. Otherwise, BSD style
/dev/ttyp<number> will be used. To use this option, you should have
devpts mounted.
@@ -136,7 +127,7 @@ config FEATURE_CLEAN_UP
default n
help
As a size optimization, busybox normally exits without explicitly
freeing dynamically allocated memory or closing files. This saves
freeing dynamically allocated memory or closing files. This saves
space since the OS will clean up for us, but it can confuse debuggers
like valgrind, which report tons of memory and resource leaks.
@@ -161,7 +152,7 @@ config FEATURE_SUID
If you're really paranoid and don't want to do this, build two
busybox binaries with different applets in them (and the appropriate
symlinks pointing to each binary), and only set the suid bit on the
one that needs it. The applets currently marked to need the suid bit
one that needs it. The applets currently marked to need the suid bit
are login, passwd, su, ping, traceroute, crontab, dnsd, ipcrm, ipcs,
and vlock.
@@ -171,7 +162,7 @@ config FEATURE_SUID_CONFIG
depends on FEATURE_SUID
help
Allow the SUID / SGID state of an applet to be determined at runtime
by checking /etc/busybox.conf. (This is sort of a poor man's sudo.)
by checking /etc/busybox.conf. (This is sort of a poor man's sudo.)
The format of this file is as follows:
<applet> = [Ssx-][Ssx-][x-] (<username>|<uid>).(<groupname>|<gid>)
@@ -179,12 +170,11 @@ config FEATURE_SUID_CONFIG
An example might help:
[SUID]
su = ssx root.0 # applet su can be run by anyone and runs with
# euid=0/egid=0
su = ssx root.0 # applet su can be run by anyone and runs with euid=0/egid=0
su = ssx # exactly the same
mount = sx- root.disk # applet mount can be run by root and members
# of group disk and runs with euid=0
mount = sx- root.disk # applet mount can be run by root and members of group disk
# and runs with euid=0
cp = --- # disable applet cp for everyone
@@ -203,15 +193,14 @@ config FEATURE_SUID_CONFIG_QUIET
default y
depends on FEATURE_SUID_CONFIG
help
/etc/busybox.conf should be readable by the user needing the SUID,
check this option to avoid users to be notified about missing
permissions.
/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 SELINUX
bool "Support NSA Security Enhanced Linux"
default n
help
Enable support for SELinux in applets ls, ps, and id. Also provide
Enable support for SELinux in applets ls, ps, and id. Also provide
the option of compiling in SELinux applets.
If you do not have a complete SELinux userland installed, this stuff
@@ -246,9 +235,9 @@ config BUSYBOX_EXEC_PATH
default "/proc/self/exe"
help
When Busybox applets need to run other busybox applets, BusyBox
sometimes needs to exec() itself. When the /proc filesystem is
sometimes needs to exec() itself. When the /proc filesystem is
mounted, /proc/self/exe always points to the currently running
executable. If you haven't got /proc, set this to wherever you
executable. If you haven't got /proc, set this to wherever you
want to run BusyBox from.
# These are auto-selected by other options
@@ -315,7 +304,7 @@ config BUILD_LIBBUSYBOX
busybox code.
This feature allows every applet to be built as a tiny
separate executable. Enabling it for "one big busybox binary"
separate executable. Enabling it for "one big busybox binary"
approach serves no purpose and increases code size.
You should almost certainly say "no" to this.
@@ -332,7 +321,7 @@ config BUILD_LIBBUSYBOX
### standalone application which uses libbusybox say 'Y'.
###
### Note: libbusybox is GPL, not LGPL, and exports no stable API that
### might act as a copyright barrier. We can and will modify the
### might act as a copyright barrier. We can and will modify the
### exported function set between releases (even minor version number
### changes), and happily break out-of-tree features.
###
@@ -341,7 +330,7 @@ config BUILD_LIBBUSYBOX
config FEATURE_INDIVIDUAL
bool "Produce a binary for each applet, linked against libbusybox"
default y
depends on BUILD_LIBBUSYBOX
depends on !STATIC && BUILD_LIBBUSYBOX
help
If your CPU architecture doesn't allow for sharing text/rodata
sections of running binaries, but allows for runtime dynamic
@@ -359,7 +348,7 @@ config FEATURE_INDIVIDUAL
config FEATURE_SHARED_BUSYBOX
bool "Produce additional busybox binary linked against libbusybox"
default y
depends on BUILD_LIBBUSYBOX
depends on !STATIC && BUILD_LIBBUSYBOX
help
Build busybox, dynamically linked against libbusybox.so.N.N.N.
@@ -390,11 +379,11 @@ config LFS
select FDISK_SUPPORT_LARGE_DISKS
help
If you want to build BusyBox with large file support, then enable
this option. This will have no effect if your kernel or your C
library lacks large file support for large files. Some of the
this option. This will have no effect if your kernel or your C
library lacks large file support for large files. Some of the
programs that can benefit from large file support include dd, gzip,
cp, mount, tar, and many others. If you want to access files larger
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
cp, mount, tar, and many others. If you want to access files larger
than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'.
config CROSS_COMPILER_PREFIX
string "Cross Compiler prefix"
@@ -415,20 +404,20 @@ config DEBUG
default n
help
Say Y here if you wish to examine BusyBox internals while applets are
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
running. This increases the size of the binary considerably, and
should only be used when doing development. If you are doing
development and want to debug BusyBox, answer Y.
Most people should answer N.
config DEBUG_PESSIMIZE
bool "Disable compiler optimizations"
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
stepping through it with a debugger. This switches it off, resulting
in a much bigger executable that more closely matches the source
code.
@@ -445,28 +434,27 @@ choice
default NO_DEBUG_LIB
help
Using an additional debugging library will make BusyBox become
considerable larger and will cause it to run more slowly. You
considerable larger and will cause it to run more slowly. You
should always leave this option disabled for production use.
dmalloc support:
----------------
This enables compiling with dmalloc ( http://dmalloc.com/ )
which is an excellent public domain mem leak and malloc problem
detector. To enable dmalloc, before running busybox you will
detector. To enable dmalloc, before running busybox you will
want to properly set your environment, for example:
export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile
The 'debug=' value is generated using the following command
dmalloc -p log-stats -p log-non-free -p log-bad-space \
-p log-elapsed-time -p check-fence -p check-heap \
-p check-lists -p check-blank -p check-funcs -p realloc-copy \
-p allow-free-null
dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
-p check-fence -p check-heap -p check-lists -p check-blank \
-p check-funcs -p realloc-copy -p allow-free-null
Electric-fence support:
-----------------------
This enables compiling with Electric-fence support. Electric
This enables compiling with Electric-fence support. Electric
fence is another very useful malloc debugging library which uses
your computer's virtual memory hardware to detect illegal memory
accesses. This support will make BusyBox be considerable larger
accesses. This support will make BusyBox be considerable larger
and run slower, so you should leave this option disabled unless
you are hunting a hard to find memory problem.
@@ -488,12 +476,9 @@ config INCLUDE_SUSv2
help
This option will enable backwards compatibility with SuSv2,
specifically, old-style numeric options ('command -1 <file>')
will be supported in head, tail, and fold. (Note: should
will be supported in head, tail, and fold. (Note: should
affect renice too.)
config PARSE
bool "Uniform config file parser debugging applet: parse"
endmenu
menu 'Installation Options'
@@ -521,8 +506,8 @@ config INSTALL_APPLET_SYMLINKS
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.
Install applets as hard-links to the busybox binary. This might count
on a filesystem with few inodes.
config INSTALL_APPLET_SCRIPT_WRAPPERS
bool "as script wrappers"
@@ -558,8 +543,7 @@ config INSTALL_SH_APPLET_HARDLINK
config INSTALL_SH_APPLET_SCRIPT_WRAPPER
bool "as script wrapper"
help
Install /bin/sh applet as script wrapper that call the busybox
binary.
Install /bin/sh applet as script wrapper that call the busybox binary.
endchoice
+9 -11
View File
@@ -1,6 +1,6 @@
VERSION = 1
PATCHLEVEL = 12
SUBLEVEL = 2
PATCHLEVEL = 11
SUBLEVEL = 3
EXTRAVERSION =
NAME = Unnamed
@@ -932,9 +932,8 @@ endif # CONFIG_MODULES
# make distclean Remove editor backup files, patch leftover files and the like
# Directories & files removed with 'make clean'
CLEAN_DIRS += $(MODVERDIR) _install 0_lib
CLEAN_FILES += busybox busybox_unstripped* busybox.links \
System.map .kernelrelease \
CLEAN_DIRS += $(MODVERDIR)
CLEAN_FILES += busybox busybox_unstripped* System.map .kernelrelease \
.tmp_kallsyms* .tmp_version .tmp_busybox* .tmp_System.map
# Directories & files removed with 'make mrproper'
@@ -945,8 +944,7 @@ MRPROPER_FILES += .config .config.old include/asm .version .old_version \
include/usage_compressed.h \
include/applet_tables.h \
applets/usage \
.kernelrelease Module.symvers tags TAGS cscope* \
busybox_old
.kernelrelease Module.symvers tags TAGS cscope*
# clean - Delete most, but leave enough to build external modules
#
@@ -962,7 +960,7 @@ clean: archclean $(clean-dirs)
$(call cmd,rmdirs)
$(call cmd,rmfiles)
@find . $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-type f -print | xargs rm -f
@@ -986,9 +984,9 @@ PHONY += distclean
distclean: mrproper
@find $(srctree) $(RCS_FIND_IGNORE) \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
-o -name '.*.rej' -o -name '*.tmp' -o -size 0 \
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f
@@ -1092,7 +1090,7 @@ clean: rm-dirs := $(MODVERDIR)
clean: $(clean-dirs)
$(call cmd,rmdirs)
@find $(KBUILD_EXTMOD) $(RCS_FIND_IGNORE) \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
\( -name '*.[oas]' -o -name '*.ko' -o -name '.*.cmd' \
-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \) \
-type f -print | xargs rm -f
+1 -2
View File
@@ -44,13 +44,12 @@ CFLAGS += $(call cc-option,-falign-functions=1 -falign-jumps=1 -falign-labels=1
# FIXME: These warnings are at least partially to be concerned about and should
# be fixed..
#CFLAGS += $(call cc-option,-Wconversion,)
#CFLAGS+=$(call cc-option,-Wconversion,)
ifneq ($(CONFIG_DEBUG),y)
CFLAGS += $(call cc-option,-Os,)
else
CFLAGS += $(call cc-option,-g,)
#CFLAGS += "-D_FORTIFY_SOURCE=2"
ifeq ($(CONFIG_DEBUG_PESSIMIZE),y)
CFLAGS += $(call cc-option,-O0,)
else
+6 -4
View File
@@ -122,7 +122,7 @@ bugs:
illegal instruction
i am using debian unstable, kernel version 2.4.25-vrs2 on a netwinder,
and the latest uclibc from cvs.
and the latest uclibc from cvs. thanks for the wonderful program!
-diligent
@@ -173,8 +173,10 @@ Portability:
you're into that sort of thing, start small (selecting just a few applets)
and work your way up.
In 2005 Shaun Jackman has ported busybox to a combination of newlib
and libgloss, and some of his patches have been integrated.
Shaun Jackman has recently (2005) ported busybox to a combination of newlib
and libgloss, and some of his patches have been integrated. This platform
may join glibc/uclibc and Linux as a supported combination with the 1.1
release, but is not supported in 1.0.
Supported hardware:
@@ -195,5 +197,5 @@ Supported hardware:
Please feed suggestions, bug reports, insults, and bribes back to the busybox
maintainer:
Denys Vlasenko
Denis Vlasenko
<vda.linux@googlemail.com>
+40 -50
View File
@@ -1,7 +1,7 @@
#
# Automatically generated make config: don't edit
# Busybox version: 1.12.0.svn
# Wed Aug 20 00:24:07 2008
# Busybox version: 1.11.0.svn
# Mon Apr 21 23:20:35 2008
#
CONFIG_HAVE_DOT_CONFIG=y
@@ -13,8 +13,6 @@ CONFIG_HAVE_DOT_CONFIG=y
# General Configuration
#
CONFIG_DESKTOP=y
# CONFIG_EXTRA_COMPAT is not set
CONFIG_FEATURE_ASSUME_UNICODE=y
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
@@ -40,25 +38,21 @@ CONFIG_FEATURE_HAVE_RPC=y
# Build Options
#
# CONFIG_STATIC is not set
# CONFIG_PIE is not set
CONFIG_NOMMU=y
# CONFIG_BUILD_LIBBUSYBOX is not set
# CONFIG_FEATURE_INDIVIDUAL is not set
# CONFIG_FEATURE_SHARED_BUSYBOX is not set
CONFIG_LFS=y
CONFIG_CROSS_COMPILER_PREFIX=""
#
# Debugging Options
#
# CONFIG_DEBUG is not set
# CONFIG_DEBUG_PESSIMIZE is not set
# CONFIG_WERROR is not set
CONFIG_NO_DEBUG_LIB=y
# CONFIG_DMALLOC is not set
# CONFIG_EFENCE is not set
CONFIG_INCLUDE_SUSv2=y
# CONFIG_PARSE is not set
#
# Installation Options
@@ -92,7 +86,6 @@ CONFIG_FEATURE_VERBOSE_CP_MESSAGE=y
CONFIG_FEATURE_COPYBUF_KB=4
CONFIG_MONOTONIC_SYSCALL=y
CONFIG_IOCTL_HEX2STR_ERROR=y
CONFIG_FEATURE_HWIB=y
#
# Applets
@@ -101,10 +94,6 @@ CONFIG_FEATURE_HWIB=y
#
# Archival Utilities
#
CONFIG_FEATURE_SEAMLESS_LZMA=y
CONFIG_FEATURE_SEAMLESS_BZ2=y
CONFIG_FEATURE_SEAMLESS_GZ=y
CONFIG_FEATURE_SEAMLESS_Z=y
CONFIG_AR=y
CONFIG_FEATURE_AR_LONG_FILENAMES=y
CONFIG_BUNZIP2=y
@@ -115,11 +104,17 @@ CONFIG_DPKG=y
CONFIG_DPKG_DEB=y
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
CONFIG_GUNZIP=y
CONFIG_FEATURE_GUNZIP_UNCOMPRESS=y
CONFIG_GZIP=y
CONFIG_RPM2CPIO=y
CONFIG_RPM=y
CONFIG_FEATURE_RPM_BZ2=y
CONFIG_TAR=y
CONFIG_FEATURE_TAR_CREATE=y
CONFIG_FEATURE_TAR_GZIP=y
CONFIG_FEATURE_TAR_BZIP2=y
CONFIG_FEATURE_TAR_LZMA=y
CONFIG_FEATURE_TAR_COMPRESS=y
CONFIG_FEATURE_TAR_AUTODETECT=y
CONFIG_FEATURE_TAR_FROM=y
CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY=y
@@ -132,6 +127,17 @@ CONFIG_UNLZMA=y
CONFIG_FEATURE_LZMA_FAST=y
CONFIG_UNZIP=y
#
# Common options for cpio and tar
#
#
# Common options for dpkg and dpkg_deb
#
CONFIG_FEATURE_DEB_TAR_GZ=y
CONFIG_FEATURE_DEB_TAR_BZ2=y
CONFIG_FEATURE_DEB_TAR_LZMA=y
#
# Coreutils
#
@@ -210,7 +216,6 @@ CONFIG_SEQ=y
CONFIG_SHA1SUM=y
CONFIG_SLEEP=y
CONFIG_FEATURE_FANCY_SLEEP=y
CONFIG_FEATURE_FLOAT_SLEEP=y
CONFIG_SORT=y
CONFIG_FEATURE_SORT_BIG=y
CONFIG_SPLIT=y
@@ -282,10 +287,8 @@ CONFIG_RESIZE=y
CONFIG_FEATURE_RESIZE_PRINT=y
CONFIG_SETCONSOLE=y
CONFIG_FEATURE_SETCONSOLE_LONG_OPTIONS=y
CONFIG_SETFONT=y
CONFIG_SETKEYCODES=y
CONFIG_SETLOGCONS=y
CONFIG_SHOWKEY=y
#
# Debian Utilities
@@ -383,9 +386,8 @@ CONFIG_MESG=y
# Login/Password Management Utilities
#
CONFIG_FEATURE_SHADOWPASSWDS=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_USE_BB_SHADOW=y
CONFIG_USE_BB_CRYPT=y
CONFIG_USE_BB_PWD_GRP=y
CONFIG_ADDGROUP=y
CONFIG_FEATURE_ADDUSER_TO_GROUP=y
CONFIG_DELGROUP=y
@@ -422,30 +424,25 @@ CONFIG_LSATTR=y
#
# Linux Module Utilities
#
CONFIG_MODPROBE_SMALL=y
CONFIG_FEATURE_MODPROBE_SMALL_OPTIONS_ON_CMDLINE=y
CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
# CONFIG_DEPMOD is not set
# CONFIG_FEATURE_DEPMOD_PRUNE_FANCY is not set
# CONFIG_FEATURE_DEPMOD_ALIAS is not set
# CONFIG_INSMOD is not set
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP is not set
# CONFIG_FEATURE_INSMOD_LOAD_MAP_FULL is not set
# CONFIG_RMMOD is not set
# CONFIG_LSMOD is not set
# CONFIG_FEATURE_LSMOD_PRETTY_2_6_OUTPUT is not set
# CONFIG_MODPROBE is not set
# CONFIG_FEATURE_MODPROBE_MULTIPLE_OPTIONS is not set
# CONFIG_FEATURE_MODPROBE_FANCY_ALIAS is not set
# CONFIG_FEATURE_MODPROBE_BLACKLIST is not set
# CONFIG_FEATURE_CHECK_TAINTED_MODULE is not set
# CONFIG_FEATURE_2_4_MODULES is not set
# CONFIG_FEATURE_2_6_MODULES is not set
CONFIG_DEFAULT_MODULES_DIR="/lib/modules"
CONFIG_DEFAULT_DEPMOD_FILE="modules.dep"
CONFIG_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
#
@@ -523,13 +520,11 @@ CONFIG_FEATURE_MOUNT_FLAGS=y
CONFIG_FEATURE_MOUNT_FSTAB=y
CONFIG_PIVOT_ROOT=y
CONFIG_RDATE=y
CONFIG_RDEV=y
CONFIG_READPROFILE=y
CONFIG_RTCWAKE=y
CONFIG_SCRIPT=y
CONFIG_SETARCH=y
CONFIG_SWAPONOFF=y
CONFIG_FEATURE_SWAPON_PRI=y
CONFIG_SWITCH_ROOT=y
CONFIG_UMOUNT=y
CONFIG_FEATURE_UMOUNT_ALL=y
@@ -567,10 +562,7 @@ CONFIG_DC=y
CONFIG_EJECT=y
CONFIG_FEATURE_EJECT_SCSI=y
CONFIG_FBSPLASH=y
CONFIG_INOTIFYD=y
CONFIG_LAST=y
CONFIG_FEATURE_LAST_SMALL=y
# CONFIG_FEATURE_LAST_FANCY is not set
CONFIG_LESS=y
CONFIG_FEATURE_LESS_MAXLINES=9999999
CONFIG_FEATURE_LESS_BRACKETS=y
@@ -598,6 +590,7 @@ CONFIG_RUNLEVEL=y
CONFIG_RX=y
CONFIG_SETSID=y
CONFIG_STRINGS=y
CONFIG_SYMLINKS=y
CONFIG_TASKSET=y
CONFIG_FEATURE_TASKSET_FANCY=y
CONFIG_TIME=y
@@ -682,7 +675,6 @@ CONFIG_NC_SERVER=y
CONFIG_NC_EXTRA=y
CONFIG_NETSTAT=y
CONFIG_FEATURE_NETSTAT_WIDE=y
CONFIG_FEATURE_NETSTAT_PRG=y
CONFIG_NSLOOKUP=y
CONFIG_PING=y
CONFIG_PING6=y
@@ -773,7 +765,6 @@ CONFIG_FEATURE_SH_IS_NONE=y
# CONFIG_ASH_MATH_SUPPORT_64 is not set
# CONFIG_ASH_GETOPTS is not set
# CONFIG_ASH_BUILTIN_ECHO is not set
# CONFIG_ASH_BUILTIN_PRINTF is not set
# CONFIG_ASH_BUILTIN_TEST is not set
# CONFIG_ASH_CMDCMD is not set
# CONFIG_ASH_MAIL is not set
@@ -787,7 +778,6 @@ CONFIG_HUSH_JOB=y
CONFIG_HUSH_TICK=y
CONFIG_HUSH_IF=y
CONFIG_HUSH_LOOPS=y
CONFIG_HUSH_CASE=y
CONFIG_LASH=y
CONFIG_MSH=y
+1 -1
View File
@@ -11,7 +11,7 @@
#include "busybox.h"
#if ENABLE_BUILD_LIBBUSYBOX
int main(int argc UNUSED_PARAM, char **argv)
int main(int argc ATTRIBUTE_UNUSED, char **argv)
{
return lbb_main(argv);
}
+110 -57
View File
@@ -5,36 +5,12 @@
menu "Archival Utilities"
config FEATURE_SEAMLESS_LZMA
bool "Make tar, rpm, modprobe etc understand .lzma data"
default n
help
Make tar, rpm, modprobe etc understand .lzma data.
config FEATURE_SEAMLESS_BZ2
bool "Make tar, rpm, modprobe etc understand .bz2 data"
default n
help
Make tar, rpm, modprobe etc understand .bz2 data.
config FEATURE_SEAMLESS_GZ
bool "Make tar, rpm, modprobe etc understand .gz data"
default n
help
Make tar, rpm, modprobe etc understand .gz data.
config FEATURE_SEAMLESS_Z
bool "Make tar and gunzip understand .Z data"
default n
help
Make tar and gunzip understand .Z data.
config AR
bool "ar"
default n
help
ar is an archival utility program used to create, modify, and
extract contents from archives. An archive is a single file holding
extract contents from archives. An archive is a single file holding
a collection of other files in a structure that makes it possible to
retrieve the original individual files (called archive members).
The original files' contents, mode (permissions), timestamp, owner,
@@ -57,8 +33,8 @@ config FEATURE_AR_LONG_FILENAMES
default n
depends on AR
help
By default the ar format can only store the first 15 characters of
the filename, this option removes that limitation.
By default the ar format can only store the first 15 characters of the
filename, this option removes that limitation.
It supports the GNU ar long filename method which moves multiple long
filenames into a the data section of a new ar entry.
@@ -67,7 +43,7 @@ config BUNZIP2
default n
help
bunzip2 is a compression utility using the Burrows-Wheeler block
sorting text compression algorithm, and Huffman coding. Compression
sorting text compression algorithm, and Huffman coding. Compression
is generally considerably better than that achieved by more
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
@@ -80,7 +56,7 @@ config BZIP2
default n
help
bzip2 is a compression utility using the Burrows-Wheeler block
sorting text compression algorithm, and Huffman coding. Compression
sorting text compression algorithm, and Huffman coding. Compression
is generally considerably better than that achieved by more
conventional LZ77/LZ78-based compressors, and approaches the
performance of the PPM family of statistical compressors.
@@ -92,15 +68,15 @@ config CPIO
bool "cpio"
default n
help
cpio is an archival utility program used to create, modify, and
extract contents from archives.
cpio is an archival utility program used to create, modify, and extract
contents from archives.
cpio has 110 bytes of overheads for every stored file.
This implementation of cpio can extract cpio archives created in the
"newc" or "crc" format, it cannot create or modify them.
Unless you have a specific application which requires cpio, you
should probably say N here.
Unless you have a specific application which requires cpio, you should
probably say N here.
config FEATURE_CPIO_O
bool "Support for archive creation"
@@ -114,33 +90,30 @@ config DPKG
bool "dpkg"
default n
help
dpkg is a medium-level tool to install, build, remove and manage
Debian packages.
dpkg is a medium-level tool to install, build, remove and manage Debian packages.
This implementation of dpkg has a number of limitations,
you should use the official dpkg if possible.
This implementation of dpkg has a number of limitations, you should use the
official dpkg if possible.
config DPKG_DEB
bool "dpkg_deb"
default n
help
dpkg-deb packs, unpacks and provides information about Debian
archives.
dpkg-deb packs, unpacks and provides information about Debian archives.
This implementation of dpkg-deb cannot pack archives.
Unless you have a specific application which requires dpkg-deb,
say N here.
Unless you have a specific application which requires dpkg-deb, you should
probably say N here.
config FEATURE_DPKG_DEB_EXTRACT_ONLY
bool "Extract only (-x)"
default n
depends on DPKG_DEB
help
This reduces dpkg-deb to the equivalent of
"ar -p <deb> data.tar.gz | tar -zx". However it saves space as none
of the extra dpkg-deb, ar or tar options are needed, they are linked
to internally.
This reduces dpkg-deb to the equivalent of "ar -p <deb> data.tar.gz | tar -zx".
However it saves space as none of the extra dpkg-deb, ar or tar options are
needed, they are linked to internally.
config GUNZIP
bool "gunzip"
@@ -150,6 +123,15 @@ config GUNZIP
You can use the `-t' option to test the integrity of
an archive, without decompressing it.
config FEATURE_GUNZIP_UNCOMPRESS
bool "Uncompress support"
default n
depends on GUNZIP
help
Enable if you want gunzip to have the ability to decompress
archives created by the program compress (not much
used anymore).
config GZIP
bool "gzip"
default n
@@ -169,6 +151,13 @@ config RPM
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.
config TAR
bool "tar"
default n
@@ -177,8 +166,6 @@ config TAR
create compressed archives. It's probably the most widely used
UNIX archive program.
if TAR
config FEATURE_TAR_CREATE
bool "Enable archive creation"
default y
@@ -187,13 +174,45 @@ config FEATURE_TAR_CREATE
If you enable this option you'll be able to create
tar archives using the `-c' option.
config FEATURE_TAR_AUTODETECT
bool "Autodetect gz/bz2 compressed tarballs"
config FEATURE_TAR_GZIP
bool "Enable -z option"
default y
depends on TAR
help
If you enable this option tar will be able to call gzip,
when creating or extracting tar gziped archives.
config FEATURE_TAR_BZIP2
bool "Enable -j option to handle .tar.bz2 files"
default n
depends on FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA
depends on TAR
help
If you enable this option you'll be able to extract
archives compressed with bzip2.
config FEATURE_TAR_LZMA
bool "Enable -a option to handle .tar.lzma files"
default n
depends on TAR
help
If you enable this option you'll be able to extract
archives compressed with lzma.
config FEATURE_TAR_COMPRESS
bool "Enable -Z option"
default n
depends on TAR
help
If you enable this option tar will be able to call uncompress,
when extracting .tar.Z archives.
config FEATURE_TAR_AUTODETECT
bool "Let tar autodetect gz/bz2 compresses tarballs"
default n
depends on FEATURE_TAR_GZIP || FEATURE_TAR_BZIP2
help
With this option tar can automatically detect gzip/bzip2 compressed
tarballs. Currently it works only on files (not pipes etc).
tarballs. Currently it works only on seekable streams.
config FEATURE_TAR_FROM
bool "Enable -X (exclude from) and -T (include from) options)"
@@ -218,9 +237,8 @@ config FEATURE_TAR_OLDSUN_COMPATIBILITY
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.
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 "Support for GNU tar extensions (long filenames)"
@@ -246,8 +264,6 @@ config FEATURE_TAR_UNAME_GNAME
listings (-t) and preserving permissions when unpacking (-p).
+200 bytes.
endif #tar
config UNCOMPRESS
bool "uncompress"
default n
@@ -260,7 +276,7 @@ config UNLZMA
default n
help
unlzma is a compression utility using the Lempel-Ziv-Markov chain
compression algorithm, and range coding. Compression
compression algorithm, and range coding. Compression
is generally considerably better than that achieved by the bzip2
compressors.
@@ -288,4 +304,41 @@ config UNZIP
current directory. Use the `-d' option to extract to a
directory of your choice.
comment "Common options for cpio and tar"
depends on CPIO || TAR
comment "Common options for dpkg and dpkg_deb"
depends on DPKG || DPKG_DEB
config FEATURE_DEB_TAR_GZ
bool "gzip debian packages (normal)"
default y if DPKG || DPKG_DEB
depends on DPKG || DPKG_DEB
help
This is the default compression method inside the debian ar file.
If you want compatibility with standard .deb's you should say yes here.
config FEATURE_DEB_TAR_BZ2
bool "bzip2 debian packages"
default n
depends on DPKG || DPKG_DEB
help
This allows dpkg and dpkg-deb to extract deb's that are compressed internally
with bzip2 instead of gzip.
You only want this if you are creating your own custom debian packages that
use an internal control.tar.bz2 or data.tar.bz2.
config FEATURE_DEB_TAR_LZMA
bool "lzma debian packages"
default n
depends on DPKG || DPKG_DEB
help
This allows dpkg and dpkg-deb to extract deb's that are compressed
internally with lzma instead of gzip.
You only want this if you are creating your own custom debian
packages that use an internal control.tar.lzma or data.tar.lzma.
endmenu
+11 -3
View File
@@ -16,7 +16,7 @@
#include "libbb.h"
#include "unarchive.h"
static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
static void header_verbose_list_ar(const file_header_t *file_header)
{
const char *mode = bb_mode_string(file_header->mode);
char *mtime;
@@ -45,6 +45,7 @@ int ar_main(int argc, char **argv)
archive_handle_t *archive_handle;
unsigned opt;
char magic[8];
archive_handle = init_handle();
@@ -62,7 +63,7 @@ int ar_main(int argc, char **argv)
archive_handle->action_data = data_extract_all;
}
if (opt & AR_OPT_PRESERVE_DATE) {
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
}
if (opt & AR_OPT_VERBOSE) {
archive_handle->action_header = header_verbose_list_ar;
@@ -81,7 +82,14 @@ int ar_main(int argc, char **argv)
llist_add_to(&(archive_handle->accept), argv[optind++]);
}
unpack_ar_archive(archive_handle);
xread(archive_handle->src_fd, magic, 7);
if (strncmp(magic, "!<arch>", 7) != 0) {
bb_error_msg_and_die("invalid ar magic");
}
archive_handle->offset += 7;
while (get_header_ar(archive_handle) == EXIT_SUCCESS)
continue;
return EXIT_SUCCESS;
}
+11 -17
View File
@@ -28,7 +28,7 @@ int open_to_or_warn(int to_fd, const char *filename, int flags, int mode)
return 0;
}
int FAST_FUNC bbunpack(char **argv,
int bbunpack(char **argv,
char* (*make_new_name)(char *filename),
USE_DESKTOP(long long) int (*unpacker)(void)
)
@@ -73,12 +73,6 @@ int FAST_FUNC bbunpack(char **argv,
bb_error_msg("%s: unknown suffix - ignored", filename);
goto err;
}
/* -f: overwrite existing output files */
if (option_mask32 & OPT_FORCE) {
unlink(new_name);
}
/* O_EXCL: "real" bunzip2 doesn't overwrite files */
/* GNU gunzip does not bail out, but goes to next file */
if (open_to_or_warn(STDOUT_FILENO, new_name, O_WRONLY | O_CREAT | O_EXCL,
@@ -161,11 +155,11 @@ char* make_new_name_bunzip2(char *filename)
static
USE_DESKTOP(long long) int unpack_bunzip2(void)
{
return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO);
return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
}
int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bunzip2_main(int argc UNUSED_PARAM, char **argv)
int bunzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
getopt32(argv, "cfvdt");
argv += optind;
@@ -218,8 +212,8 @@ char* make_new_name_gunzip(char *filename)
extension++;
if (strcmp(extension, "tgz" + 1) == 0
#if ENABLE_FEATURE_SEAMLESS_Z
|| (extension[0] == 'Z' && extension[1] == '\0')
#if ENABLE_FEATURE_GUNZIP_UNCOMPRESS
|| strcmp(extension, "Z") == 0
#endif
) {
extension[-1] = '\0';
@@ -244,8 +238,8 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
unsigned char magic2;
magic2 = xread_char(STDIN_FILENO);
if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
if (ENABLE_FEATURE_GUNZIP_UNCOMPRESS && magic2 == 0x9d) {
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
} else if (magic2 == 0x8b) {
status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
} else {
@@ -277,7 +271,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
*/
int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int gunzip_main(int argc UNUSED_PARAM, char **argv)
int gunzip_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
getopt32(argv, "cfvdtn");
argv += optind;
@@ -315,7 +309,7 @@ USE_DESKTOP(long long) int unpack_unlzma(void)
}
int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int unlzma_main(int argc UNUSED_PARAM, char **argv)
int unlzma_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
getopt32(argv, "cf");
argv += optind;
@@ -351,13 +345,13 @@ USE_DESKTOP(long long) int unpack_uncompress(void)
if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
bb_error_msg("invalid magic");
} else {
status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
status = uncompress(STDIN_FILENO, STDOUT_FILENO);
}
return status;
}
int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int uncompress_main(int argc UNUSED_PARAM, char **argv)
int uncompress_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
getopt32(argv, "cf");
argv += optind;
+1 -1
View File
@@ -1,4 +1,4 @@
This file is an abridged version of README from bzip2 1.0.4
This file is an abridged version of README from bizp2 1.0.4
Build instructions (which are not relevant to busyboxed bzip2)
are removed.
===========================================================
+2 -2
View File
@@ -33,7 +33,7 @@ typedef unsigned char Bool;
#define False ((Bool)0)
#if BZ_LIGHT_DEBUG
static void bz_assert_fail(int errcode) NORETURN;
static void bz_assert_fail(int errcode) ATTRIBUTE_NORETURN;
#define AssertH(cond, errcode) \
do { \
if (!(cond)) \
@@ -170,7 +170,7 @@ typedef struct EState {
/* map of bytes used in block */
int32_t nInUse;
Bool inUse[256] ALIGNED(sizeof(long));
Bool inUse[256] __attribute__(( aligned(sizeof(long)) ));
uint8_t unseqToSeq[256];
/* stuff for coding the MTF values */
+4 -4
View File
@@ -141,7 +141,7 @@ char* make_new_name_bzip2(char *filename)
}
int bzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int bzip2_main(int argc UNUSED_PARAM, char **argv)
int bzip2_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
unsigned opt;
@@ -162,11 +162,11 @@ int bzip2_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "s2"; /* -s means -2 (compatibility) */
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" USE_BUNZIP2("dt") "123456789qzs");
opt = getopt32(argv, "cfv" USE_BUNZIP2("d") "123456789qzs" );
#if ENABLE_BUNZIP2 /* bunzip2_main may not be visible... */
if (opt & 0x18) // -d and/or -t
if (opt & 0x8) // -d
return bunzip2_main(argc, argv);
opt >>= 5;
opt >>= 4;
#else
opt >>= 3;
#endif
+23 -21
View File
@@ -178,19 +178,19 @@ static int cpio_o(void)
}
#endif
/* GNU cpio 2.9 --help (abridged):
/* GNU cpio (GNU cpio) 2.9 help (abridged):
Modes:
Main operation mode:
-i, --extract Extract files from an archive
-o, --create Create the archive
-p, --pass-through Copy-pass mode [was ist das?!]
-p, --pass-through Copy-pass mode (was ist das?!)
-t, --list List the archive
Options valid in any mode:
Operation modifiers valid in any mode:
--block-size=SIZE I/O block size = SIZE * 512 bytes
-B I/O block size = 5120 bytes
-c Use the old portable (ASCII) archive format
-C, --io-size=NUMBER I/O block size in bytes
-C, --io-size=NUMBER I/O block size to the given NUMBER bytes
-f, --nonmatching Only copy files that do not match given pattern
-F, --file=FILE Use FILE instead of standard input or output
-H, --format=FORMAT Use given archive FORMAT
@@ -204,7 +204,7 @@ static int cpio_o(void)
-W, --warning=FLAG Control warning display: 'none','truncate','all';
multiple options accumulate
Options valid only in --extract mode:
Operation modifiers valid only in --extract mode:
-b, --swap Swap both halfwords of words and bytes of
halfwords in the data (equivalent to -sS)
-r, --rename Interactively rename files
@@ -215,36 +215,38 @@ static int cpio_o(void)
extract or list from FILE
--only-verify-crc Verify CRC's, don't actually extract the files
Options valid only in --create mode:
Operation modifiers valid only in --create mode:
-A, --append Append to an existing archive
-O FILE File to use instead of standard output
Options valid only in --pass-through mode:
Operation modifiers valid only in --pass-through mode:
-l, --link Link files instead of copying them, when possible
Options valid in --extract and --create modes:
Operation modifiers valid in --extract and --create modes:
--absolute-filenames Do not strip file system prefix components from
the file names
--no-absolute-filenames Create all files relative to the current dir
Options valid in --create and --pass-through modes:
Operation modifiers valid in --create and --pass-through modes:
-0, --null A list of filenames is terminated by a NUL
-a, --reset-access-time Reset the access times of files after reading them
-I FILE File to use instead of standard input
-L, --dereference Dereference symbolic links (copy the files
-L, --dereference Dereference symbolic links (copy the files
that they point to instead of copying the links)
-R, --owner=[USER][:.][GROUP] Set owner of created files
Options valid in --extract and --pass-through modes:
Operation modifiers valid in --extract and --pass-through modes:
-d, --make-directories Create leading directories where needed
-m, --preserve-modification-time Retain mtime when creating files
-m, --preserve-modification-time
Retain previous file modification times when
creating files
--no-preserve-owner Do not change the ownership of the files
--sparse Write files with blocks of zeros as sparse files
-u, --unconditional Replace all files unconditionally
*/
int cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cpio_main(int argc UNUSED_PARAM, char **argv)
int cpio_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
archive_handle_t *archive_handle;
char *cpio_filename;
@@ -262,7 +264,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
CPIO_OPT_FORMAT = (1 << 8),
};
#if ENABLE_GETOPT_LONG
#if ENABLE_GETOPT_LONG && ENABLE_DESKTOP
applet_long_options =
"extract\0" No_argument "i"
"list\0" No_argument "t"
@@ -277,7 +279,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
archive_handle = init_handle();
archive_handle->src_fd = STDIN_FILENO;
archive_handle->seek = seek_by_read;
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
archive_handle->flags = ARCHIVE_EXTRACT_NEWER;
#if ENABLE_FEATURE_CPIO_O
opt = getopt32(argv, "ituvF:dmoH:", &cpio_filename, &cpio_fmt);
@@ -287,7 +289,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
bb_show_usage();
if (opt & CPIO_OPT_FILE) {
fclose(stdout);
stdout = fopen_for_write(cpio_filename);
stdout = fopen(cpio_filename, "w");
/* Paranoia: I don't trust libc that much */
xdup2(fileno(stdout), STDOUT_FILENO);
}
@@ -314,8 +316,8 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
archive_handle->action_data = data_extract_all;
}
if (opt & CPIO_OPT_UNCONDITIONAL) {
archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
archive_handle->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->flags &= ~ARCHIVE_EXTRACT_NEWER;
}
if (opt & CPIO_OPT_VERBOSE) {
if (archive_handle->action_header == header_list) {
@@ -329,10 +331,10 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
archive_handle->seek = seek_by_jump;
}
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
}
if (opt & CPIO_OPT_PRESERVE_MTIME) {
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
}
while (*argv) {
+21 -20
View File
@@ -382,8 +382,9 @@ static int search_for_provides(int needle, int start_at)
*/
static void add_edge_to_node(common_node_t *node, edge_t *edge)
{
node->edge = xrealloc_vector(node->edge, 2, node->num_of_edges);
node->edge[node->num_of_edges++] = edge;
node->num_of_edges++;
node->edge = xrealloc(node->edge, sizeof(edge_t) * (node->num_of_edges + 1));
node->edge[node->num_of_edges - 1] = edge;
}
/*
@@ -748,7 +749,7 @@ static void index_status_file(const char *filename)
status_node_t *status_node = NULL;
unsigned status_num;
status_file = xfopen_for_read(filename);
status_file = xfopen(filename, "r");
while ((control_buffer = xmalloc_fgetline_str(status_file, "\n\n")) != NULL) {
const unsigned package_num = fill_package_struct(control_buffer);
if (package_num != -1) {
@@ -790,8 +791,8 @@ static void write_buffer_no_status(FILE *new_status_file, const char *control_bu
/* This could do with a cleanup */
static void write_status_file(deb_file_t **deb_file)
{
FILE *old_status_file = xfopen_for_read("/var/lib/dpkg/status");
FILE *new_status_file = xfopen_for_write("/var/lib/dpkg/status.udeb");
FILE *old_status_file = xfopen("/var/lib/dpkg/status", "r");
FILE *new_status_file = xfopen("/var/lib/dpkg/status.udeb", "w");
char *package_name;
char *status_from_file;
char *control_buffer = NULL;
@@ -971,7 +972,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
* installed package for conflicts*/
while (deb_file[i] != NULL) {
const unsigned package_num = deb_file[i]->package;
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
conflicts[conflicts_num] = package_num;
conflicts_num++;
/* add provides to conflicts list */
@@ -988,7 +989,7 @@ static int check_deps(deb_file_t **deb_file, int deb_start /*, int dep_max_count
new_node->version = package_hashtable[package_num]->edge[j]->version;
package_hashtable[conflicts_package_num] = new_node;
}
conflicts = xrealloc_vector(conflicts, 2, conflicts_num);
conflicts = xrealloc(conflicts, sizeof(int) * (conflicts_num + 1));
conflicts[conflicts_num] = conflicts_package_num;
conflicts_num++;
}
@@ -1161,7 +1162,7 @@ static char **create_list(const char *filename)
int count;
/* don't use [xw]fopen here, handle error ourself */
list_stream = fopen_for_read(filename);
list_stream = fopen(filename, "r");
if (list_stream == NULL) {
return NULL;
}
@@ -1169,9 +1170,9 @@ static char **create_list(const char *filename)
file_list = NULL;
count = 0;
while ((line = xmalloc_fgetline(list_stream)) != NULL) {
file_list = xrealloc_vector(file_list, 2, count);
file_list = xrealloc(file_list, sizeof(char *) * (count + 2));
file_list[count++] = line;
/*file_list[count] = NULL; - xrealloc_vector did it */
file_list[count] = NULL;
}
fclose(list_stream);
@@ -1438,10 +1439,10 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
tar_handle->src_fd = ar_handle->src_fd;
/* We don't care about data.tar.* or debian-binary, just control.tar.* */
#if ENABLE_FEATURE_SEAMLESS_GZ
#if ENABLE_FEATURE_DEB_TAR_GZ
llist_add_to(&(ar_handle->accept), (char*)"control.tar.gz");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_DEB_TAR_BZ2
llist_add_to(&(ar_handle->accept), (char*)"control.tar.bz2");
#endif
@@ -1458,10 +1459,10 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
tar_handle->src_fd = ar_handle->src_fd;
/* We don't care about control.tar.* or debian-binary, just data.tar.* */
#if ENABLE_FEATURE_SEAMLESS_GZ
#if ENABLE_FEATURE_DEB_TAR_GZ
llist_add_to(&(ar_handle->accept), (char*)"data.tar.gz");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_DEB_TAR_BZ2
llist_add_to(&(ar_handle->accept), (char*)"data.tar.bz2");
#endif
@@ -1481,7 +1482,7 @@ static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, lli
return ar_handle->sub_archive->buffer;
}
static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
static void data_extract_all_prefix(archive_handle_t *archive_handle)
{
char *name_ptr = archive_handle->file_header->name;
@@ -1531,7 +1532,7 @@ static void unpack_package(deb_file_t *deb_file)
archive_handle->sub_archive->filter = filter_accept_list;
archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = info_prefix;
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle);
/* Run the preinst prior to extracting */
@@ -1542,12 +1543,12 @@ static void unpack_package(deb_file_t *deb_file)
init_archive_deb_data(archive_handle);
archive_handle->sub_archive->action_data = data_extract_all_prefix;
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
archive_handle->sub_archive->flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
unpack_ar_archive(archive_handle);
/* Create the list file */
list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
out_stream = xfopen_for_write(list_filename);
out_stream = xfopen(list_filename, "w");
while (archive_handle->sub_archive->passed) {
/* the leading . has been stripped by data_extract_all_prefix already */
fputs(archive_handle->sub_archive->passed->data, out_stream);
@@ -1582,7 +1583,7 @@ static void configure_package(deb_file_t *deb_file)
}
int dpkg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dpkg_main(int argc UNUSED_PARAM, char **argv)
int dpkg_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
deb_file_t **deb_file = NULL;
status_node_t *status_node;
@@ -1633,7 +1634,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
/* Read arguments and store relevant info in structs */
while (*argv) {
/* deb_count = nb_elem - 1 and we need nb_elem + 1 to allocate terminal node [NULL pointer] */
deb_file = xrealloc_vector(deb_file, 2, deb_count);
deb_file = xrealloc(deb_file, sizeof(deb_file[0]) * (deb_count + 2));
deb_file[deb_count] = xzalloc(sizeof(deb_file[0][0]));
if (opt & (OPT_install | OPT_unpack)) {
/* -i/-u: require filename */
+13 -20
View File
@@ -20,8 +20,8 @@ int dpkg_deb_main(int argc, char **argv)
archive_handle_t *tar_archive;
llist_t *control_tar_llist = NULL;
unsigned opt;
const char *extract_dir;
int need_args;
const char *extract_dir = NULL;
short argcount = 1;
/* Setup the tar archive handle */
tar_archive = init_handle();
@@ -31,33 +31,29 @@ int dpkg_deb_main(int argc, char **argv)
ar_archive->sub_archive = tar_archive;
ar_archive->filter = filter_accept_list_reassign;
#if ENABLE_FEATURE_SEAMLESS_GZ
#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");
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#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");
#endif
opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX";
opt = getopt32(argv, "cefXx");
argv += optind;
argc -= optind;
if (opt & DPKG_DEB_OPT_CONTENTS) {
tar_archive->action_header = header_verbose_list;
}
extract_dir = NULL;
need_args = 1;
if (opt & DPKG_DEB_OPT_CONTROL) {
ar_archive->accept = control_tar_llist;
tar_archive->action_data = data_extract_all;
if (1 == argc) {
if (optind + 1 == argc) {
extract_dir = "./DEBIAN";
} else {
need_args++;
argcount++;
}
}
if (opt & DPKG_DEB_OPT_FIELD) {
@@ -74,31 +70,28 @@ int dpkg_deb_main(int argc, char **argv)
}
if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) {
tar_archive->action_data = data_extract_all;
need_args = 2;
argcount = 2;
}
if (need_args != argc) {
if ((optind + argcount) != argc) {
bb_show_usage();
}
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY);
tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY);
/* Work out where to extract the files */
/* Workout where to extract the files */
/* 2nd argument is a dir name */
if (argv[1]) {
extract_dir = argv[1];
if (argv[optind]) {
extract_dir = argv[optind];
}
if (extract_dir) {
mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */
xchdir(extract_dir);
}
/* Do it */
unpack_ar_archive(ar_archive);
/* Cleanup */
if (ENABLE_FEATURE_CLEAN_UP)
close(ar_archive->src_fd);
close(ar_archive->src_fd);
return EXIT_SUCCESS;
}
+3 -4
View File
@@ -2043,15 +2043,15 @@ int gzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#if ENABLE_GUNZIP
int gzip_main(int argc, char **argv)
#else
int gzip_main(int argc UNUSED_PARAM, char **argv)
int gzip_main(int argc ATTRIBUTE_UNUSED, char **argv)
#endif
{
unsigned opt;
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
opt = getopt32(argv, "cfv" USE_GUNZIP("dt") "q123456789n");
opt = getopt32(argv, "cfv" USE_GUNZIP("d") "q123456789n" );
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
if (opt & 0x18) // -d and/or -t
if (opt & 0x8) // -d
return gunzip_main(argc, argv);
#endif
option_mask32 &= 0x7; /* ignore -q, -0..9 */
@@ -2062,7 +2062,6 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2))
+ sizeof(struct globals));
barrier();
G2.l_desc.dyn_tree = G2.dyn_ltree;
G2.l_desc.static_tree = G2.static_ltree;
G2.l_desc.extra_bits = extra_lbits;
+21 -5
View File
@@ -18,6 +18,8 @@ lib-y:= \
header_skip.o \
header_list.o \
header_verbose_list.o \
\
archive_xread_all_eof.o \
\
seek_by_read.o \
seek_by_jump.o \
@@ -32,20 +34,34 @@ 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) += decompress_unzip.o 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) += decompress_unzip.o
lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_RPM2CPIO) += decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += open_transformer.o decompress_unzip.o get_header_cpio.o
lib-$(CONFIG_RPM) += decompress_unzip.o 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) += decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
lib-$(CONFIG_UNZIP) += decompress_unzip.o
lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o
lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_unzip.o get_header_tar_gz.o
lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o get_header_tar_bz2.o
lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o get_header_tar_lzma.o
lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
@@ -0,0 +1,20 @@
/* vi: set sw=4 ts=4: */
/*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include "unarchive.h"
ssize_t archive_xread_all_eof(archive_handle_t *archive_handle,
unsigned char *buf, size_t count)
{
ssize_t size;
size = full_read(archive_handle->src_fd, buf, count);
if (size != 0 && size != (ssize_t)count) {
bb_error_msg_and_die("short read: %u of %u",
(unsigned)size, (unsigned)count);
}
return size;
}
+1 -1
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
void data_align(archive_handle_t *archive_handle, unsigned boundary)
{
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
+12 -12
View File
@@ -6,20 +6,20 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
void data_extract_all(archive_handle_t *archive_handle)
{
file_header_t *file_header = archive_handle->file_header;
int dst_fd;
int res;
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
if (archive_handle->flags & ARCHIVE_CREATE_LEADING_DIRS) {
char *name = xstrdup(file_header->name);
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
free(name);
}
/* Check if the file already exists */
if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
if (archive_handle->flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
/* Remove the entry if it exists */
if (((file_header->mode & S_IFMT) != S_IFDIR)
&& (unlink(file_header->name) == -1)
@@ -29,7 +29,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
file_header->name);
}
}
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
else if (archive_handle->flags & ARCHIVE_EXTRACT_NEWER) {
/* Remove the existing entry if its older than the extracted entry */
struct stat statbuf;
if (lstat(file_header->name, &statbuf) == -1) {
@@ -38,7 +38,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
}
else if (statbuf.st_mtime <= file_header->mtime) {
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
if (!(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_error_msg("%s not created: newer or "
"same age file exists", file_header->name);
}
@@ -58,7 +58,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
) {
/* hard link */
res = link(file_header->link_target, file_header->name);
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
if ((res == -1) && !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)) {
bb_perror_msg("cannot create %slink "
"from %s to %s", "hard",
file_header->name,
@@ -78,7 +78,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFDIR:
res = mkdir(file_header->name, file_header->mode);
if ((res == -1) && (errno != EISDIR)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("cannot make dir %s", file_header->name);
}
@@ -87,7 +87,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* Symlink */
res = symlink(file_header->link_target, file_header->name);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("cannot create %slink "
"from %s to %s", "sym",
@@ -101,7 +101,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
case S_IFIFO:
res = mknod(file_header->name, file_header->mode, file_header->device);
if ((res == -1)
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
&& !(archive_handle->flags & ARCHIVE_EXTRACT_QUIET)
) {
bb_perror_msg("cannot create node %s", file_header->name);
}
@@ -111,7 +111,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
}
}
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_OWN)) {
#if ENABLE_FEATURE_TAR_UNAME_GNAME
uid_t uid = file_header->uid;
gid_t gid = file_header->gid;
@@ -133,11 +133,11 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
/* uclibc has no lchmod, glibc is even stranger -
* it has lchmod which seems to do nothing!
* so we use chmod... */
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_PERM)) {
if (!(archive_handle->flags & ARCHIVE_NOPRESERVE_PERM)) {
chmod(file_header->name, file_header->mode);
}
/* same for utime */
if (archive_handle->ah_flags & ARCHIVE_PRESERVE_DATE) {
if (archive_handle->flags & ARCHIVE_PRESERVE_DATE) {
struct utimbuf t;
t.actime = t.modtime = file_header->mtime;
utime(file_header->name, &t);
@@ -8,7 +8,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
void data_extract_to_buffer(archive_handle_t *archive_handle)
{
unsigned int size = archive_handle->file_header->size;
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_extract_to_stdout(archive_handle_t *archive_handle)
void data_extract_to_stdout(archive_handle_t *archive_handle)
{
bb_copyfd_exact_size(archive_handle->src_fd,
STDOUT_FILENO,
+1 -1
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC data_skip(archive_handle_t *archive_handle)
void data_skip(archive_handle_t *archive_handle)
{
archive_handle->seek(archive_handle, archive_handle->file_header->size);
}
+9 -28
View File
@@ -482,7 +482,7 @@ static int get_next_block(bunzip_data *bd)
error (all errors are negative numbers). If out_fd!=-1, outbuf and len
are ignored, data is written to out_fd and return is RETVAL_OK or error.
*/
int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
int read_bunzip(bunzip_data *bd, char *outbuf, int len)
{
const unsigned *dbuf;
int pos, current, previous, gotcount;
@@ -584,14 +584,13 @@ int FAST_FUNC read_bunzip(bunzip_data *bd, char *outbuf, int len)
/* Because bunzip2 is used for help text unpacking, and because bb_show_usage()
should work for NOFORK applets too, we must be extremely careful to not leak
any allocations! */
int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf,
int len)
{
bunzip_data *bd;
unsigned i;
enum {
BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0',
h0 = ('h' << 8) + '0',
BZh0 = ('B' << 24) + ('Z' << 16) + ('h' << 8) + '0'
};
/* Figure out how much data to allocate */
@@ -618,18 +617,12 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in
if (i) return i;
/* Ensure that file starts with "BZh['1'-'9']." */
/* Update: now caller verifies 1st two bytes, makes .gz/.bz2
* integration easier */
/* was: */
/* i = get_bits(bd, 32); */
/* if ((unsigned)(i - BZh0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA; */
i = get_bits(bd, 16);
if ((unsigned)(i - h0 - 1) >= 9) return RETVAL_NOT_BZIP_DATA;
i = get_bits(bd, 32);
if ((unsigned)(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 - h0);
bd->dbufSize = 100000 * (i - BZh0);
/* Cannot use xmalloc - may leak bd in NOFORK case! */
bd->dbuf = malloc_or_warn(bd->dbufSize * sizeof(int));
@@ -640,7 +633,7 @@ int FAST_FUNC start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *in
return RETVAL_OK;
}
void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
void dealloc_bunzip(bunzip_data *bd)
{
free(bd->dbuf);
free(bd);
@@ -648,7 +641,7 @@ void FAST_FUNC dealloc_bunzip(bunzip_data *bd)
/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
USE_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
unpack_bz2_stream(int src_fd, int dst_fd)
{
USE_DESKTOP(long long total_written = 0;)
@@ -689,17 +682,6 @@ unpack_bz2_stream(int src_fd, int dst_fd)
return i ? i : USE_DESKTOP(total_written) + 0;
}
USE_DESKTOP(long long) int FAST_FUNC
unpack_bz2_stream_prime(int src_fd, int dst_fd)
{
unsigned char magic[2];
xread(src_fd, magic, 2);
if (magic[0] != 'B' || magic[1] != 'Z') {
bb_error_msg_and_die("invalid magic");
}
return unpack_bz2_stream(src_fd, dst_fd);
}
#ifdef TESTING
static char *const bunzip_errors[] = {
@@ -711,10 +693,9 @@ static char *const bunzip_errors[] = {
/* Dumb little test thing, decompress stdin to stdout */
int main(int argc, char **argv)
{
int i;
int i = unpack_bz2_stream(0, 1);
char c;
int i = unpack_bz2_stream_prime(0, 1);
if (i < 0)
fprintf(stderr, "%s\n", bunzip_errors[-i]);
else if (read(STDIN_FILENO, &c, 1))
@@ -1,4 +1,6 @@
/* vi: set sw=4 ts=4: */
#include "libbb.h"
/* uncompress for busybox -- (c) 2002 Robert Griebl
*
* based on the original compress42.c source
@@ -24,10 +26,6 @@
*
*/
#include "libbb.h"
#include "unarchive.h"
/* Default input buffer size */
#define IBUFSIZ 2048
@@ -72,8 +70,8 @@
* be stored in the compressed file.
*/
USE_DESKTOP(long long) int FAST_FUNC
unpack_Z_stream(int fd_in, int fd_out)
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;
+21 -24
View File
@@ -45,7 +45,7 @@ typedef struct {
/* Called twice: once at startup and once in rc_normalize() */
static void rc_read(rc_t *rc)
static void rc_read(rc_t * rc)
{
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
if (buffer_size <= 0)
@@ -58,9 +58,9 @@ static void rc_read(rc_t *rc)
static rc_t* rc_init(int fd) /*, int buffer_size) */
{
int i;
rc_t *rc;
rc_t* rc;
rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);
rc = xmalloc(sizeof(rc_t) + RC_BUFFER_SIZE);
rc->fd = fd;
/* rc->buffer_size = buffer_size; */
@@ -78,20 +78,21 @@ static rc_t* rc_init(int fd) /*, int buffer_size) */
}
/* Called once */
static ALWAYS_INLINE void rc_free(rc_t *rc)
static ALWAYS_INLINE void rc_free(rc_t * rc)
{
free(rc);
if (ENABLE_FEATURE_CLEAN_UP)
free(rc);
}
/* Called twice, but one callsite is in speed_inline'd rc_is_bit_0_helper() */
static void rc_do_normalize(rc_t *rc)
static void rc_do_normalize(rc_t * rc)
{
if (rc->ptr >= rc->buffer_end)
rc_read(rc);
rc->range <<= 8;
rc->code = (rc->code << 8) | *rc->ptr++;
}
static ALWAYS_INLINE void rc_normalize(rc_t *rc)
static ALWAYS_INLINE void rc_normalize(rc_t * rc)
{
if (rc->range < (1 << RC_TOP_BITS)) {
rc_do_normalize(rc);
@@ -104,25 +105,25 @@ static ALWAYS_INLINE void rc_normalize(rc_t *rc)
* Thus rc_is_bit_0 is always inlined, and rc_is_bit_0_helper is inlined
* only if we compile for speed.
*/
static speed_inline uint32_t rc_is_bit_0_helper(rc_t *rc, uint16_t *p)
static speed_inline uint32_t rc_is_bit_0_helper(rc_t * rc, uint16_t * p)
{
rc_normalize(rc);
rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
return rc->bound;
}
static ALWAYS_INLINE int rc_is_bit_0(rc_t *rc, uint16_t *p)
static ALWAYS_INLINE int rc_is_bit_0(rc_t * rc, uint16_t * p)
{
uint32_t t = rc_is_bit_0_helper(rc, p);
return rc->code < t;
}
/* Called ~10 times, but very small, thus inlined */
static speed_inline void rc_update_bit_0(rc_t *rc, uint16_t *p)
static speed_inline void rc_update_bit_0(rc_t * rc, uint16_t * p)
{
rc->range = rc->bound;
*p += ((1 << RC_MODEL_TOTAL_BITS) - *p) >> RC_MOVE_BITS;
}
static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)
static speed_inline void rc_update_bit_1(rc_t * rc, uint16_t * p)
{
rc->range -= rc->bound;
rc->code -= rc->bound;
@@ -130,7 +131,7 @@ static speed_inline void rc_update_bit_1(rc_t *rc, uint16_t *p)
}
/* Called 4 times in unlzma loop */
static int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)
static int rc_get_bit(rc_t * rc, uint16_t * p, int *symbol)
{
if (rc_is_bit_0(rc, p)) {
rc_update_bit_0(rc, p);
@@ -144,7 +145,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 ALWAYS_INLINE int rc_direct_bit(rc_t * rc)
{
rc_normalize(rc);
rc->range >>= 1;
@@ -157,7 +158,7 @@ static ALWAYS_INLINE int rc_direct_bit(rc_t *rc)
/* Called twice */
static speed_inline void
rc_bit_tree_decode(rc_t *rc, uint16_t *p, int num_levels, int *symbol)
rc_bit_tree_decode(rc_t * rc, uint16_t * p, int num_levels, int *symbol)
{
int i = num_levels;
@@ -228,7 +229,7 @@ enum {
};
USE_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
unpack_lzma_stream(int src_fd, int dst_fd)
{
USE_DESKTOP(long long total_written = 0;)
@@ -488,16 +489,12 @@ unpack_lzma_stream(int src_fd, int dst_fd)
}
}
{
SKIP_DESKTOP(int total_written = 0; /* success */)
USE_DESKTOP(total_written += buffer_pos;)
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
if (full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {
bad:
total_written = -1; /* failure */
}
rc_free(rc);
free(p);
free(buffer);
return total_written;
return -1;
}
rc_free(rc);
USE_DESKTOP(total_written += buffer_pos;)
return USE_DESKTOP(total_written) + 0;
}
+3 -3
View File
@@ -244,7 +244,7 @@ static void huft_free_all(STATE_PARAM_ONLY)
inflate_codes_td = NULL;
}
static void abort_unzip(STATE_PARAM_ONLY) NORETURN;
static void abort_unzip(STATE_PARAM_ONLY) ATTRIBUTE_NORETURN;
static void abort_unzip(STATE_PARAM_ONLY)
{
huft_free_all(PASS_STATE_ONLY);
@@ -1033,7 +1033,7 @@ inflate_unzip_internal(STATE_PARAM int in, int out)
/* For unzip */
USE_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
inflate_unzip(inflate_unzip_result *res, off_t compr_size, int in, int out)
{
USE_DESKTOP(long long) int n;
@@ -1176,7 +1176,7 @@ static int check_header_gzip(STATE_PARAM_ONLY)
return 1;
}
USE_DESKTOP(long long) int FAST_FUNC
USE_DESKTOP(long long) int
unpack_gz_stream(int in, int out)
{
uint32_t v32;
+1 -1
View File
@@ -9,7 +9,7 @@
#include "unarchive.h"
/* Accept any non-null name, its not really a filter at all */
char FAST_FUNC filter_accept_all(archive_handle_t *archive_handle)
char filter_accept_all(archive_handle_t *archive_handle)
{
if (archive_handle->file_header->name)
return EXIT_SUCCESS;
+1 -1
View File
@@ -11,7 +11,7 @@
/*
* Accept names that are in the accept list, ignoring reject list.
*/
char FAST_FUNC filter_accept_list(archive_handle_t *archive_handle)
char filter_accept_list(archive_handle_t *archive_handle)
{
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name))
return EXIT_SUCCESS;
@@ -8,41 +8,34 @@
#include "libbb.h"
#include "unarchive.h"
/* Built and used only if ENABLE_DPKG || ENABLE_DPKG_DEB */
/*
* 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 FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
char filter_accept_list_reassign(archive_handle_t *archive_handle)
{
/* Check the file entry is in the accept list */
if (find_list_entry(archive_handle->accept, archive_handle->file_header->name)) {
const char *name_ptr;
/* Find extension */
/* Extract the last 2 extensions */
name_ptr = strrchr(archive_handle->file_header->name, '.');
if (!name_ptr)
return EXIT_FAILURE;
name_ptr++;
/* Modify the subarchive handler based on the extension */
if (ENABLE_FEATURE_SEAMLESS_GZ
&& strcmp(name_ptr, "gz") == 0
) {
#if ENABLE_FEATURE_DEB_TAR_GZ
if (strcmp(name_ptr, ".gz") == 0) {
archive_handle->action_data_subarchive = get_header_tar_gz;
return EXIT_SUCCESS;
}
if (ENABLE_FEATURE_SEAMLESS_BZ2
&& strcmp(name_ptr, "bz2") == 0
) {
#endif
#if ENABLE_FEATURE_DEB_TAR_BZ2
if (strcmp(name_ptr, ".bz2") == 0) {
archive_handle->action_data_subarchive = get_header_tar_bz2;
return EXIT_SUCCESS;
}
if (ENABLE_FEATURE_SEAMLESS_LZMA
&& strcmp(name_ptr, "lzma") == 0
) {
#endif
if (ENABLE_FEATURE_DEB_TAR_LZMA && !strcmp(name_ptr, ".lzma")) {
archive_handle->action_data_subarchive = get_header_tar_lzma;
return EXIT_SUCCESS;
}
@@ -11,7 +11,7 @@
/*
* Accept names that are in the accept list and not in the reject list
*/
char FAST_FUNC filter_accept_reject_list(archive_handle_t *archive_handle)
char filter_accept_reject_list(archive_handle_t *archive_handle)
{
const char *key;
const llist_t *reject_entry;
+2 -2
View File
@@ -10,7 +10,7 @@
#include "unarchive.h"
/* Find a string in a shell pattern list */
const llist_t* FAST_FUNC find_list_entry(const llist_t *list, const char *filename)
const llist_t *find_list_entry(const llist_t *list, const char *filename)
{
while (list) {
if (fnmatch(list->data, filename, 0) == 0) {
@@ -24,7 +24,7 @@ const llist_t* FAST_FUNC find_list_entry(const llist_t *list, const char *filena
/* Same, but compares only path components present in pattern
* (extra trailing path components in filename are assumed to match)
*/
const llist_t* FAST_FUNC find_list_entry2(const llist_t *list, const char *filename)
const llist_t *find_list_entry2(const llist_t *list, const char *filename)
{
char buf[PATH_MAX];
int pattern_slash_cnt;
+4 -5
View File
@@ -7,7 +7,7 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
char get_header_ar(archive_handle_t *archive_handle)
{
int err;
file_header_t *typed = archive_handle->file_header;
@@ -108,13 +108,12 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(typed);
#if ENABLE_DPKG || ENABLE_DPKG_DEB
if (archive_handle->sub_archive) {
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
continue;
} else
#endif
/* repeat */;
} else {
archive_handle->action_data(archive_handle);
}
} else {
data_skip(archive_handle);
}
+30 -42
View File
@@ -17,32 +17,24 @@ typedef struct hardlinks_t {
char name[1];
} hardlinks_t;
char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
char get_header_cpio(archive_handle_t *archive_handle)
{
static hardlinks_t *saved_hardlinks = NULL;
static hardlinks_t *saved_hardlinks_created = NULL;
file_header_t *file_header = archive_handle->file_header;
char cpio_header[110];
char dummy[16];
int namesize;
int major, minor, nlink, mode, inode;
unsigned size, uid, gid, mtime;
#define hardlinks_to_create (*(hardlinks_t **)(&archive_handle->ah_priv[0]))
#define created_hardlinks (*(hardlinks_t **)(&archive_handle->ah_priv[1]))
// if (!archive_handle->ah_priv_inited) {
// archive_handle->ah_priv_inited = 1;
// hardlinks_to_create = NULL;
// created_hardlinks = NULL;
// }
/* There can be padding before archive header */
data_align(archive_handle, 4);
size = full_read(archive_handle->src_fd, cpio_header, 110);
if (size == 0) {
if (archive_xread_all_eof(archive_handle, (unsigned char*)cpio_header, 110) == 0) {
goto create_hardlinks;
}
if (size != 110) {
bb_error_msg_and_die("short read");
}
archive_handle->offset += 110;
if (strncmp(&cpio_header[0], "07070", 5) != 0
@@ -51,21 +43,19 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
bb_error_msg_and_die("unsupported cpio format, use newc or crc");
}
if (sscanf(cpio_header + 6,
sscanf(cpio_header + 6,
"%8x" "%8x" "%8x" "%8x"
"%8x" "%8x" "%8x" /*maj,min:*/ "%*16c"
/*rmaj,rmin:*/"%8x" "%8x" "%8x" /*chksum: "%*8c"*/,
"%8x" "%8x" "%8x" /*maj,min:*/ "%16c"
/*rmaj,rmin:*/"%8x" "%8x" "%8x" /*chksum:*/ "%8c",
&inode, &mode, &uid, &gid,
&nlink, &mtime, &size,
&major, &minor, &namesize) != 10)
bb_error_msg_and_die("damaged cpio file");
&nlink, &mtime, &size, dummy,
&major, &minor, &namesize, dummy);
file_header->mode = mode;
file_header->uid = uid;
file_header->gid = gid;
file_header->mtime = mtime;
file_header->size = size;
namesize &= 0x1fff; /* paranoia: limit names to 8k chars */
file_header->name = xzalloc(namesize + 1);
/* Read in filename */
xread(archive_handle->src_fd, file_header->name, namesize);
@@ -80,17 +70,17 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
goto create_hardlinks;
}
file_header->link_target = NULL;
if (S_ISLNK(file_header->mode)) {
file_header->size &= 0x1fff; /* paranoia: limit names to 8k chars */
file_header->link_target = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, file_header->link_target, file_header->size);
archive_handle->offset += file_header->size;
file_header->size = 0; /* Stop possible seeks in future */
} else {
file_header->link_target = NULL;
}
// TODO: data_extract_all can't deal with hardlinks to non-files...
// when fixed, change S_ISREG to !S_ISDIR here
// (should be !S_ISDIR instead of S_ISREG here)
if (nlink > 1 && S_ISREG(file_header->mode)) {
hardlinks_t *new = xmalloc(sizeof(*new) + namesize);
@@ -102,13 +92,13 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
strcpy(new->name, file_header->name);
/* Put file on a linked list for later */
if (size == 0) {
new->next = hardlinks_to_create;
hardlinks_to_create = new;
new->next = saved_hardlinks;
saved_hardlinks = new;
return EXIT_SUCCESS; /* Skip this one */
/* TODO: this breaks cpio -t (it does not show hardlinks) */
}
new->next = created_hardlinks;
created_hardlinks = new;
new->next = saved_hardlinks_created;
saved_hardlinks_created = new;
}
file_header->device = makedev(major, minor);
@@ -132,23 +122,18 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
free(file_header->link_target);
free(file_header->name);
while (hardlinks_to_create) {
while (saved_hardlinks) {
hardlinks_t *cur;
hardlinks_t *make_me = hardlinks_to_create;
hardlinks_to_create = make_me->next;
hardlinks_t *make_me = saved_hardlinks;
saved_hardlinks = make_me->next;
memset(file_header, 0, sizeof(*file_header));
file_header->mtime = make_me->mtime;
file_header->name = make_me->name;
file_header->mode = make_me->mode;
file_header->uid = make_me->uid;
file_header->gid = make_me->gid;
/*file_header->size = 0;*/
/*file_header->link_target = NULL;*/
/* Try to find a file we are hardlinked to */
cur = created_hardlinks;
cur = saved_hardlinks_created;
while (cur) {
/* TODO: must match maj/min too! */
if (cur->inode == make_me->inode) {
@@ -163,17 +148,20 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
}
/* Oops... no file with such inode was created... do it now
* (happens when hardlinked files are empty (zero length)) */
file_header->mtime = make_me->mtime;
file_header->uid = make_me->uid ;
file_header->gid = make_me->gid ;
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
archive_handle->action_data(archive_handle);
/* Move to the list of created hardlinked files */
make_me->next = created_hardlinks;
created_hardlinks = make_me;
make_me->next = saved_hardlinks_created;
saved_hardlinks_created = make_me;
next_link: ;
}
while (created_hardlinks) {
hardlinks_t *p = created_hardlinks;
created_hardlinks = p->next;
while (saved_hardlinks_created) {
hardlinks_t *p = saved_hardlinks_created;
saved_hardlinks_created = p->next;
free(p);
}
+68 -78
View File
@@ -14,13 +14,26 @@
#include "libbb.h"
#include "unarchive.h"
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
static char *longname;
static char *linkname;
#else
enum {
longname = 0,
linkname = 0,
};
#endif
/* NB: _DESTROYS_ str[len] character! */
static unsigned long long getOctal(char *str, int len)
{
unsigned long long v;
/* NB: leading spaces are allowed. Using strtoull to handle that.
* The downside is that we accept e.g. "-123" too :)
*/
/* Actually, tar header allows leading spaces also.
* Oh well, we will be liberal and skip this...
* The only downside probably is that we allow "-123" too :)
if (*str < '0' || *str > '7')
bb_error_msg_and_die("corrupted octal value in tar header");
*/
str[len] = '\0';
v = strtoull(str, &str, 8);
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
@@ -30,8 +43,13 @@ static unsigned long long getOctal(char *str, int len)
#define GET_OCTAL(a) getOctal((a), sizeof(a))
void BUG_tar_header_size(void);
char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
char get_header_tar(archive_handle_t *archive_handle)
{
static smallint end;
#if ENABLE_FEATURE_TAR_AUTODETECT
static smallint not_first;
#endif
file_header_t *file_header = archive_handle->file_header;
struct {
/* ustar header, Posix 1003.1 */
@@ -47,7 +65,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
/* POSIX: "ustar" NUL "00" */
/* GNU tar: "ustar " NUL */
/* Normally it's defined as magic[6] followed by
* version[2], but we put them together to simplify code
* version[2], but we put them together to save code.
*/
char magic[8]; /* 257-264 */
char uname[32]; /* 265-296 */
@@ -64,22 +82,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
#endif
int parse_names;
/* Our "private data" */
#define p_end (*(smallint *)(&archive_handle->ah_priv[0]))
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
#define p_longname (*(char* *)(&archive_handle->ah_priv[1]))
#define p_linkname (*(char* *)(&archive_handle->ah_priv[2]))
#else
#define p_longname 0
#define p_linkname 0
#endif
// if (!archive_handle->ah_priv_inited) {
// archive_handle->ah_priv_inited = 1;
// p_end = 0;
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_longname = NULL;)
// USE_FEATURE_TAR_GNU_EXTENSIONS(p_linkname = NULL;)
// }
if (sizeof(tar) != 512)
BUG_tar_header_size();
@@ -92,46 +94,37 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
again_after_align:
#if ENABLE_DESKTOP
/* to prevent misdetection of bz2 sig */
*(uint32_t*)(&tar) = 0;
i = full_read(archive_handle->src_fd, &tar, 512);
/* If GNU tar sees EOF in above read, it says:
/* if GNU tar sees EOF in above read, it says:
* "tar: A lone zero block at N", where N = kilobyte
* where EOF was met (not EOF block, actual EOF!),
* and exits with EXIT_SUCCESS.
* and tar will exit with error code 0.
* We will mimic exit(EXIT_SUCCESS), although we will not mimic
* the message and we don't check whether we indeed
* saw zero block directly before this. */
if (i == 0) {
if (i == 0)
xfunc_error_retval = 0;
short_read:
if (i != 512)
bb_error_msg_and_die("short read");
}
if (i != 512) {
USE_FEATURE_TAR_AUTODETECT(goto autodetect;)
goto short_read;
}
#else
i = 512;
xread(archive_handle->src_fd, &tar, i);
xread(archive_handle->src_fd, &tar, 512);
#endif
archive_handle->offset += i;
archive_handle->offset += 512;
/* If there is no filename its an empty header */
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
if (p_end) {
/* Second consecutive empty header - end of archive.
if (end) {
/* This is the second consecutive empty header! End of archive!
* Read until the end to empty the pipe from gz or bz2
*/
while (full_read(archive_handle->src_fd, &tar, 512) == 512)
continue;
return EXIT_FAILURE;
}
p_end = 1;
end = 1;
return EXIT_SUCCESS;
}
p_end = 0;
end = 0;
/* Check header has valid magic, "ustar" is for the proper tar,
* five NULs are for the old tar format */
@@ -140,20 +133,21 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|| memcmp(tar.magic, "\0\0\0\0", 5) != 0)
) {
#if ENABLE_FEATURE_TAR_AUTODETECT
char FAST_FUNC (*get_header_ptr)(archive_handle_t *);
char (*get_header_ptr)(archive_handle_t *);
USE_DESKTOP(autodetect:)
/* tar gz/bz autodetect: check for gz/bz2 magic.
* If we see the magic, and it is the very first block,
* If it is the very first block, and we see the magic,
* we can switch to get_header_tar_gz/bz2/lzma().
* Needs seekable fd. I wish recv(MSG_PEEK) works
* on any fd... */
#if ENABLE_FEATURE_SEAMLESS_GZ
if (not_first)
goto err;
#if ENABLE_FEATURE_TAR_GZIP
if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */
get_header_ptr = get_header_tar_gz;
} else
#endif
#if ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_TAR_BZIP2
if (tar.name[0] == 'B' && tar.name[1] == 'Z'
&& tar.name[2] == 'h' && isdigit(tar.name[3])
) { /* bzip2 */
@@ -161,10 +155,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
} else
#endif
goto err;
/* Two different causes for lseek() != 0:
* unseekable fd (would like to support that too, but...),
* or not first block (false positive, it's not .gz/.bz2!) */
if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
if (lseek(archive_handle->src_fd, -512, SEEK_CUR) != 0)
goto err;
while (get_header_ptr(archive_handle) == EXIT_SUCCESS)
continue;
@@ -174,6 +165,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
bb_error_msg_and_die("invalid tar magic");
}
#if ENABLE_FEATURE_TAR_AUTODETECT
not_first = 1;
#endif
/* Do checksum on headers.
* POSIX says that checksum is done on unsigned bytes, but
* Sun and HP-UX gets it wrong... more details in
@@ -224,7 +219,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
tar.prefix[0] = t;
}
file_header->link_target = NULL;
if (!p_linkname && parse_names && tar.linkname[0]) {
if (!linkname && parse_names && tar.linkname[0]) {
file_header->link_target = xstrndup(tar.linkname, sizeof(tar.linkname));
/* FIXME: what if we have non-link object with link_target? */
/* Will link_target be free()ed? */
@@ -241,7 +236,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
file_header->mode = 07777 & GET_OCTAL(tar.mode);
file_header->name = NULL;
if (!p_longname && parse_names) {
if (!longname && parse_names) {
/* we trash mode[0] here, it's ok */
//tar.name[sizeof(tar.name)] = '\0'; - gcc 4.3.0 would complain
tar.mode[0] = '\0';
@@ -266,48 +261,43 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
case '0':
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
if (last_char_is(file_header->name, '/')) {
goto set_dir;
}
file_header->mode |= S_IFDIR;
} else
#endif
file_header->mode |= S_IFREG;
break;
case '2':
file_header->mode |= S_IFLNK;
/* have seen tarballs with size field containing
* the size of the link target's name */
size0:
file_header->size = 0;
break;
case '3':
file_header->mode |= S_IFCHR;
goto size0; /* paranoia */
break;
case '4':
file_header->mode |= S_IFBLK;
goto size0;
break;
case '5':
USE_FEATURE_TAR_OLDGNU_COMPATIBILITY(set_dir:)
file_header->mode |= S_IFDIR;
goto size0;
break;
case '6':
file_header->mode |= S_IFIFO;
goto size0;
break;
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
case 'L':
/* free: paranoia: tar with several consecutive longnames */
free(p_longname);
free(longname);
/* For paranoia reasons we allocate extra NUL char */
p_longname = xzalloc(file_header->size + 1);
longname = xzalloc(file_header->size + 1);
/* We read ASCIZ string, including NUL */
xread(archive_handle->src_fd, p_longname, file_header->size);
xread(archive_handle->src_fd, longname, file_header->size);
archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */
/* gcc 4.1.1 didn't optimize it into jump */
/* so we will do it ourself, this also saves stack */
goto again;
case 'K':
free(p_linkname);
p_linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, p_linkname, file_header->size);
free(linkname);
linkname = xzalloc(file_header->size + 1);
xread(archive_handle->src_fd, linkname, file_header->size);
archive_handle->offset += file_header->size;
/* return get_header_tar(archive_handle); */
goto again;
@@ -334,16 +324,16 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
}
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
if (p_longname) {
file_header->name = p_longname;
p_longname = NULL;
if (longname) {
file_header->name = longname;
longname = NULL;
}
if (p_linkname) {
file_header->link_target = p_linkname;
p_linkname = NULL;
if (linkname) {
file_header->link_target = linkname;
linkname = NULL;
}
#endif
if (strncmp(file_header->name, "/../"+1, 3) == 0
if (!strncmp(file_header->name, "/../"+1, 3)
|| strstr(file_header->name, "/../")
) {
bb_error_msg_and_die("name with '..' encountered: '%s'",
@@ -355,11 +345,11 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
cp = last_char_is(file_header->name, '/');
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
archive_handle->action_header(/*archive_handle->*/ file_header);
archive_handle->action_header(archive_handle->file_header);
/* Note that we kill the '/' only after action_header() */
/* (like GNU tar 1.15.1: verbose mode outputs "dir/dir/") */
if (cp) *cp = '\0';
archive_handle->ah_flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->flags |= ARCHIVE_EXTRACT_QUIET;
archive_handle->action_data(archive_handle);
llist_add_to(&(archive_handle->passed), file_header->name);
} else {
@@ -369,7 +359,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
archive_handle->offset += file_header->size;
free(file_header->link_target);
/* Do not free(file_header->name)! (why?) */
/* Do not free(file_header->name)! */
#if ENABLE_FEATURE_TAR_UNAME_GNAME
free(file_header->uname);
free(file_header->gname);
+2 -2
View File
@@ -6,12 +6,12 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_bz2(archive_handle_t *archive_handle)
char get_header_tar_bz2(archive_handle_t *archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer(archive_handle->src_fd, unpack_bz2_stream_prime, "bunzip2");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+2 -3
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
char get_header_tar_gz(archive_handle_t *archive_handle)
{
#if BB_MMU
unsigned char magic[2];
@@ -20,13 +20,12 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
* need the header. */
#if BB_MMU
xread(archive_handle->src_fd, &magic, 2);
/* Can skip this check, but error message will be less clear */
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("invalid gzip magic");
}
#endif
open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+2 -2
View File
@@ -9,12 +9,12 @@
#include "libbb.h"
#include "unarchive.h"
char FAST_FUNC get_header_tar_lzma(archive_handle_t *archive_handle)
char get_header_tar_lzma(archive_handle_t * archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
+1 -1
View File
@@ -5,7 +5,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_list(const file_header_t *file_header)
void header_list(const file_header_t *file_header)
{
puts(file_header->name);
}
+1 -1
View File
@@ -5,6 +5,6 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_skip(const file_header_t *file_header UNUSED_PARAM)
void header_skip(const file_header_t *file_header ATTRIBUTE_UNUSED)
{
}
+1 -1
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
void header_verbose_list(const file_header_t *file_header)
{
struct tm *mtime = localtime(&(file_header->mtime));
+1 -1
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
archive_handle_t* FAST_FUNC init_handle(void)
archive_handle_t *init_handle(void)
{
archive_handle_t *archive_handle;
+13 -13
View File
@@ -11,8 +11,8 @@
* On MMU machine, the transform_prog is removed by macro magic
* in include/unarchive.h. On NOMMU, transformer is removed.
*/
void FAST_FUNC open_transformer(int fd,
USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
int open_transformer(int src_fd,
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
const char *transform_prog)
{
struct fd_pair fd_pipe;
@@ -23,29 +23,28 @@ void FAST_FUNC open_transformer(int fd,
#if BB_MMU
pid = fork();
if (pid == -1)
bb_perror_msg_and_die("vfork" + 1);
bb_perror_msg_and_die("can't fork");
#else
pid = vfork();
if (pid == -1)
bb_perror_msg_and_die("vfork");
bb_perror_msg_and_die("can't vfork");
#endif
if (pid == 0) {
/* child process */
close(fd_pipe.rd); /* we don't want to read from the parent */
close(fd_pipe.rd); /* We don't want to read from the parent */
// FIXME: error check?
#if BB_MMU
transformer(fd, fd_pipe.wr);
transformer(src_fd, fd_pipe.wr);
if (ENABLE_FEATURE_CLEAN_UP) {
close(fd_pipe.wr); /* send EOF */
close(fd);
close(fd_pipe.wr); /* Send EOF */
close(src_fd);
}
/* must be _exit! bug was actually seen here */
_exit(EXIT_SUCCESS);
exit(EXIT_SUCCESS);
#else
{
char *argv[4];
xmove_fd(fd, 0);
xmove_fd(src_fd, 0);
xmove_fd(fd_pipe.wr, 1);
argv[0] = (char*)transform_prog;
argv[1] = (char*)"-cf";
@@ -59,6 +58,7 @@ void FAST_FUNC open_transformer(int fd,
}
/* parent process */
close(fd_pipe.wr); /* don't want to write to the child */
xmove_fd(fd_pipe.rd, fd);
close(fd_pipe.wr); /* Don't want to write to the child */
return fd_pipe.rd;
}
+2 -4
View File
@@ -6,11 +6,9 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
void seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
{
if (amount
&& lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1
) {
if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
if (errno == ESPIPE)
seek_by_read(archive_handle, amount);
else
+1 -1
View File
@@ -9,7 +9,7 @@
/* If we are reading through a pipe, or from stdin then we can't lseek,
* we must read and discard the data to skip over it.
*/
void FAST_FUNC seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
void seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
{
if (jump_size)
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
+2 -3
View File
@@ -6,7 +6,7 @@
#include "libbb.h"
#include "unarchive.h"
void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
void unpack_ar_archive(archive_handle_t *ar_archive)
{
char magic[7];
@@ -16,6 +16,5 @@ void FAST_FUNC unpack_ar_archive(archive_handle_t *ar_archive)
}
ar_archive->offset += 7;
while (get_header_ar(ar_archive) == EXIT_SUCCESS)
continue;
while (get_header_ar(ar_archive) == EXIT_SUCCESS);
}
+19 -18
View File
@@ -190,7 +190,7 @@ static void extract_cpio_gz(int fd)
archive_handle_t *archive_handle;
unsigned char magic[2];
#if BB_MMU
USE_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd);
USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
enum { xformer_prog = 0 };
#else
enum { xformer = 0 };
@@ -202,11 +202,10 @@ static void extract_cpio_gz(int fd)
archive_handle->seek = seek_by_read;
//archive_handle->action_header = header_list;
archive_handle->action_data = data_extract_all;
archive_handle->ah_flags = ARCHIVE_PRESERVE_DATE | ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
archive_handle->flags |= ARCHIVE_CREATE_LEADING_DIRS;
archive_handle->src_fd = fd;
/*archive_handle->offset = 0; - init_handle() did it */
// TODO: open_zipped does the same
archive_handle->offset = 0;
xread(archive_handle->src_fd, &magic, 2);
#if BB_MMU
@@ -214,19 +213,21 @@ static void extract_cpio_gz(int fd)
#else
xformer_prog = "gunzip";
#endif
if (magic[0] != 0x1f || magic[1] != 0x8b) {
if (!ENABLE_FEATURE_SEAMLESS_BZ2
|| magic[0] != 'B' || magic[1] != 'Z'
) {
bb_error_msg_and_die("no gzip"
USE_FEATURE_SEAMLESS_BZ2("/bzip2")
" magic");
}
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;
xformer = unpack_bz2_stream;
#else
xformer_prog = "bunzip2";
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 {
#if !BB_MMU
/* NOMMU version of open_transformer execs an external unzipper that should
@@ -236,7 +237,7 @@ static void extract_cpio_gz(int fd)
}
xchdir("/"); /* Install RPM's to root */
open_transformer(archive_handle->src_fd, xformer, xformer_prog);
archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog);
archive_handle->offset = 0;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
@@ -279,12 +280,12 @@ static rpm_index **rpm_gettags(int fd, int *num_tags)
tmpindex->type = ntohl(tmpindex->type);
tmpindex->count = ntohl(tmpindex->count);
tmpindex->offset = storepos + ntohl(tmpindex->offset);
if (pass == 0)
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)
if (pass==0)
xlseek(fd, (8 - (xlseek(fd,0,SEEK_CUR) % 8)) % 8, SEEK_CUR);
}
tags = xrealloc(tags, tagindex * sizeof(struct rpmtag *)); /* realloc tags to save space */
+56 -62
View File
@@ -36,7 +36,7 @@
#define block_buf bb_common_bufsiz1
#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
#if !ENABLE_FEATURE_TAR_GZIP && !ENABLE_FEATURE_TAR_BZIP2
/* Do not pass gzip flag to writeTarFile() */
#define writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude, gzip) \
writeTarFile(tar_fd, verboseFlag, dereferenceFlag, include, exclude)
@@ -396,8 +396,8 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
#define exclude_file(excluded_files, file) 0
#endif
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth UNUSED_PARAM)
static int writeFileToTarball(const char *fileName, struct stat *statbuf,
void *userData, int depth ATTRIBUTE_UNUSED)
{
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
const char *header_name;
@@ -503,19 +503,19 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
#if !(ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2)
#define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
#endif
/* Don't inline: vfork scares gcc and pessimizes code */
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
{
pid_t gzipPid;
#if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_TAR_GZIP && ENABLE_FEATURE_TAR_BZIP2
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
#elif ENABLE_FEATURE_SEAMLESS_GZ
#elif ENABLE_FEATURE_TAR_GZIP
const char *zip_exec = "gzip";
#else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
#else /* only ENABLE_FEATURE_TAR_BZIP2 */
const char *zip_exec = "bzip2";
#endif
// On Linux, vfork never unpauses parent early, although standard
@@ -538,7 +538,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
gzipPid = vfork();
if (gzipPid < 0)
bb_perror_msg_and_die("vfork");
bb_perror_msg_and_die("can't vfork");
if (gzipPid == 0) {
/* child */
@@ -579,7 +579,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
bb_perror_msg_and_die("cannot exec %s", zip_exec);
}
}
#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
#endif /* ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2 */
/* gcc 4.2.1 inlines it, making code bigger */
@@ -601,7 +601,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
bb_perror_msg_and_die("cannot stat tar file");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
if (gzip)
vfork_compressor(tbInfo.tarFd, gzip);
#endif
@@ -637,7 +637,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
if (gzip) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
@@ -663,7 +663,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
llist_t *newlist = NULL;
while (list) {
src_stream = xfopen_for_read(llist_pop(&list));
src_stream = xfopen(llist_pop(&list), "r");
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
/* kill trailing '/' unless the string is just "/" */
char *cp = last_char_is(line, '/');
@@ -679,8 +679,8 @@ static llist_t *append_file_list_to_list(llist_t *list)
#define append_file_list_to_list(x) 0
#endif
#if ENABLE_FEATURE_SEAMLESS_Z
static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
#if ENABLE_FEATURE_TAR_COMPRESS
static char get_header_tar_Z(archive_handle_t *archive_handle)
{
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
@@ -692,7 +692,7 @@ static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
bb_error_msg_and_die("invalid magic");
}
open_transformer(archive_handle->src_fd, unpack_Z_stream, "uncompress");
archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress");
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
continue;
@@ -729,14 +729,14 @@ static void handle_SIGCHLD(int status)
enum {
OPTBIT_KEEP_OLD = 7,
USE_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
USE_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
USE_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
USE_FEATURE_SEAMLESS_LZMA(OPTBIT_LZMA ,)
USE_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
USE_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
USE_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
USE_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
USE_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
USE_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
USE_FEATURE_TAR_BZIP2( OPTBIT_BZIP2 ,)
USE_FEATURE_TAR_LZMA( OPTBIT_LZMA ,)
USE_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
USE_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
USE_FEATURE_TAR_GZIP( OPTBIT_GZIP ,)
USE_FEATURE_TAR_COMPRESS(OPTBIT_COMPRESS ,)
OPTBIT_NOPRESERVE_OWN,
OPTBIT_NOPRESERVE_PERM,
OPT_TEST = 1 << 0, // t
@@ -747,14 +747,14 @@ enum {
OPT_P = 1 << 5, // p
OPT_VERBOSE = 1 << 6, // v
OPT_KEEP_OLD = 1 << 7, // k
OPT_CREATE = USE_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = USE_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = USE_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = USE_FEATURE_SEAMLESS_LZMA((1 << OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = USE_FEATURE_TAR_FROM( (1 << OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
OPT_GZIP = USE_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
OPT_COMPRESS = USE_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
OPT_CREATE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_CREATE )) + 0, // c
OPT_DEREFERENCE = USE_FEATURE_TAR_CREATE( (1<<OPTBIT_DEREFERENCE )) + 0, // h
OPT_BZIP2 = USE_FEATURE_TAR_BZIP2( (1<<OPTBIT_BZIP2 )) + 0, // j
OPT_LZMA = USE_FEATURE_TAR_LZMA( (1<<OPTBIT_LZMA )) + 0, // a
OPT_INCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_INCLUDE_FROM)) + 0, // T
OPT_EXCLUDE_FROM = USE_FEATURE_TAR_FROM( (1<<OPTBIT_EXCLUDE_FROM)) + 0, // X
OPT_GZIP = USE_FEATURE_TAR_GZIP( (1<<OPTBIT_GZIP )) + 0, // z
OPT_COMPRESS = USE_FEATURE_TAR_COMPRESS((1<<OPTBIT_COMPRESS )) + 0, // Z
OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
};
@@ -772,20 +772,20 @@ static const char tar_longopts[] ALIGN1 =
"create\0" No_argument "c"
"dereference\0" No_argument "h"
# endif
# if ENABLE_FEATURE_SEAMLESS_BZ2
# if ENABLE_FEATURE_TAR_BZIP2
"bzip2\0" No_argument "j"
# endif
# if ENABLE_FEATURE_SEAMLESS_LZMA
# if ENABLE_FEATURE_TAR_LZMA
"lzma\0" No_argument "a"
# endif
# if ENABLE_FEATURE_TAR_FROM
"files-from\0" Required_argument "T"
"exclude-from\0" Required_argument "X"
# endif
# if ENABLE_FEATURE_SEAMLESS_GZ
# if ENABLE_FEATURE_TAR_GZIP
"gzip\0" No_argument "z"
# endif
# if ENABLE_FEATURE_SEAMLESS_Z
# if ENABLE_FEATURE_TAR_COMPRESS
"compress\0" No_argument "Z"
# endif
"no-same-owner\0" No_argument "\xfd"
@@ -800,9 +800,9 @@ static const char tar_longopts[] ALIGN1 =
#endif
int tar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int tar_main(int argc UNUSED_PARAM, char **argv)
int tar_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
char FAST_FUNC (*get_header_ptr)(archive_handle_t *) = get_header_tar;
char (*get_header_ptr)(archive_handle_t *) = get_header_tar;
archive_handle_t *tar_handle;
char *base_dir = NULL;
const char *tar_filename = "-";
@@ -814,9 +814,9 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Initialise default values */
tar_handle = init_handle();
tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
| ARCHIVE_PRESERVE_DATE
| ARCHIVE_EXTRACT_UNCONDITIONAL;
tar_handle->flags = ARCHIVE_CREATE_LEADING_DIRS
| ARCHIVE_PRESERVE_DATE
| ARCHIVE_EXTRACT_UNCONDITIONAL;
/* Prepend '-' to the first argument if required */
opt_complementary = "--:" // first arg is options
@@ -834,12 +834,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
#endif
opt = getopt32(argv,
"txC:f:Opvk"
USE_FEATURE_TAR_CREATE( "ch" )
USE_FEATURE_SEAMLESS_BZ2( "j" )
USE_FEATURE_SEAMLESS_LZMA("a" )
USE_FEATURE_TAR_FROM( "T:X:")
USE_FEATURE_SEAMLESS_GZ( "z" )
USE_FEATURE_SEAMLESS_Z( "Z" )
USE_FEATURE_TAR_CREATE( "ch" )
USE_FEATURE_TAR_BZIP2( "j" )
USE_FEATURE_TAR_LZMA( "a" )
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
@@ -862,13 +862,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->action_data = data_extract_to_stdout;
if (opt & OPT_KEEP_OLD)
tar_handle->ah_flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
tar_handle->flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
if (opt & OPT_NOPRESERVE_OWN)
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_OWN;
tar_handle->flags |= ARCHIVE_NOPRESERVE_OWN;
if (opt & OPT_NOPRESERVE_PERM)
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
tar_handle->flags |= ARCHIVE_NOPRESERVE_PERM;
if (opt & OPT_GZIP)
get_header_ptr = get_header_tar_gz;
@@ -922,7 +922,8 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_stream = stdout;
/* Mimicking GNU tar 1.15.1: */
flags = O_WRONLY | O_CREAT | O_TRUNC;
flags = O_WRONLY|O_CREAT|O_TRUNC;
/* was doing unlink; open(O_WRONLY|O_CREAT|O_EXCL); why? */
} else {
tar_stream = stdin;
flags = O_RDONLY;
@@ -932,14 +933,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
tar_handle->src_fd = fileno(tar_stream);
tar_handle->seek = seek_by_read;
} else {
if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) {
get_header_ptr = get_header_tar;
tar_handle->src_fd = open_zipped(tar_filename);
if (tar_handle->src_fd < 0)
bb_perror_msg_and_die("can't open '%s'", tar_filename);
} else {
tar_handle->src_fd = xopen(tar_filename, flags);
}
tar_handle->src_fd = xopen(tar_filename, flags);
}
}
@@ -953,11 +947,11 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* create an archive */
if (opt & OPT_CREATE) {
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
#if ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2
int zipMode = 0;
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
if (ENABLE_FEATURE_TAR_GZIP && (opt & OPT_GZIP))
zipMode = 1;
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
if (ENABLE_FEATURE_TAR_BZIP2 && (opt & OPT_BZIP2))
zipMode = 2;
#endif
/* NB: writeTarFile() closes tar_handle->src_fd */
+17 -25
View File
@@ -51,13 +51,13 @@ typedef union {
uint16_t method; /* 4-5 */
uint16_t modtime; /* 6-7 */
uint16_t moddate; /* 8-9 */
uint32_t crc32 PACKED; /* 10-13 */
uint32_t cmpsize PACKED; /* 14-17 */
uint32_t ucmpsize PACKED; /* 18-21 */
uint32_t crc32 ATTRIBUTE_PACKED; /* 10-13 */
uint32_t cmpsize ATTRIBUTE_PACKED; /* 14-17 */
uint32_t ucmpsize ATTRIBUTE_PACKED; /* 18-21 */
uint16_t filename_len; /* 22-23 */
uint16_t extra_len; /* 24-25 */
} formatted PACKED;
} zip_header_t; /* PACKED - gcc 4.2.1 doesn't like it (spews warning) */
} formatted ATTRIBUTE_PACKED;
} zip_header_t; /* ATTRIBUTE_PACKED - gcc 4.2.1 doesn't like it (spews warning) */
/* Check the offset of the last element, not the length. This leniency
* allows for poor packing, whereby the overall struct may be too long,
@@ -258,11 +258,10 @@ int unzip_main(int argc, char **argv)
/* Check magic number */
xread(src_fd, &magic, 4);
/* Central directory? It's at the end, so exit */
if (magic == ZIP_CDS_MAGIC)
break;
if (magic != ZIP_FILEHEADER_MAGIC)
bb_error_msg_and_die("invalid zip magic %08X", (int)magic);
bb_error_msg_and_die("invalid zip magic %08X", magic);
/* Read the file header */
xread(src_fd, zip_header.raw, ZIP_HEADER_LEN);
@@ -270,12 +269,6 @@ int unzip_main(int argc, char **argv)
if ((zip_header.formatted.method != 0) && (zip_header.formatted.method != 8)) {
bb_error_msg_and_die("unsupported method %d", zip_header.formatted.method);
}
if (zip_header.formatted.flags & (0x0008|0x0001)) {
/* 0x0001 - encrypted */
/* 0x0008 - streaming. [u]cmpsize can be reliably gotten
* only from Central Directory. See unzip_doc.txt */
bb_error_msg_and_die("zip flags 8 and 1 are not supported");
}
/* Read filename */
free(dst_fn);
@@ -315,7 +308,7 @@ int unzip_main(int argc, char **argv)
} else if (last_char_is(dst_fn, '/')) { /* Extract directory */
if (stat(dst_fn, &stat_buf) == -1) {
if (errno != ENOENT) {
bb_perror_msg_and_die("cannot stat '%s'", dst_fn);
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
if (verbose) {
printf(" creating: %s\n", dst_fn);
@@ -332,10 +325,10 @@ 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);
bb_perror_msg_and_die("cannot stat '%s'",dst_fn);
}
i = 'y';
} else { /* File already exists */
@@ -352,7 +345,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);
bb_error_msg_and_die("'%s' exists but is not regular file",dst_fn);
}
}
}
@@ -391,19 +384,18 @@ int unzip_main(int argc, char **argv)
free(dst_fn);
dst_fn = xstrdup(key_buf);
chomp(dst_fn);
goto check_file;
goto _check_file;
default:
printf("error: invalid response [%c]\n",(char)i);
goto check_file;
goto _check_file;
}
// Looks like bug (data descriptor cannot be identified this way)
// /* Data descriptor section */
// if (zip_header.formatted.flags & 4) {
// /* skip over duplicate crc, compressed size and uncompressed size */
// unzip_skip(src_fd, 12);
// }
/* Data descriptor section */
if (zip_header.formatted.flags & 4) {
/* skip over duplicate crc, compressed size and uncompressed size */
unzip_skip(src_fd, 12);
}
}
if (listing && verbose) {
Binary file not shown.
Binary file not shown.
-12
View File
@@ -95,12 +95,6 @@ config FEATURE_SETCONSOLE_LONG_OPTIONS
help
Support long options for the setconsole applet.
config SETFONT
bool "setfont"
default n
help
Allows to load console screen map. Useful for i18n.
config SETKEYCODES
bool "setkeycodes"
default n
@@ -114,10 +108,4 @@ config SETLOGCONS
help
This program redirects the output console of kernel messages.
config SHOWKEY
bool "showkey"
default n
help
Shows keys pressed.
endmenu
-2
View File
@@ -16,7 +16,5 @@ lib-$(CONFIG_LOADKMAP) += loadkmap.o
lib-$(CONFIG_OPENVT) += openvt.o
lib-$(CONFIG_RESET) += reset.o
lib-$(CONFIG_RESIZE) += resize.o
lib-$(CONFIG_SETFONT) += loadfont.o
lib-$(CONFIG_SETKEYCODES) += setkeycodes.o
lib-$(CONFIG_SETLOGCONS) += setlogcons.o
lib-$(CONFIG_SHOWKEY) += showkey.o
+2 -1
View File
@@ -19,6 +19,7 @@ int chvt_main(int argc, char **argv)
}
num = xatou_range(argv[1], 1, 63);
console_make_active(get_console_fd_or_die(), num);
/* double cast suppresses "cast to ptr from int of different size" */
console_make_active(get_console_fd(), num);
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -13,7 +13,7 @@
#include "libbb.h"
int clear_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int clear_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int clear_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
return printf("\033[H\033[J") != 6;
}
+2 -2
View File
@@ -16,7 +16,7 @@
enum { VT_DISALLOCATE = 0x5608 }; /* free memory associated to vt */
int deallocvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int deallocvt_main(int argc UNUSED_PARAM, char **argv)
int deallocvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
/* num = 0 deallocate all unused consoles */
int num = 0;
@@ -28,6 +28,6 @@ int deallocvt_main(int argc UNUSED_PARAM, char **argv)
}
/* double cast suppresses "cast to ptr from int of different size" */
xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
return EXIT_SUCCESS;
}
+2 -2
View File
@@ -24,7 +24,7 @@ struct kbentry {
#define MAX_NR_KEYMAPS 256
int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int dumpkmap_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
{
struct kbentry ke;
int i, j, fd;
@@ -32,7 +32,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
/* bb_warn_ignoring_args(argc>=2);*/
fd = get_console_fd_or_die();
fd = xopen(CURRENT_VC, O_RDWR);
write(STDOUT_FILENO, "bkeymap", 7);
+10 -8
View File
@@ -2,7 +2,7 @@
/*
* Mini kbd_mode implementation for busybox
*
* Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
* Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com>
* written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
* console-utils v0.2.3, licensed under GNU GPLv2
*
@@ -14,20 +14,22 @@
#include <linux/kd.h>
int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv)
{
int fd;
unsigned opt;
enum {
SCANCODE = (1 << 0),
ASCII = (1 << 1),
MEDIUMRAW = (1 << 2),
UNICODE = (1 << 3)
SCANCODE = (1<<0),
ASCII = (1<<1),
MEDIUMRAW= (1<<2),
UNICODE = (1<<3)
};
static const char KD_xxx[] ALIGN1 = "saku";
opt = getopt32(argv, KD_xxx);
fd = get_console_fd_or_die();
fd = get_console_fd();
/* if (fd < 0)
return EXIT_FAILURE;
*/
if (!opt) { /* print current setting */
const char *mode = "unknown";
int m;
+72 -88
View File
@@ -26,7 +26,7 @@ struct psf_header {
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x)->magic1 == PSF_MAGIC1 && (x)->magic2 == PSF_MAGIC2)
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
{
@@ -37,6 +37,7 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
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);
@@ -57,7 +58,8 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
free(buf);
}
static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
{
struct unimapinit advice;
struct unimapdesc ud;
@@ -66,7 +68,7 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
int glyph;
uint16_t unicode;
maxct = tailsz; /* more than enough */
maxct = tailsz; /* more than enough */
up = xmalloc(maxct * sizeof(struct unipair));
for (glyph = 0; glyph < fontsize; glyph++) {
@@ -94,104 +96,86 @@ static void do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
xioctl(fd, PIO_UNIMAP, &ud);
}
static void do_load(int fd, struct psf_header *psfhdr, size_t len)
static void loadnewfont(int fd)
{
enum { INBUF_SIZE = 32*1024 + 1 };
int unit;
int fontsize;
int hastable;
unsigned head0, head = head;
/* test for psf first */
if (len >= sizeof(struct psf_header) && PSF_MAGIC_OK(psfhdr)) {
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 (fontsize != 256)
bb_error_msg_and_die("only fontsize 256 supported");
#endif
hastable = (psfhdr->mode & PSF_MODEHASTAB);
unit = psfhdr->charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize * unit;
if (head > len || (!hastable && head != len))
bb_error_msg_and_die("input file: bad length");
} else {
/* file with three code pages? */
if (len == 9780) {
head0 = 40;
unit = 16;
} else {
/* bare font */
if (len & 0377)
bb_error_msg_and_die("input file: bad length");
head0 = 0;
unit = len / 256;
}
fontsize = 256;
hastable = 0;
}
do_loadfont(fd, (unsigned char *)psfhdr + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, (unsigned char *)psfhdr + head, len - head, fontsize);
}
#if ENABLE_LOADFONT
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc UNUSED_PARAM, char **argv)
{
size_t len;
struct psf_header *psfhdr;
// no arguments allowed!
opt_complementary = "=0";
getopt32(argv, "");
unsigned inputlth, offset;
/* Was on stack, but 32k is a bit too much: */
unsigned char *inbuf = xmalloc(INBUF_SIZE);
/*
* We used to look at the length of the input file
* with stat(); now that we accept compressed files,
* just read the entire file.
*/
len = 32*1024; // can't be larger
psfhdr = (struct psf_header *) xmalloc_read(STDIN_FILENO, &len);
// xmalloc_open_zipped_read_close(filename, &len);
if (!psfhdr)
inputlth = full_read(STDIN_FILENO, inbuf, INBUF_SIZE);
if (inputlth < 0)
bb_perror_msg_and_die("error reading input font");
do_load(get_console_fd_or_die(), psfhdr, len);
if (inputlth >= INBUF_SIZE)
bb_error_msg_and_die("font too large");
return EXIT_SUCCESS;
}
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
unsigned head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = *(struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
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 (fontsize != 256)
bb_error_msg_and_die("only fontsize 256 supported");
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
#if ENABLE_SETFONT
int setfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setfont_main(int argc UNUSED_PARAM, char **argv)
{
size_t len;
struct psf_header *psfhdr;
char *mapfilename;
int fd;
opt_complementary = "=1";
getopt32(argv, "m:", &mapfilename);
argv += optind;
// load font
len = 32*1024; // can't be larger
psfhdr = (struct psf_header *) xmalloc_open_zipped_read_close(*argv, &len);
fd = get_console_fd_or_die();
do_load(fd, psfhdr, len);
// load the screen map, if any
if (option_mask32 & 1) { // -m
void *map = xmalloc_open_zipped_read_close(mapfilename, &len);
if (len == E_TABSZ || len == 2*E_TABSZ) {
xioctl(fd, (len == 2*E_TABSZ) ? PIO_UNISCRNMAP : PIO_SCRNMAP, map);
}
head = head0 + fontsize * unit;
if (head > inputlth || (!hastable && head != inputlth))
bb_error_msg_and_die("input file: bad length");
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
return;
}
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377)
bb_error_msg_and_die("bad input file size");
offset = 0;
unit = inputlth / 256;
}
do_loadfont(fd, inbuf + offset, unit, 256);
}
int loadfont_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadfont_main(int argc, char **argv ATTRIBUTE_UNUSED)
{
int fd;
if (argc != 1)
bb_show_usage();
fd = xopen(CURRENT_VC, O_RDWR);
loadnewfont(fd);
return EXIT_SUCCESS;
}
#endif
+2 -2
View File
@@ -26,7 +26,7 @@ struct kbentry {
#define MAX_NR_KEYMAPS 256
int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int loadkmap_main(int ATTRIBUTE_UNUSED argc, char **argv ATTRIBUTE_UNUSED)
{
struct kbentry ke;
int i, j, fd;
@@ -35,7 +35,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
/* bb_warn_ignoring_args(argc>=2);*/
fd = get_console_fd_or_die();
fd = xopen(CURRENT_VC, O_RDWR);
xread(STDIN_FILENO, flags, 7);
if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
+1 -1
View File
@@ -105,7 +105,7 @@ static NOINLINE void vfork_child(char **argv)
}
int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int openvt_main(int argc UNUSED_PARAM, char **argv)
int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
struct vt_stat vtstat;
+1 -1
View File
@@ -18,7 +18,7 @@ int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
#endif
int reset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int reset_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int reset_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
static const char *const args[] = {
"stty", "sane", NULL
+2 -2
View File
@@ -14,14 +14,14 @@
#define old_termios (*(struct termios*)&bb_common_bufsiz1)
static void
onintr(int sig UNUSED_PARAM)
onintr(int sig ATTRIBUTE_UNUSED)
{
tcsetattr(STDERR_FILENO, TCSANOW, &old_termios);
exit(EXIT_FAILURE);
}
int resize_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int resize_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int resize_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
struct termios new;
struct winsize w = { 0, 0, 0, 0 };
+1 -1
View File
@@ -11,7 +11,7 @@
#include "libbb.h"
int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setconsole_main(int argc UNUSED_PARAM, char **argv)
int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv)
{
const char *device = CURRENT_TTY;
bool reset;
+3 -3
View File
@@ -26,11 +26,11 @@ int setkeycodes_main(int argc, char **argv)
int fd, sc;
struct kbkeycode a;
if (!(argc & 1) /* if even */ || argc < 2) {
if (argc % 2 != 1 || argc < 2) {
bb_show_usage();
}
fd = get_console_fd_or_die();
fd = get_console_fd();
while (argc > 2) {
a.keycode = xatou_range(argv[2], 0, 127);
@@ -40,7 +40,7 @@ int setkeycodes_main(int argc, char **argv)
a.scancode += 128;
}
ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
"can't set SCANCODE %x to KEYCODE %d",
"failed to set SCANCODE %x to KEYCODE %d",
sc, a.keycode);
argc -= 2;
argv += 2;
+1 -1
View File
@@ -12,7 +12,7 @@
#include "libbb.h"
int setlogcons_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int setlogcons_main(int argc UNUSED_PARAM, char **argv)
int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
struct {
char fn;
-138
View File
@@ -1,138 +0,0 @@
/* vi: set sw=4 ts=4: */
/*
* shows keys pressed. inspired by kbd package
*
* Copyright (C) 2008 by Vladimir Dronnikov <dronnikov@gmail.com>
*
* Licensed under GPLv2, see file LICENSE in this tarball for details.
*/
#include "libbb.h"
#include <linux/kd.h>
// set raw tty mode
// also used by microcom
// libbb candidates?
static void xget1(int fd, struct termios *t, struct termios *oldt)
{
tcgetattr(fd, oldt);
*t = *oldt;
cfmakeraw(t);
}
static int xset1(int fd, struct termios *tio, const char *device)
{
int ret = tcsetattr(fd, TCSAFLUSH, tio);
if (ret) {
bb_perror_msg("can't tcsetattr for %s", device);
}
return ret;
}
/*
* GLOBALS
*/
struct globals {
int kbmode;
struct termios tio, tio0;
};
#define G (*ptr_to_globals)
#define kbmode (G.kbmode)
#define tio (G.tio)
#define tio0 (G.tio0)
#define INIT_G() do { \
SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
} while (0)
static void signal_handler(int signo)
{
// restore keyboard and console settings
xset1(STDIN_FILENO, &tio0, "stdin");
xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
// alarmed? -> exit 0
exit(SIGALRM == signo);
}
int showkey_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int showkey_main(int argc UNUSED_PARAM, char **argv)
{
enum {
OPT_a = (1<<0), // display the decimal/octal/hex values of the keys
OPT_k = (1<<1), // display only the interpreted keycodes (default)
OPT_s = (1<<2), // display only the raw scan-codes
};
// FIXME: aks are all mutually exclusive
getopt32(argv, "aks");
INIT_G();
// get keyboard settings
xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",
kbmode == K_RAW ? "RAW" :
(kbmode == K_XLATE ? "XLATE" :
(kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
(kbmode == K_UNICODE ? "UNICODE" : "?UNKNOWN?")))
, (option_mask32 & OPT_a) ? "when CTRL+D pressed" : "10s after last keypress"
);
// prepare for raw mode
xget1(STDIN_FILENO, &tio, &tio0);
// put stdin in raw mode
xset1(STDIN_FILENO, &tio, "stdin");
if (option_mask32 & OPT_a) {
char c;
// just read stdin char by char
while (1 == safe_read(STDIN_FILENO, &c, 1)) {
printf("%3d 0%03o 0x%02x\r\n", c, c, c);
if (04 /*CTRL-D*/ == c)
break;
}
} else {
// we should exit on any signal
bb_signals(BB_FATAL_SIGS, signal_handler);
// set raw keyboard mode
xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW));
// read and show scancodes
while (1) {
char buf[18];
int i, n;
// setup 10s watchdog
alarm(10);
// read scancodes
n = read(STDIN_FILENO, buf, sizeof(buf));
i = 0;
while (i < n) {
char c = buf[i];
// show raw scancodes ordered? ->
if (option_mask32 & OPT_s) {
printf("0x%02x ", buf[i++]);
// show interpreted scancodes (default) ? ->
} else {
int kc;
if (i+2 < n && (c & 0x7f) == 0
&& (buf[i+1] & 0x80) != 0
&& (buf[i+2] & 0x80) != 0) {
kc = ((buf[i+1] & 0x7f) << 7) | (buf[i+2] & 0x7f);
i += 3;
} else {
kc = (c & 0x7f);
i++;
}
printf("keycode %3d %s", kc, (c & 0x80) ? "release" : "press");
}
}
puts("\r");
}
}
// cleanup
signal_handler(SIGALRM);
// should never be here!
return EXIT_SUCCESS;
}
+13 -29
View File
@@ -10,7 +10,7 @@ config BASENAME
default n
help
basename is used to strip the directory and suffix from filenames,
leaving just the filename itself. Enable this option if you wish
leaving just the filename itself. Enable this option if you wish
to enable the 'basename' utility.
config CAL
@@ -24,7 +24,7 @@ config CAT
default n
help
cat is used to concatenate files and print them to the standard
output. Enable this option if you wish to enable the 'cat' utility.
output. Enable this option if you wish to enable the 'cat' utility.
config CATV
bool "catv"
@@ -117,8 +117,7 @@ config FEATURE_DD_SIGNAL_HANDLING
print to standard error the number of records read and written
so far, then to resume copying.
$ dd if=/dev/zero of=/dev/null&
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
$ dd if=/dev/zero of=/dev/null& pid=$! $ kill -USR1 $pid; sleep 1; kill $pid
10899206+0 records in 10899206+0 records out
config FEATURE_DD_IBS_OBS
@@ -233,7 +232,7 @@ config EXPR_MATH_SUPPORT_64
default n
depends on EXPR
help
Enable 64-bit math support in the expr applet. This will make
Enable 64-bit math support in the expr applet. This will make
the applet slightly larger, but will allow computation with very
large numbers.
@@ -510,33 +509,18 @@ config SHA1SUM
Compute and check SHA1 message digest
config SLEEP
bool "sleep"
bool "sleep (single integer arg with no suffix)"
default n
help
sleep is used to pause for a specified number of seconds.
It comes in 3 versions:
- small: takes one integer parameter
- fancy: takes multiple integer arguments with suffixes:
sleep 1d 2h 3m 15s
- fancy with fractional numbers:
sleep 2.3s 4.5h sleeps for 16202.3 seconds
Last one is "the most compatible" with coreutils sleep,
but it adds around 1k of code.
sleep is used to pause for a specified number of seconds,
config FEATURE_FANCY_SLEEP
bool "Enable multiple arguments and s/m/h/d suffixes"
bool "Enable multiple integer args and optional time suffixes"
default n
depends on SLEEP
help
Allow sleep to pause for specified minutes, hours, and days.
config FEATURE_FLOAT_SLEEP
bool "Enable fractional arguments"
default n
depends on FEATURE_FANCY_SLEEP
help
Allow for fractional numeric parameters.
config SORT
bool "sort"
default n
@@ -548,9 +532,9 @@ config FEATURE_SORT_BIG
default y
depends on SORT
help
Without this, sort only supports -r, -u, and an integer version
of -n. Selecting this adds sort keys, floating point support, and
more. This adds a little over 3k to a nonstatic build on x86.
Without this, sort only supports -r, -u, and an integer version
of -n. Selecting this adds sort keys, floating point support, and
more. This adds a little over 3k to a nonstatic build on x86.
The SuSv3 sort standard is available at:
http://www.opengroup.org/onlinepubs/007904975/utilities/sort.html
@@ -582,7 +566,7 @@ config FEATURE_STAT_FORMAT
depends on STAT
help
Without this, stat will not support the '-c format' option where
users can pass a custom format string for output. This adds about
users can pass a custom format string for output. This adds about
7k to a nonstatic build on amd64.
config STTY
@@ -643,7 +627,7 @@ config TEST
default n
help
test is used to check file types and compare values,
returning an appropriate exit code. The bash shell
returning an appropriate exit code. The bash shell
has test built in, ash can build it in optionally.
config FEATURE_TEST_64
@@ -754,7 +738,7 @@ config FEATURE_WC_LARGE
default n
depends on WC
help
Use "unsigned long long" in wc for count variables.
Use "unsigned long long" in wc for count variables
config WHO
bool "who"
+3 -5
View File
@@ -40,8 +40,7 @@ static const unsigned char sep1752[] ALIGN1 = {
24, 25, 26, 27, 28, 29, 30
};
/* Set to 0 or 1 in main */
#define julian ((unsigned)option_mask32)
static unsigned julian;
/* leap year -- account for Gregorian reformation in 1752 */
static int leap_year(unsigned yr)
@@ -88,8 +87,7 @@ int cal_main(int argc, char **argv)
char buf[40];
flags = getopt32(argv, "jy");
/* This sets julian = flags & 1: */
option_mask32 &= 1;
julian = flags & 1;
month = 0;
argv += optind;
argc -= optind;
@@ -102,7 +100,7 @@ int cal_main(int argc, char **argv)
time(&now);
local_time = localtime(&now);
year = local_time->tm_year + 1900;
if (!(flags & 2)) { /* no -y */
if (!(flags & 2)) {
month = local_time->tm_mon + 1;
}
} else {
+1 -1
View File
@@ -40,7 +40,7 @@ int bb_cat(char **argv)
}
int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cat_main(int argc UNUSED_PARAM, char **argv)
int cat_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
getopt32(argv, "u");
argv += optind;
+1 -1
View File
@@ -13,7 +13,7 @@
#include "libbb.h"
int catv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int catv_main(int argc UNUSED_PARAM, char **argv)
int catv_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
int retval = EXIT_SUCCESS;
int fd;
+2 -2
View File
@@ -34,7 +34,7 @@
* symbolic links encountered during recursive directory traversals.
*/
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
static int fileAction(const char *fileName, struct stat *statbuf, void* param, int depth)
{
mode_t newmode;
@@ -68,7 +68,7 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf, void
}
int chmod_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int chmod_main(int argc UNUSED_PARAM, char **argv)
int chmod_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
int retval = EXIT_SUCCESS;
char *arg, **argp;
+22 -32
View File
@@ -18,11 +18,11 @@
#define OPT_STR ("Rh" USE_DESKTOP("vcfLHP"))
#define BIT_RECURSE 1
#define OPT_RECURSE (opt & 1)
#define OPT_NODEREF (opt & 2)
#define OPT_VERBOSE (USE_DESKTOP(opt & 0x04) SKIP_DESKTOP(0))
#define OPT_CHANGED (USE_DESKTOP(opt & 0x08) SKIP_DESKTOP(0))
#define OPT_QUIET (USE_DESKTOP(opt & 0x10) SKIP_DESKTOP(0))
#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_QUIET (USE_DESKTOP(option_mask32 & 0x10) SKIP_DESKTOP(0))
/* POSIX options
* -L traverse every symbolic link to a directory encountered
* -H if a command line argument is a symbolic link to a directory, traverse it
@@ -32,27 +32,22 @@
* The last option specified shall determine the behavior of the utility." */
/* -L */
#define BIT_TRAVERSE 0x20
#define OPT_TRAVERSE (USE_DESKTOP(opt & BIT_TRAVERSE) SKIP_DESKTOP(0))
#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(opt & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
#define OPT_TRAVERSE_TOP (USE_DESKTOP(option_mask32 & BIT_TRAVERSE_TOP) SKIP_DESKTOP(0))
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
struct param_t {
struct bb_uidgid_t ugid;
chown_fptr chown_func;
};
static struct bb_uidgid_t ugid = { -1, -1 };
static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf,
void *vparam, int depth UNUSED_PARAM)
static int fileAction(const char *fileName, struct stat *statbuf,
void *cf, int depth ATTRIBUTE_UNUSED)
{
#define param (*(struct param_t*)vparam)
#define opt option_mask32
uid_t u = (param.ugid.uid == (uid_t)-1) ? statbuf->st_uid : param.ugid.uid;
gid_t g = (param.ugid.gid == (gid_t)-1) ? statbuf->st_gid : param.ugid.gid;
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;
if (param.chown_func(fileName, u, g) == 0) {
if (!((chown_fptr)cf)(fileName, u, g)) {
if (OPT_VERBOSE
|| (OPT_CHANGED && (statbuf->st_uid != u || statbuf->st_gid != g))
) {
@@ -64,30 +59,25 @@ static int FAST_FUNC fileAction(const char *fileName, struct stat *statbuf,
if (!OPT_QUIET)
bb_simple_perror_msg(fileName); /* A filename can have % in it... */
return FALSE;
#undef opt
#undef param
}
int chown_main(int argc UNUSED_PARAM, char **argv)
int chown_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
int retval = EXIT_SUCCESS;
int opt, flags;
struct param_t param;
param.ugid.uid = -1;
param.ugid.gid = -1;
param.chown_func = chown;
int flags;
chown_fptr chown_func;
opt_complementary = "-2";
opt = getopt32(argv, OPT_STR);
getopt32(argv, OPT_STR);
argv += optind;
/* This matches coreutils behavior (almost - see below) */
chown_func = chown;
if (OPT_NODEREF
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
USE_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
USE_DESKTOP( || (option_mask32 & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
) {
param.chown_func = lchown;
chown_func = lchown;
}
flags = ACTION_DEPTHFIRST; /* match coreutils order */
@@ -98,7 +88,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
if (OPT_TRAVERSE)
flags |= ACTION_FOLLOWLINKS; /* follow links if -L */
parse_chown_usergroup_or_die(&param.ugid, argv[0]);
parse_chown_usergroup_or_die(&ugid, argv[0]);
/* Ok, ready to do the deed now */
argv++;
@@ -107,7 +97,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
flags, /* flags */
fileAction, /* file action */
fileAction, /* dir action */
&param, /* user data */
chown_func, /* user data */
0) /* depth */
) {
retval = EXIT_FAILURE;
+1 -1
View File
@@ -9,7 +9,7 @@
#include "libbb.h"
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cksum_main(int argc UNUSED_PARAM, char **argv)
int cksum_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
uint32_t *crc32_table = crc32_filltable(NULL, 1);
uint32_t crc;
+55 -42
View File
@@ -14,9 +14,8 @@
#define COMM_OPT_3 (1 << 2)
/* writeline outputs the input given, appropriately aligned according to class */
static void writeline(char *line, int class)
static void writeline(char *line, int class, int flags)
{
int flags = option_mask32;
if (class == 0) {
if (flags & COMM_OPT_1)
return;
@@ -33,67 +32,81 @@ static void writeline(char *line, int class)
if (!(flags & COMM_OPT_2))
putchar('\t');
}
puts(line);
fputs(line, stdout);
}
int comm_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int comm_main(int argc UNUSED_PARAM, char **argv)
int comm_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
char *thisline[2];
FILE *stream[2];
#define LINE_LEN 100
#define BB_EOF_0 0x1
#define BB_EOF_1 0x2
char thisline[2][LINE_LEN];
FILE *streams[2];
int i;
int order;
unsigned flags;
opt_complementary = "=2";
getopt32(argv, "123");
flags = getopt32(argv, "123");
argv += optind;
for (i = 0; i < 2; ++i) {
stream[i] = xfopen_stdin(argv[i]);
streams[i] = (argv[i][0] == '-' && !argv[i][1]) ? stdin : xfopen(argv[i], "r");
fgets(thisline[i], LINE_LEN, streams[i]);
}
order = 0;
thisline[1] = thisline[0] = NULL;
while (1) {
if (order <= 0) {
free(thisline[0]);
thisline[0] = xmalloc_fgetline(stream[0]);
}
if (order >= 0) {
free(thisline[1]);
thisline[1] = xmalloc_fgetline(stream[1]);
/* This is the real core of the program - lines are compared here */
while (*thisline[0] || *thisline[1]) {
int order = 0;
i = 0;
if (feof(streams[0])) i |= BB_EOF_0;
if (feof(streams[1])) i |= BB_EOF_1;
if (!*thisline[0])
order = 1;
else if (!*thisline[1])
order = -1;
else {
int tl0_len, tl1_len;
tl0_len = strlen(thisline[0]);
tl1_len = strlen(thisline[1]);
order = memcmp(thisline[0], thisline[1], tl0_len < tl1_len ? tl0_len : tl1_len);
if (!order)
order = tl0_len < tl1_len ? -1 : tl0_len != tl1_len;
}
i = !thisline[0] + (!thisline[1] << 1);
if (i)
if (order == 0 && !i)
writeline(thisline[1], 2, flags);
else if (order > 0 && !(i & BB_EOF_1))
writeline(thisline[1], 1, flags);
else if (order < 0 && !(i & BB_EOF_0))
writeline(thisline[0], 0, flags);
if (i & BB_EOF_0 & BB_EOF_1) {
break;
order = strcmp(thisline[0], thisline[1]);
if (order >= 0)
writeline(thisline[1], order ? 1 : 2);
else
writeline(thisline[0], 0);
}
} else if (i) {
i = (i & BB_EOF_0 ? 1 : 0);
while (!feof(streams[i])) {
if ((order < 0 && i) || (order > 0 && !i))
writeline(thisline[i], i, flags);
fgets(thisline[i], LINE_LEN, streams[i]);
}
break;
/* EOF at least on one of the streams */
i &= 1;
if (thisline[i]) {
/* stream[i] is not at EOF yet */
/* we did not print thisline[i] yet */
char *p = thisline[i];
writeline(p, i);
while (1) {
free(p);
p = xmalloc_fgetline(stream[i]);
if (!p)
break;
writeline(p, i);
} else {
if (order >= 0)
fgets(thisline[1], LINE_LEN, streams[1]);
if (order <= 0)
fgets(thisline[0], LINE_LEN, streams[0]);
}
}
if (ENABLE_FEATURE_CLEAN_UP) {
fclose(stream[0]);
fclose(stream[1]);
fclose(streams[0]);
fclose(streams[1]);
}
return EXIT_SUCCESS;
+27 -35
View File
@@ -33,6 +33,11 @@ enum {
NON_RANGE = -1
};
/* growable array holding a series of lists */
static struct cut_list *cut_lists;
static unsigned int nlists; /* number of elements in above list */
static int cmpfunc(const void *a, const void *b)
{
return (((struct cut_list *) a)->startpos -
@@ -40,19 +45,18 @@ static int cmpfunc(const void *a, const void *b)
}
static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, unsigned nlists)
static void cut_file(FILE *file, char delim)
{
char *line;
unsigned linenum = 0; /* keep these zero-based to be consistent */
char *line = NULL;
unsigned int linenum = 0; /* keep these zero-based to be consistent */
/* go through every line in the file */
while ((line = xmalloc_fgetline(file)) != NULL) {
/* set up a list so we can keep track of what's been printed */
int linelen = strlen(line);
char *printed = xzalloc(linelen + 1);
char *orig_line = line;
unsigned cl_pos = 0;
char * printed = xzalloc(strlen(line) * sizeof(char));
char * orig_line = line;
unsigned int cl_pos = 0;
int spos;
/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
@@ -60,19 +64,15 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
/* print the chars specified in each cut list */
for (; cl_pos < nlists; cl_pos++) {
spos = cut_lists[cl_pos].startpos;
while (spos < linelen) {
while (spos < (int)strlen(line)) {
if (!printed[spos]) {
printed[spos] = 'X';
putchar(line[spos]);
}
spos++;
if (spos > cut_lists[cl_pos].endpos
/* NON_RANGE is -1, so if below is true,
* the above was true too (spos is >= 0) */
/* || cut_lists[cl_pos].endpos == NON_RANGE */
) {
|| cut_lists[cl_pos].endpos == NON_RANGE)
break;
}
}
}
} else if (delim == '\n') { /* cut by lines */
@@ -89,8 +89,7 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
spos++;
/* go to the next list if we're at the end of this one */
if (spos > cut_lists[cl_pos].endpos
|| cut_lists[cl_pos].endpos == NON_RANGE
) {
|| cut_lists[cl_pos].endpos == NON_RANGE) {
cl_pos++;
/* get out if there's no more lists to process */
if (cl_pos >= nlists)
@@ -149,7 +148,7 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
* this is a list, and we're not at the end of that
* list */
} while (spos <= cut_lists[cl_pos].endpos && line
&& cut_lists[cl_pos].endpos != NON_RANGE);
&& cut_lists[cl_pos].endpos != NON_RANGE);
}
}
/* if we printed anything at all, we need to finish it with a
@@ -163,23 +162,19 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
}
int cut_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int cut_main(int argc UNUSED_PARAM, char **argv)
int cut_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
/* growable array holding a series of lists */
struct cut_list *cut_lists = NULL;
unsigned nlists = 0; /* number of elements in above list */
char delim = '\t'; /* delimiter, default is tab */
char *sopt, *ltok;
unsigned opt;
opt_complementary = "b--bcf:c--bcf:f--bcf";
opt = getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok);
getopt32(argv, optstring, &sopt, &sopt, &sopt, &ltok);
// argc -= optind;
argv += optind;
if (!(opt & (CUT_OPT_BYTE_FLGS | CUT_OPT_CHAR_FLGS | CUT_OPT_FIELDS_FLGS)))
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 (opt & CUT_OPT_DELIM_FLGS) {
if (option_mask32 & CUT_OPT_DELIM_FLGS) {
if (ltok[0] && ltok[1]) { /* more than 1 char? */
bb_error_msg_and_die("the delimiter must be a single character");
}
@@ -187,10 +182,10 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
}
/* non-field (char or byte) cutting has some special handling */
if (!(opt & CUT_OPT_FIELDS_FLGS)) {
if (!(option_mask32 & CUT_OPT_FIELDS_FLGS)) {
static const char _op_on_field[] ALIGN1 = " only when operating on fields";
if (opt & CUT_OPT_SUPPRESS_FLGS) {
if (option_mask32 & CUT_OPT_SUPPRESS_FLGS) {
bb_error_msg_and_die
("suppressing non-delimited lines makes sense%s",
_op_on_field);
@@ -236,8 +231,8 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
e = EOL;
} else {
e = xatoi_u(ltok);
/* if the user specified and end position of 0,
* that means "til the end of the line" */
/* if the user specified and end position of 0, that means "til the
* end of the line */
if (e == 0)
e = EOL;
e--; /* again, arrays are zero based, lines are 1 based */
@@ -246,12 +241,9 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
}
/* add the new list */
cut_lists = xrealloc_vector(cut_lists, 4, nlists);
/* NB: startpos is always >= 0,
* while endpos may be = NON_RANGE (-1) */
cut_lists[nlists].startpos = s;
cut_lists[nlists].endpos = e;
nlists++;
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
cut_lists[nlists-1].startpos = s;
cut_lists[nlists-1].endpos = e;
}
/* make sure we got some cut positions out of all that */
@@ -276,7 +268,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
retval = EXIT_FAILURE;
continue;
}
cut_file(file, delim, cut_lists, nlists);
cut_file(file, delim);
fclose_if_not_stdin(file);
} while (*++argv);
+1 -1
View File
@@ -39,7 +39,7 @@ static void maybe_set_utc(int opt)
}
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int date_main(int argc UNUSED_PARAM, char **argv)
int date_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
struct tm tm_time;
time_t tm;
+2 -2
View File
@@ -41,7 +41,7 @@ struct globals {
#define INIT_G() memset(&G, 0, sizeof(G))
static void dd_output_status(int UNUSED_PARAM cur_signal)
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"
@@ -79,7 +79,7 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
#endif
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int dd_main(int argc UNUSED_PARAM, char **argv)
int dd_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
enum {
/* Must be in the same order as OP_conv_XXX! */
+1 -1
View File
@@ -35,7 +35,7 @@ static void convert(char *fn, int conv_type)
resolved_fn = xmalloc_follow_symlinks(fn);
if (resolved_fn == NULL)
bb_simple_perror_msg_and_die(fn);
in = xfopen_for_read(resolved_fn);
in = xfopen(resolved_fn, "r");
fstat(fileno(in), &st);
temp_fn = xasprintf("%sXXXXXX", resolved_fn);
+1 -1
View File
@@ -141,7 +141,7 @@ static unsigned long du(const char *filename)
}
int du_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int du_main(int argc UNUSED_PARAM, char **argv)
int du_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
unsigned long total;
int slink_depth_save;
+5 -8
View File
@@ -29,7 +29,7 @@
/* NB: can be used by shell even if not enabled as applet */
int echo_main(int argc UNUSED_PARAM, char **argv)
int echo_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
const char *arg;
#if !ENABLE_FEATURE_FANCY_ECHO
@@ -46,11 +46,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
* even if libc receives EBADF on write attempts, it feels determined
* to output data no matter what. So it will try later,
* and possibly will clobber future output. Not good. */
// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
if (fcntl(1, F_GETFL) == -1)
return 1; /* match coreutils 6.10 (sans error msg to stderr) */
//if (dup2(1, 1) != 1) - old way
// return 1;
if (dup2(1, 1) != 1)
return -1;
arg = *++argv;
if (!arg)
@@ -61,8 +58,8 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
char eflag = 0;
/* We must check that stdout is not closed. */
if (fcntl(1, F_GETFL) == -1)
return 1;
if (dup2(1, 1) != 1)
return -1;
while (1) {
arg = *++argv;
+3 -3
View File
@@ -29,8 +29,6 @@
* - use xfunc_error_retval
*/
/* This is a NOEXEC applet. Be very careful! */
#include "libbb.h"
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
@@ -41,7 +39,7 @@ static const char env_longopts[] ALIGN1 =
#endif
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int env_main(int argc UNUSED_PARAM, char **argv)
int env_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
/* cleanenv was static - why? */
char *cleanenv[1];
@@ -121,3 +119,5 @@ int env_main(int argc UNUSED_PARAM, char **argv)
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+1 -1
View File
@@ -126,7 +126,7 @@ static void unexpand(FILE *file, unsigned int tab_size, unsigned opt)
#endif
int expand_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int expand_main(int argc UNUSED_PARAM, char **argv)
int expand_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
/* Default 8 spaces for 1 tab */
const char *opt_t = "8";
+1 -1
View File
@@ -15,7 +15,7 @@
/* This is a NOFORK applet. Be very careful! */
int false_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int false_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int false_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv)
{
return EXIT_FAILURE;
}
+1 -1
View File
@@ -14,7 +14,7 @@
/* This is a NOFORK applet. Be very careful! */
int hostid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int hostid_main(int argc, char **argv UNUSED_PARAM)
int hostid_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
if (argc > 1) {
bb_show_usage();
+1 -1
View File
@@ -37,7 +37,7 @@ static int printf_full(unsigned int id, const char *arg, const char prefix)
}
int id_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int id_main(int argc UNUSED_PARAM, char **argv)
int id_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
struct passwd *p;
uid_t uid;
+51 -32
View File
@@ -17,9 +17,9 @@ static const char install_longopts[] ALIGN1 =
"directory\0" No_argument "d"
"preserve-timestamps\0" No_argument "p"
"strip\0" No_argument "s"
"group\0" Required_argument "g"
"mode\0" Required_argument "m"
"owner\0" Required_argument "o"
"group\0" No_argument "g"
"mode\0" No_argument "m"
"owner\0" No_argument "o"
/* autofs build insists of using -b --suffix=.orig */
/* TODO? (short option for --suffix is -S) */
#if ENABLE_SELINUX
@@ -76,9 +76,8 @@ int install_main(int argc, char **argv)
const char *mode_str;
int copy_flags = FILEUTILS_DEREFERENCE | FILEUTILS_FORCE;
int flags;
int min_args = 1;
int ret = EXIT_SUCCESS;
int isdir = 0;
int isdir;
#if ENABLE_SELINUX
security_context_t scontext;
bool use_default_selinux_context = 1;
@@ -134,43 +133,63 @@ int install_main(int argc, char **argv)
bb_parse_mode(mode_str, &mode);
uid = (flags & OPT_OWNER) ? get_ug_id(uid_str, xuname2uid) : getuid();
gid = (flags & OPT_GROUP) ? get_ug_id(gid_str, xgroup2gid) : getgid();
if (flags & (OPT_OWNER|OPT_GROUP))
umask(0);
last = argv[argc - 1];
if (!(flags & OPT_DIRECTORY)) {
argv[argc - 1] = NULL;
min_args++;
/* coreutils install resolves link in this case, don't use lstat */
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
/* Create directories
* don't use bb_make_directory() as it can't change uid or gid
* perhaps bb_make_directory() should be improved.
*/
if (flags & OPT_DIRECTORY) {
while ((arg = *argv++) != NULL) {
char *slash = arg;
while (1) {
slash = strchr(slash + 1, '/');
if (slash)
*slash = '\0';
if (mkdir(arg, mode | 0111) == -1) {
if (errno != EEXIST) {
bb_perror_msg("cannot create %s", arg);
ret = EXIT_FAILURE;
break;
}
} /* dir was created, chown? */
else if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(arg, uid, gid) == -1
) {
bb_perror_msg("cannot change ownership of %s", arg);
ret = EXIT_FAILURE;
break;
}
if (!slash)
break;
*slash = '/';
}
}
return ret;
}
if (argc < min_args)
if (argc < 2)
bb_show_usage();
last = argv[argc - 1];
argv[argc - 1] = NULL;
/* coreutils install resolves link in this case, don't use lstat */
isdir = stat(last, &statbuf) < 0 ? 0 : S_ISDIR(statbuf.st_mode);
while ((arg = *argv++) != NULL) {
char *dest = last;
if (flags & OPT_DIRECTORY) {
dest = arg;
/* GNU coreutils 6.9 does not set uid:gid
* on intermediate created directories
* (only on last one) */
if (bb_make_directory(dest, 0755, FILEUTILS_RECUR)) {
ret = EXIT_FAILURE;
goto next;
}
} else {
if (isdir)
dest = concat_path_file(last, basename(arg));
if (copy_file(arg, dest, copy_flags)) {
/* copy is not made */
ret = EXIT_FAILURE;
goto next;
}
if (isdir)
dest = concat_path_file(last, basename(arg));
if (copy_file(arg, dest, copy_flags)) {
/* copy is not made */
ret = EXIT_FAILURE;
goto next;
}
/* Set the file mode */
if ((flags & OPT_MODE) && chmod(dest, mode) == -1) {
bb_perror_msg("can't change %s of %s", "permissions", dest);
bb_perror_msg("cannot change permissions of %s", dest);
ret = EXIT_FAILURE;
}
#if ENABLE_SELINUX
@@ -181,7 +200,7 @@ int install_main(int argc, char **argv)
if ((flags & (OPT_OWNER|OPT_GROUP))
&& lchown(dest, uid, gid) == -1
) {
bb_perror_msg("can't change %s of %s", "ownership", dest);
bb_perror_msg("cannot change ownership of %s", dest);
ret = EXIT_FAILURE;
}
if (flags & OPT_STRIP) {
+3 -3
View File
@@ -12,10 +12,10 @@
typedef int (*stat_func)(const char *fn, struct stat *ps);
int cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf) FAST_FUNC;
int cp_mv_stat(const char *fn, struct stat *fn_stat) FAST_FUNC;
int cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf);
int cp_mv_stat(const char *fn, struct stat *fn_stat);
mode_t getopt_mk_fifo_nod(char **argv) FAST_FUNC;
mode_t getopt_mk_fifo_nod(char **argv);
#if __GNUC_PREREQ(4,1)
# pragma GCC visibility pop
+2 -2
View File
@@ -23,7 +23,7 @@
#include "libbb.h"
#include "coreutils.h"
int FAST_FUNC cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
int cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
{
if (sf(fn, fn_stat) < 0) {
if (errno != ENOENT) {
@@ -44,7 +44,7 @@ int FAST_FUNC cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
return 1;
}
int FAST_FUNC cp_mv_stat(const char *fn, struct stat *fn_stat)
int cp_mv_stat(const char *fn, struct stat *fn_stat)
{
return cp_mv_stat2(fn, fn_stat, stat);
}
+1 -1
View File
@@ -23,7 +23,7 @@
#include "libbb.h"
#include "coreutils.h"
mode_t FAST_FUNC getopt_mk_fifo_nod(char **argv)
mode_t getopt_mk_fifo_nod(char **argv)
{
mode_t mode = 0666;
char *smode = NULL;
+1 -1
View File
@@ -25,7 +25,7 @@
/* This is a NOFORK applet. Be very careful! */
int logname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int logname_main(int argc, char **argv UNUSED_PARAM)
int logname_main(int argc, char ATTRIBUTE_UNUSED **argv)
{
char buf[128];
+6 -7
View File
@@ -825,7 +825,7 @@ static const char ls_color_opt[] ALIGN1 =
int ls_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int ls_main(int argc UNUSED_PARAM, char **argv)
int ls_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
struct dnode **dnd;
struct dnode **dnf;
@@ -837,8 +837,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
int dnfiles;
int dndirs;
int i;
/* need to initialize since --color has _an optional_ argument */
USE_FEATURE_LS_COLOR(const char *color_opt = "always";)
USE_FEATURE_LS_COLOR(char *color_opt;)
INIT_G();
@@ -889,15 +888,15 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
if (ENABLE_FEATURE_LS_COLOR_IS_DEFAULT && isatty(STDOUT_FILENO)) {
char *p = getenv("LS_COLORS");
/* LS_COLORS is unset, or (not empty && not "none") ? */
if (!p || (p[0] && strcmp(p, "none") != 0))
if (!p || (p[0] && strcmp(p, "none")))
show_color = 1;
}
if (opt & (1 << i)) { /* next flag after short options */
if (strcmp("always", color_opt) == 0)
if (!color_opt || !strcmp("always", color_opt))
show_color = 1;
else if (strcmp("never", color_opt) == 0)
else if (color_opt && !strcmp("never", color_opt))
show_color = 0;
else if (strcmp("auto", color_opt) == 0 && isatty(STDOUT_FILENO))
else if (color_opt && !strcmp("auto", color_opt) && isatty(STDOUT_FILENO))
show_color = 1;
}
#endif
+7 -7
View File
@@ -33,8 +33,8 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
} context;
uint8_t *hash_value = NULL;
RESERVE_CONFIG_UBUFFER(in_buf, 4096);
void FAST_FUNC (*update)(const void*, size_t, void*);
void FAST_FUNC (*final)(void*, void*);
void (*update)(const void*, size_t, void*);
void (*final)(void*, void*);
src_fd = open_or_warn_stdin(filename);
if (src_fd < 0) {
@@ -44,13 +44,13 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
/* figure specific hash algorithims */
if (ENABLE_MD5SUM && hash_algo==HASH_MD5) {
md5_begin(&context.md5);
update = (void*)md5_hash;
final = (void*)md5_end;
update = (void (*)(const void*, size_t, void*))md5_hash;
final = (void (*)(void*, void*))md5_end;
hash_len = 16;
} else if (ENABLE_SHA1SUM && hash_algo==HASH_SHA1) {
sha1_begin(&context.sha1);
update = (void*)sha1_hash;
final = (void*)sha1_end;
update = (void (*)(const void*, size_t, void*))sha1_hash;
final = (void (*)(void*, void*))sha1_end;
hash_len = 20;
} else {
bb_error_msg_and_die("algorithm not supported");
@@ -75,7 +75,7 @@ static uint8_t *hash_file(const char *filename, hash_algo_t hash_algo)
}
int md5_sha1_sum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
int md5_sha1_sum_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
int return_value = EXIT_SUCCESS;
uint8_t *hash_value;
+1 -1
View File
@@ -14,7 +14,7 @@
#include "libcoreutils/coreutils.h"
int mkfifo_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mkfifo_main(int argc UNUSED_PARAM, char **argv)
int mkfifo_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
mode_t mode;
int retval = EXIT_SUCCESS;
+6 -6
View File
@@ -26,13 +26,16 @@ static const char mv_longopts[] ALIGN1 =
#define OPT_FILEUTILS_FORCE 1
#define OPT_FILEUTILS_INTERACTIVE 2
static const char fmt[] ALIGN1 =
"cannot overwrite %sdirectory with %sdirectory";
int mv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int mv_main(int argc, char **argv)
{
struct stat dest_stat;
const char *last;
const char *dest;
unsigned flags;
unsigned long flags;
int dest_exists;
int status = 0;
int copy_flag = 0;
@@ -54,7 +57,7 @@ int mv_main(int argc, char **argv)
return EXIT_FAILURE;
}
if (!(dest_exists & 2)) { /* last is not a directory */
if (!(dest_exists & 2)) {
dest = last;
goto DO_MOVE;
}
@@ -85,13 +88,10 @@ int mv_main(int argc, char **argv)
int source_exists;
if (errno != EXDEV
|| (source_exists = cp_mv_stat2(*argv, &source_stat, lstat)) < 1
|| (source_exists = cp_mv_stat(*argv, &source_stat)) < 1
) {
bb_perror_msg("cannot rename '%s'", *argv);
} else {
static const char fmt[] ALIGN1 =
"cannot overwrite %sdirectory with %sdirectory";
if (dest_exists) {
if (dest_exists == 3) {
if (source_exists != 3) {
+25 -26
View File
@@ -24,7 +24,7 @@
#define ishexdigit(c) (isxdigit)(c)
static void
odoffset(dumper_t *dumper, int argc, char ***argvp)
odoffset(int argc, char ***argvp)
{
char *num, *p;
int base;
@@ -57,7 +57,7 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
base = 0;
/*
* skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
* bb_dump_skip over leading '+', 'x[0-9a-fA-f]' or '0x', and
* set base.
*/
if (p[0] == '+')
@@ -70,13 +70,11 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
base = 16;
}
/* skip over the number */
/* bb_dump_skip over the number */
if (base == 16)
for (num = p; ishexdigit(*p); ++p)
continue;
for (num = p; ishexdigit(*p); ++p);
else
for (num = p; isdecdigit(*p); ++p)
continue;
for (num = p; isdecdigit(*p); ++p);
/* check for no number */
if (num == p)
@@ -89,23 +87,23 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
base = 10;
}
dumper->dump_skip = strtol(num, &end, base ? base : 8);
bb_dump_skip = strtol(num, &end, base ? base : 8);
/* if end isn't the same as p, we got a non-octal digit */
if (end != p)
dumper->dump_skip = 0;
bb_dump_skip = 0;
else {
if (*p) {
if (*p == 'b') {
dumper->dump_skip *= 512;
bb_dump_skip *= 512;
++p;
} else if (*p == 'B') {
dumper->dump_skip *= 1024;
bb_dump_skip *= 1024;
++p;
}
}
if (*p)
dumper->dump_skip = 0;
bb_dump_skip = 0;
else {
++*argvp;
/*
@@ -122,9 +120,9 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
}
if (base == 10) {
x_or_d = 'd';
DO_X_OR_D:
dumper->fshead->nextfu->fmt[TYPE_OFFSET]
= dumper->fshead->nextfs->nextfu->fmt[TYPE_OFFSET]
DO_X_OR_D:
bb_dump_fshead->nextfu->fmt[TYPE_OFFSET]
= bb_dump_fshead->nextfs->nextfu->fmt[TYPE_OFFSET]
= x_or_d;
}
}
@@ -163,35 +161,36 @@ int od_main(int argc, char **argv)
int ch;
int first = 1;
char *p;
dumper_t *dumper = alloc_dumper();
bb_dump_vflag = FIRST;
bb_dump_length = -1;
while ((ch = getopt(argc, argv, od_opts)) > 0) {
if (ch == 'v') {
dumper->dump_vflag = ALL;
bb_dump_vflag = ALL;
} else if (((p = strchr(od_opts, ch)) != NULL) && (*p != '\0')) {
if (first) {
first = 0;
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \"");
bb_dump_add("\"%07.7_Ao\n\"");
bb_dump_add("\"%07.7_ao \"");
} else {
bb_dump_add(dumper, "\" \"");
bb_dump_add("\" \"");
}
bb_dump_add(dumper, add_strings[(int)od_o2si[(p - od_opts)]]);
bb_dump_add(add_strings[(int)od_o2si[(p-od_opts)]]);
} else { /* P, p, s, w, or other unhandled */
bb_show_usage();
}
}
if (!dumper->fshead) {
bb_dump_add(dumper, "\"%07.7_Ao\n\"");
bb_dump_add(dumper, "\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
if (!bb_dump_fshead) {
bb_dump_add("\"%07.7_Ao\n\"");
bb_dump_add("\"%07.7_ao \" 8/2 \"%06o \" \"\\n\"");
}
argc -= optind;
argv += optind;
odoffset(dumper, argc, &argv);
odoffset(argc, &argv);
return bb_dump_dump(dumper, argv);
return bb_dump_dump(argv);
}
#endif /* ENABLE_DESKTOP */
+5 -5
View File
@@ -364,7 +364,7 @@ print_long_double(size_t n_bytes, const char *block, const char *fmt_string)
static void
print_named_ascii(size_t n_bytes, const char *block,
const char *unused_fmt_string UNUSED_PARAM)
const char *unused_fmt_string ATTRIBUTE_UNUSED)
{
/* Names for some non-printing characters. */
static const char charname[33][3] ALIGN1 = {
@@ -404,7 +404,7 @@ print_named_ascii(size_t n_bytes, const char *block,
static void
print_ascii(size_t n_bytes, const char *block,
const char *unused_fmt_string UNUSED_PARAM)
const char *unused_fmt_string ATTRIBUTE_UNUSED)
{
// buf[N] pos: 01234 56789
char buf[12] = " x\0 0xx\0";
@@ -735,9 +735,9 @@ decode_format_string(const char *s)
assert(s != next);
s = next;
spec = xrealloc_vector(spec, 4, n_specs);
memcpy(&spec[n_specs], &tspec, sizeof(spec[0]));
n_specs++;
spec = xrealloc(spec, n_specs * sizeof(*spec));
memcpy(&spec[n_specs-1], &tspec, sizeof *spec);
}
}
@@ -814,7 +814,7 @@ skip(off_t n_skip)
typedef void FN_format_address(off_t address, char c);
static void
format_address_none(off_t address UNUSED_PARAM, char c UNUSED_PARAM)
format_address_none(off_t address ATTRIBUTE_UNUSED, char c ATTRIBUTE_UNUSED)
{
}
+1 -1
View File
@@ -11,7 +11,7 @@
#include "libbb.h"
int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int printenv_main(int argc UNUSED_PARAM, char **argv)
int printenv_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
/* no variables specified, show whole env */
if (!argv[1]) {
+94 -153
View File
@@ -33,83 +33,60 @@
The 'format' argument is re-used as many times as necessary
to convert all of the given arguments.
David MacKenzie <djm@gnu.ai.mit.edu>
*/
David MacKenzie <djm@gnu.ai.mit.edu> */
// 19990508 Busy Boxed! Dave Cinege
#include "libbb.h"
/* A note on bad input: neither bash 3.2 nor coreutils 6.10 stop on it.
* They report it:
* bash: printf: XXX: invalid number
* printf: XXX: expected a numeric value
* bash: printf: 123XXX: invalid number
* printf: 123XXX: value not completely converted
* but then they use 0 (or partially converted numeric prefix) as a value
* and continue. They exit with 1 in this case.
* Both accept insane field width/precision (e.g. %9999999999.9999999999d).
* Both print error message and assume 0 if %*.*f width/precision is "bad"
* (but negative numbers are not "bad").
* Both accept negative numbers for %u specifier.
*
* We try to be compatible. We are not compatible here:
* - we do not accept -NUM for %u
* - exit code is 0 even if "invalid number" was seen (FIXME)
* See "if (errno)" checks in the code below.
*/
typedef void (*converter)(const char *arg, void *result);
typedef void FAST_FUNC (*converter)(const char *arg, void *result);
static int multiconvert(const char *arg, void *result, converter convert)
static void multiconvert(const char *arg, void *result, converter convert)
{
char s[sizeof(int)*3 + 2];
if (*arg == '"' || *arg == '\'') {
arg = utoa((unsigned char)arg[1]);
sprintf(s, "%d", (unsigned char)arg[1]);
arg = s;
}
errno = 0;
convert(arg, result);
if (errno) {
bb_error_msg("%s: invalid number", arg);
return 1;
}
return 0;
/* if there was conversion error, print unconverted string */
if (errno)
fputs(arg, stderr);
}
static void FAST_FUNC conv_strtoul(const char *arg, void *result)
static void conv_strtoul(const char *arg, void *result)
{
*(unsigned long*)result = bb_strtoul(arg, NULL, 0);
}
static void FAST_FUNC conv_strtol(const char *arg, void *result)
static void conv_strtol(const char *arg, void *result)
{
*(long*)result = bb_strtol(arg, NULL, 0);
}
static void FAST_FUNC conv_strtod(const char *arg, void *result)
static void conv_strtod(const char *arg, void *result)
{
char *end;
/* Well, this one allows leading whitespace... so what? */
/* What I like much less is that "-" accepted too! :( */
/* Well, this one allows leading whitespace... so what */
/* What I like much less is that "-" is accepted too! :( */
*(double*)result = strtod(arg, &end);
if (end[0]) {
errno = ERANGE;
*(double*)result = 0;
}
if (end[0]) errno = ERANGE;
}
/* Callers should check errno to detect errors */
static unsigned long my_xstrtoul(const char *arg)
{
unsigned long result;
if (multiconvert(arg, &result, conv_strtoul))
result = 0;
multiconvert(arg, &result, conv_strtoul);
return result;
}
static long my_xstrtol(const char *arg)
{
long result;
if (multiconvert(arg, &result, conv_strtol))
result = 0;
multiconvert(arg, &result, conv_strtol);
return result;
}
static double my_xstrtod(const char *arg)
{
double result;
@@ -119,14 +96,14 @@ static double my_xstrtod(const char *arg)
static void print_esc_string(char *str)
{
while (*str) {
for (; *str; str++) {
if (*str == '\\') {
str++;
bb_putchar(bb_process_escape_sequence((const char **)&str));
} else {
bb_putchar(*str);
str++;
}
}
}
@@ -134,109 +111,88 @@ static void print_direc(char *format, unsigned fmt_length,
int field_width, int precision,
const char *argument)
{
long lv;
double dv;
char saved;
char *have_prec, *have_width;
have_prec = strstr(format, ".*");
have_width = strchr(format, '*');
if (have_width - 1 == have_prec)
have_width = NULL;
saved = format[fmt_length];
format[fmt_length] = '\0';
switch (format[fmt_length - 1]) {
case 'c':
printf(format, *argument);
break;
case 'd':
case 'i':
lv = my_xstrtol(argument);
print_long:
/* if (errno) return; - see comment at the top */
if (!have_width) {
if (!have_prec)
printf(format, lv);
if (field_width < 0) {
if (precision < 0)
printf(format, my_xstrtol(argument));
else
printf(format, precision, lv);
printf(format, precision, my_xstrtol(argument));
} else {
if (!have_prec)
printf(format, field_width, lv);
if (precision < 0)
printf(format, field_width, my_xstrtol(argument));
else
printf(format, field_width, precision, lv);
printf(format, field_width, precision, my_xstrtol(argument));
}
break;
case 'o':
case 'u':
case 'x':
case 'X':
lv = my_xstrtoul(argument);
/* cheat: unsigned long and long have same width, so... */
goto print_long;
case 's':
/* Are char* and long the same? (true for most arches) */
if (sizeof(argument) == sizeof(lv)) {
lv = (long)(ptrdiff_t)argument;
goto print_long;
} else { /* Hope compiler will optimize it out */
if (!have_width) {
if (!have_prec)
printf(format, argument);
else
printf(format, precision, argument);
} else {
if (!have_prec)
printf(format, field_width, argument);
else
printf(format, field_width, precision, argument);
}
break;
if (field_width < 0) {
if (precision < 0)
printf(format, my_xstrtoul(argument));
else
printf(format, precision, my_xstrtoul(argument));
} else {
if (precision < 0)
printf(format, field_width, my_xstrtoul(argument));
else
printf(format, field_width, precision, my_xstrtoul(argument));
}
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
dv = my_xstrtod(argument);
/* if (errno) return; */
if (!have_width) {
if (!have_prec)
printf(format, dv);
if (field_width < 0) {
if (precision < 0)
printf(format, my_xstrtod(argument));
else
printf(format, precision, dv);
printf(format, precision, my_xstrtod(argument));
} else {
if (!have_prec)
printf(format, field_width, dv);
if (precision < 0)
printf(format, field_width, my_xstrtod(argument));
else
printf(format, field_width, precision, dv);
printf(format, field_width, precision, my_xstrtod(argument));
}
break;
} /* switch */
case 'c':
printf(format, *argument);
break;
case 's':
if (field_width < 0) {
if (precision < 0)
printf(format, argument);
else
printf(format, precision, argument);
} else {
if (precision < 0)
printf(format, field_width, argument);
else
printf(format, field_width, precision, argument);
}
break;
}
format[fmt_length] = saved;
}
/* Handle params for "%*.*f". Negative numbers are ok (compat). */
static int get_width_prec(const char *str)
{
int v = bb_strtoi(str, NULL, 10);
if (errno) {
bb_error_msg("%s: invalid number", str);
v = 0;
}
return v;
}
/* Print the text in FORMAT, using ARGV for arguments to any '%' directives.
Return advanced ARGV. */
static char **print_formatted(char *f, char **argv)
{
char *direc_start; /* Start of % directive. */
unsigned direc_length; /* Length of % directive. */
int field_width; /* Arg to first '*' */
int precision; /* Arg to second '*' */
int field_width; /* Arg to first '*', or -1 if none. */
int precision; /* Arg to second '*', or -1 if none. */
char **saved_argv = argv;
for (; *f; ++f) {
@@ -244,7 +200,7 @@ static char **print_formatted(char *f, char **argv)
case '%':
direc_start = f++;
direc_length = 1;
field_width = precision = 0;
field_width = precision = -1;
if (*f == '%') {
bb_putchar('%');
break;
@@ -263,8 +219,11 @@ static char **print_formatted(char *f, char **argv)
if (*f == '*') {
++f;
++direc_length;
if (*argv)
field_width = get_width_prec(*argv++);
if (*argv) {
field_width = my_xstrtoul(*argv);
++argv;
} else
field_width = 0;
} else {
while (isdigit(*f)) {
++f;
@@ -277,47 +236,33 @@ static char **print_formatted(char *f, char **argv)
if (*f == '*') {
++f;
++direc_length;
if (*argv)
precision = get_width_prec(*argv++);
} else {
if (*argv) {
precision = my_xstrtoul(*argv);
++argv;
} else
precision = 0;
} else
while (isdigit(*f)) {
++f;
++direc_length;
}
}
}
/* Remove size modifiers - "%Ld" would try to printf
* long long, we pass long, and it spews garbage */
if ((*f | 0x20) == 'l' || *f == 'h' || *f == 'z') {
overlapping_strcpy(f, f + 1);
}
//FIXME: actually, the same happens with bare "%d":
//it printfs an int, but we pass long!
//What saves us is that on most arches stack slot
//is pointer-sized -> long-sized -> ints are promoted to longs
// for variadic functions -> printf("%d", int_v) is in reality
// indistinqushable from printf("%d", long_v) ->
// since printf("%d", int_v) works, printf("%d", long_v) has to work.
//But "clean" solution would be to add "l" to d,i,o,x,X.
//Probably makes sense to go all the way to "ll" then.
//Coreutils support long long-sized arguments.
/* needed - try "printf %" without it */
if (!strchr("diouxXfeEgGcs", *f)) {
bb_error_msg("%s: invalid format", direc_start);
/* causes main() to exit with error */
return saved_argv - 1;
if (*f == 'l' || *f == 'L' || *f == 'h') {
++f;
++direc_length;
}
/*
if (!strchr ("diouxXfeEgGcs", *f))
fprintf(stderr, "%%%c: invalid directive", *f);
*/
++direc_length;
if (*argv) {
print_direc(direc_start, direc_length, field_width,
precision, *argv);
++argv;
} else {
} else
print_direc(direc_start, direc_length, field_width,
precision, "");
}
/* if (errno) return saved_argv - 1; */
break;
case '\\':
if (*++f == 'c') {
@@ -334,30 +279,26 @@ static char **print_formatted(char *f, char **argv)
return argv;
}
int printf_main(int argc UNUSED_PARAM, char **argv)
int printf_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
char *format;
char **argv2;
/* We must check that stdout is not closed.
* The reason for this is highly non-obvious.
* printf_main is used from shell.
* The reason for this is highly non-obvious. printf_main is used from shell.
* Shell must correctly handle 'printf "%s" foo'
* if stdout is closed. With stdio, output gets shoveled into
* stdout buffer, and even fflush cannot clear it out. It seems that
* even if libc receives EBADF on write attempts, it feels determined
* to output data no matter what. So it will try later,
* and possibly will clobber future output. Not good. */
// TODO: check fcntl() & O_ACCMODE == O_WRONLY or O_RDWR?
if (fcntl(1, F_GETFL) == -1)
return 1; /* match coreutils 6.10 (sans error msg to stderr) */
//if (dup2(1, 1) != 1) - old way
// return 1;
if (dup2(1, 1) != 1)
return -1;
/* bash builtin errors out on "printf '-%s-\n' foo",
* coreutils-6.9 works. Both work with "printf -- '-%s-\n' foo".
* We will mimic coreutils. */
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && !argv[1][2])
if (argv[1] && argv[1][0] == '-' && argv[1][1] == '-' && argv[1][2] == '\0')
argv++;
if (!argv[1])
bb_show_usage();
@@ -368,12 +309,12 @@ int printf_main(int argc UNUSED_PARAM, char **argv)
do {
argv = argv2;
argv2 = print_formatted(format, argv);
} while (argv2 > argv && *argv2);
} while (argv2 != argv && *argv2);
/* coreutils compat (bash doesn't do this):
if (*argv)
fprintf(stderr, "excess args ignored");
*/
return (argv2 < argv); /* if true, print_formatted errored out */
return EXIT_SUCCESS;
}
+1 -1
View File
@@ -12,7 +12,7 @@
/* This is a NOFORK applet. Be very careful! */
int pwd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
int pwd_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
{
char *buf;
Loaded 100 of 542 files, more files were not shown because too many files have changed in this diff. Show more